NetCDF  4.5.0
dparallel.c
Go to the documentation of this file.
1 
8 #include "config.h"
9 #include "ncdispatch.h"
10 
16 int nc_create_par(const char *path, int cmode, MPI_Comm comm,
17  MPI_Info info, int *ncidp)
18 {
19 #ifndef USE_PARALLEL
20  return NC_ENOPAR;
21 #else
22  NC_MPI_INFO data;
23 
24  /* One of these two parallel IO modes must be chosen by the user,
25  * or else pnetcdf must be in use. */
26  if (!(cmode & NC_MPIIO || cmode & NC_MPIPOSIX) &&
27  !(cmode & NC_PNETCDF))
28  return NC_EINVAL;
29 
30  data.comm = comm;
31  data.info = info;
32  return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
33 #endif /* USE_PARALLEL */
34 }
35 
41 int
42 nc_open_par(const char *path, int mode, MPI_Comm comm,
43  MPI_Info info, int *ncidp)
44 {
45 #ifndef USE_PARALLEL
46  return NC_ENOPAR;
47 #else
48  NC_MPI_INFO mpi_data;
49 
50  /* One of these two parallel IO modes must be chosen by the user,
51  * or else pnetcdf must be in use. */
52  if ((mode & NC_MPIIO) || (mode & NC_MPIPOSIX)) {
53  /* ok */
54  } else if(mode & NC_PNETCDF) {
55  /* ok */
56  } else
57  return NC_EINVAL;
58 
59  mpi_data.comm = comm;
60  mpi_data.info = info;
61 
62  return NC_open(path, mode, 0, NULL, 1, &mpi_data, ncidp);
63 #endif /* USE_PARALLEL */
64 }
65 
71 int
72 nc_open_par_fortran(const char *path, int mode, int comm,
73  int info, int *ncidp)
74 {
75 #ifndef USE_PARALLEL
76  return NC_ENOPAR;
77 #else
78  MPI_Comm comm_c;
79  MPI_Info info_c;
80 
81  /* Convert fortran comm and info to C comm and info, if there is a
82  * function to do so. Otherwise just pass them. */
83 #ifdef HAVE_MPI_COMM_F2C
84  comm_c = MPI_Comm_f2c(comm);
85  info_c = MPI_Info_f2c(info);
86 #else
87  comm_c = (MPI_Comm)comm;
88  info_c = (MPI_Info)info;
89 #endif
90 
91  return nc_open_par(path, mode, comm_c, info_c, ncidp);
92 #endif
93 }
94 
95 /* This function will change the parallel access of a variable from
96  * independent to collective. */
97 int
98 nc_var_par_access(int ncid, int varid, int par_access)
99 {
100  NC* ncp;
101 
102  int stat = NC_NOERR;
103 
104  if ((stat = NC_check_id(ncid, &ncp)))
105  return stat;
106 
107 #ifndef USE_PARALLEL
108  return NC_ENOPAR;
109 #else
110  return ncp->dispatch->var_par_access(ncid,varid,par_access);
111 #endif
112 }
113 
114 /* when calling from fortran: convert MPI_Comm and MPI_Info to C */
115 int
116 nc_create_par_fortran(const char *path, int cmode, int comm,
117  int info, int *ncidp)
118 {
119 #ifndef USE_PARALLEL
120  return NC_ENOPAR;
121 #else
122  MPI_Comm comm_c;
123  MPI_Info info_c;
124 
125  /* Convert fortran comm and info to C comm and info, if there is a
126  * function to do so. Otherwise just pass them. */
127 #ifdef HAVE_MPI_COMM_F2C
128  comm_c = MPI_Comm_f2c(comm);
129  info_c = MPI_Info_f2c(info);
130 #else
131  comm_c = (MPI_Comm)comm;
132  info_c = (MPI_Info)info;
133 #endif
134 
135  return nc_create_par(path, cmode, comm_c, info_c, ncidp);
136 #endif
137 }
#define NC_PNETCDF
Use parallel-netcdf library; alias for NC_MPIIO.
Definition: netcdf.h:158
#define NC_MPIIO
Turn on MPI I/O.
Definition: netcdf.h:151
int nc_open_par(const char *path, int mode, MPI_Comm comm, MPI_Info info, int *ncidp)
This function opens a file for parallel I/O.
Definition: dparallel.c:42
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:318
int nc_open_par_fortran(const char *path, int mode, int comm, int info, int *ncidp)
Fortran needs to pass MPI comm/info as integers.
Definition: dparallel.c:72
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
Definition: netcdf.h:436
int nc_create_par(const char *path, int cmode, MPI_Comm comm, MPI_Info info, int *ncidp)
This function creates a file for use with parallel I/O.
Definition: dparallel.c:16
#define NC_NOERR
No Error.
Definition: netcdf.h:308
#define NC_MPIPOSIX
Turn on MPI POSIX I/O.
Definition: netcdf.h:154

Return to the Main Unidata NetCDF page.
Generated on Sat Dec 30 2017 10:59:33 for NetCDF. NetCDF is a Unidata library.