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

Return to the Main Unidata NetCDF page.
Generated on Tue May 3 2016 08:56:00 for NetCDF. NetCDF is a Unidata library.