NetCDF 4.9.3
Loading...
Searching...
No Matches
dparallel.c
Go to the documentation of this file.
1/* Copyright 2018 University Corporation for Atmospheric
2 Research/Unidata. See COPYRIGHT file for more info. */
8#include "config.h"
9#include "ncdispatch.h"
10#ifdef HAVE_STDIO_H
11#include <stdio.h>
12#endif
13
100int nc_create_par(const char *path, int cmode, MPI_Comm comm,
101 MPI_Info info, int *ncidp)
102{
103#ifndef USE_PARALLEL
104 NC_UNUSED(path);
105 NC_UNUSED(cmode);
106 NC_UNUSED(comm);
107 NC_UNUSED(info);
108 NC_UNUSED(ncidp);
109 return NC_ENOPAR;
110#else
111 NC_MPI_INFO data;
112
113#ifndef USE_PNETCDF
114 /* PnetCDF is disabled but user wants to create classic file in parallel */
115 if (!(cmode & NC_NETCDF4))
116 return NC_ENOTBUILT;
117#endif
118
119#ifndef USE_NETCDF4
120 /* NETCDF4 is disabled but user wants to create NETCDF4 file in parallel */
121 if (cmode & NC_NETCDF4)
122 return NC_ENOTBUILT;
123#endif
124
125 /* Can't use both parallel and diskless|inmemory|mmap. */
126 if (cmode & (NC_DISKLESS|NC_INMEMORY|NC_MMAP))
127 return NC_EINVAL;
128
129 data.comm = comm;
130 data.info = info;
131 return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
132#endif /* USE_PARALLEL */
133}
134
207int
208nc_open_par(const char *path, int omode, MPI_Comm comm,
209 MPI_Info info, int *ncidp)
210{
211#ifndef USE_PARALLEL
212 NC_UNUSED(path);
213 NC_UNUSED(omode);
214 NC_UNUSED(comm);
215 NC_UNUSED(info);
216 NC_UNUSED(ncidp);
217 return NC_ENOPAR;
218#else
219 NC_MPI_INFO mpi_data;
220
221 mpi_data.comm = comm;
222 mpi_data.info = info;
223
224 return NC_open(path, omode, 0, NULL, 1, &mpi_data, ncidp);
225#endif /* USE_PARALLEL */
226}
227
260int
261nc_open_par_fortran(const char *path, int omode, int comm,
262 int info, int *ncidp)
263{
264#ifndef USE_PARALLEL
265 NC_UNUSED(path);
266 NC_UNUSED(omode);
267 NC_UNUSED(comm);
268 NC_UNUSED(info);
269 NC_UNUSED(ncidp);
270 return NC_ENOPAR;
271#else
272 MPI_Comm comm_c;
273 MPI_Info info_c;
274
275 /* Convert fortran comm and info to C comm and info, if there is a
276 * function to do so. Otherwise just pass them. */
277#ifdef HAVE_MPI_COMM_F2C
278 comm_c = MPI_Comm_f2c(comm);
279#else
280 comm_c = (MPI_Comm)comm;
281#endif
282#ifdef HAVE_MPI_INFO_F2C
283 info_c = MPI_Info_f2c(info);
284#else
285 info_c = (MPI_Info)info;
286#endif
287
288 return nc_open_par(path, omode, comm_c, info_c, ncidp);
289#endif
290}
291
380int
381nc_var_par_access(int ncid, int varid, int par_access)
382{
383#ifndef USE_PARALLEL
384 NC_UNUSED(ncid);
385 NC_UNUSED(varid);
386 NC_UNUSED(par_access);
387 return NC_ENOPAR;
388#else
389 int stat = NC_NOERR;
390 NC* ncp;
391
392 if ((stat = NC_check_id(ncid, &ncp)))
393 return stat;
394
395 return ncp->dispatch->var_par_access(ncid,varid,par_access);
396#endif
397}
398
437int
438nc_create_par_fortran(const char *path, int cmode, int comm,
439 int info, int *ncidp)
440{
441#ifndef USE_PARALLEL
442 NC_UNUSED(path);
443 NC_UNUSED(cmode);
444 NC_UNUSED(comm);
445 NC_UNUSED(info);
446 NC_UNUSED(ncidp);
447 return NC_ENOPAR;
448#else
449 MPI_Comm comm_c;
450 MPI_Info info_c;
451
452 /* Convert fortran comm and info to C comm and info, if there is a
453 * function to do so. Otherwise just pass them. */
454#ifdef HAVE_MPI_COMM_F2C
455 comm_c = MPI_Comm_f2c(comm);
456#else
457 comm_c = (MPI_Comm)comm;
458#endif
459#ifdef HAVE_MPI_INFO_F2C
460 info_c = MPI_Info_f2c(info);
461#else
462 info_c = (MPI_Info)info;
463#endif
464
465 return nc_create_par(path, cmode, comm_c, info_c, ncidp);
466#endif
467}
int nc_open_par(const char *path, int omode, MPI_Comm comm, MPI_Info info, int *ncidp)
Open an existing netCDF file for parallel I/O.
Definition dparallel.c:208
int nc_create_par(const char *path, int cmode, MPI_Comm comm, MPI_Info info, int *ncidp)
Create a netCDF file for parallel I/O.
Definition dparallel.c:100
int nc_var_par_access(int ncid, int varid, int par_access)
This function will change the parallel access of a variable from independent to collective and vice v...
Definition dparallel.c:381
int nc_open_par_fortran(const char *path, int omode, int comm, int info, int *ncidp)
This is the same as nc_open_par(), but accepts the MPI comm/info as integers.
Definition dparallel.c:261
int nc_create_par_fortran(const char *path, int cmode, int comm, int info, int *ncidp)
Create a netCDF file for parallel access from the Fortran API.
Definition dparallel.c:438
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
Definition netcdf.h:162
#define NC_MMAP
Definition netcdf.h:141
#define NC_INMEMORY
Read from memory.
Definition netcdf.h:172
#define NC_DISKLESS
Use diskless file.
Definition netcdf.h:140
#define NC_EINVAL
Invalid Argument.
Definition netcdf.h:388
#define NC_NOERR
No Error.
Definition netcdf.h:378
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
Definition netcdf.h:504
#define NC_ENOTBUILT
Attempt to use feature that was not turned on when netCDF was built.
Definition netcdf.h:518