NetCDF  4.6.3
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
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 extern int fileno(FILE*);
14 
101 int nc_create_par(const char *path, int cmode, MPI_Comm comm,
102  MPI_Info info, int *ncidp)
103 {
104 #ifndef USE_PARALLEL
105  NC_UNUSED(path);
106  NC_UNUSED(cmode);
107  NC_UNUSED(comm);
108  NC_UNUSED(info);
109  NC_UNUSED(ncidp);
110  return NC_ENOPAR;
111 #else
112  NC_MPI_INFO data;
113 
114 #ifndef USE_PNETCDF
115  /* PnetCDF is disabled but user wants to create classic file in parallel */
116  if (!(cmode & NC_NETCDF4))
117  return NC_ENOTBUILT;
118 #endif
119 
120 #ifndef USE_NETCDF4
121  /* NETCDF4 is disabled but user wants to create NETCDF4 file in parallel */
122  if (cmode & NC_NETCDF4)
123  return NC_ENOTBUILT;
124 #endif
125 
126  data.comm = comm;
127  data.info = info;
128  return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
129 #endif /* USE_PARALLEL */
130 }
131 
204 int
205 nc_open_par(const char *path, int omode, MPI_Comm comm,
206  MPI_Info info, int *ncidp)
207 {
208 #ifndef USE_PARALLEL
209  NC_UNUSED(path);
210  NC_UNUSED(omode);
211  NC_UNUSED(comm);
212  NC_UNUSED(info);
213  NC_UNUSED(ncidp);
214  return NC_ENOPAR;
215 #else
216  NC_MPI_INFO mpi_data;
217 
218  mpi_data.comm = comm;
219  mpi_data.info = info;
220 
221  return NC_open(path, omode, 0, NULL, 1, &mpi_data, ncidp);
222 #endif /* USE_PARALLEL */
223 }
224 
257 int
258 nc_open_par_fortran(const char *path, int omode, int comm,
259  int info, int *ncidp)
260 {
261 #ifndef USE_PARALLEL
262  NC_UNUSED(path);
263  NC_UNUSED(omode);
264  NC_UNUSED(comm);
265  NC_UNUSED(info);
266  NC_UNUSED(ncidp);
267  return NC_ENOPAR;
268 #else
269  MPI_Comm comm_c;
270  MPI_Info info_c;
271 
272  /* Convert fortran comm and info to C comm and info, if there is a
273  * function to do so. Otherwise just pass them. */
274 #ifdef HAVE_MPI_COMM_F2C
275  comm_c = MPI_Comm_f2c(comm);
276 #else
277  comm_c = (MPI_Comm)comm;
278 #endif
279 #ifdef HAVE_MPI_INFO_F2C
280  info_c = MPI_Info_f2c(info);
281 #else
282  info_c = (MPI_Info)info;
283 #endif
284 
285  return nc_open_par(path, omode, comm_c, info_c, ncidp);
286 #endif
287 }
288 
362 int
363 nc_var_par_access(int ncid, int varid, int par_access)
364 {
365 #ifndef USE_PARALLEL
366  NC_UNUSED(ncid);
367  NC_UNUSED(varid);
368  NC_UNUSED(par_access);
369  return NC_ENOPAR;
370 #else
371  int stat = NC_NOERR;
372  NC* ncp;
373 
374  if ((stat = NC_check_id(ncid, &ncp)))
375  return stat;
376 
377  return ncp->dispatch->var_par_access(ncid,varid,par_access);
378 #endif
379 }
380 
419 int
420 nc_create_par_fortran(const char *path, int cmode, int comm,
421  int info, int *ncidp)
422 {
423 #ifndef USE_PARALLEL
424  NC_UNUSED(path);
425  NC_UNUSED(cmode);
426  NC_UNUSED(comm);
427  NC_UNUSED(info);
428  NC_UNUSED(ncidp);
429  return NC_ENOPAR;
430 #else
431  MPI_Comm comm_c;
432  MPI_Info info_c;
433 
434  /* Convert fortran comm and info to C comm and info, if there is a
435  * function to do so. Otherwise just pass them. */
436 #ifdef HAVE_MPI_COMM_F2C
437  comm_c = MPI_Comm_f2c(comm);
438 #else
439  comm_c = (MPI_Comm)comm;
440 #endif
441 #ifdef HAVE_MPI_INFO_F2C
442  info_c = MPI_Info_f2c(info);
443 #else
444  info_c = (MPI_Info)info;
445 #endif
446 
447  return nc_create_par(path, cmode, comm_c, info_c, ncidp);
448 #endif
449 }
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:205
#define NC_ENOTBUILT
Attempt to use feature that was not turned on when netCDF was built.
Definition: netcdf.h:463
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:101
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:420
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:363
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
Definition: netcdf.h:151
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
Definition: netcdf.h:449
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:258
#define NC_NOERR
No Error.
Definition: netcdf.h:323

Return to the Main Unidata NetCDF page.
Generated on Sat Apr 6 2019 08:19:00 for NetCDF. NetCDF is a Unidata library.