NetCDF  4.7.0
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 
100 int 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 
207 int
208 nc_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 
260 int
261 nc_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 
365 int
366 nc_var_par_access(int ncid, int varid, int par_access)
367 {
368 #ifndef USE_PARALLEL
369  NC_UNUSED(ncid);
370  NC_UNUSED(varid);
371  NC_UNUSED(par_access);
372  return NC_ENOPAR;
373 #else
374  int stat = NC_NOERR;
375  NC* ncp;
376 
377  if ((stat = NC_check_id(ncid, &ncp)))
378  return stat;
379 
380  return ncp->dispatch->var_par_access(ncid,varid,par_access);
381 #endif
382 }
383 
422 int
423 nc_create_par_fortran(const char *path, int cmode, int comm,
424  int info, int *ncidp)
425 {
426 #ifndef USE_PARALLEL
427  NC_UNUSED(path);
428  NC_UNUSED(cmode);
429  NC_UNUSED(comm);
430  NC_UNUSED(info);
431  NC_UNUSED(ncidp);
432  return NC_ENOPAR;
433 #else
434  MPI_Comm comm_c;
435  MPI_Info info_c;
436 
437  /* Convert fortran comm and info to C comm and info, if there is a
438  * function to do so. Otherwise just pass them. */
439 #ifdef HAVE_MPI_COMM_F2C
440  comm_c = MPI_Comm_f2c(comm);
441 #else
442  comm_c = (MPI_Comm)comm;
443 #endif
444 #ifdef HAVE_MPI_INFO_F2C
445  info_c = MPI_Info_f2c(info);
446 #else
447  info_c = (MPI_Info)info;
448 #endif
449 
450  return nc_create_par(path, cmode, comm_c, info_c, ncidp);
451 #endif
452 }
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
#define NC_INMEMORY
Read from memory.
Definition: netcdf.h:161
#define NC_ENOTBUILT
Attempt to use feature that was not turned on when netCDF was built.
Definition: netcdf.h:465
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:335
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_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:423
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:366
#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:451
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
#define NC_NOERR
No Error.
Definition: netcdf.h:325
#define NC_DISKLESS
Use diskless file.
Definition: netcdf.h:129
#define NC_MMAP
Definition: netcdf.h:130

Return to the Main Unidata NetCDF page.
Generated on Mon Apr 29 2019 10:59:59 for NetCDF. NetCDF is a Unidata library.