Skip to content

parallel=True seem to make netcdf4 ignore format='NETCDF4' and fall back on 'NETCDF3_classic' #820

Description

@ThibHlln

Hi there,

I am running into issues when I try to create a NetCDF file (in the NETCDF4 flavour) with parallel I/O using mpi4py and Open MPI. When I create a Dataset(my_file_name, 'w', format='NetCDF4', parallel=True), and then check the file format, I get NETCDF3_CLASSIC. However, when I create a Dataset(my_file_name, 'w', format='NetCDF4', parallel=False), I get what I want (i.e. a NETCDF4 file).

I know the NetCDF-C library is properly configured for Parallel IO because I don't run into any issue with parallel=True as long as I am not using unlimited dimensions and I don't put them as the first dimension for a multi-dimensional variable. When I try to do this, I get thrown an exception:

File "netCDF4/_netCDF4.pyx", line 2533, in netCDF4._netCDF4.Dataset.createVariable
RuntimeError: NetCDF: NC_UNLIMITED in the wrong index

This error is not surprising because the file is a NETCDF3_CLASSIC, not a NETCDF4 (against my will), and as far as I understand it, there is this requirement for version NETCDF3_CLASSIC that the unlimited dimensions should be the first dimensions of a multi-dimensional variable, which is not the case for NETCDF4.

I am using a High Performance Cluster running on Linux, python 2.7.14, netCDF4 1.4.0, netcdf-c 4.6.1, mpi4py 3.0.0, Open MPI 2.1.1.

Is it the expected behaviour that the use of parallel I/O overwrites user-defined file format to fall back onto NETCDF3_CLASSIC?

Here is my piece of code, if this is of any help.

self.database = Dataset(self.db_file, 'w', parallel=True)
# create structure of NetCDF file
# metadata
self.database.description = "Monte Carlo Simulations."
# dimensions
self.database.createDimension("NbSamples", 50000)
self.database.createDimension("NbParameters", 10)
self.database.createDimension("NbObjFunctions", 14)
# variables
params = self.database.createVariable("Parameters", np.float32, ("NbSamples", "NbParameters"),
                                                           zlib=True, complevel=compression)
params.units = ', '.join(self.model.parameters.names)
objfns = self.database.createVariable("ObjFunctions", np.float32, ("NbSamples", "NbObjFunctions"),
                                                        zlib=True, complevel=compression)
objfns.units = ', '.join(self.obj_fn_names)
if self.save_sim:
    # dimension
    self.database.createDimension("DateTime", None)  # Unlimited dimension
    # coordinate variables
    times = self.database.createVariable("DateTime", np.float64, ("DateTime",), zlib=True)
    times.units = 'seconds since 1970-01-01 00:00:00.0'
    # variable
    simu = self.database.createVariable("Simulations", np.float32, ("NbSamples", "DateTime"),
                                                          zlib=True, complevel=compression)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions