netCDF  4.3.0
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
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
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  MPI_Comm comm_c = 0;
24  MPI_Info info_c = 0;
25 
26  /* One of these two parallel IO modes must be chosen by the user,
27  * or else pnetcdf must be in use. */
28  if (!(cmode & NC_MPIIO || cmode & NC_MPIPOSIX) &&
29  !(cmode & NC_PNETCDF))
30  return NC_EINVAL;
31 
32  comm_c = (MPI_Comm)comm;
33  info_c = (MPI_Info)info;
34 
35  data.comm = comm_c;
36  data.info = info_c;
37  return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
38 #endif /* USE_PARALLEL */
39 }
40 
41 /* This function opens a file for parallel I/O. */
42 int
43 nc_open_par(const char *path, int mode, MPI_Comm comm,
44  MPI_Info info, int *ncidp)
45 {
46 #ifndef USE_PARALLEL
47  return NC_ENOPAR;
48 #else
49  NC_MPI_INFO mpi_data;
50 
51  /* One of these two parallel IO modes must be chosen by the user,
52  * or else pnetcdf must be in use. */
53  if ((mode & NC_MPIIO) || (mode & NC_MPIPOSIX)) {
54  /* ok */
55  } else if(mode & NC_PNETCDF) {
56  /* ok */
57  } else
58  return NC_EINVAL;
59 
60  mpi_data.comm = comm;
61  mpi_data.info = info;
62 
63  return NC_open(path, mode, 0, NULL, 1, &mpi_data, ncidp);
64 #endif /* USE_PARALLEL */
65 }
66 
67 /* Fortran needs to pass MPI comm/info as integers. */
68 int
69 nc_open_par_fortran(const char *path, int mode, int comm,
70  int info, int *ncidp)
71 {
72 #ifndef USE_PARALLEL
73  return NC_ENOPAR;
74 #else
75 
76  MPI_Comm comm_c = 0;
77  MPI_Info info_c = 0;
78 
79  /* Convert fortran comm and info to C comm and info, if there is a
80  * function to do so. Otherwise just pass them. */
81 #ifdef HAVE_MPI_COMM_F2C
82  comm_c = MPI_Comm_f2c(comm);
83  info_c = MPI_Info_f2c(info);
84 #else
85  comm_c = (MPI_Comm)comm;
86  info_c = (MPI_Info)info;
87 #endif
88 
89  return nc_open_par(path, mode, comm_c, info_c, ncidp);
90 #endif
91 }
92 
93 /* This function will change the parallel access of a variable from
94  * independent to collective. */
95 int
96 nc_var_par_access(int ncid, int varid, int par_access)
97 {
98  NC* ncp;
99 
100  int stat = NC_NOERR;
101 
102  if ((stat = NC_check_id(ncid, &ncp)))
103  return stat;
104 
105 #ifndef USE_PARALLEL
106  return NC_ENOPAR;
107 #else
108  return ncp->dispatch->var_par_access(ncid,varid,par_access);
109 #endif
110 }
111 
112 /* when calling from fortran: convert MPI_Comm and MPI_Info to C */
113 int
114 nc_create_par_fortran(const char *path, int cmode, int comm,
115  int info, int *ncidp)
116 {
117 #ifndef USE_PARALLEL
118  return NC_ENOPAR;
119 #else
120  MPI_Comm comm_c = 0;
121  MPI_Info info_c = 0;
122 #ifdef USE_PARALLEL
123 #ifdef HAVE_MPI_COMM_F2C
124  comm_c = MPI_Comm_f2c(comm);
125  info_c = MPI_Info_f2c(info);
126 #else
127  comm_c = (MPI_Comm)comm;
128  info_c = (MPI_Info)info;
129 #endif
130 #endif
131  return nc_create_par(path, cmode, comm_c, info_c, ncidp);
132 #endif
133 }
134 
135 
136 

Generated on Tue Jul 9 2013 19:18:05 for netCDF. NetCDF is a Unidata library.