[409] | 1 | /** \file |
---|
| 2 | This file has the parallel I/O functions. |
---|
| 3 | |
---|
| 4 | Copyright 2010 University Corporation for Atmospheric |
---|
| 5 | Research/Unidata. See COPYRIGHT file for more info. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include <config.h> |
---|
| 9 | #include <netcdf_f.h> |
---|
| 10 | #include "ncdispatch.h" |
---|
| 11 | |
---|
| 12 | /* This function creates a file for use with parallel I/O. */ |
---|
| 13 | int |
---|
| 14 | nc_create_par(const char *path, int cmode, MPI_Comm comm, |
---|
| 15 | MPI_Info info, int *ncidp) |
---|
| 16 | { |
---|
| 17 | #ifndef USE_PARALLEL |
---|
| 18 | return NC_ENOPAR; |
---|
| 19 | #else |
---|
| 20 | NC_MPI_INFO data; |
---|
| 21 | MPI_Comm comm_c = 0; |
---|
| 22 | MPI_Info info_c = 0; |
---|
| 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 | comm_c = (MPI_Comm)comm; |
---|
| 31 | info_c = (MPI_Info)info; |
---|
| 32 | |
---|
| 33 | data.comm = comm_c; |
---|
| 34 | data.info = info_c; |
---|
| 35 | return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp); |
---|
| 36 | #endif /* USE_PARALLEL */ |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /* This function opens a file for parallel I/O. */ |
---|
| 40 | int |
---|
| 41 | nc_open_par(const char *path, int mode, MPI_Comm comm, |
---|
| 42 | MPI_Info info, int *ncidp) |
---|
| 43 | { |
---|
| 44 | #ifndef USE_PARALLEL |
---|
| 45 | return NC_ENOPAR; |
---|
| 46 | #else |
---|
| 47 | NC_MPI_INFO mpi_data; |
---|
| 48 | |
---|
| 49 | /* One of these two parallel IO modes must be chosen by the user, |
---|
| 50 | * or else pnetcdf must be in use. */ |
---|
| 51 | if (!(mode & NC_MPIIO || mode & NC_MPIPOSIX) && |
---|
| 52 | !(mode & NC_PNETCDF)) |
---|
| 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 | |
---|
| 71 | MPI_Comm comm_c = 0; |
---|
| 72 | MPI_Info info_c = 0; |
---|
| 73 | |
---|
| 74 | /* Convert fortran comm and info to C comm and info, if there is a |
---|
| 75 | * function to do so. Otherwise just pass them. */ |
---|
| 76 | #ifdef HAVE_MPI_COMM_F2C |
---|
| 77 | comm_c = MPI_Comm_f2c(comm); |
---|
| 78 | info_c = MPI_Info_f2c(info); |
---|
| 79 | #else |
---|
| 80 | comm_c = (MPI_Comm)comm; |
---|
| 81 | info_c = (MPI_Info)info; |
---|
| 82 | #endif |
---|
| 83 | |
---|
| 84 | return nc_open_par(path, mode, comm_c, info_c, ncidp); |
---|
| 85 | #endif |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /* This function will change the parallel access of a variable from |
---|
| 89 | * independent to collective. */ |
---|
| 90 | int |
---|
| 91 | nc_var_par_access(int ncid, int varid, int par_access) |
---|
| 92 | { |
---|
| 93 | NC* ncp; |
---|
| 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 = 0; |
---|
| 115 | MPI_Info info_c = 0; |
---|
| 116 | #ifdef USE_PARALLEL |
---|
| 117 | #ifdef HAVE_MPI_COMM_F2C |
---|
| 118 | comm_c = MPI_Comm_f2c(comm); |
---|
| 119 | info_c = MPI_Info_f2c(info); |
---|
| 120 | #else |
---|
| 121 | comm_c = (MPI_Comm)comm; |
---|
| 122 | info_c = (MPI_Info)info; |
---|
| 123 | #endif |
---|
| 124 | #endif |
---|
| 125 | return nc_create_par(path, cmode, comm_c, info_c, ncidp); |
---|
| 126 | #endif |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|