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

Return to the Main Unidata NetCDF page.
Generated on Wed Aug 19 2015 17:25:41 for NetCDF. NetCDF is a Unidata library.