netCDF  4.2.1.1
/usr/src/RPM/BUILD/libnetcdf7-mpi-4.2.1.1/libdispatch/dparallel.c
Go to the documentation of this file.
00001 
00008 #include <config.h>
00009 #include <netcdf_f.h>
00010 #include "ncdispatch.h"
00011 
00012 /* This function creates a file for use with parallel I/O. */
00013 int
00014 nc_create_par(const char *path, int cmode, MPI_Comm comm, 
00015               MPI_Info info, int *ncidp)
00016 {
00017 #ifndef USE_PARALLEL
00018    return NC_ENOPAR;
00019 #else   
00020    NC_MPI_INFO data;
00021    MPI_Comm comm_c = 0;
00022    MPI_Info info_c = 0;
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    comm_c = (MPI_Comm)comm;
00031    info_c = (MPI_Info)info;
00032 
00033    data.comm = comm_c;
00034    data.info = info_c;
00035    return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
00036 #endif /* USE_PARALLEL */
00037 }
00038 
00039 /* This function opens a file for parallel I/O. */
00040 int
00041 nc_open_par(const char *path, int mode, MPI_Comm comm, 
00042             MPI_Info info, int *ncidp)
00043 {
00044 #ifndef USE_PARALLEL
00045    return NC_ENOPAR;
00046 #else
00047    NC_MPI_INFO mpi_data;
00048 
00049    /* One of these two parallel IO modes must be chosen by the user,
00050     * or else pnetcdf must be in use. */
00051    if (!(mode & NC_MPIIO || mode & NC_MPIPOSIX) &&
00052        !(mode & NC_PNETCDF))
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 
00071    MPI_Comm comm_c = 0;
00072    MPI_Info info_c = 0;
00073 
00074    /* Convert fortran comm and info to C comm and info, if there is a
00075     * function to do so. Otherwise just pass them. */
00076 #ifdef HAVE_MPI_COMM_F2C
00077    comm_c = MPI_Comm_f2c(comm);
00078    info_c = MPI_Info_f2c(info);
00079 #else
00080    comm_c = (MPI_Comm)comm;
00081    info_c = (MPI_Info)info;
00082 #endif
00083 
00084    return nc_open_par(path, mode, comm_c, info_c, ncidp);
00085 #endif
00086 }
00087 
00088 /* This function will change the parallel access of a variable from
00089  * independent to collective. */
00090 int
00091 nc_var_par_access(int ncid, int varid, int par_access)
00092 {
00093     NC* ncp;
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 = 0;
00115    MPI_Info info_c = 0;
00116 #ifdef USE_PARALLEL
00117 #ifdef HAVE_MPI_COMM_F2C
00118    comm_c = MPI_Comm_f2c(comm);
00119    info_c = MPI_Info_f2c(info);
00120 #else
00121    comm_c = (MPI_Comm)comm;
00122    info_c = (MPI_Info)info;
00123 #endif
00124 #endif
00125    return nc_create_par(path, cmode, comm_c, info_c, ncidp);
00126 #endif
00127 }
00128 
00129 
00130 
 All Data Structures Files Functions Variables Typedefs Defines

Generated on Fri Sep 14 2012 07:36:39 for netCDF. NetCDF is a Unidata library.