The function ncmpi_put_vard writes values into a netCDF variable of an opened netCDF file. The part of the netCDF variable to write is specified by an MPI derived data type whose flattened displacements are relative to the beginning file offset of the variable.
These API must be called while the file is in data mode.
The corresponding collective APIs have the suffix name "_all" and must be called in collective data mode.
int ncmpi_put_vard (int ncid, int varid, MPI_Datatype filetype, const void *buf, MPI_Offset bufcount, MPI_Datatype buftype); int ncmpi_put_vard_all (int ncid, int varid, MPI_Datatype filetype, const void *buf, MPI_Offset bufcount, MPI_Datatype buftype);
NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.
Variable ID. Starting from version 1.10.0, filetype argument may cover more than one variable. In this case, varid is the ID of the first variable. However, variables accessed by filetype must be either all fixed-size variables or all record variables. In addition, the variables accessed by filetype must be of the same external NC data type. Thie limitation allows the same data type conversion to perform on the entire write buffer. When calling the collevtive ncmpi_put_vard_all(), different MPI processes may use different variable IDs, ncid.
An MPI derived data type that describes the file access layout. The element datatype that is used to construct filetype must conformed with the external NC data type of the variable defined in the file, i.e. MPI_FLOAT being used to construct filetype vs. NC_FLOAT being the NC data type of the variable(s). Starting from version 1.10.0, filetype may cover more than one variable. In this case, all variables accessed by the filetype must be of the same NC data type. For record variables, accessing more than one record is possible. One might need the size of record block (i.e. the sum of single records of all record variables defined in the file) which can be obtained from a call to ncmpi_inq_recsize. In addition, filetype must meet the following MPI-IO requirement specified in MPI standard Chapter 13.3. File displacements of filetype must be non-negative and in a monotonically nondecreasing order. If the file is opened for writing, filetype is not permitted to contain overlapping regions. It is fine for filetype to be MPI_DATATYPE_NULL, which indicates a zero-length write request. For independent APIs, a zero-length request is returned immediately. For collective APIs, the process with a zero-length request will still proceed to participate the collective MPI operations inside the PnetCDF library.
Pointer to the write buffer.
An integer indicates the number of MPI derived data type elements in the buf to be written to the file. This argument is ignored if buftype is MPI_DATATYPE_NULL.
An MPI derived data type that describes the memory layout of buf. There can only be a single element data type contained in buftype. It is fine for buftype to be MPI_DATATYPE_NULL, which indicates the write buffer is contiguous and its amount is equal to the size of filetype. In this case, argument bufcount is ignored and users must ensure the memory space pointed by argument buf is at least of size of filetype.
ncmpi_put_vard returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:
Here is an example using ncmpi_put_vard.
#include <pnetcdf.h> ... #define NY 2 #define NX 5 MPI_Offset start, count; int array_of_sizes, array_of_subsizes, array_of_starts; int buf[NY][NX]; MPI_Datatype filetype; ... MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* create an MPI derived data type */ array_of_sizes = 2; array_of_sizes = NX*nprocs; array_of_subsizes = 2; array_of_subsizes = NX; array_of_starts = 0; array_of_starts = NX*rank; MPI_Type_create_subarray(2, array_of_sizes, array_of_subsizes, array_of_starts, MPI_ORDER_C, MPI_INT, &filetype); MPI_Type_commit(&filetype); err = ncmpi_put_vard_all(ncid, varid, filetype, buf, 2*NX, MPI_INT);