2018-12-07 05:29:57 +08:00
|
|
|
/* Copyright 2018 University Corporation for Atmospheric
|
2018-08-21 07:05:29 +08:00
|
|
|
Research/Unidata. See COPYRIGHT file for more info. */
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @internal This file has the parallel I/O functions which correspond
|
|
|
|
* to the serial I/O functions.
|
2010-06-03 21:24:43 +08:00
|
|
|
*/
|
2012-08-02 01:18:58 +08:00
|
|
|
#include "config.h"
|
2010-08-05 10:44:59 +08:00
|
|
|
#include "ncdispatch.h"
|
2018-12-06 10:20:43 +08:00
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2016-01-15 07:02:00 +08:00
|
|
|
/**
|
2017-11-08 18:05:22 +08:00
|
|
|
Create a netCDF file for parallel I/O.
|
|
|
|
|
|
|
|
This function creates a new netCDF file for parallel I/O access.
|
|
|
|
|
|
|
|
Parallel I/O access is only available in library build which support
|
|
|
|
parallel I/O. To support parallel I/O, netCDF must be built with
|
2018-09-22 06:32:36 +08:00
|
|
|
netCDF-4 enabled (configure options --enable-netcdf-4 and --enable-parallel4)
|
|
|
|
and with a HDF5 library that supports parallel I/O, or with support for the
|
|
|
|
PnetCDF library via the --enable-pnetcdf option.
|
2018-09-23 09:22:34 +08:00
|
|
|
This function is collective, i.e. must be called by all MPI processes defined
|
|
|
|
in the MPI communicator, argument comm. In addition,
|
|
|
|
values of arguments of this function must be the same among all MPI processes.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
|
|
|
See nc_create() for a fuller discussion of file creation.
|
|
|
|
|
|
|
|
\note When opening a netCDF-4 file HDF5 error reporting is turned off,
|
|
|
|
if it is on. This doesn't stop the HDF5 error stack from recording the
|
|
|
|
errors, it simply stops their display to the user through stderr.
|
|
|
|
|
|
|
|
\param path The file name of the new netCDF dataset.
|
|
|
|
|
|
|
|
\param cmode The creation mode flag. The following flags are available:
|
2018-09-21 01:59:19 +08:00
|
|
|
NC_CLOBBER (overwrite existing file),
|
2017-11-08 18:05:22 +08:00
|
|
|
NC_NOCLOBBER (do not overwrite existing file),
|
|
|
|
NC_NETCDF4 (create netCDF-4/HDF5 file),
|
|
|
|
NC_CLASSIC_MODEL (enforce netCDF classic mode on netCDF-4/HDF5 files),
|
2018-09-23 09:22:34 +08:00
|
|
|
NC_64BIT_OFFSET (create CDF-2 file),
|
|
|
|
NC_64BIT_DATA (create CDF-5 file).
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param comm the MPI communicator specifying the processes participating the
|
|
|
|
parallel I/O to this file.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param info MPI info object containing I/O hints or MPI_INFO_NULL.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
|
|
|
\param ncidp Pointer to location where returned netCDF ID is to be
|
|
|
|
stored.
|
|
|
|
|
|
|
|
\returns ::NC_NOERR No error.
|
|
|
|
\returns ::NC_ENOPAR Library was not built with parallel I/O features.
|
2018-09-21 01:59:19 +08:00
|
|
|
\returns ::NC_EPERM: Attempting to create a netCDF file in a directory where you do not have permission to create files.
|
2018-09-17 07:15:15 +08:00
|
|
|
\returns ::NC_ENOTBUILT Library was not built with NETCDF4 or PnetCDF.
|
2018-09-23 09:22:34 +08:00
|
|
|
\returns ::NC_EEXIST Specifying a file name of a file that exists and also specifying NC_NOCLOBBER.
|
2017-11-08 18:05:22 +08:00
|
|
|
\returns ::NC_EINVAL Invalid input parameters.
|
|
|
|
\returns ::NC_ENOMEM System out of memory.
|
|
|
|
\returns ::NC_EHDFERR HDF5 error (netCDF-4 files only).
|
|
|
|
\returns ::NC_EFILEMETA Error writing netCDF-4 file-level metadata in
|
|
|
|
HDF5 file. (netCDF-4 files only).
|
|
|
|
|
|
|
|
<h1>Example</h1>
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
In this example from nc_test4/tst_parallel.c, a file is created for
|
2017-11-08 18:05:22 +08:00
|
|
|
parallel I/O.
|
|
|
|
|
|
|
|
\code
|
|
|
|
int mpi_size, mpi_rank;
|
|
|
|
MPI_Comm comm = MPI_COMM_WORLD;
|
|
|
|
MPI_Info info = MPI_INFO_NULL;
|
|
|
|
int ncid, v1id, dimids[NDIMS];
|
|
|
|
char file_name[NC_MAX_NAME + 1];
|
|
|
|
|
|
|
|
MPI_Init(&argc,&argv);
|
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
|
|
|
|
|
2023-05-01 06:01:49 +08:00
|
|
|
snprintf(file_name, sizeof(file_name), "%s/%s", TEMP_LARGE, FILE);
|
2018-09-17 07:15:15 +08:00
|
|
|
if ((res = nc_create_par(file_name, NC_NETCDF4, comm, info, &ncid))) ERR;
|
2017-11-08 18:05:22 +08:00
|
|
|
|
|
|
|
if (nc_def_dim(ncid, "d1", DIMSIZE, dimids)) ERR;
|
|
|
|
if (nc_def_dim(ncid, "d2", DIMSIZE, &dimids[1])) ERR;
|
|
|
|
if (nc_def_dim(ncid, "d3", NUM_SLABS, &dimids[2])) ERR;
|
2016-01-15 02:02:23 +08:00
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
if ((res = nc_def_var(ncid, "v1", NC_INT, NDIMS, dimids, &v1id))) ERR;
|
2016-01-15 02:02:23 +08:00
|
|
|
|
2018-10-02 14:19:44 +08:00
|
|
|
... use collective I/O
|
|
|
|
err = nc_var_par_access(ncid, v1id, NC_COLLECTIVE); ERR
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
if ((res = nc_enddef(ncid))) ERR;
|
|
|
|
|
|
|
|
...
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
if ((res = nc_close(ncid))) ERR;
|
2017-11-08 18:05:22 +08:00
|
|
|
\endcode
|
|
|
|
\author Ed Hartnett, Dennis Heimbigner
|
|
|
|
\ingroup datasets
|
2016-01-15 02:02:23 +08:00
|
|
|
*/
|
|
|
|
int nc_create_par(const char *path, int cmode, MPI_Comm comm,
|
2018-09-23 09:22:34 +08:00
|
|
|
MPI_Info info, int *ncidp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_PARALLEL
|
2019-01-11 23:45:42 +08:00
|
|
|
NC_UNUSED(path);
|
|
|
|
NC_UNUSED(cmode);
|
|
|
|
NC_UNUSED(comm);
|
|
|
|
NC_UNUSED(info);
|
|
|
|
NC_UNUSED(ncidp);
|
2018-09-23 09:22:34 +08:00
|
|
|
return NC_ENOPAR;
|
2018-09-18 14:27:57 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
NC_MPI_INFO data;
|
2018-09-17 07:15:15 +08:00
|
|
|
|
|
|
|
#ifndef USE_PNETCDF
|
2018-09-23 09:22:34 +08:00
|
|
|
/* PnetCDF is disabled but user wants to create classic file in parallel */
|
|
|
|
if (!(cmode & NC_NETCDF4))
|
|
|
|
return NC_ENOTBUILT;
|
2018-09-17 07:15:15 +08:00
|
|
|
#endif
|
2016-01-15 02:02:23 +08:00
|
|
|
|
2018-09-17 07:15:15 +08:00
|
|
|
#ifndef USE_NETCDF4
|
|
|
|
/* NETCDF4 is disabled but user wants to create NETCDF4 file in parallel */
|
2018-09-23 09:22:34 +08:00
|
|
|
if (cmode & NC_NETCDF4)
|
|
|
|
return NC_ENOTBUILT;
|
2018-09-17 07:15:15 +08:00
|
|
|
#endif
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2019-02-27 01:01:35 +08:00
|
|
|
/* Can't use both parallel and diskless|inmemory|mmap. */
|
|
|
|
if (cmode & (NC_DISKLESS|NC_INMEMORY|NC_MMAP))
|
|
|
|
return NC_EINVAL;
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
data.comm = comm;
|
|
|
|
data.info = info;
|
|
|
|
return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
|
2018-09-18 14:27:57 +08:00
|
|
|
#endif /* USE_PARALLEL */
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
/**
|
2017-11-03 02:57:16 +08:00
|
|
|
Open an existing netCDF file for parallel I/O.
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
This function opens an existing netCDF dataset for parallel I/O access. It
|
|
|
|
determines the underlying file format automatically. Use the same call to open
|
|
|
|
a netCDF classic, 64-bit offset, CDF-5, or netCDF-4 file.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
|
|
|
Parallel I/O access is only available in library build which support
|
|
|
|
parallel I/O. To support parallel I/O, netCDF must be built with
|
2018-09-22 06:32:36 +08:00
|
|
|
netCDF-4 enabled (configure options --enable-netcdf-4 and --enable-parallel4)
|
|
|
|
and with a HDF5 library that supports parallel I/O, or with support for the
|
|
|
|
PnetCDF library via the --enable-pnetcdf option.
|
2018-09-23 09:22:34 +08:00
|
|
|
This function is collective, i.e. must be called by all MPI processes defined
|
|
|
|
in the MPI communicator, argument comm. In addition,
|
|
|
|
values of arguments of this function must be the same among all MPI processes.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
|
|
|
It is not necessary to pass any information about the format of the
|
|
|
|
file being opened. The file type will be detected automatically by the
|
|
|
|
netCDF library.
|
|
|
|
|
|
|
|
As of version 4.3.1.2, multiple calls to nc_open_par() with the same
|
|
|
|
path will return the same ncid value.
|
|
|
|
|
|
|
|
\note When opening a netCDF-4 file HDF5 error reporting is turned off,
|
|
|
|
if it is on. This doesn't stop the HDF5 error stack from recording the
|
|
|
|
errors, it simply stops their display to the user through stderr.
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
\param path File name for netCDF dataset to be opened.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2018-09-22 06:32:36 +08:00
|
|
|
\param omode The open mode flag may be NC_WRITE (for read/write
|
|
|
|
access) or NC_NOWRITE (for read-only access).
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param comm the MPI communicator specifying the processes participating the
|
|
|
|
parallel I/O to this file.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param info MPI info object containing I/O hints or MPI_INFO_NULL.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
|
|
|
\param ncidp Pointer to location where returned netCDF ID is to be
|
|
|
|
stored.
|
|
|
|
|
|
|
|
nc_open_par() returns the value NC_NOERR if no errors
|
|
|
|
occurred. Otherwise, the returned status indicates an error. Possible
|
|
|
|
causes of errors include:
|
|
|
|
|
|
|
|
\returns ::NC_NOERR No error.
|
2018-09-17 07:15:15 +08:00
|
|
|
\returns ::NC_ENOPAR Library was not built with parallel I/O features.
|
2018-09-21 01:59:19 +08:00
|
|
|
\returns ::NC_EPERM: Attempting to open a netCDF file where you do not have permission to write the file.
|
2018-09-17 07:15:15 +08:00
|
|
|
\returns ::NC_ENOTBUILT Library was not built with NETCDF4 or PnetCDF.
|
2017-11-03 02:57:16 +08:00
|
|
|
\returns ::NC_EINVAL Invalid parameters.
|
|
|
|
\returns ::NC_ENOTNC Not a netCDF file.
|
|
|
|
\returns ::NC_ENOMEM Out of memory.
|
|
|
|
\returns ::NC_EHDFERR HDF5 error. (NetCDF-4 files only.)
|
2018-09-23 09:22:34 +08:00
|
|
|
\returns ::NC_EDIMMETA Error in netCDF-4 dimension metadata (NetCDF-4 files only.)
|
2016-01-15 06:33:50 +08:00
|
|
|
|
2017-11-03 02:57:16 +08:00
|
|
|
<h1>Examples</h1>
|
|
|
|
|
|
|
|
Here is an example using nc_open_par() from examples/C/parallel_vara.c.
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
\code
|
2017-11-03 02:57:16 +08:00
|
|
|
#include <mpi.h>
|
|
|
|
#include <netcdf.h>
|
|
|
|
#include <netcdf_par.h>
|
|
|
|
...
|
|
|
|
int ncid, omode;
|
|
|
|
char filename[128];
|
|
|
|
...
|
2018-09-17 07:15:15 +08:00
|
|
|
omode = NC_NOWRITE;
|
2017-11-03 02:57:16 +08:00
|
|
|
err = nc_open_par(filename, omode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid); FATAL_ERR
|
2017-11-08 18:05:22 +08:00
|
|
|
\endcode
|
|
|
|
\author Ed Hartnett, Dennis Heimbigner
|
|
|
|
\ingroup datasets
|
2016-01-15 06:33:50 +08:00
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2018-09-17 07:15:15 +08:00
|
|
|
nc_open_par(const char *path, int omode, MPI_Comm comm,
|
2018-09-23 09:22:34 +08:00
|
|
|
MPI_Info info, int *ncidp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_PARALLEL
|
2019-01-11 23:45:42 +08:00
|
|
|
NC_UNUSED(path);
|
|
|
|
NC_UNUSED(omode);
|
|
|
|
NC_UNUSED(comm);
|
|
|
|
NC_UNUSED(info);
|
|
|
|
NC_UNUSED(ncidp);
|
2018-09-23 09:22:34 +08:00
|
|
|
return NC_ENOPAR;
|
2018-09-18 14:27:57 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
NC_MPI_INFO mpi_data;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
mpi_data.comm = comm;
|
|
|
|
mpi_data.info = info;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
return NC_open(path, omode, 0, NULL, 1, &mpi_data, ncidp);
|
2018-09-18 14:27:57 +08:00
|
|
|
#endif /* USE_PARALLEL */
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
/**
|
|
|
|
This is the same as nc_open_par(), but accepts the MPI comm/info as
|
|
|
|
integers.
|
|
|
|
|
|
|
|
\param path File name for netCDF dataset to be opened.
|
|
|
|
|
2018-09-22 06:32:36 +08:00
|
|
|
\param omode The open mode flag may be NC_WRITE (for read/write
|
|
|
|
access) or NC_NOWRITE (for read-only access).
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param comm the MPI communicator specifying the processes participating the
|
|
|
|
parallel I/O to this file.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param info MPI info object containing I/O hints or MPI_INFO_NULL.
|
2016-01-15 07:02:00 +08:00
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
\param ncidp Pointer to location where returned netCDF ID is to be
|
|
|
|
stored.
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
nc_open_par() returns the value NC_NOERR if no errors occurred. Otherwise, the
|
|
|
|
returned status indicates an error. Possible causes of errors include:
|
2016-01-15 07:02:00 +08:00
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
\returns ::NC_NOERR No error.
|
|
|
|
\returns ::NC_EINVAL Invalid parameters.
|
|
|
|
\returns ::NC_ENOTNC Not a netCDF file.
|
|
|
|
\returns ::NC_ENOMEM Out of memory.
|
|
|
|
\returns ::NC_EHDFERR HDF5 error. (NetCDF-4 files only.)
|
|
|
|
\returns ::NC_EDIMMETA Error in netCDF-4 dimension metadata. (NetCDF-4
|
|
|
|
files only.)
|
|
|
|
|
|
|
|
\author Ed Hartnett
|
|
|
|
\ingroup datasets
|
|
|
|
\internal
|
2016-01-15 07:02:00 +08:00
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2018-09-22 06:32:36 +08:00
|
|
|
nc_open_par_fortran(const char *path, int omode, int comm,
|
2018-09-23 09:22:34 +08:00
|
|
|
int info, int *ncidp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_PARALLEL
|
2019-01-11 23:45:42 +08:00
|
|
|
NC_UNUSED(path);
|
|
|
|
NC_UNUSED(omode);
|
|
|
|
NC_UNUSED(comm);
|
|
|
|
NC_UNUSED(info);
|
|
|
|
NC_UNUSED(ncidp);
|
2018-09-23 09:22:34 +08:00
|
|
|
return NC_ENOPAR;
|
2010-06-03 21:24:43 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
MPI_Comm comm_c;
|
|
|
|
MPI_Info info_c;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
/* Convert fortran comm and info to C comm and info, if there is a
|
|
|
|
* function to do so. Otherwise just pass them. */
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef HAVE_MPI_COMM_F2C
|
2018-09-23 09:22:34 +08:00
|
|
|
comm_c = MPI_Comm_f2c(comm);
|
2010-06-03 21:24:43 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
comm_c = (MPI_Comm)comm;
|
2018-09-22 06:32:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MPI_INFO_F2C
|
2018-09-23 09:22:34 +08:00
|
|
|
info_c = MPI_Info_f2c(info);
|
2018-09-22 06:32:36 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
info_c = (MPI_Info)info;
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
return nc_open_par(path, omode, comm_c, info_c, ncidp);
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
/**
|
|
|
|
@ingroup datasets
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
This function will change the parallel access of a variable from
|
|
|
|
independent to collective and vice versa.
|
2018-10-02 14:19:44 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
This function is collective, i.e. must be called by all MPI
|
|
|
|
processes defined in the MPI communicator used in nc_create_par()
|
|
|
|
or nc_open_par(). In addition, values of arguments of this function
|
|
|
|
must be the same among all MPI processes.
|
2018-09-22 06:32:36 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
To obtain a good I/O performance, users are recommended to use
|
|
|
|
collective mode. In addition, switching between collective and
|
|
|
|
independent I/O mode can be expensive.
|
2019-12-20 22:10:13 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
In netcdf-c-4.7.4 or later, using hdf5-1.10.2 or later, the zlib,
|
|
|
|
szip, fletcher32, and other filters may be used when writing data
|
|
|
|
with parallel I/O. The use of these filters require collective
|
|
|
|
access. Turning on the zlib (deflate) or fletcher32 filter for a
|
|
|
|
variable will automatically set its access to collective if the
|
|
|
|
file has been opened for parallel I/O. Attempts to set access to
|
|
|
|
independent will return ::NC_EINVAL.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@note When the library is build with --enable-pnetcdf, and when
|
|
|
|
file is opened/created to use PnetCDF library to perform parallel
|
|
|
|
I/O underneath, argument varid is ignored and the mode changed by
|
|
|
|
this function applies to all variables. This is because PnetCDF
|
|
|
|
does not support access mode change for individual variables. In
|
|
|
|
this case, users may use NC_GLOBAL in varid argument for better
|
|
|
|
program readability.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@param ncid NetCDF or group ID, from a previous call to
|
|
|
|
nc_open_par(), nc_create_par(), nc_def_grp(), or associated inquiry
|
|
|
|
functions such as nc_inq_ncid().
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@param varid Variable ID
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@param par_access NC_COLLECTIVE or NC_INDEPENDENT.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@return ::NC_NOERR No error.
|
|
|
|
@return ::NC_EBADID Invalid ncid passed.
|
|
|
|
@return ::NC_ENOTVAR Invalid varid passed.
|
2022-07-07 00:37:02 +08:00
|
|
|
@return ::NC_ENOPAR File was not opened with nc_open_par/nc_create_par.
|
2020-03-03 07:36:56 +08:00
|
|
|
@return ::NC_EINVAL Invalid par_access specified, or attempt to set
|
|
|
|
filtered variable to independent access.
|
2017-11-03 02:57:16 +08:00
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
<h1>Example</h1>
|
|
|
|
|
|
|
|
Here is an example from examples/C/parallel_vara.c which changes
|
|
|
|
the parallel access of a variable and then writes to it.
|
|
|
|
|
|
|
|
@code
|
2017-11-03 02:57:16 +08:00
|
|
|
#define NY 10
|
|
|
|
#define NX 4
|
|
|
|
|
|
|
|
#include <mpi.h>
|
|
|
|
#include <netcdf.h>
|
|
|
|
#include <netcdf_par.h>
|
|
|
|
...
|
|
|
|
char filename[128];
|
|
|
|
int err, ncid, cmode, varid, dimid, dimid[2], buf[NY][NX];
|
|
|
|
size_t global_ny, global_nx, start[2], count[2];
|
|
|
|
...
|
|
|
|
global_ny = NY;
|
|
|
|
global_nx = NX * nprocs;
|
|
|
|
...
|
2018-09-23 09:22:34 +08:00
|
|
|
cmode = NC_CLOBBER;
|
2017-11-03 02:57:16 +08:00
|
|
|
err = nc_create_par(filename, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid); FATAL_ERR
|
|
|
|
...
|
|
|
|
err = nc_def_dim(ncid, "Y", global_ny, &dimid[0]); ERR
|
|
|
|
err = nc_def_dim(ncid, "X", global_nx, &dimid[1]); ERR
|
|
|
|
err = nc_def_var(ncid, "var", NC_INT, 2, dimid, &varid); ERR
|
|
|
|
...
|
2018-10-02 14:19:44 +08:00
|
|
|
... set collective I/O globally (for all variables)
|
|
|
|
err = nc_var_par_access(ncid, NC_GLOBAL, NC_COLLECTIVE); ERR
|
|
|
|
|
2017-11-03 02:57:16 +08:00
|
|
|
err = nc_enddef(ncid); ERR
|
|
|
|
...
|
|
|
|
start[0] = 0;
|
|
|
|
start[1] = NX * rank;
|
|
|
|
count[0] = NY;
|
|
|
|
count[1] = NX;
|
|
|
|
|
|
|
|
err = nc_put_vara_int(ncid, varid, start, count, &buf[0][0]); ERR
|
|
|
|
|
2020-03-03 07:36:56 +08:00
|
|
|
@endcode
|
|
|
|
@author Ed Hartnett, Dennis Heimbigner
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
|
|
|
nc_var_par_access(int ncid, int varid, int par_access)
|
|
|
|
{
|
2018-09-21 01:59:19 +08:00
|
|
|
#ifndef USE_PARALLEL
|
2019-01-11 23:45:42 +08:00
|
|
|
NC_UNUSED(ncid);
|
|
|
|
NC_UNUSED(varid);
|
|
|
|
NC_UNUSED(par_access);
|
2018-09-21 01:59:19 +08:00
|
|
|
return NC_ENOPAR;
|
|
|
|
#else
|
2012-03-17 06:29:09 +08:00
|
|
|
int stat = NC_NOERR;
|
2018-09-21 01:59:19 +08:00
|
|
|
NC* ncp;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
if ((stat = NC_check_id(ncid, &ncp)))
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
return ncp->dispatch->var_par_access(ncid,varid,par_access);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-08 18:05:22 +08:00
|
|
|
/**
|
|
|
|
Create a netCDF file for parallel access from the Fortran API.
|
|
|
|
|
|
|
|
This function calls nc_create_par() after converting the MPI comm and
|
|
|
|
info from Fortran to C, if necessary.
|
|
|
|
|
|
|
|
\param path The file name of the new netCDF dataset.
|
|
|
|
|
|
|
|
\param cmode The creation mode flag. The following flags are available:
|
2018-09-21 01:59:19 +08:00
|
|
|
NC_CLOBBER (overwrite existing file),
|
2017-11-08 18:05:22 +08:00
|
|
|
NC_NOCLOBBER (do not overwrite existing file),
|
|
|
|
NC_NETCDF4 (create netCDF-4/HDF5 file),
|
|
|
|
NC_CLASSIC_MODEL (enforce netCDF classic mode on netCDF-4/HDF5 files),
|
2018-09-23 09:22:34 +08:00
|
|
|
NC_64BIT_OFFSET (create CDF-2 file)
|
|
|
|
NC_64BIT_DATA (create CDF-5 file)
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param comm the MPI communicator specifying the processes participating the
|
|
|
|
parallel I/O to this file.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
2018-09-21 01:59:19 +08:00
|
|
|
\param info MPI info object containing I/O hints or MPI_INFO_NULL.
|
2017-11-08 18:05:22 +08:00
|
|
|
|
|
|
|
\param ncidp Pointer to location where returned netCDF ID is to be
|
|
|
|
stored.
|
|
|
|
|
|
|
|
\returns ::NC_NOERR No error.
|
|
|
|
\returns ::NC_ENOPAR Library was not built with parallel I/O features.
|
2018-09-21 01:59:19 +08:00
|
|
|
\returns ::NC_EPERM: Attempting to create a netCDF file in a directory where you do not have permission to create files.
|
2017-11-08 18:05:22 +08:00
|
|
|
\returns ::NC_EINVAL Invalid input parameters.
|
|
|
|
\returns ::NC_ENOMEM System out of memory.
|
|
|
|
\returns ::NC_ENOTNC Binary format could not be determined.
|
|
|
|
\returns ::NC_EHDFERR HDF5 error (netCDF-4 files only).
|
|
|
|
\returns ::NC_EFILEMETA Error writing netCDF-4 file-level metadata in
|
|
|
|
HDF5 file. (netCDF-4 files only).
|
|
|
|
|
|
|
|
\author Ed Hartnett, Dennis Heimbigner
|
|
|
|
\ingroup datasets
|
|
|
|
\internal
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-15 02:02:23 +08:00
|
|
|
nc_create_par_fortran(const char *path, int cmode, int comm,
|
2018-09-23 09:22:34 +08:00
|
|
|
int info, int *ncidp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_PARALLEL
|
2019-01-11 23:45:42 +08:00
|
|
|
NC_UNUSED(path);
|
|
|
|
NC_UNUSED(cmode);
|
|
|
|
NC_UNUSED(comm);
|
|
|
|
NC_UNUSED(info);
|
|
|
|
NC_UNUSED(ncidp);
|
2018-09-23 09:22:34 +08:00
|
|
|
return NC_ENOPAR;
|
2010-06-03 21:24:43 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
MPI_Comm comm_c;
|
|
|
|
MPI_Info info_c;
|
2013-07-09 05:31:13 +08:00
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
/* Convert fortran comm and info to C comm and info, if there is a
|
|
|
|
* function to do so. Otherwise just pass them. */
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef HAVE_MPI_COMM_F2C
|
2018-09-23 09:22:34 +08:00
|
|
|
comm_c = MPI_Comm_f2c(comm);
|
2010-06-03 21:24:43 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
comm_c = (MPI_Comm)comm;
|
2018-09-22 06:32:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MPI_INFO_F2C
|
2018-09-23 09:22:34 +08:00
|
|
|
info_c = MPI_Info_f2c(info);
|
2018-09-22 06:32:36 +08:00
|
|
|
#else
|
2018-09-23 09:22:34 +08:00
|
|
|
info_c = (MPI_Info)info;
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
2013-07-09 05:31:13 +08:00
|
|
|
|
2018-09-23 09:22:34 +08:00
|
|
|
return nc_create_par(path, cmode, comm_c, info_c, ncidp);
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
|
|
|
}
|