NetCDF
4.3.2
|
00001 00008 #include "config.h" 00009 #ifdef USE_PARALLEL 00010 #include "netcdf_f.h" 00011 #endif /* USE_PARALLEL */ 00012 #include "ncdispatch.h" 00013 00014 /* This function creates a file for use with parallel I/O. */ 00015 int 00016 nc_create_par(const char *path, int cmode, MPI_Comm comm, 00017 MPI_Info info, int *ncidp) 00018 { 00019 #ifndef USE_PARALLEL 00020 return NC_ENOPAR; 00021 #else 00022 NC_MPI_INFO data; 00023 00024 /* One of these two parallel IO modes must be chosen by the user, 00025 * or else pnetcdf must be in use. */ 00026 if (!(cmode & NC_MPIIO || cmode & NC_MPIPOSIX) && 00027 !(cmode & NC_PNETCDF)) 00028 return NC_EINVAL; 00029 00030 data.comm = comm; 00031 data.info = info; 00032 return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp); 00033 #endif /* USE_PARALLEL */ 00034 } 00035 00036 /* This function opens a file for parallel I/O. */ 00037 int 00038 nc_open_par(const char *path, int mode, MPI_Comm comm, 00039 MPI_Info info, int *ncidp) 00040 { 00041 #ifndef USE_PARALLEL 00042 return NC_ENOPAR; 00043 #else 00044 NC_MPI_INFO mpi_data; 00045 00046 /* One of these two parallel IO modes must be chosen by the user, 00047 * or else pnetcdf must be in use. */ 00048 if ((mode & NC_MPIIO) || (mode & NC_MPIPOSIX)) { 00049 /* ok */ 00050 } else if(mode & NC_PNETCDF) { 00051 /* ok */ 00052 } else 00053 return NC_EINVAL; 00054 00055 mpi_data.comm = comm; 00056 mpi_data.info = info; 00057 00058 return NC_open(path, mode, 0, NULL, 1, &mpi_data, ncidp); 00059 #endif /* USE_PARALLEL */ 00060 } 00061 00062 /* Fortran needs to pass MPI comm/info as integers. */ 00063 int 00064 nc_open_par_fortran(const char *path, int mode, int comm, 00065 int info, int *ncidp) 00066 { 00067 #ifndef USE_PARALLEL 00068 return NC_ENOPAR; 00069 #else 00070 MPI_Comm comm_c; 00071 MPI_Info info_c; 00072 00073 /* Convert fortran comm and info to C comm and info, if there is a 00074 * function to do so. Otherwise just pass them. */ 00075 #ifdef HAVE_MPI_COMM_F2C 00076 comm_c = MPI_Comm_f2c(comm); 00077 info_c = MPI_Info_f2c(info); 00078 #else 00079 comm_c = (MPI_Comm)comm; 00080 info_c = (MPI_Info)info; 00081 #endif 00082 00083 return nc_open_par(path, mode, comm_c, info_c, ncidp); 00084 #endif 00085 } 00086 00087 /* This function will change the parallel access of a variable from 00088 * independent to collective. */ 00089 int 00090 nc_var_par_access(int ncid, int varid, int par_access) 00091 { 00092 NC* ncp; 00093 00094 int stat = NC_NOERR; 00095 00096 if ((stat = NC_check_id(ncid, &ncp))) 00097 return stat; 00098 00099 #ifndef USE_PARALLEL 00100 return NC_ENOPAR; 00101 #else 00102 return ncp->dispatch->var_par_access(ncid,varid,par_access); 00103 #endif 00104 } 00105 00106 /* when calling from fortran: convert MPI_Comm and MPI_Info to C */ 00107 int 00108 nc_create_par_fortran(const char *path, int cmode, int comm, 00109 int info, int *ncidp) 00110 { 00111 #ifndef USE_PARALLEL 00112 return NC_ENOPAR; 00113 #else 00114 MPI_Comm comm_c; 00115 MPI_Info info_c; 00116 00117 /* Convert fortran comm and info to C comm and info, if there is a 00118 * function to do so. Otherwise just pass them. */ 00119 #ifdef HAVE_MPI_COMM_F2C 00120 comm_c = MPI_Comm_f2c(comm); 00121 info_c = MPI_Info_f2c(info); 00122 #else 00123 comm_c = (MPI_Comm)comm; 00124 info_c = (MPI_Info)info; 00125 #endif 00126 00127 return nc_create_par(path, cmode, comm_c, info_c, ncidp); 00128 #endif 00129 } 00130 00131 00132