From 8e34e307c9a63dc67f94d7036f1c190ac9829fc5 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 5 May 2016 10:32:04 -0400 Subject: [PATCH 01/83] manually merged async changes from ejh_27 --- CMakeLists.txt | 1 + src/clib/CMakeLists.txt | 10 +- src/clib/pio.h | 2 + src/clib/pio_msg.c | 968 ++++++++++++++++++++++++++++++++++++ src/clib/pio_put_nc_async.c | 118 +++-- src/clib/pioc.c | 457 +++++++++++++++++ tests/unit/CMakeLists.txt | 15 + tests/unit/test_intercomm.c | 399 +++++++++++++++ 8 files changed, 1915 insertions(+), 55 deletions(-) create mode 100644 src/clib/pio_msg.c create mode 100644 tests/unit/test_intercomm.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ddaf9a15b88..b284128d2da6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH) #===== Library Options ===== option (PIO_ENABLE_FORTRAN "Enable the Fortran library builds" ON) option (PIO_ENABLE_TIMING "Enable the use of the GPTL timing library" ON) +option (PIO_ENABLE_ASYNC "Enable the use of asychronus IO operations" OFF) option (PIO_TEST_BIG_ENDIAN "Enable test to see if machine is big endian" ON) option (PIO_USE_MPIIO "Enable support for MPI-IO auto detect" ON) option (PIO_USE_MPISERIAL "Enable mpi-serial support (instead of MPI)" OFF) diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 093aeac70c16..f5448d4d5c23 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -17,12 +17,18 @@ set (PIO_C_SRCS topology.c pio_darray.c bget.c) -set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c +set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c) -add_library (pioc ${PIO_C_SRCS} ${PIO_GENNC_SRCS}) +if (PIO_ENABLE_ASYNC) + set (PIO_ADDL_SRCS pio_nc2.c pio_msg.c) +else () + set (PIO_ADDL_SRCS pio_nc.c) +endif () + +add_library (pioc ${PIO_C_SRCS} ${PIO_GENNC_SRCS} ${PIO_ADDL_SRCS}) # set up include-directories include_directories( diff --git a/src/clib/pio.h b/src/clib/pio.h index 5185a133b0e5..e96f754e57e7 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -481,6 +481,8 @@ int PIOc_InitDecomp(const int iosysid, const int basetype,const int ndims, const int PIOc_Init_Intracomm(const MPI_Comm comp_comm, const int num_iotasks, const int stride, const int base, const int rearr, int *iosysidp); +int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, MPI_Comm *comp_comms, + MPI_Comm io_comm, int *iosysidp); int PIOc_closefile(int ncid); int PIOc_createfile(const int iosysid, int *ncidp, int *iotype, const char *fname, const int mode); diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c new file mode 100644 index 000000000000..a2bc45e955e5 --- /dev/null +++ b/src/clib/pio_msg.c @@ -0,0 +1,968 @@ +/** + * @file + * @author Ed Hartnett + * @date 2016 + * @brief PIO async msg handling + * + * @see http://code.google.com/p/parallelio/ + */ + +#include +#include + +/** This function is run on the IO tasks to create a netCDF file. */ +int create_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int len; + int iotype; + char *filename; + int mode; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d create_file_handler comproot = %d\n", my_rank, ios->comproot); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d create_file_handler got parameter len = %d\n", my_rank, len); + if (!(filename = malloc(len + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&iotype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&mode, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d create_file_handler got parameters len = %d " + "filename = %s iotype = %d mode = %d\n", + my_rank, len, filename, iotype, mode); + + /* Call the create file function. */ + if ((ret = PIOc_createfile(ios->iosysid, &ncid, &iotype, filename, mode))) + return ret; + + /* Free resources. */ + free(filename); + + printf("%d create_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to close a netCDF file. It is + * only ever run on the IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int close_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d close_file_handler\n", my_rank); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d create_file_handler got parameter ncid = %d\n", my_rank, ncid); + + /* Call the close file function. */ + if ((ret = PIOc_closefile(ncid))) + return ret; + + printf("%d close_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to inq a netCDF file. It is + * only ever run on the IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d inq_handler msg = %d\n", my_rank, msg); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + + /* Call the inq file function. */ + int ndims, nvars, ngatts, unlimdimid; + int *ndimsp = NULL, *nvarsp = NULL, *ngattsp = NULL, *unlimdimidp = NULL; + switch (msg) + { + case PIO_MSG_INQ: + ndimsp = &ndims; + nvarsp = &nvars; + ngattsp = &ngatts; + unlimdimidp = &unlimdimid; + break; + case PIO_MSG_INQ_NVARS: + nvarsp = &nvars; + break; + case PIO_MSG_INQ_NDIMS: + ndimsp = &ndims; + break; + case PIO_MSG_INQ_NATTS: + ngattsp = &ngatts; + break; + case PIO_MSG_INQ_UNLIMDIM: + unlimdimidp = &unlimdimid; + break; + default: + return PIO_EINVAL; + } + + /* Call the inq function to get the values. */ + if ((ret = PIOc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp))) + return ret; + + return PIO_NOERR; +} + +/** Do an inq_dim on a netCDF dimension. This function is only run on + * IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_dim_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int dimid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d inq_handler msg = %d\n", my_rank, msg); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&dimid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + + /* Call the inq_dim function. */ + char *dimnamep = NULL; + PIO_Offset *dimlenp = NULL; + char dimname[NC_MAX_NAME + 1]; + PIO_Offset dimlen; + switch (msg) + { + case PIO_MSG_INQ_DIM: + dimnamep = dimname; + dimlenp = &dimlen; + break; + case PIO_MSG_INQ_DIMLEN: + dimlenp = &dimlen; + break; + case PIO_MSG_INQ_DIMNAME: + dimnamep = dimname; + break; + default: + return PIO_EINVAL; + } + + /* Call the inq function to get the values. */ + if ((ret = PIOc_inq_dim(ncid, dimid, dimnamep, dimlenp))) + return ret; + + return PIO_NOERR; +} + +/** Do an inq_dimid on a netCDF dimension name. This function is only + * run on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_dimid_handler(iosystem_desc_t *ios) +{ + int ncid; + int dimid; + int mpierr; + int ret; + int namelen; + char *name; + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + + /* Call the inq_dimid function. */ + if ((ret = PIOc_inq_dimid(ncid, name, &dimid))) + return ret; + + /* Free resources. */ + free(name); + + return PIO_NOERR; +} + +/** Handle attribute operations. This code only runs on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int att_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int varid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inv_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); + + /* Call the inq_var function. */ + char name[NC_MAX_NAME + 1], *namep; + nc_type xtype, *xtypep = NULL; + int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; + int ndims, dimids[NC_MAX_DIMS], natts; + switch (msg) + { + case PIO_MSG_INQ_VAR: + namep = name; + xtypep = &xtype; + ndimsp = &ndims; + dimidsp = dimids; + nattsp = &natts; + break; + case PIO_MSG_INQ_VARNATTS: + nattsp = &natts; + break; + case PIO_MSG_INQ_VARNAME: + namep = name; + break; + case PIO_MSG_INQ_VARNDIMS: + ndimsp = &ndims; + break; + case PIO_MSG_INQ_VARDIMID: + dimidsp = dimids; + break; + case PIO_MSG_INQ_VARTYPE: + xtypep = &xtype; + break; + default: + return PIO_EINVAL; + } + + /* Call the inq function to get the values. */ + if ((ret = PIOc_inq_var(ncid, varid, namep, xtypep, ndimsp, dimidsp, nattsp))) + return ret; + + return PIO_NOERR; +} + +/** Do an inq_var on a netCDF variable. This function is only run on + * IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_var_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int varid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inv_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); + + /* Call the inq_var function. */ + char name[NC_MAX_NAME + 1], *namep; + nc_type xtype, *xtypep = NULL; + int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; + int ndims, dimids[NC_MAX_DIMS], natts; + switch (msg) + { + case PIO_MSG_INQ_VAR: + namep = name; + xtypep = &xtype; + ndimsp = &ndims; + dimidsp = dimids; + nattsp = &natts; + break; + case PIO_MSG_INQ_VARNATTS: + nattsp = &natts; + break; + case PIO_MSG_INQ_VARNAME: + namep = name; + break; + case PIO_MSG_INQ_VARNDIMS: + ndimsp = &ndims; + break; + case PIO_MSG_INQ_VARDIMID: + dimidsp = dimids; + break; + case PIO_MSG_INQ_VARTYPE: + xtypep = &xtype; + break; + default: + return PIO_EINVAL; + } + + /* Call the inq function to get the values. */ + if ((ret = PIOc_inq_var(ncid, varid, namep, xtypep, ndimsp, dimidsp, nattsp))) + return ret; + + return PIO_NOERR; +} + +/** Do an inq_varid on a netCDF variable name. This function is only + * run on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_varid_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int mpierr; + int ret; + int namelen; + char *name; + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + + /* Call the inq_dimid function. */ + if ((ret = PIOc_inq_varid(ncid, name, &varid))) + return ret; + + /* Free resources. */ + free(name); + + return PIO_NOERR; +} + +/** This function is run on the IO tasks to sync a netCDF file. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int sync_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d sync_file_handler\n", my_rank); + + /* Get the parameters for this function that the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d sync_file_handler got parameter ncid = %d\n", my_rank, ncid); + + /* Call the sync file function. */ + if ((ret = PIOc_sync(ncid))) + return ret; + + printf("%d sync_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to enddef a netCDF file. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int enddef_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d enddef_file_handler\n", my_rank); + + /* Get the parameters for this function that the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d enddef_file_handler got parameter ncid = %d\n", my_rank, ncid); + + /* Call the sync file function. */ + if ((ret = PIOc_enddef(ncid))) + return ret; + + printf("%d enddef_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to define a netCDF + * variable. */ +int def_var_handler(iosystem_desc_t *ios) +{ + int ncid; + int len, namelen; + int iotype; + char *name; + int mode; + int mpierr; + int ret; + int varid; + nc_type xtype; + int ndims; + int *dimids; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d def_var_handler comproot = %d\n", my_rank, ios->comproot); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc(namelen + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&xtype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(dimids = malloc(ndims * sizeof(int)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(dimids, ndims, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d def_var_handler got parameters namelen = %d " + "name = %s len = %d ncid = %d\n", + my_rank, namelen, name, len, ncid); + + /* Call the create file function. */ + if ((ret = PIOc_def_var(ncid, name, xtype, ndims, dimids, &varid))) + return ret; + + /* Free resources. */ + free(name); + free(dimids); + + printf("%d def_var_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to define a netCDF + * dimension. */ +int def_dim_handler(iosystem_desc_t *ios) +{ + int ncid; + int len, namelen; + int iotype; + char *name; + int mode; + int mpierr; + int ret; + int dimid; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d def_dim_handler comproot = %d\n", my_rank, ios->comproot); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d def_dim_handler ncid = %d namelen %d\n", my_rank, ncid, namelen); + if (!(name = malloc(namelen + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d def_dim_handler got parameters namelen = %d " + "name = %s len = %d ncid = %d\n", + my_rank, namelen, name, len, ncid); + + /* Call the create file function. */ + if ((ret = PIOc_def_dim(ncid, name, len, &dimid))) + return ret; + + /* Free resources. */ + free(name); + + printf("%d def_dim_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks. It reads or writes an array + * of data to a netCDF variable. + * + * @param ios pointer to the iosystem_desc_t data. + * @param msg the message sent my the comp root task. + * + * @return PIO_NOERR for success, error code otherwise. */ +int vara_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int len, namelen; + int iotype; + char *name; + int mode; + int mpierr; + int ret; + int varid; + nc_type xtype; + int ndims; + int *dimids; + void *data; + int size_in_bytes; + PIO_Offset *count, *start; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d def_var_handler comproot = %d\n", my_rank, ios->comproot); + + if (msg == PIO_MSG_PUT_VARA) + { + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((ret = PIOc_inq_varndims(ncid, varid, &ndims))) + return ret; + if (!(start = malloc(ndims * sizeof(int)))) + return PIO_ENOMEM; + if (!(count = malloc(ndims * sizeof(int)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(start, ndims, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(count, ndims, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + int size = 1; + for (int d = 0; d < ndims; d++) + size *= count[d]; + size_in_bytes = size * sizeof(int); + if (!(data = malloc(size_in_bytes))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(data, size_in_bytes, MPI_INT, 0, + ios->intercomm))) + return PIO_EIO; + printf("%d def_var_handler got parameters namelen = %d " + "name = %s len = %d ncid = %d\n", + my_rank, namelen, name, len, ncid); + + /* Call the create file function. */ + if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) + return ret; + + /* Free resources. */ + free(start); + free(count); + free(data); + } + else + { + + } + + printf("%d vara_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to open a netCDF file. + * + * @param ios pointer to the iosystem_desc_t data. + * + * @return PIO_NOERR for success, error code otherwise. */ +int open_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int len; + int iotype; + char *filename; + int mode; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d open_file_handler comproot = %d\n", my_rank, ios->comproot); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d open_file_handler got parameter len = %d\n", my_rank, len); + if (!(filename = malloc(len + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&iotype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&mode, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d open_file_handler got parameters len = %d " + "filename = %s iotype = %d mode = %d\n", + my_rank, len, filename, iotype, mode); + + /* Call the open file function. */ + if ((ret = PIOc_openfile(ios->iosysid, &ncid, &iotype, filename, mode))) + return ret; + + /* Free resources. */ + free(filename); + + printf("%d open_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +/** This function is run on the IO tasks to delete a netCDF file. + * + * @param ios pointer to the iosystem_desc_t data. + * + * @return PIO_NOERR for success, error code otherwise. */ +int delete_file_handler(iosystem_desc_t *ios) +{ + int ncid; + int len; + char *filename; + int mpierr; + int ret; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d delete_file_handler comproot = %d\n", my_rank, ios->comproot); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + printf("%d open_file_handler got parameter len = %d\n", my_rank, len); + if (!(filename = malloc(len + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + printf("%d delete_file_handler got parameters len = %d filename = %s\n", + my_rank, len, filename); + + /* Call the delete file function. */ + if ((ret = PIOc_deletefile(ios->iosysid, filename))) + return ret; + + /* Free resources. */ + free(filename); + + printf("%d delete_file_handler succeeded!\n", my_rank); + return PIO_NOERR; +} + +int initdecomp_dof_handler(iosystem_desc_t *ios) +{ + return PIO_NOERR; +} + +int writedarray_handler(iosystem_desc_t *ios) +{ + return PIO_NOERR; +} + +int readdarray_handler(iosystem_desc_t *ios) +{ + return PIO_NOERR; +} + +int seterrorhandling_handler(iosystem_desc_t *ios) +{ + return PIO_NOERR; +} + +int var_handler(iosystem_desc_t *ios, int msg) +{ + return PIO_NOERR; +} + +int freedecomp_handler(iosystem_desc_t *ios) +{ + return PIO_NOERR; +} + +int finalize_handler(iosystem_desc_t *ios) +{ + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d finalize_handler called\n", my_rank); + return PIO_NOERR; +} + +int pio_callback_handler(iosystem_desc_t *ios, int msg) +{ + return PIO_NOERR; +} + +/** This function is called by the IO tasks. This function will not + return, unless there is an error. */ +int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) +{ + iosystem_desc_t *my_iosys; + int msg = 0; + MPI_Request req[component_count]; + MPI_Status status; + int index; + int mpierr; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d pio_msg_handler called\n", my_rank); + + /* Have IO comm rank 0 (the ioroot) register to receive + * (non-blocking) for a message from each of the comproots. */ + if (!io_rank) + { + for (int cmp = 0; cmp < component_count; cmp++) + { + my_iosys = &iosys[cmp]; + printf("%d about to call MPI_Irecv\n", my_rank); + mpierr = MPI_Irecv(&msg, 1, MPI_INT, my_iosys->comproot, MPI_ANY_TAG, + my_iosys->union_comm, &req[cmp]); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + } + + /* If the message is not -1, keep processing messages. */ + while (msg != -1) + { + /* Wait until any one of the requests are complete. */ + if (!io_rank) + { + printf("%d about to call MPI_Waitany req[0] = %d MPI_REQUEST_NULL = %d\n", + my_rank, req[0], MPI_REQUEST_NULL); + mpierr = MPI_Waitany(component_count, req, &index, &status); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + printf("%d Waitany returned index = %d req[%d] = %d\n", my_rank, + index, index, req[index]); + } + + /* Broadcast the index of the computational component that + * originated the request to the rest of the IO tasks. */ + printf("%d about to call index MPI_Bcast index = %d\n", my_rank, index); + mpierr = MPI_Bcast(&index, 1, MPI_INT, 0, iosys->io_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + my_iosys = &iosys[index]; + printf("%d index MPI_Bcast complete index = %d\n", my_rank, index); + + /* Broadcast the msg value to the rest of the IO tasks. */ + printf("%d about to call msg MPI_Bcast\n", my_rank); + mpierr = MPI_Bcast(&msg, 1, MPI_INT, 0, my_iosys->io_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + printf("%d msg MPI_Bcast complete msg = %d\n", my_rank, msg); + + /* Handle the message. This code is run on all IO tasks. */ + switch (msg) + { + case PIO_MSG_CREATE_FILE: + create_file_handler(my_iosys); + break; + case PIO_MSG_SYNC: + sync_file_handler(my_iosys); + break; + case PIO_MSG_ENDDEF: + enddef_file_handler(my_iosys); + break; + case PIO_MSG_OPEN_FILE: + open_file_handler(my_iosys); + break; + case PIO_MSG_CLOSE_FILE: + close_file_handler(my_iosys); + break; + case PIO_MSG_DELETE_FILE: + delete_file_handler(my_iosys); + break; + case PIO_MSG_DEF_DIM: + def_dim_handler(my_iosys); + break; + case PIO_MSG_DEF_VAR: + def_var_handler(my_iosys); + break; + case PIO_MSG_INQ: + case PIO_MSG_INQ_NVARS: + case PIO_MSG_INQ_NDIMS: + case PIO_MSG_INQ_NATTS: + case PIO_MSG_INQ_UNLIMDIM: + inq_handler(my_iosys, msg); + break; + case PIO_MSG_INQ_DIM: + case PIO_MSG_INQ_DIMLEN: + case PIO_MSG_INQ_DIMNAME: + inq_dim_handler(my_iosys, msg); + break; + case PIO_MSG_INQ_DIMID: + inq_dimid_handler(my_iosys); + break; + case PIO_MSG_INQ_VAR: + case PIO_MSG_INQ_VARNATTS: + case PIO_MSG_INQ_VARNAME: + case PIO_MSG_INQ_VARNDIMS: + case PIO_MSG_INQ_VARDIMID: + case PIO_MSG_INQ_VARTYPE: + inq_var_handler(my_iosys, msg); + break; + case PIO_MSG_GET_ATT_INT: + att_handler(my_iosys, msg); + break; + case PIO_MSG_PUT_ATT_INT: + att_handler(my_iosys, msg); + break; + case PIO_MSG_INQ_VARID: + inq_varid_handler(my_iosys); + break; + case PIO_MSG_INITDECOMP_DOF: + initdecomp_dof_handler(my_iosys); + break; + case PIO_MSG_WRITEDARRAY: + writedarray_handler(my_iosys); + break; + case PIO_MSG_READDARRAY: + readdarray_handler(my_iosys); + break; + case PIO_MSG_SETERRORHANDLING: + seterrorhandling_handler(my_iosys); + break; + case PIO_MSG_GET_VAR1: + var_handler(my_iosys, msg); + break; + case PIO_MSG_PUT_VAR1: + var_handler(my_iosys, msg); + break; + case PIO_MSG_PUT_VARA: + vara_handler(my_iosys, msg); + break; + case PIO_MSG_FREEDECOMP: + freedecomp_handler(my_iosys); + break; + case PIO_MSG_EXIT: + finalize_handler(my_iosys); + msg = -1; + break; + default: + pio_callback_handler(my_iosys, msg); + } + + /* Unless finalize was called, listen for another msg from the + * component whose message we just handled. */ + if (!io_rank && msg != -1) + { + my_iosys = &iosys[index]; + mpierr = MPI_Irecv(&msg, 1, MPI_INT, my_iosys->comproot, MPI_ANY_TAG, my_iosys->union_comm, + &req[index]); + printf("%d pio_msg_handler called MPI_Irecv req[%d] = %d\n", my_rank, index, req[index]); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + + } + + return PIO_NOERR; +} + +int +pio_iosys_print(int my_rank, iosystem_desc_t *iosys) +{ + printf("%d iosysid: %d\n", my_rank, iosys->iosysid); + if (iosys->union_comm == MPI_COMM_NULL) + printf("%d union_comm: MPI_COMM_NULL ", my_rank); + else + printf("%d union_comm: %d ", my_rank, iosys->union_comm); + + if (iosys->comp_comm == MPI_COMM_NULL) + printf("comp_comm: MPI_COMM_NULL "); + else + printf("comp_comm: %d ", iosys->comp_comm); + + if (iosys->io_comm == MPI_COMM_NULL) + printf("io_comm: MPI_COMM_NULL "); + else + printf("io_comm: %d ", iosys->io_comm); + + if (iosys->intercomm == MPI_COMM_NULL) + printf("intercomm: MPI_COMM_NULL\n"); + else + printf("intercomm: %d\n", iosys->intercomm); + + printf("%d num_iotasks=%d num_comptasks=%d union_rank=%d, comp_rank=%d, " + "io_rank=%d async_interface=%d\n", + my_rank, iosys->num_iotasks, iosys->num_comptasks, iosys->union_rank, + iosys->comp_rank, iosys->io_rank, iosys->async_interface); + + printf("%d ioroot=%d comproot=%d iomaster=%d, compmaster=%d\n", + my_rank, iosys->ioroot, iosys->comproot, iosys->iomaster, + iosys->compmaster); + + printf("%d iotasks:", my_rank); + for (int i = 0; i < iosys->num_iotasks; i++) + printf("%d ", iosys->ioranks[i]); + printf("\n"); + return PIO_NOERR; +} + diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index c0b621eb903d..dd9693a3abe2 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -1022,7 +1022,8 @@ int PIOc_put_var_short (int ncid, int varid, const short *op) /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const int *op) +int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const int *op) { int ierr; int msg; @@ -1032,6 +1033,9 @@ int PIOc_put_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_ var_desc_t *vdesc; PIO_Offset usage; int *request; + int size; + int ret; + int ndims; ierr = PIO_NOERR; @@ -1044,7 +1048,15 @@ int PIOc_put_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if ((ret = PIOc_inq_varndims(ncid, varid, &ndims))) + return ret; + mpierr = MPI_Bcast((void *)start, ndims, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)count, ndims, MPI_INT, ios->compmaster, ios->intercomm); + for (int d = 0, size = 1; d < ndims; d++) + size *= count[d]; + mpierr = MPI_Bcast((void *)op, size, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1122,7 +1134,7 @@ int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const u if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1200,7 +1212,7 @@ int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1278,7 +1290,7 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1356,7 +1368,7 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1434,7 +1446,7 @@ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1512,7 +1524,7 @@ int PIOc_put_var_int (int ncid, int varid, const int *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1590,7 +1602,7 @@ int PIOc_put_var_longlong (int ncid, int varid, const long long *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1668,7 +1680,7 @@ int PIOc_put_var_schar (int ncid, int varid, const signed char *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1746,7 +1758,7 @@ int PIOc_put_var_uint (int ncid, int varid, const unsigned int *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1824,7 +1836,7 @@ int PIOc_put_var (int ncid, int varid, const void *buf, PIO_Offset bufcount, MPI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1902,7 +1914,7 @@ int PIOc_put_vara_ushort (int ncid, int varid, const PIO_Offset start[], const P if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1980,7 +1992,7 @@ int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2058,7 +2070,7 @@ int PIOc_put_vara_uint (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2136,7 +2148,7 @@ int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2214,7 +2226,7 @@ int PIOc_put_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], cons if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2292,7 +2304,7 @@ int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], const un if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2370,7 +2382,7 @@ int PIOc_put_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2448,7 +2460,7 @@ int PIOc_put_vars_schar (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2526,7 +2538,7 @@ int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *bu if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2604,7 +2616,7 @@ int PIOc_put_vara_float (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2682,7 +2694,7 @@ int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], const fl if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2760,7 +2772,7 @@ int PIOc_put_varm_float (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2838,7 +2850,7 @@ int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const cha if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2916,7 +2928,7 @@ int PIOc_put_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2994,7 +3006,7 @@ int PIOc_put_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3072,7 +3084,7 @@ int PIOc_put_vars_double (int ncid, int varid, const PIO_Offset start[], const P if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3150,7 +3162,7 @@ int PIOc_put_vara_longlong (int ncid, int varid, const PIO_Offset start[], const if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3228,7 +3240,7 @@ int PIOc_put_var_double (int ncid, int varid, const double *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3306,7 +3318,7 @@ int PIOc_put_var_float (int ncid, int varid, const float *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3384,7 +3396,7 @@ int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], cons if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3462,7 +3474,7 @@ int PIOc_put_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3540,7 +3552,7 @@ int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const uns if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3618,7 +3630,7 @@ int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3696,7 +3708,7 @@ int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3774,7 +3786,7 @@ int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3852,7 +3864,7 @@ int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const si if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -3930,7 +3942,7 @@ int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], cons if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4008,7 +4020,7 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4086,7 +4098,7 @@ int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offs if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4164,7 +4176,7 @@ int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4242,7 +4254,7 @@ int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const d if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4320,7 +4332,7 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4398,7 +4410,7 @@ int PIOc_put_var_text (int ncid, int varid, const char *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4476,7 +4488,7 @@ int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4554,7 +4566,7 @@ int PIOc_put_var1_short (int ncid, int varid, const PIO_Offset index[], const sh if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4632,7 +4644,7 @@ int PIOc_put_vars_longlong (int ncid, int varid, const PIO_Offset start[], const if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4710,7 +4722,7 @@ int PIOc_put_vara_double (int ncid, int varid, const PIO_Offset start[], const P if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4788,7 +4800,7 @@ int PIOc_put_vars (int ncid, int varid, const PIO_Offset start[], const PIO_Offs if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4866,7 +4878,7 @@ int PIOc_put_var_uchar (int ncid, int varid, const unsigned char *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -4944,7 +4956,7 @@ int PIOc_put_var_long (int ncid, int varid, const long *op) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -5022,7 +5034,7 @@ int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } diff --git a/src/clib/pioc.c b/src/clib/pioc.c index 22d6ea3307f1..b9127d47b8b8 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -341,6 +341,463 @@ int PIOc_InitDecomp_bc(const int iosysid, const int basetype,const int ndims, co } +/** @ingroup PIO_init + * Library initialization used when IO tasks are distinct from compute + * tasks. + * + * This is a collective call. Input parameters are read on + * comp_rank=0 values on other tasks are ignored. This variation of + * PIO_init sets up a distinct set of tasks to handle IO, these tasks + * do not return from this call. Instead they go to an internal loop + * and wait to receive further instructions from the computational + * tasks. + * + * For 4 tasks, to have 2 of them be computational, and 2 of them + * be IO, I would provide the following: + * + * component_count = 1 + * + * peer_comm = MPI_COMM_WORLD + * + * comp_comms = an array with one element, an MPI (intra) communicator + * that contains the two tasks designated to do computation + * (processors 0, 1). + + * io_comm = an MPI (intra) communicator with the other two tasks (2, + * 3). + * + * iosysidp = pointer that gets the IO system ID. + * + * Fortran function (from PIO1, in piolib_mod.F90) is: + * + * subroutine init_intercom(component_count, peer_comm, comp_comms, + * io_comm, iosystem, rearr_opts) + * + * Some notes from Jim: + * + * Components and Component Count + * ------------------------------ + * + * It's a cesm thing - the cesm model is composed of several component + * models (atm, ocn, ice, lnd, etc) that may or may not be collocated + * on mpi tasks. Since for intercomm the IOCOMM tasks are a subset of + * the compute tasks for a given component we have a separate iocomm + * for each model component. and we call init_inracomm independently + * for each component. + * + * When the IO tasks are independent of any model component then we + * can have all of the components share one set of iotasks and we call + * init_intercomm once with the information for all components. + * + * Inter vs Intra Communicators + * ---------------------------- + * + * ​For an intra you just need to provide the compute comm, pio creates + * an io comm as a subset of that compute comm. + * + * For an inter you need to provide multiple comms - peer comm is the + * communicator that is going to encompass all of the tasks - usually + * this will be mpi_comm_world. Then you need to provide a comm for + * each component model that will share the io server, then an + * io_comm. + * + * Example of Communicators + * ------------------------ + * + * Starting from MPI_COMM_WORLD the calling program will create an + * IO_COMM and one or more COMP_COMMs, I think an example might be best: + * + * Suppose we have 10 tasks and 2 of them will be IO tasks. Then 0:7 + * are in COMP_COMM and 8:9 are in IO_COMM In this case on tasks 0:7 + * COMP_COMM is defined and IO_COMM is MPI_COMM_NULL and on tasks 8:9 + * IO_COMM is defined and COMP_COMM is MPI_COMM_NULL The communicators + * to handle communications between COMP_COMM and IO_COMM are defined + * in init_intercomm and held in a pio internal data structure. + * + * Return or Not + * ------------- + * + * The io_comm tasks do not return from the init_intercomm routine. + * + * Sequence of Events to do Asynch I/O + * ----------------------------------- + * + * Here is the sequence of events that needs to occur when an IO + * operation is called from the collection of compute tasks. I'm + * going to use pio_put_var because write_darray has some special + * characteristics that make it a bit more complicated... + * + * Compute tasks call pio_put_var with an integer argument + * + * The MPI_Send sends a message from comp_rank=0 to io_rank=0 on + * union_comm (a comm defined as the union of io and compute tasks) + * msg is an integer which indicates the function being called, in + * this case the msg is PIO_MSG_PUT_VAR_INT + * + * The iotasks now know what additional arguments they should expect + * to receive from the compute tasks, in this case a file handle, a + * variable id, the length of the array and the array itself. + * + * The iotasks now have the information they need to complete the + * operation and they call the pio_put_var routine. (In pio1 this bit + * of code is in pio_get_put_callbacks.F90.in) + * + * After the netcdf operation is completed (in the case of an inq or + * get operation) the result is communicated back to the compute + * tasks. + * + * + * @param component_count The number of computational (ex. model) + * components to associate with this IO component + * + * @param peer_comm The communicator from which all other communicator + * arguments are derived + * + * @param comp_comms An array containing the computational + * communicator for each of the computational components. The I/O + * tasks pass MPI_COMM_NULL for this parameter. + * +`* @param io_comm The io communicator. Processing tasks pass + * MPI_COMM_NULL for this parameter. + * + * @param iosysidp An array of length component_count. It will get the + * iosysid for each component. + * + * @return PIO_NOERR on success, error code otherwise. + */ +int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, + MPI_Comm *comp_comms, MPI_Comm io_comm, int *iosysidp) +{ + iosystem_desc_t *iosys; + iosystem_desc_t *my_iosys; + int ierr = PIO_NOERR; + int mpierr; + int my_rank; + int iam; + int io_leader, comp_leader; + int root; + + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + /* Allocate struct to hold io system info for each component. */ + if (!(iosys = (iosystem_desc_t *) calloc(1, sizeof(iosystem_desc_t) * component_count))) + ierr = PIO_ENOMEM; + + if (!ierr) + for (int cmp = 0; cmp < component_count; cmp++) + { + /* These are used when using the intercomm. */ + int comp_master = MPI_PROC_NULL, io_master = MPI_PROC_NULL; + + /* Get a pointer to the iosys struct */ + my_iosys = &iosys[cmp]; + + /* Create an MPI info object. */ + CheckMPIReturn(MPI_Info_create(&(my_iosys->info)),__FILE__,__LINE__); + + /* This task is part of the computation communicator. */ + if (comp_comms[cmp] != MPI_COMM_NULL) + { + /* Copy the computation communicator. */ + mpierr = MPI_Comm_dup(comp_comms[cmp], &my_iosys->comp_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create an MPI group with the computation tasks. */ + mpierr = MPI_Comm_group(my_iosys->comp_comm, &my_iosys->compgroup); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find out how many tasks are in this communicator. */ + mpierr = MPI_Comm_size(iosys->comp_comm, &my_iosys->num_comptasks); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Set the rank within the comp_comm. */ + mpierr = MPI_Comm_rank(my_iosys->comp_comm, &my_iosys->comp_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in peer_comm. */ + iam = -1; + mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the comp leader in peer_comm. */ + if (!my_iosys->comp_rank) + { + mpierr = MPI_Comm_rank(peer_comm, &iam); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + iam = -1; + + /* Find the lucky comp_leader task. */ + mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Is this the compmaster? Only if the comp_rank is zero. */ + if (!my_iosys->comp_rank) + { + my_iosys->compmaster = MPI_ROOT; + comp_master = MPI_ROOT; + } + else + my_iosys->compmaster = MPI_PROC_NULL; + + /* Set up the intercomm from the computation side. */ + mpierr = MPI_Intercomm_create(my_iosys->comp_comm, 0, peer_comm, + io_leader, cmp, &my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create the union communicator. */ + mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + { + my_iosys->comp_comm = MPI_COMM_NULL; + my_iosys->compgroup = MPI_GROUP_NULL; + my_iosys->comp_rank = -1; + } + + /* This task is part of the IO communicator, so set up the + * IO stuff. */ + if (io_comm != MPI_COMM_NULL) + { + /* Copy the IO communicator. */ + mpierr = MPI_Comm_dup(io_comm, &my_iosys->io_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Get an MPI group that includes the io tasks. */ + mpierr = MPI_Comm_group(my_iosys->io_comm, &my_iosys->iogroup); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find out how many tasks are in this communicator. */ + mpierr = MPI_Comm_size(iosys->io_comm, &my_iosys->num_iotasks); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Set the rank within the io_comm. */ + mpierr = MPI_Comm_rank(my_iosys->io_comm, &my_iosys->io_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in peer_comm. */ + if (!my_iosys->io_rank) + { + mpierr = MPI_Comm_rank(peer_comm, &iam); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + iam = -1; + + /* Find the lucky io_leader task. */ + mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the comp leader in peer_comm. */ + iam = -1; + mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* This is an io task. */ + my_iosys->ioproc = true; + + /* Is this the iomaster? Only if the io_rank is zero. */ + if (!my_iosys->io_rank) + { + my_iosys->iomaster = MPI_ROOT; + io_master = MPI_ROOT; + } + else + my_iosys->iomaster = 0; + + /* Set up the intercomm from the I/O side. */ + mpierr = MPI_Intercomm_create(my_iosys->io_comm, 0, peer_comm, + comp_leader, cmp, &my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create the union communicator. */ + mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + } + else + { + my_iosys->io_comm = MPI_COMM_NULL; + my_iosys->iogroup = MPI_GROUP_NULL; + my_iosys->io_rank = -1; + my_iosys->ioproc = false; + my_iosys->iomaster = false; + } + + /* my_comm points to the union communicator for async, and + * the comp_comm for non-async. It should not be freed + * since it is not a proper copy of the commuicator, just + * a copy of the reference to it. */ + my_iosys->my_comm = my_iosys->union_comm; + + /* Find rank in union communicator. */ + mpierr = MPI_Comm_rank(my_iosys->union_comm, &my_iosys->union_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in the union communicator. */ + if (!my_iosys->io_rank) + my_iosys->ioroot = my_iosys->union_rank; + else + my_iosys->ioroot = -1; + + /* Distribute the answer to all tasks. */ + mpierr = MPI_Allreduce(&my_iosys->ioroot, &root, 1, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + my_iosys->ioroot = root; + + /* Find the rank of the computation leader in the union + * communicator. */ + if (!my_iosys->comp_rank) + my_iosys->comproot = my_iosys->union_rank; + else + my_iosys->comproot = -1; + + /* Distribute the answer to all tasks. */ + mpierr = MPI_Allreduce(&my_iosys->comproot, &root, 1, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + my_iosys->comproot = root; + + /* Send the number of tasks in the IO and computation + communicators to each other over the intercomm. This is + a one-to-all bcast from the local task that passes + MPI_ROOT as the root (all other local tasks should pass + MPI_PROC_NULL as the root). The bcast is recieved by + all the members of the leaf group which each pass the + rank of the root relative to the root group. */ + if (io_comm != MPI_COMM_NULL) + { + comp_master = 0; + mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + else + { + io_master = 0; + mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + + /* Allocate an array to hold the ranks of the IO tasks + * within the union communicator. */ + printf("%d allocating for %d iotasks\n", my_rank, my_iosys->num_iotasks); + if (!(my_iosys->ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) + return PIO_ENOMEM; + printf("%d allocated\n", my_rank); + + /* Allocate a temp array to help get the IO ranks. */ + int *tmp_ioranks; + if (!(tmp_ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) + return PIO_ENOMEM; + + /* Init array, then have IO tasks set their values, then + * use allreduce to distribute results to all tasks. */ + for (int cnt = 0 ; cnt < my_iosys->num_iotasks; cnt++) + tmp_ioranks[cnt] = -1; + if (io_comm != MPI_COMM_NULL) + tmp_ioranks[my_iosys->io_rank] = my_iosys->union_rank; + mpierr = MPI_Allreduce(tmp_ioranks, my_iosys->ioranks, my_iosys->num_iotasks, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + + /* Free temp array. */ + free(tmp_ioranks); + + /* Set the default error handling. */ + my_iosys->error_handler = PIO_INTERNAL_ERROR; + + /* We do support asynch interface. */ + my_iosys->async_interface = true; + + /* For debug purposes, print the contents of the struct. */ + for (int t = 0; t < my_iosys->num_iotasks + my_iosys->num_comptasks; t++) + { + MPI_Barrier(my_iosys->union_comm); + if (my_rank == t) + pio_iosys_print(my_rank, my_iosys); + } + + /* Add this id to the list of PIO iosystem ids. */ + iosysidp[cmp] = pio_add_to_iosystem_list(my_iosys); + printf("%d added to iosystem_list iosysid = %d\n", my_rank, iosysidp[cmp]); + + /* Now call the function from which the IO tasks will not + * return until the PIO_MSG_EXIT message is sent. */ + if (io_comm != MPI_COMM_NULL) + { + printf("%d about to call pio_msg_handler\n", my_rank); + if ((ierr = pio_msg_handler(my_iosys->io_rank, component_count, iosys))) + return ierr; + } + + } + + /* If there was an error, make sure all tasks see it. */ + if (ierr) + { + /*mpierr = MPI_Bcast(&ierr, 1, MPI_INT, iosys->my_rank, iosys->intercomm);*/ + mpierr = MPI_Bcast(&ierr, 1, MPI_INT, 0, iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + + return ierr; +} + /** ** @ingroup PIO_init ** @brief library initialization used when IO tasks are a subset of compute tasks diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 66d8995f7af1..3d26a75f18c3 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -43,6 +43,11 @@ if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU") PRIVATE -ffree-line-length-none) endif() +if (PIO_ENABLE_ASYNC) + add_executable (test_intercomm EXCLUDE_FROM_ALL test_intercomm.c) + target_link_libraries (test_intercomm pioc) + add_dependencies (tests test_intercomm) +endif () add_executable (test_names EXCLUDE_FROM_ALL test_names.c) target_link_libraries (test_names pioc) add_executable (test_nc4 EXCLUDE_FROM_ALL test_nc4.c) @@ -62,6 +67,10 @@ add_dependencies (tests pio_unit_test) set (DEFAULT_TEST_TIMEOUT 240) if (PIO_USE_MPISERIAL) + if (PIO_ENABLE_ASYNC) + add_test(NAME test_intercomm + COMMAND test_intercomm) + endif () add_test(NAME test_names COMMAND test_names) add_test(NAME test_nc4 @@ -71,6 +80,12 @@ if (PIO_USE_MPISERIAL) set_tests_properties(pio_unit_test PROPERTIES TIMEOUT ${DEFAULT_TEST_TIMEOUT}) else () + if (PIO_ENABLE_ASYNC) + add_mpi_test(test_intercomm + EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_intercomm + NUMPROCS 4 + TIMEOUT ${DEFAULT_TEST_TIMEOUT}) + endif () add_mpi_test(test_names EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_names NUMPROCS 4 diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c new file mode 100644 index 000000000000..a78a1d6b71db --- /dev/null +++ b/tests/unit/test_intercomm.c @@ -0,0 +1,399 @@ +/** + * @file Tests for PIOc_Intercomm. This tests the Init_Intercomm() + * function, and basic asynch I/O capability. + * + */ +#include +#ifdef TIMING +#include +#endif + +/** The number of possible output netCDF output flavors available to + * the ParallelIO library. */ +#define NUM_NETCDF_FLAVORS 4 + +/** The number of dimensions in the test data. */ +#define NDIM 1 + +/** The length of our test data. */ +#define DIM_LEN 4 + +/** The length of data on each (of 2) computational task. */ +#define LOCAL_DIM_LEN 2 + +/** The name of the dimension in the netCDF output file. */ +#define DIM_NAME "dim_test_intercomm" + +/** The name of the variable in the netCDF output file. */ +#define VAR_NAME "var_test_intercomm" + +/** The name of the global attribute in the netCDF output file. */ +#define ATT_NAME "gatt_test_intercomm" + +/** Error code for when things go wrong. */ +#define ERR_AWFUL 1111 +#define ERR_WRONG 2222 + +/** Handle MPI errors. This should only be used with MPI library + * function calls. */ +#define MPIERR(e) do { \ + MPI_Error_string(e, err_buffer, &resultlen); \ + fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \ + MPI_Finalize(); \ + return ERR_AWFUL; \ + } while (0) + +/** Handle non-MPI errors by finalizing the MPI library and exiting + * with an exit code. */ +#define ERR(e) do { \ + fprintf(stderr, "Error %d in %s, line %d\n", e, __FILE__, __LINE__); \ + MPI_Finalize(); \ + return e; \ + } while (0) + +/** Global err buffer for MPI. When there is an MPI error, this buffer + * is used to store the error message that is associated with the MPI + * error. */ +char err_buffer[MPI_MAX_ERROR_STRING]; + +/** This is the length of the most recent MPI error message, stored + * int the global error string. */ +int resultlen; + +/** Run Tests for Init_Intercomm + * + * @param argc argument count + * @param argv array of arguments + */ +int +main(int argc, char **argv) +{ + int verbose = 1; + + /** Zero-based rank of processor. */ + int my_rank; + + /** Number of processors involved in current execution. */ + int ntasks; + + /** Specifies the flavor of netCDF output format. */ + int iotype; + + /** Different output flavors. */ + int format[NUM_NETCDF_FLAVORS] = {PIO_IOTYPE_PNETCDF, + PIO_IOTYPE_NETCDF, + PIO_IOTYPE_NETCDF4C, + PIO_IOTYPE_NETCDF4P}; + + /** Names for the output files. */ + char filename[NUM_NETCDF_FLAVORS][NC_MAX_NAME + 1] = {"test_nc4_pnetcdf.nc", + "test_nc4_classic.nc", + "test_nc4_serial4.nc", + "test_nc4_parallel4.nc"}; + + /** Number of processors that will do IO. In this test we + * will do IO from all processors. */ + int niotasks; + + /** The ID for the parallel I/O system. */ + int iosysid; + + /** The ncid of the netCDF file. */ + int ncid; + + /** The ID of the netCDF varable. */ + int varid; + + /** Return code. */ + int ret; + + /** Index for loops. */ + int fmt, d, d1, i; + +#ifdef TIMING + /* Initialize the GPTL timing library. */ + if ((ret = GPTLinitialize ())) + return ret; +#endif + + /* Initialize MPI. */ + if ((ret = MPI_Init(&argc, &argv))) + MPIERR(ret); + + /* Learn my rank and the total number of processors. */ + if ((ret = MPI_Comm_rank(MPI_COMM_WORLD, &my_rank))) + MPIERR(ret); + if ((ret = MPI_Comm_size(MPI_COMM_WORLD, &ntasks))) + MPIERR(ret); + + /* Check that a valid number of processors was specified. */ + if (!(ntasks == 1 || ntasks == 2 || ntasks == 4 || + ntasks == 8 || ntasks == 16)) + fprintf(stderr, "test_intercomm Number of processors must be exactly 4!\n"); + if (verbose) + printf("%d: test_intercomm ParallelIO Library test_intercomm running on %d processors.\n", + my_rank, ntasks); + + /* keep things simple - 1 iotask per MPI process */ + niotasks = ntasks; + + /* For example, if I have 4 processors, and I want to have 2 of them be computational, */ + /* and 2 of them be IO: component count is 1 */ + /* peer_comm = MPI_COMM_WORLD */ + /* comp_comms is an array of comms of size 1 with a comm defined just over tasks (0,1) */ + /* io_comm is a comm over tasks (2,3) */ + + /* Initialize the PIO IO system. This specifies how many and which + * processors are involved in I/O. */ +#define COMPONENT_COUNT 1 + MPI_Comm comp_comms; + MPI_Comm io_comm; + MPI_Group io_group; + MPI_Group comp_group; + + /* Tasks 0 and 1 will be computational. Tasks 2 and 3 will be I/O + * tasks. */ + + // Get the group of processes in MPI_COMM_WORLD + MPI_Group world_group; + MPI_Comm_group(MPI_COMM_WORLD, &world_group); + int comp_task; + + if (my_rank == 0 || my_rank == 1) + { + /* We will define comp_comm. The io_comm will get null. */ + io_comm = MPI_COMM_NULL; + int n = 2; + const int ranks[2] = {0, 1}; + + /* Construct a group with ranks 0, 1 in world_group. */ + MPI_Group_incl(world_group, n, ranks, &comp_group); + MPI_Comm_create_group(MPI_COMM_WORLD, comp_group, 0, &comp_comms); + if (verbose) + printf("%d test_intercomm included in comp_group.\n", my_rank); + + comp_task = 1; + } + else + { + /* We will define io_comm. The comp_comms array will get nulls. */ + comp_comms = MPI_COMM_NULL; + int n = 2; + const int ranks[2] = {2, 3}; + + /* Construct a group with ranks 2, 3 in world_group. */ + MPI_Group_incl(world_group, n, ranks, &io_group); + MPI_Comm_create_group(MPI_COMM_WORLD, io_group, 0, &io_comm); + if (verbose) + printf("%d test_intercomm included in io_group.\n", my_rank); + + comp_task = 0; + } + + if ((ret = PIOc_Init_Intercomm(COMPONENT_COUNT, MPI_COMM_WORLD, &comp_comms, + io_comm, &iosysid))) + ERR(ret); + if (verbose) + printf("%d test_intercomm init intercomm returned %d iosysid = %d\n", my_rank, ret, + iosysid); + + /* All the netCDF calls are only executed on the computation + * tasks. The IO tasks have not returned from PIOc_Init_Intercomm, + * and when the do, they should go straight to finalize. */ + if (comp_task) + { + for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) + { + int ncid, varid, dimid; + PIO_Offset start[NDIM], count[NDIM] = {0}; + int data[LOCAL_DIM_LEN]; + + /* Create a netCDF file with one dimension and one variable. */ + if (verbose) + printf("%d test_intercomm creating file %s\n", my_rank, filename[fmt]); + if ((ret = PIOc_createfile(iosysid, &ncid, &format[fmt], filename[fmt], + NC_CLOBBER))) + ERR(ret); + if (verbose) + printf("%d test_intercomm file created ncid = %d\n", my_rank, ncid); + + if (verbose) + printf("%d test_intercomm defining dimension %s\n", my_rank, DIM_NAME); + if ((ret = PIOc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid))) + ERR(ret); + if (verbose) + printf("%d test_intercomm defining variable %s\n", my_rank, VAR_NAME); + if ((ret = PIOc_def_var(ncid, VAR_NAME, NC_INT, NDIM, &dimid, &varid))) + ERR(ret); + + /* Add a global attribute. */ + /* int att_data = 42; */ + /* if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) */ + /* ERR(ret); */ + + /* Close the file. */ + if (verbose) + printf("%d test_intercomm ending define mode ncid = %d\n", my_rank, ncid); + if ((ret = PIOc_enddef(ncid))) + ERR(ret); + + /* Write some data. */ + for (int i = 0; i < LOCAL_DIM_LEN; i++) + data[i] = my_rank; + if (verbose) + printf("%d test_intercomm writing data\n", my_rank); + start[0] = !my_rank ? 0 : 2; + /* if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) */ + /* ERR(ret); */ + + /* Close the file. */ + if (verbose) + printf("%d test_intercomm closing file ncid = %d\n", my_rank, ncid); + if ((ret = PIOc_closefile(ncid))) + ERR(ret); + + /* Re-open the file to check it. */ + if (verbose) + printf("%d test_intercomm opening file %s\n", my_rank, filename[fmt]); + if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], + NC_NOWRITE))) + ERR(ret); + + /* Find the number of dimensions, variables, and global attributes.*/ + int ndims, nvars, ngatts, unlimdimid; + if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) + ERR(ret); + if (ndims != 1 || nvars != 1 || ngatts != 0 || unlimdimid != -1) + ERR(ERR_WRONG); + int ndims2, nvars2, ngatts2, unlimdimid2; + if ((ret = PIOc_inq_ndims(ncid, &ndims2))) + ERR(ret); + if (ndims2 != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_nvars(ncid, &nvars2))) + ERR(ret); + if (nvars2 != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_natts(ncid, &ngatts2))) + ERR(ret); + if (ngatts2 != 0) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) + ERR(ret); + if (unlimdimid != -1) + ERR(ERR_WRONG); + + /* Check out the dimension. */ + char dimname[NC_MAX_NAME + 1]; + PIO_Offset dimlen; + if ((ret = PIOc_inq_dim(ncid, 0, dimname, &dimlen))) + ERR(ret); + printf("%d test_intercomm dim name is %s VAR_NAME is %s\n", my_rank, dimname, VAR_NAME); + if (strcmp(dimname, DIM_NAME) || dimlen != DIM_LEN) + ERR(ERR_WRONG); + char dimname2[NC_MAX_NAME + 1]; + PIO_Offset dimlen2; + if ((ret = PIOc_inq_dimname(ncid, 0, dimname2))) + ERR(ret); + if (strcmp(dimname2, DIM_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_dimlen(ncid, 0, &dimlen2))) + ERR(ret); + if (dimlen2 != DIM_LEN) + ERR(ERR_WRONG); + int dimid2; + if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) + ERR(ret); + if (dimid2 != 0) + ERR(ERR_WRONG); + + /* Check out the variable. */ + char varname[NC_MAX_NAME + 1]; + nc_type vartype; + int varndims, vardimids, varnatts; + if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) + ERR(ret); + if (strcmp(varname, VAR_NAME) || vartype != NC_INT || varndims != NDIM || + vardimids != 0 || varnatts != 0) + ERR(ERR_WRONG); + char varname2[NC_MAX_NAME + 1]; + nc_type vartype2; + int varndims2, vardimids2, varnatts2; + if ((ret = PIOc_inq_varname(ncid, 0, varname2))) + ERR(ret); + if (strcmp(varname2, VAR_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_vartype(ncid, 0, &vartype2))) + ERR(ret); + if (vartype2 != NC_INT) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_varndims(ncid, 0, &varndims2))) + ERR(ret); + if (varndims2 != NDIM) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_vardimid(ncid, 0, &vardimids2))) + ERR(ret); + if (vardimids2 != 0) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_varnatts(ncid, 0, &varnatts2))) + ERR(ret); + if (varnatts2 != 0) + ERR(ERR_WRONG); + int varid2; + if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) + ERR(ret); + if (varid2 != 0) + ERR(ERR_WRONG); + + /* Close the file. */ + if (verbose) + printf("%d test_intercomm closing file (again) ncid = %d\n", my_rank, ncid); + if ((ret = PIOc_closefile(ncid))) + ERR(ret); + + /* Now delete the file. */ + if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) + ERR(ret); + /* if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], */ + /* NC_NOWRITE)) != PIO_ENFILE) */ + /* ERR(ERR_AWFUL); */ + + } /* next netcdf format flavor */ + } + + /* Free local MPI resources. */ + if (verbose) + printf("%d test_intercomm Freeing local MPI resources...\n", my_rank); + MPI_Group_free(&world_group); + if (comp_task) + { + MPI_Group_free(&comp_group); + MPI_Comm_free(&comp_comms); + } + else + { + MPI_Group_free(&io_group); + MPI_Comm_free(&io_comm); + } + + /* Finalize the IO system. */ + if (verbose) + printf("%d test_intercomm Freeing PIO resources...\n", my_rank); + if ((ret = PIOc_finalize(iosysid))) + ERR(ret); + + /* Finalize the MPI library. */ + MPI_Finalize(); + +#ifdef TIMING + /* Finalize the GPTL timing library. */ + if ((ret = GPTLfinalize())) + return ret; +#endif + + if (verbose) + printf("%d test_intercomm SUCCESS!!\n", my_rank); + + + return 0; +} From b16142f0337bb356578f2e3a5d2147e5774eaa87 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 5 May 2016 11:02:16 -0400 Subject: [PATCH 02/83] got non-async build working --- src/clib/CMakeLists.txt | 12 +- src/clib/pio_msg.c | 457 +++++++++++++++++++++++++++++++++++++++ src/clib/pioc.c | 458 ---------------------------------------- 3 files changed, 464 insertions(+), 463 deletions(-) diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index f5448d4d5c23..21d7dcb375ee 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -18,14 +18,16 @@ set (PIO_C_SRCS topology.c bget.c) set (PIO_GENNC_SRCS - ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c) + ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c) if (PIO_ENABLE_ASYNC) - set (PIO_ADDL_SRCS pio_nc2.c pio_msg.c) + set (PIO_ADDL_SRCS pio_nc_async.c pio_put_nc_async.c pio_get_nc_async.c pio_msg.c) else () - set (PIO_ADDL_SRCS pio_nc.c) + set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c) + set (PIO_ADDL_SRCS ${PIO_GENNC_SRC}) endif () add_library (pioc ${PIO_C_SRCS} ${PIO_GENNC_SRCS} ${PIO_ADDL_SRCS}) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index a2bc45e955e5..ed13ebec41c3 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -966,3 +966,460 @@ pio_iosys_print(int my_rank, iosystem_desc_t *iosys) return PIO_NOERR; } +/** @ingroup PIO_init + * Library initialization used when IO tasks are distinct from compute + * tasks. + * + * This is a collective call. Input parameters are read on + * comp_rank=0 values on other tasks are ignored. This variation of + * PIO_init sets up a distinct set of tasks to handle IO, these tasks + * do not return from this call. Instead they go to an internal loop + * and wait to receive further instructions from the computational + * tasks. + * + * For 4 tasks, to have 2 of them be computational, and 2 of them + * be IO, I would provide the following: + * + * component_count = 1 + * + * peer_comm = MPI_COMM_WORLD + * + * comp_comms = an array with one element, an MPI (intra) communicator + * that contains the two tasks designated to do computation + * (processors 0, 1). + + * io_comm = an MPI (intra) communicator with the other two tasks (2, + * 3). + * + * iosysidp = pointer that gets the IO system ID. + * + * Fortran function (from PIO1, in piolib_mod.F90) is: + * + * subroutine init_intercom(component_count, peer_comm, comp_comms, + * io_comm, iosystem, rearr_opts) + * + * Some notes from Jim: + * + * Components and Component Count + * ------------------------------ + * + * It's a cesm thing - the cesm model is composed of several component + * models (atm, ocn, ice, lnd, etc) that may or may not be collocated + * on mpi tasks. Since for intercomm the IOCOMM tasks are a subset of + * the compute tasks for a given component we have a separate iocomm + * for each model component. and we call init_inracomm independently + * for each component. + * + * When the IO tasks are independent of any model component then we + * can have all of the components share one set of iotasks and we call + * init_intercomm once with the information for all components. + * + * Inter vs Intra Communicators + * ---------------------------- + * + * ​For an intra you just need to provide the compute comm, pio creates + * an io comm as a subset of that compute comm. + * + * For an inter you need to provide multiple comms - peer comm is the + * communicator that is going to encompass all of the tasks - usually + * this will be mpi_comm_world. Then you need to provide a comm for + * each component model that will share the io server, then an + * io_comm. + * + * Example of Communicators + * ------------------------ + * + * Starting from MPI_COMM_WORLD the calling program will create an + * IO_COMM and one or more COMP_COMMs, I think an example might be best: + * + * Suppose we have 10 tasks and 2 of them will be IO tasks. Then 0:7 + * are in COMP_COMM and 8:9 are in IO_COMM In this case on tasks 0:7 + * COMP_COMM is defined and IO_COMM is MPI_COMM_NULL and on tasks 8:9 + * IO_COMM is defined and COMP_COMM is MPI_COMM_NULL The communicators + * to handle communications between COMP_COMM and IO_COMM are defined + * in init_intercomm and held in a pio internal data structure. + * + * Return or Not + * ------------- + * + * The io_comm tasks do not return from the init_intercomm routine. + * + * Sequence of Events to do Asynch I/O + * ----------------------------------- + * + * Here is the sequence of events that needs to occur when an IO + * operation is called from the collection of compute tasks. I'm + * going to use pio_put_var because write_darray has some special + * characteristics that make it a bit more complicated... + * + * Compute tasks call pio_put_var with an integer argument + * + * The MPI_Send sends a message from comp_rank=0 to io_rank=0 on + * union_comm (a comm defined as the union of io and compute tasks) + * msg is an integer which indicates the function being called, in + * this case the msg is PIO_MSG_PUT_VAR_INT + * + * The iotasks now know what additional arguments they should expect + * to receive from the compute tasks, in this case a file handle, a + * variable id, the length of the array and the array itself. + * + * The iotasks now have the information they need to complete the + * operation and they call the pio_put_var routine. (In pio1 this bit + * of code is in pio_get_put_callbacks.F90.in) + * + * After the netcdf operation is completed (in the case of an inq or + * get operation) the result is communicated back to the compute + * tasks. + * + * + * @param component_count The number of computational (ex. model) + * components to associate with this IO component + * + * @param peer_comm The communicator from which all other communicator + * arguments are derived + * + * @param comp_comms An array containing the computational + * communicator for each of the computational components. The I/O + * tasks pass MPI_COMM_NULL for this parameter. + * +`* @param io_comm The io communicator. Processing tasks pass + * MPI_COMM_NULL for this parameter. + * + * @param iosysidp An array of length component_count. It will get the + * iosysid for each component. + * + * @return PIO_NOERR on success, error code otherwise. + */ +int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, + MPI_Comm *comp_comms, MPI_Comm io_comm, int *iosysidp) +{ + iosystem_desc_t *iosys; + iosystem_desc_t *my_iosys; + int ierr = PIO_NOERR; + int mpierr; + int my_rank; + int iam; + int io_leader, comp_leader; + int root; + + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + /* Allocate struct to hold io system info for each component. */ + if (!(iosys = (iosystem_desc_t *) calloc(1, sizeof(iosystem_desc_t) * component_count))) + ierr = PIO_ENOMEM; + + if (!ierr) + for (int cmp = 0; cmp < component_count; cmp++) + { + /* These are used when using the intercomm. */ + int comp_master = MPI_PROC_NULL, io_master = MPI_PROC_NULL; + + /* Get a pointer to the iosys struct */ + my_iosys = &iosys[cmp]; + + /* Create an MPI info object. */ + CheckMPIReturn(MPI_Info_create(&(my_iosys->info)),__FILE__,__LINE__); + + /* This task is part of the computation communicator. */ + if (comp_comms[cmp] != MPI_COMM_NULL) + { + /* Copy the computation communicator. */ + mpierr = MPI_Comm_dup(comp_comms[cmp], &my_iosys->comp_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create an MPI group with the computation tasks. */ + mpierr = MPI_Comm_group(my_iosys->comp_comm, &my_iosys->compgroup); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find out how many tasks are in this communicator. */ + mpierr = MPI_Comm_size(iosys->comp_comm, &my_iosys->num_comptasks); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Set the rank within the comp_comm. */ + mpierr = MPI_Comm_rank(my_iosys->comp_comm, &my_iosys->comp_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in peer_comm. */ + iam = -1; + mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the comp leader in peer_comm. */ + if (!my_iosys->comp_rank) + { + mpierr = MPI_Comm_rank(peer_comm, &iam); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + iam = -1; + + /* Find the lucky comp_leader task. */ + mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Is this the compmaster? Only if the comp_rank is zero. */ + if (!my_iosys->comp_rank) + { + my_iosys->compmaster = MPI_ROOT; + comp_master = MPI_ROOT; + } + else + my_iosys->compmaster = MPI_PROC_NULL; + + /* Set up the intercomm from the computation side. */ + mpierr = MPI_Intercomm_create(my_iosys->comp_comm, 0, peer_comm, + io_leader, cmp, &my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create the union communicator. */ + mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + { + my_iosys->comp_comm = MPI_COMM_NULL; + my_iosys->compgroup = MPI_GROUP_NULL; + my_iosys->comp_rank = -1; + } + + /* This task is part of the IO communicator, so set up the + * IO stuff. */ + if (io_comm != MPI_COMM_NULL) + { + /* Copy the IO communicator. */ + mpierr = MPI_Comm_dup(io_comm, &my_iosys->io_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Get an MPI group that includes the io tasks. */ + mpierr = MPI_Comm_group(my_iosys->io_comm, &my_iosys->iogroup); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find out how many tasks are in this communicator. */ + mpierr = MPI_Comm_size(iosys->io_comm, &my_iosys->num_iotasks); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Set the rank within the io_comm. */ + mpierr = MPI_Comm_rank(my_iosys->io_comm, &my_iosys->io_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in peer_comm. */ + if (!my_iosys->io_rank) + { + mpierr = MPI_Comm_rank(peer_comm, &iam); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + else + iam = -1; + + /* Find the lucky io_leader task. */ + mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the comp leader in peer_comm. */ + iam = -1; + mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* This is an io task. */ + my_iosys->ioproc = true; + + /* Is this the iomaster? Only if the io_rank is zero. */ + if (!my_iosys->io_rank) + { + my_iosys->iomaster = MPI_ROOT; + io_master = MPI_ROOT; + } + else + my_iosys->iomaster = 0; + + /* Set up the intercomm from the I/O side. */ + mpierr = MPI_Intercomm_create(my_iosys->io_comm, 0, peer_comm, + comp_leader, cmp, &my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Create the union communicator. */ + mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + } + else + { + my_iosys->io_comm = MPI_COMM_NULL; + my_iosys->iogroup = MPI_GROUP_NULL; + my_iosys->io_rank = -1; + my_iosys->ioproc = false; + my_iosys->iomaster = false; + } + + /* my_comm points to the union communicator for async, and + * the comp_comm for non-async. It should not be freed + * since it is not a proper copy of the commuicator, just + * a copy of the reference to it. */ + my_iosys->my_comm = my_iosys->union_comm; + + /* Find rank in union communicator. */ + mpierr = MPI_Comm_rank(my_iosys->union_comm, &my_iosys->union_rank); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + + /* Find the rank of the io leader in the union communicator. */ + if (!my_iosys->io_rank) + my_iosys->ioroot = my_iosys->union_rank; + else + my_iosys->ioroot = -1; + + /* Distribute the answer to all tasks. */ + mpierr = MPI_Allreduce(&my_iosys->ioroot, &root, 1, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + my_iosys->ioroot = root; + + /* Find the rank of the computation leader in the union + * communicator. */ + if (!my_iosys->comp_rank) + my_iosys->comproot = my_iosys->union_rank; + else + my_iosys->comproot = -1; + + /* Distribute the answer to all tasks. */ + mpierr = MPI_Allreduce(&my_iosys->comproot, &root, 1, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + my_iosys->comproot = root; + + /* Send the number of tasks in the IO and computation + communicators to each other over the intercomm. This is + a one-to-all bcast from the local task that passes + MPI_ROOT as the root (all other local tasks should pass + MPI_PROC_NULL as the root). The bcast is recieved by + all the members of the leaf group which each pass the + rank of the root relative to the root group. */ + if (io_comm != MPI_COMM_NULL) + { + comp_master = 0; + mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + else + { + io_master = 0; + mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, + my_iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + } + + /* Allocate an array to hold the ranks of the IO tasks + * within the union communicator. */ + printf("%d allocating for %d iotasks\n", my_rank, my_iosys->num_iotasks); + if (!(my_iosys->ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) + return PIO_ENOMEM; + printf("%d allocated\n", my_rank); + + /* Allocate a temp array to help get the IO ranks. */ + int *tmp_ioranks; + if (!(tmp_ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) + return PIO_ENOMEM; + + /* Init array, then have IO tasks set their values, then + * use allreduce to distribute results to all tasks. */ + for (int cnt = 0 ; cnt < my_iosys->num_iotasks; cnt++) + tmp_ioranks[cnt] = -1; + if (io_comm != MPI_COMM_NULL) + tmp_ioranks[my_iosys->io_rank] = my_iosys->union_rank; + mpierr = MPI_Allreduce(tmp_ioranks, my_iosys->ioranks, my_iosys->num_iotasks, MPI_INT, MPI_MAX, + my_iosys->union_comm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + + /* Free temp array. */ + free(tmp_ioranks); + + /* Set the default error handling. */ + my_iosys->error_handler = PIO_INTERNAL_ERROR; + + /* We do support asynch interface. */ + my_iosys->async_interface = true; + + /* For debug purposes, print the contents of the struct. */ + /* for (int t = 0; t < my_iosys->num_iotasks + my_iosys->num_comptasks; t++) */ + /* { */ + /* MPI_Barrier(my_iosys->union_comm); */ + /* if (my_rank == t) */ + /* pio_iosys_print(my_rank, my_iosys); */ + /* } */ + + /* Add this id to the list of PIO iosystem ids. */ + iosysidp[cmp] = pio_add_to_iosystem_list(my_iosys); + printf("%d added to iosystem_list iosysid = %d\n", my_rank, iosysidp[cmp]); + + /* Now call the function from which the IO tasks will not + * return until the PIO_MSG_EXIT message is sent. */ + if (io_comm != MPI_COMM_NULL) + { + printf("%d about to call pio_msg_handler\n", my_rank); + if ((ierr = pio_msg_handler(my_iosys->io_rank, component_count, iosys))) + return ierr; + } + + } + + /* If there was an error, make sure all tasks see it. */ + if (ierr) + { + /*mpierr = MPI_Bcast(&ierr, 1, MPI_INT, iosys->my_rank, iosys->intercomm);*/ + mpierr = MPI_Bcast(&ierr, 1, MPI_INT, 0, iosys->intercomm); + CheckMPIReturn(mpierr, __FILE__, __LINE__); + if (mpierr) + ierr = PIO_EIO; + } + + return ierr; +} + diff --git a/src/clib/pioc.c b/src/clib/pioc.c index b9127d47b8b8..afe7e85d9819 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -340,464 +340,6 @@ int PIOc_InitDecomp_bc(const int iosysid, const int basetype,const int ndims, co return PIO_NOERR; } - -/** @ingroup PIO_init - * Library initialization used when IO tasks are distinct from compute - * tasks. - * - * This is a collective call. Input parameters are read on - * comp_rank=0 values on other tasks are ignored. This variation of - * PIO_init sets up a distinct set of tasks to handle IO, these tasks - * do not return from this call. Instead they go to an internal loop - * and wait to receive further instructions from the computational - * tasks. - * - * For 4 tasks, to have 2 of them be computational, and 2 of them - * be IO, I would provide the following: - * - * component_count = 1 - * - * peer_comm = MPI_COMM_WORLD - * - * comp_comms = an array with one element, an MPI (intra) communicator - * that contains the two tasks designated to do computation - * (processors 0, 1). - - * io_comm = an MPI (intra) communicator with the other two tasks (2, - * 3). - * - * iosysidp = pointer that gets the IO system ID. - * - * Fortran function (from PIO1, in piolib_mod.F90) is: - * - * subroutine init_intercom(component_count, peer_comm, comp_comms, - * io_comm, iosystem, rearr_opts) - * - * Some notes from Jim: - * - * Components and Component Count - * ------------------------------ - * - * It's a cesm thing - the cesm model is composed of several component - * models (atm, ocn, ice, lnd, etc) that may or may not be collocated - * on mpi tasks. Since for intercomm the IOCOMM tasks are a subset of - * the compute tasks for a given component we have a separate iocomm - * for each model component. and we call init_inracomm independently - * for each component. - * - * When the IO tasks are independent of any model component then we - * can have all of the components share one set of iotasks and we call - * init_intercomm once with the information for all components. - * - * Inter vs Intra Communicators - * ---------------------------- - * - * ​For an intra you just need to provide the compute comm, pio creates - * an io comm as a subset of that compute comm. - * - * For an inter you need to provide multiple comms - peer comm is the - * communicator that is going to encompass all of the tasks - usually - * this will be mpi_comm_world. Then you need to provide a comm for - * each component model that will share the io server, then an - * io_comm. - * - * Example of Communicators - * ------------------------ - * - * Starting from MPI_COMM_WORLD the calling program will create an - * IO_COMM and one or more COMP_COMMs, I think an example might be best: - * - * Suppose we have 10 tasks and 2 of them will be IO tasks. Then 0:7 - * are in COMP_COMM and 8:9 are in IO_COMM In this case on tasks 0:7 - * COMP_COMM is defined and IO_COMM is MPI_COMM_NULL and on tasks 8:9 - * IO_COMM is defined and COMP_COMM is MPI_COMM_NULL The communicators - * to handle communications between COMP_COMM and IO_COMM are defined - * in init_intercomm and held in a pio internal data structure. - * - * Return or Not - * ------------- - * - * The io_comm tasks do not return from the init_intercomm routine. - * - * Sequence of Events to do Asynch I/O - * ----------------------------------- - * - * Here is the sequence of events that needs to occur when an IO - * operation is called from the collection of compute tasks. I'm - * going to use pio_put_var because write_darray has some special - * characteristics that make it a bit more complicated... - * - * Compute tasks call pio_put_var with an integer argument - * - * The MPI_Send sends a message from comp_rank=0 to io_rank=0 on - * union_comm (a comm defined as the union of io and compute tasks) - * msg is an integer which indicates the function being called, in - * this case the msg is PIO_MSG_PUT_VAR_INT - * - * The iotasks now know what additional arguments they should expect - * to receive from the compute tasks, in this case a file handle, a - * variable id, the length of the array and the array itself. - * - * The iotasks now have the information they need to complete the - * operation and they call the pio_put_var routine. (In pio1 this bit - * of code is in pio_get_put_callbacks.F90.in) - * - * After the netcdf operation is completed (in the case of an inq or - * get operation) the result is communicated back to the compute - * tasks. - * - * - * @param component_count The number of computational (ex. model) - * components to associate with this IO component - * - * @param peer_comm The communicator from which all other communicator - * arguments are derived - * - * @param comp_comms An array containing the computational - * communicator for each of the computational components. The I/O - * tasks pass MPI_COMM_NULL for this parameter. - * -`* @param io_comm The io communicator. Processing tasks pass - * MPI_COMM_NULL for this parameter. - * - * @param iosysidp An array of length component_count. It will get the - * iosysid for each component. - * - * @return PIO_NOERR on success, error code otherwise. - */ -int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, - MPI_Comm *comp_comms, MPI_Comm io_comm, int *iosysidp) -{ - iosystem_desc_t *iosys; - iosystem_desc_t *my_iosys; - int ierr = PIO_NOERR; - int mpierr; - int my_rank; - int iam; - int io_leader, comp_leader; - int root; - - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - - /* Allocate struct to hold io system info for each component. */ - if (!(iosys = (iosystem_desc_t *) calloc(1, sizeof(iosystem_desc_t) * component_count))) - ierr = PIO_ENOMEM; - - if (!ierr) - for (int cmp = 0; cmp < component_count; cmp++) - { - /* These are used when using the intercomm. */ - int comp_master = MPI_PROC_NULL, io_master = MPI_PROC_NULL; - - /* Get a pointer to the iosys struct */ - my_iosys = &iosys[cmp]; - - /* Create an MPI info object. */ - CheckMPIReturn(MPI_Info_create(&(my_iosys->info)),__FILE__,__LINE__); - - /* This task is part of the computation communicator. */ - if (comp_comms[cmp] != MPI_COMM_NULL) - { - /* Copy the computation communicator. */ - mpierr = MPI_Comm_dup(comp_comms[cmp], &my_iosys->comp_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Create an MPI group with the computation tasks. */ - mpierr = MPI_Comm_group(my_iosys->comp_comm, &my_iosys->compgroup); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find out how many tasks are in this communicator. */ - mpierr = MPI_Comm_size(iosys->comp_comm, &my_iosys->num_comptasks); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Set the rank within the comp_comm. */ - mpierr = MPI_Comm_rank(my_iosys->comp_comm, &my_iosys->comp_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find the rank of the io leader in peer_comm. */ - iam = -1; - mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find the rank of the comp leader in peer_comm. */ - if (!my_iosys->comp_rank) - { - mpierr = MPI_Comm_rank(peer_comm, &iam); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - } - else - iam = -1; - - /* Find the lucky comp_leader task. */ - mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Is this the compmaster? Only if the comp_rank is zero. */ - if (!my_iosys->comp_rank) - { - my_iosys->compmaster = MPI_ROOT; - comp_master = MPI_ROOT; - } - else - my_iosys->compmaster = MPI_PROC_NULL; - - /* Set up the intercomm from the computation side. */ - mpierr = MPI_Intercomm_create(my_iosys->comp_comm, 0, peer_comm, - io_leader, cmp, &my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Create the union communicator. */ - mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - } - else - { - my_iosys->comp_comm = MPI_COMM_NULL; - my_iosys->compgroup = MPI_GROUP_NULL; - my_iosys->comp_rank = -1; - } - - /* This task is part of the IO communicator, so set up the - * IO stuff. */ - if (io_comm != MPI_COMM_NULL) - { - /* Copy the IO communicator. */ - mpierr = MPI_Comm_dup(io_comm, &my_iosys->io_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Get an MPI group that includes the io tasks. */ - mpierr = MPI_Comm_group(my_iosys->io_comm, &my_iosys->iogroup); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find out how many tasks are in this communicator. */ - mpierr = MPI_Comm_size(iosys->io_comm, &my_iosys->num_iotasks); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Set the rank within the io_comm. */ - mpierr = MPI_Comm_rank(my_iosys->io_comm, &my_iosys->io_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find the rank of the io leader in peer_comm. */ - if (!my_iosys->io_rank) - { - mpierr = MPI_Comm_rank(peer_comm, &iam); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - } - else - iam = -1; - - /* Find the lucky io_leader task. */ - mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find the rank of the comp leader in peer_comm. */ - iam = -1; - mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* This is an io task. */ - my_iosys->ioproc = true; - - /* Is this the iomaster? Only if the io_rank is zero. */ - if (!my_iosys->io_rank) - { - my_iosys->iomaster = MPI_ROOT; - io_master = MPI_ROOT; - } - else - my_iosys->iomaster = 0; - - /* Set up the intercomm from the I/O side. */ - mpierr = MPI_Intercomm_create(my_iosys->io_comm, 0, peer_comm, - comp_leader, cmp, &my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Create the union communicator. */ - mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - } - else - { - my_iosys->io_comm = MPI_COMM_NULL; - my_iosys->iogroup = MPI_GROUP_NULL; - my_iosys->io_rank = -1; - my_iosys->ioproc = false; - my_iosys->iomaster = false; - } - - /* my_comm points to the union communicator for async, and - * the comp_comm for non-async. It should not be freed - * since it is not a proper copy of the commuicator, just - * a copy of the reference to it. */ - my_iosys->my_comm = my_iosys->union_comm; - - /* Find rank in union communicator. */ - mpierr = MPI_Comm_rank(my_iosys->union_comm, &my_iosys->union_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - - /* Find the rank of the io leader in the union communicator. */ - if (!my_iosys->io_rank) - my_iosys->ioroot = my_iosys->union_rank; - else - my_iosys->ioroot = -1; - - /* Distribute the answer to all tasks. */ - mpierr = MPI_Allreduce(&my_iosys->ioroot, &root, 1, MPI_INT, MPI_MAX, - my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - my_iosys->ioroot = root; - - /* Find the rank of the computation leader in the union - * communicator. */ - if (!my_iosys->comp_rank) - my_iosys->comproot = my_iosys->union_rank; - else - my_iosys->comproot = -1; - - /* Distribute the answer to all tasks. */ - mpierr = MPI_Allreduce(&my_iosys->comproot, &root, 1, MPI_INT, MPI_MAX, - my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - my_iosys->comproot = root; - - /* Send the number of tasks in the IO and computation - communicators to each other over the intercomm. This is - a one-to-all bcast from the local task that passes - MPI_ROOT as the root (all other local tasks should pass - MPI_PROC_NULL as the root). The bcast is recieved by - all the members of the leaf group which each pass the - rank of the root relative to the root group. */ - if (io_comm != MPI_COMM_NULL) - { - comp_master = 0; - mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, - my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, - my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - } - else - { - io_master = 0; - mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, - my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, - my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - } - - /* Allocate an array to hold the ranks of the IO tasks - * within the union communicator. */ - printf("%d allocating for %d iotasks\n", my_rank, my_iosys->num_iotasks); - if (!(my_iosys->ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) - return PIO_ENOMEM; - printf("%d allocated\n", my_rank); - - /* Allocate a temp array to help get the IO ranks. */ - int *tmp_ioranks; - if (!(tmp_ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) - return PIO_ENOMEM; - - /* Init array, then have IO tasks set their values, then - * use allreduce to distribute results to all tasks. */ - for (int cnt = 0 ; cnt < my_iosys->num_iotasks; cnt++) - tmp_ioranks[cnt] = -1; - if (io_comm != MPI_COMM_NULL) - tmp_ioranks[my_iosys->io_rank] = my_iosys->union_rank; - mpierr = MPI_Allreduce(tmp_ioranks, my_iosys->ioranks, my_iosys->num_iotasks, MPI_INT, MPI_MAX, - my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - - /* Free temp array. */ - free(tmp_ioranks); - - /* Set the default error handling. */ - my_iosys->error_handler = PIO_INTERNAL_ERROR; - - /* We do support asynch interface. */ - my_iosys->async_interface = true; - - /* For debug purposes, print the contents of the struct. */ - for (int t = 0; t < my_iosys->num_iotasks + my_iosys->num_comptasks; t++) - { - MPI_Barrier(my_iosys->union_comm); - if (my_rank == t) - pio_iosys_print(my_rank, my_iosys); - } - - /* Add this id to the list of PIO iosystem ids. */ - iosysidp[cmp] = pio_add_to_iosystem_list(my_iosys); - printf("%d added to iosystem_list iosysid = %d\n", my_rank, iosysidp[cmp]); - - /* Now call the function from which the IO tasks will not - * return until the PIO_MSG_EXIT message is sent. */ - if (io_comm != MPI_COMM_NULL) - { - printf("%d about to call pio_msg_handler\n", my_rank); - if ((ierr = pio_msg_handler(my_iosys->io_rank, component_count, iosys))) - return ierr; - } - - } - - /* If there was an error, make sure all tasks see it. */ - if (ierr) - { - /*mpierr = MPI_Bcast(&ierr, 1, MPI_INT, iosys->my_rank, iosys->intercomm);*/ - mpierr = MPI_Bcast(&ierr, 1, MPI_INT, 0, iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); - if (mpierr) - ierr = PIO_EIO; - } - - return ierr; -} - /** ** @ingroup PIO_init ** @brief library initialization used when IO tasks are a subset of compute tasks From d2664aff6c95c9229ad3979e90ac43aa92c77bda Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 5 May 2016 13:28:00 -0400 Subject: [PATCH 03/83] got async option working --- src/clib/CMakeLists.txt | 13 ++++---- src/clib/pio_msg.c | 60 ++++++++++++++----------------------- src/clib/pio_nc_async.c | 18 +++++++++-- tests/unit/test_intercomm.c | 4 ++- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 21d7dcb375ee..023b7b3dcbec 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -15,22 +15,21 @@ set (PIO_C_SRCS topology.c pio_spmd.c pio_rearrange.c pio_darray.c + pio_nc4.c bget.c) -set (PIO_GENNC_SRCS - ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c) +set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c + ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c) if (PIO_ENABLE_ASYNC) set (PIO_ADDL_SRCS pio_nc_async.c pio_put_nc_async.c pio_get_nc_async.c pio_msg.c) else () - set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c) set (PIO_ADDL_SRCS ${PIO_GENNC_SRC}) endif () -add_library (pioc ${PIO_C_SRCS} ${PIO_GENNC_SRCS} ${PIO_ADDL_SRCS}) +add_library (pioc ${PIO_C_SRCS} ${PIO_ADDL_SRCS}) # set up include-directories include_directories( diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index ed13ebec41c3..480f16ad7a41 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -241,6 +241,11 @@ int att_handler(iosystem_desc_t *ios, int msg) int varid; int mpierr; int ret; + char *name; + size_t namelen; + int len; + nc_type xtype; + int *op; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); @@ -251,45 +256,25 @@ int att_handler(iosystem_desc_t *ios, int msg) return PIO_EIO; if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inv_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); - - /* Call the inq_var function. */ - char name[NC_MAX_NAME + 1], *namep; - nc_type xtype, *xtypep = NULL; - int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; - int ndims, dimids[NC_MAX_DIMS], natts; - switch (msg) - { - case PIO_MSG_INQ_VAR: - namep = name; - xtypep = &xtype; - ndimsp = &ndims; - dimidsp = dimids; - nattsp = &natts; - break; - case PIO_MSG_INQ_VARNATTS: - nattsp = &natts; - break; - case PIO_MSG_INQ_VARNAME: - namep = name; - break; - case PIO_MSG_INQ_VARNDIMS: - ndimsp = &ndims; - break; - case PIO_MSG_INQ_VARDIMID: - dimidsp = dimids; - break; - case PIO_MSG_INQ_VARTYPE: - xtypep = &xtype; - break; - default: - return PIO_EINVAL; - } + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(name = malloc(namelen * sizeof(char)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast((void *)name, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(op = malloc(len * sizeof(int)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d att_handler ncid = %d varid = %d\n", my_rank, ncid, varid); - /* Call the inq function to get the values. */ - if ((ret = PIOc_inq_var(ncid, varid, namep, xtypep, ndimsp, dimidsp, nattsp))) + /* Call the function to write the attribute. */ + if ((ret = PIOc_put_att_int(ncid, varid, name, xtype, len, op))) return ret; - + + /* Free resources. */ + free(name); + free(op); + return PIO_NOERR; } @@ -528,6 +513,7 @@ int def_dim_handler(iosystem_desc_t *ios) * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + printf("%d def_dim_handler ncid = %d\n", my_rank, ncid); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; printf("%d def_dim_handler ncid = %d namelen %d\n", my_rank, ncid, namelen); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 9e9f04a45db7..32267c8b27fb 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2874,6 +2874,11 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ iosystem_desc_t *ios; file_desc_t *file; char *errstr; + size_t namelen; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name); errstr = NULL; ierr = PIO_NOERR; @@ -2887,8 +2892,17 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d PIOc_put_att_int BCast msg = %d\n", my_rank, msg); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d PIOc_put_att_int ncid = %d, varid = %d namelen = %d name = %s xtype = %d len = %d\n", + my_rank, file->fh, varid, namelen, name, xtype, len); } @@ -3965,8 +3979,6 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); namelen = strlen(name); printf("bcasting namelen = %d name = %s len = %d\n", namelen, name, len); - if (!ios->compmaster) - ios->compmaster = MPI_PROC_NULL; mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index a78a1d6b71db..f616b28c1e8e 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -227,7 +227,9 @@ main(int argc, char **argv) ERR(ret); /* Add a global attribute. */ - /* int att_data = 42; */ + if (verbose) + printf("%d test_intercomm writing attribute %s\n", my_rank, ATT_NAME); + int att_data = 42; /* if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) */ /* ERR(ret); */ From badb925c40b98326eecb302be283d40f1e9d0817 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 5 May 2016 13:47:50 -0400 Subject: [PATCH 04/83] got non-async build working again --- src/clib/CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 023b7b3dcbec..475aa6196a41 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -20,13 +20,12 @@ set (PIO_C_SRCS topology.c set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c ${CMAKE_CURRENT_BINARY_DIR}/pio_get_nc.c - ${CMAKE_CURRENT_BINARY_DIR}/pio_nc4.c ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c) if (PIO_ENABLE_ASYNC) set (PIO_ADDL_SRCS pio_nc_async.c pio_put_nc_async.c pio_get_nc_async.c pio_msg.c) else () - set (PIO_ADDL_SRCS ${PIO_GENNC_SRC}) + set (PIO_ADDL_SRCS ${PIO_GENNC_SRCS}) endif () add_library (pioc ${PIO_C_SRCS} ${PIO_ADDL_SRCS}) @@ -203,12 +202,9 @@ else () pio_get_nc.c COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/pio_nc.c pio_nc.c - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/pio_nc4.c - pio_nc4.c DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pio_put_nc.c ${CMAKE_CURRENT_SOURCE_DIR}/pio_get_nc.c - ${CMAKE_CURRENT_SOURCE_DIR}/pio_nc.c - ${CMAKE_CURRENT_SOURCE_DIR}/pio_nc4.c) + ${CMAKE_CURRENT_SOURCE_DIR}/pio_nc.c) endif () From 3b0ad2671a782e5a9e52e0ea670b41c6096719a2 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 6 May 2016 11:45:24 -0400 Subject: [PATCH 05/83] got attribut put working --- src/clib/pio_file.c | 28 +++++++++++----------- src/clib/pio_msg.c | 34 +++++++++++++++++++------- src/clib/pio_nc_async.c | 10 ++++---- tests/unit/test_intercomm.c | 48 ++++++++++++++++--------------------- 4 files changed, 66 insertions(+), 54 deletions(-) diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index 461c8d2b4ca3..c4ccb4d0fbc9 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -113,20 +113,20 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, // If we failed to open a file due to an incompatible type of NetCDF, try it // once with just plain old basic NetCDF -#ifdef _NETCDF - if((ierr == NC_ENOTNC || ierr == NC_EINVAL) && (file->iotype != PIO_IOTYPE_NETCDF)) { - if(ios->iomaster) printf("PIO2 pio_file.c retry NETCDF\n"); - // reset ierr on all tasks - ierr = PIO_NOERR; - // reset file markers for NETCDF on all tasks - file->iotype = PIO_IOTYPE_NETCDF; - - // open netcdf file serially on main task - if(ios->io_rank==0){ - ierr = nc_open(filename, file->mode, &(file->fh)); } - - } -#endif +/* #ifdef _NETCDF */ +/* if((ierr == NC_ENOTNC || ierr == NC_EINVAL) && (file->iotype != PIO_IOTYPE_NETCDF)) { */ +/* if(ios->iomaster) printf("PIO2 pio_file.c retry NETCDF\n"); */ +/* // reset ierr on all tasks */ +/* ierr = PIO_NOERR; */ +/* // reset file markers for NETCDF on all tasks */ +/* file->iotype = PIO_IOTYPE_NETCDF; */ + +/* // open netcdf file serially on main task */ +/* if(ios->io_rank==0){ */ +/* ierr = nc_open(filename, file->mode, &(file->fh)); } */ + +/* } */ +/* #endif */ } ierr = check_netcdf(file, ierr, __FILE__,__LINE__); diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 480f16ad7a41..8dd59e4439d6 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -241,14 +241,15 @@ int att_handler(iosystem_desc_t *ios, int msg) int varid; int mpierr; int ret; - char *name; - size_t namelen; + char *name5; + int namelen; int len; nc_type xtype; int *op; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d att_handler\n", my_rank); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -257,22 +258,28 @@ int att_handler(iosystem_desc_t *ios, int msg) if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!(name = malloc(namelen * sizeof(char)))) + if (!(name5 = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; - mpierr = MPI_Bcast((void *)name, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!(op = malloc(len * sizeof(int)))) return PIO_ENOMEM; mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d att_handler ncid = %d varid = %d\n", my_rank, ncid, varid); /* Call the function to write the attribute. */ - if ((ret = PIOc_put_att_int(ncid, varid, name, xtype, len, op))) + if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, len, op))) return ret; + free(op); + if (!(op = malloc(20))) + { + printf("%d att_handler4 ncid = %d varid = %d namelen = %d name = %d\n", + my_rank, ncid, varid, namelen, name5); + } + /* Free resources. */ - free(name); + free(name5); free(op); return PIO_NOERR; @@ -301,7 +308,7 @@ int inq_var_handler(iosystem_desc_t *ios, int msg) return PIO_EIO; if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inv_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); + printf("%d inq_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); /* Call the inq_var function. */ char name[NC_MAX_NAME + 1], *namep; @@ -758,6 +765,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) MPI_Status status; int index; int mpierr; + int ret; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); @@ -856,7 +864,8 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) inq_var_handler(my_iosys, msg); break; case PIO_MSG_GET_ATT_INT: - att_handler(my_iosys, msg); + ret = att_handler(my_iosys, msg); + printf("att_handler returned %d\n", ret); break; case PIO_MSG_PUT_ATT_INT: att_handler(my_iosys, msg); @@ -896,6 +905,13 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) pio_callback_handler(my_iosys, msg); } + /* If an error was returned by the handler, do something! */ + if (ret) + { + printf("hander returned error code %d\n", ret); + MPI_Finalize(); + } + /* Unless finalize was called, listen for another msg from the * component whose message we just handled. */ if (!io_rank && msg != -1) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 32267c8b27fb..b35b20299189 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -562,8 +562,8 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, * the IO root task. */ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); namelen = strlen(name); printf("bcasting namelen = %d name = %s\n", namelen, name); if (!ios->compmaster) @@ -2891,13 +2891,15 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); printf("%d PIOc_put_att_int BCast msg = %d\n", my_rank, msg); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); namelen = strlen(name); mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_put_att_int about to send name = %s\n", my_rank, name); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_put_att_int sent name = %s\n", my_rank, name); mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index f616b28c1e8e..592b7b5e6ee5 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -4,6 +4,7 @@ * */ #include +#include #ifdef TIMING #include #endif @@ -76,9 +77,6 @@ main(int argc, char **argv) /** Number of processors involved in current execution. */ int ntasks; - /** Specifies the flavor of netCDF output format. */ - int iotype; - /** Different output flavors. */ int format[NUM_NETCDF_FLAVORS] = {PIO_IOTYPE_PNETCDF, PIO_IOTYPE_NETCDF, @@ -91,10 +89,6 @@ main(int argc, char **argv) "test_nc4_serial4.nc", "test_nc4_parallel4.nc"}; - /** Number of processors that will do IO. In this test we - * will do IO from all processors. */ - int niotasks; - /** The ID for the parallel I/O system. */ int iosysid; @@ -134,9 +128,6 @@ main(int argc, char **argv) printf("%d: test_intercomm ParallelIO Library test_intercomm running on %d processors.\n", my_rank, ntasks); - /* keep things simple - 1 iotask per MPI process */ - niotasks = ntasks; - /* For example, if I have 4 processors, and I want to have 2 of them be computational, */ /* and 2 of them be IO: component count is 1 */ /* peer_comm = MPI_COMM_WORLD */ @@ -216,11 +207,14 @@ main(int argc, char **argv) ERR(ret); if (verbose) printf("%d test_intercomm file created ncid = %d\n", my_rank, ncid); - + + /* Define a dimension. */ if (verbose) printf("%d test_intercomm defining dimension %s\n", my_rank, DIM_NAME); if ((ret = PIOc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid))) ERR(ret); + + /* Define a 1-D variable. */ if (verbose) printf("%d test_intercomm defining variable %s\n", my_rank, VAR_NAME); if ((ret = PIOc_def_var(ncid, VAR_NAME, NC_INT, NDIM, &dimid, &varid))) @@ -230,21 +224,21 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm writing attribute %s\n", my_rank, ATT_NAME); int att_data = 42; - /* if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) */ - /* ERR(ret); */ + if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) + ERR(ret); - /* Close the file. */ + /* End define mode. */ if (verbose) printf("%d test_intercomm ending define mode ncid = %d\n", my_rank, ncid); if ((ret = PIOc_enddef(ncid))) ERR(ret); /* Write some data. */ - for (int i = 0; i < LOCAL_DIM_LEN; i++) - data[i] = my_rank; - if (verbose) - printf("%d test_intercomm writing data\n", my_rank); - start[0] = !my_rank ? 0 : 2; + /* for (int i = 0; i < LOCAL_DIM_LEN; i++) */ + /* data[i] = my_rank; */ + /* if (verbose) */ + /* printf("%d test_intercomm writing data\n", my_rank); */ + /* start[0] = !my_rank ? 0 : 2; */ /* if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) */ /* ERR(ret); */ @@ -258,14 +252,14 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm opening file %s\n", my_rank, filename[fmt]); if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], - NC_NOWRITE))) + NC_NOWRITE))) ERR(ret); /* Find the number of dimensions, variables, and global attributes.*/ int ndims, nvars, ngatts, unlimdimid; if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) ERR(ret); - if (ndims != 1 || nvars != 1 || ngatts != 0 || unlimdimid != -1) + if (ndims != 1 || nvars != 1 || ngatts != 1 || unlimdimid != -1) ERR(ERR_WRONG); int ndims2, nvars2, ngatts2, unlimdimid2; if ((ret = PIOc_inq_ndims(ncid, &ndims2))) @@ -278,7 +272,7 @@ main(int argc, char **argv) ERR(ERR_WRONG); if ((ret = PIOc_inq_natts(ncid, &ngatts2))) ERR(ret); - if (ngatts2 != 0) + if (ngatts2 != 1) ERR(ERR_WRONG); if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) ERR(ret); @@ -292,13 +286,13 @@ main(int argc, char **argv) ERR(ret); printf("%d test_intercomm dim name is %s VAR_NAME is %s\n", my_rank, dimname, VAR_NAME); if (strcmp(dimname, DIM_NAME) || dimlen != DIM_LEN) - ERR(ERR_WRONG); + ERR(ERR_WRONG); char dimname2[NC_MAX_NAME + 1]; PIO_Offset dimlen2; if ((ret = PIOc_inq_dimname(ncid, 0, dimname2))) ERR(ret); if (strcmp(dimname2, DIM_NAME)) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_dimlen(ncid, 0, &dimlen2))) ERR(ret); if (dimlen2 != DIM_LEN) @@ -316,7 +310,7 @@ main(int argc, char **argv) if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) ERR(ret); if (strcmp(varname, VAR_NAME) || vartype != NC_INT || varndims != NDIM || - vardimids != 0 || varnatts != 0) + vardimids != 0 || varnatts != 0) ERR(ERR_WRONG); char varname2[NC_MAX_NAME + 1]; nc_type vartype2; @@ -354,8 +348,8 @@ main(int argc, char **argv) ERR(ret); /* Now delete the file. */ - if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) - ERR(ret); + /* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */ + /* ERR(ret); */ /* if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], */ /* NC_NOWRITE)) != PIO_ENFILE) */ /* ERR(ERR_AWFUL); */ From aee5878a304d2e57de2daa5b3a679991a4d92996 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 9 May 2016 16:41:35 -0400 Subject: [PATCH 06/83] development of async inq functions --- src/clib/pio_internal.h | 8 - src/clib/pio_msg.c | 230 ++++--- src/clib/pio_nc_async.c | 1151 +++++++++++------------------------ tests/unit/test_intercomm.c | 244 +++++--- 4 files changed, 666 insertions(+), 967 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 740b8fdf1a6d..2e9ab413076e 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -174,7 +174,6 @@ enum PIO_MSG{ PIO_MSG_PUT_ATT_INT, PIO_MSG_RENAME_ATT, PIO_MSG_DEL_ATT, - PIO_MSG_INQ_NATTS, PIO_MSG_INQ, PIO_MSG_GET_ATT_TEXT, PIO_MSG_GET_ATT_SHORT, @@ -189,21 +188,16 @@ enum PIO_MSG{ PIO_MSG_GET_ATT_ULONGLONG, PIO_MSG_GET_ATT_USHORT, PIO_MSG_PUT_ATT_ULONGLONG, - PIO_MSG_INQ_DIMLEN, PIO_MSG_GET_ATT_UINT, PIO_MSG_GET_ATT_LONGLONG, PIO_MSG_PUT_ATT_SCHAR, PIO_MSG_PUT_ATT_FLOAT, - PIO_MSG_INQ_NVARS, PIO_MSG_RENAME_DIM, PIO_MSG_INQ_VARNDIMS, PIO_MSG_GET_ATT_LONG, PIO_MSG_INQ_DIM, PIO_MSG_INQ_DIMID, - PIO_MSG_INQ_UNLIMDIM, PIO_MSG_INQ_VARDIMID, - PIO_MSG_INQ_ATTLEN, - PIO_MSG_INQ_DIMNAME, PIO_MSG_PUT_ATT_USHORT, PIO_MSG_GET_ATT_FLOAT, PIO_MSG_SYNC, @@ -212,11 +206,9 @@ enum PIO_MSG{ PIO_MSG_GET_ATT_SCHAR, PIO_MSG_INQ_ATTID, PIO_MSG_DEF_DIM, - PIO_MSG_INQ_NDIMS, PIO_MSG_INQ_VARTYPE, PIO_MSG_GET_ATT_INT, PIO_MSG_GET_ATT_DOUBLE, - PIO_MSG_INQ_ATTTYPE, PIO_MSG_PUT_ATT_UCHAR, PIO_MSG_GET_ATT_UCHAR, PIO_MSG_PUT_VARS_UCHAR, diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 8dd59e4439d6..732b4a2377d2 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -88,50 +88,51 @@ int close_file_handler(iosystem_desc_t *ios) * only ever run on the IO tasks. * * @param ios pointer to the iosystem_desc_t. - * @param msg the message sent my the comp root task. * @return PIO_NOERR for success, error code otherwise. */ -int inq_handler(iosystem_desc_t *ios, int msg) +int inq_handler(iosystem_desc_t *ios) { int ncid; + int ndims, nvars, ngatts, unlimdimid; + int *ndimsp = NULL, *nvarsp = NULL, *ngattsp = NULL, *unlimdimidp = NULL; + char ndims_present, nvars_present, ngatts_present, unlimdimid_present; int mpierr; int ret; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_handler msg = %d\n", my_rank, msg); + printf("%d inq_handler\n", my_rank); /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + printf("%d inq_handler1\n", my_rank); + if ((mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_handler2\n", my_rank); + if ((mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_handler3\n", my_rank); + if ((mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_handler4\n", my_rank); + if ((mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_handler ndims_present = %d nvars_present = %d ngatts_present = %d unlimdimid_present = %d\n", + my_rank, ndims_present, nvars_present, ngatts_present, unlimdimid_present); - /* Call the inq file function. */ - int ndims, nvars, ngatts, unlimdimid; - int *ndimsp = NULL, *nvarsp = NULL, *ngattsp = NULL, *unlimdimidp = NULL; - switch (msg) - { - case PIO_MSG_INQ: + /* NULLs passed in to any of the pointers in the original call + * need to be matched with NULLs here. Assign pointers where + * non-NULL pointers were passed in. */ + if (ndims_present) ndimsp = &ndims; + if (nvars_present) nvarsp = &nvars; + if (ngatts_present) ngattsp = &ngatts; + if (unlimdimid_present) unlimdimidp = &unlimdimid; - break; - case PIO_MSG_INQ_NVARS: - nvarsp = &nvars; - break; - case PIO_MSG_INQ_NDIMS: - ndimsp = &ndims; - break; - case PIO_MSG_INQ_NATTS: - ngattsp = &ngatts; - break; - case PIO_MSG_INQ_UNLIMDIM: - unlimdimidp = &unlimdimid; - break; - default: - return PIO_EINVAL; - } /* Call the inq function to get the values. */ if ((ret = PIOc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp))) @@ -151,12 +152,18 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) { int ncid; int dimid; + char name_present, len_present; + char *dimnamep = NULL; + PIO_Offset *dimlenp = NULL; + char dimname[NC_MAX_NAME + 1]; + PIO_Offset dimlen; + int mpierr; int ret; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_handler msg = %d\n", my_rank, msg); + printf("%d inq_dim_handler\n", my_rank); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -164,27 +171,18 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) return PIO_EIO; if ((mpierr = MPI_Bcast(&dimid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + if ((mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_handler name_present = %d len_present = %d\n", + my_rank, name_present, len_present); - /* Call the inq_dim function. */ - char *dimnamep = NULL; - PIO_Offset *dimlenp = NULL; - char dimname[NC_MAX_NAME + 1]; - PIO_Offset dimlen; - switch (msg) - { - case PIO_MSG_INQ_DIM: + /* Set the non-null pointers. */ + if (name_present) dimnamep = dimname; + if (len_present) dimlenp = &dimlen; - break; - case PIO_MSG_INQ_DIMLEN: - dimlenp = &dimlen; - break; - case PIO_MSG_INQ_DIMNAME: - dimnamep = dimname; - break; - default: - return PIO_EINVAL; - } /* Call the inq function to get the values. */ if ((ret = PIOc_inq_dim(ncid, dimid, dimnamep, dimlenp))) @@ -202,25 +200,42 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) int inq_dimid_handler(iosystem_desc_t *ios) { int ncid; - int dimid; + int *dimidp = NULL, dimid; int mpierr; + int id_present; int ret; int namelen; char *name; + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d inq_dimid_handler\n", my_rank); + /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + printf("%d inq_dimid_handler ncid = %d\n", my_rank, ncid); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + printf("%d inq_dimid_handler ncid = %d namelen = %d\n", my_rank, ncid, namelen); if (!(name = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; + printf("%d inq_dimid_handler ncid = %d namelen = %d name = %s\n", + my_rank, ncid, namelen, name); + if ((mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d\n", + my_rank, ncid, namelen, name, id_present); + + /* Set non-null pointer. */ + if (id_present) + dimidp = &dimid; /* Call the inq_dimid function. */ - if ((ret = PIOc_inq_dimid(ncid, name, &dimid))) + if ((ret = PIOc_inq_dimid(ncid, name, dimidp))) return ret; /* Free resources. */ @@ -229,13 +244,14 @@ int inq_dimid_handler(iosystem_desc_t *ios) return PIO_NOERR; } -/** Handle attribute operations. This code only runs on IO tasks. +/** Handle attribute inquiry operations. This code only runs on IO + * tasks. * * @param ios pointer to the iosystem_desc_t. * @param msg the message sent my the comp root task. * @return PIO_NOERR for success, error code otherwise. */ -int att_handler(iosystem_desc_t *ios, int msg) +int inq_att_handler(iosystem_desc_t *ios, int msg) { int ncid; int varid; @@ -243,13 +259,13 @@ int att_handler(iosystem_desc_t *ios, int msg) int ret; char *name5; int namelen; - int len; + PIO_Offset attlen; nc_type xtype; - int *op; + int *op, *ip; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d att_handler\n", my_rank); + printf("%d inq_att_handler\n", my_rank); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -260,27 +276,92 @@ int att_handler(iosystem_desc_t *ios, int msg) mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!(name5 = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; - mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!(op = malloc(len * sizeof(int)))) - return PIO_ENOMEM; - mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); - - /* Call the function to write the attribute. */ - if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, len, op))) + mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, + ios->intercomm); + + /* Call the function to learn about the attribute. */ + if ((ret = PIOc_inq_att(ncid, varid, name5, &xtype, &attlen))) return ret; - free(op); - if (!(op = malloc(20))) + return PIO_NOERR; +} + +/** Handle attribute operations. This code only runs on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int att_handler(iosystem_desc_t *ios, int msg) +{ + int ncid; + int varid; + int mpierr; + int ret; + char *name5; + int namelen; + PIO_Offset len; + nc_type xtype; + int *op, *ip; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d att_handler\n", my_rank); + + if (msg == PIO_MSG_PUT_ATT_INT) { - printf("%d att_handler4 ncid = %d varid = %d namelen = %d name = %d\n", - my_rank, ncid, varid, namelen, name5); + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(name5 = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!(op = malloc(len * sizeof(int)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); + + /* Call the function to write the attribute. */ + if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, len, op))) + return ret; + + /* Free resources. */ + free(name5); + free(op); } + else if (msg = PIO_MSG_GET_ATT_INT) + { + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(name5 = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - /* Free resources. */ - free(name5); - free(op); + /* Allocate space for the attribute data. */ + if ((ret = PIOc_inq_attlen(ncid, varid, name5, &len))) + return ret; + if (!(ip = malloc(len * sizeof(int)))) + return PIO_ENOMEM; + + /* Call the function to read the attribute. */ + if ((ret = PIOc_get_att_int(ncid, varid, name5, ip))) + return ret; + printf("%d att_handler got att with first element %d\n", my_rank, ip[0]); + + /* Free resources. */ + free(name5); + free(ip); + } return PIO_NOERR; } @@ -841,15 +922,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) def_var_handler(my_iosys); break; case PIO_MSG_INQ: - case PIO_MSG_INQ_NVARS: - case PIO_MSG_INQ_NDIMS: - case PIO_MSG_INQ_NATTS: - case PIO_MSG_INQ_UNLIMDIM: - inq_handler(my_iosys, msg); + inq_handler(my_iosys); break; case PIO_MSG_INQ_DIM: - case PIO_MSG_INQ_DIMLEN: - case PIO_MSG_INQ_DIMNAME: inq_dim_handler(my_iosys, msg); break; case PIO_MSG_INQ_DIMID: @@ -864,15 +939,16 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) inq_var_handler(my_iosys, msg); break; case PIO_MSG_GET_ATT_INT: + case PIO_MSG_PUT_ATT_INT: ret = att_handler(my_iosys, msg); printf("att_handler returned %d\n", ret); break; - case PIO_MSG_PUT_ATT_INT: - att_handler(my_iosys, msg); - break; case PIO_MSG_INQ_VARID: inq_varid_handler(my_iosys); break; + case PIO_MSG_INQ_ATT: + inq_att_handler(my_iosys, msg); + break; case PIO_MSG_INITDECOMP_DOF: initdecomp_dof_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b35b20299189..12a208d7f3d8 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -18,136 +18,147 @@ #include #include -/** Internal function to call nc_inq. Call this function only in I/O - * tasks. */ -int -pio_io_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, - int *unlimdimidp) -{ - file_desc_t *file; - char *errstr = NULL; - int ierr = PIO_NOERR; - - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d pio_io_inq ncid = %d\n", my_rank, ncid); - - if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; - - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - printf("%d pio_io_inq file->iosystem->io_rank = %d\n", my_rank, file->iosystem->io_rank); - if (!file->iosystem->io_rank) - { - /* Should not be necessary to do this - nc_inq should - * handle null pointers. This has been reported as a bug - * to netCDF developers. */ - int tmp_ndims, tmp_var, tmp_gatts, tmp_unl; - if (!ndimsp) - ndimsp = &tmp_ndims; - if (!nvarsp) - nvarsp = &tmp_var; - if (!ngattsp) - ngattsp = &tmp_gatts; - if (!unlimdimidp) - unlimdimidp = &tmp_unl; - ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - - if(ierr != PIO_NOERR) - { - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - - return ierr; -} - /** * @ingroup PIOc_inq * The PIO-C interface for the NetCDF function nc_inq. * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: + * This routine is called collectively by all tasks in the + * communicator ios.union_comm. For more information on the underlying + * NetCDF commmand please read about this function in the NetCDF + * documentation at: * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See + * + * @return PIO_NOERR for success, error code otherwise. See * PIOc_Set_File_Error_Handling */ -int PIOc_inq (int ncid, int *ndimsp, int *nvarsp, int *ngattsp, - int *unlimdimidp) +int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, + int *unlimdimidp) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - + int msg = PIO_MSG_INQ; /** Message for async notification. */ + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + char *errstr = NULL; /** String for error messages. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr; /** Return code from MPI function codes. */ + + /* For debugging purposes. */ int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); printf("%d PIOc_inq ncid = %d\n", my_rank, ncid); - - errstr = NULL; - ierr = PIO_NOERR; - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ; - if(ios->async_interface && ! ios->ioproc){ + /* For async, on non-IO tasks, send the necessary information to + * the IO tasks over the intercomm. Whether or not the pointers + * are NULL are passed as integers, either true or false. */ + if (ios->async_interface && ! ios->ioproc) + { + char ndims_present = ndimsp ? true : false; + char nvars_present = nvarsp ? true : false; + char ngatts_present = ngattsp ? true : false; + char unlimdimid_present = unlimdimidp ? true : false; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast ncid = %d\n", my_rank, file->fh); + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast ndims_present = %d\n", my_rank, ndims_present); + mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast nvars_present = %d\n", my_rank, nvars_present); + mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast ngatts_present = %d\n", my_rank, ngatts_present); + mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast unlimdimid_present = %d\n", my_rank, unlimdimid_present); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { + switch (file->iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if (!file->iosystem->io_rank) + { + /* Should not be necessary to do this - nc_inq should + * handle null pointers. This has been reported as a bug + * to netCDF developers. */ + int tmp_ndims, tmp_nvars, tmp_ngatts, tmp_unlimdimid; + ierr = nc_inq(ncid, &tmp_ndims, &tmp_nvars, &tmp_ngatts, &tmp_unlimdimid); + if (ndimsp) + *ndimsp = tmp_ndims; + if (nvarsp) + *nvarsp = tmp_nvars; + if (ngattsp) + *ngattsp = tmp_ngatts; + if (unlimdimidp) + *unlimdimidp = tmp_unlimdimid; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } - if(ios->ioproc){ - ierr = pio_io_inq(file->fh, ndimsp, nvarsp, ngattsp, unlimdimidp); - printf("%d PIOc_inq pio_io_inq returned %d\n", my_rank, ierr); + if(ierr != PIO_NOERR) + { + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + printf("%d PIOc_inq netcdf call returned %d\n", my_rank, ierr); ierr = check_netcdf(file, ierr, errstr,__LINE__); } - if(ndimsp != NULL) + + /* Broadcast results to all tasks. If pointers were NULL, then + * ignore that parameter. */ + if (ndimsp) { - printf("%d PIOc_inq Bcast ios->ioroot = %d *ndimsp = %d\n", my_rank, ios->ioroot, *ndimsp); mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc__inq bcast ndims = %d\n", my_rank, *ndimsp); } - if(nvarsp != NULL) + if(nvarsp) + { mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(ngattsp != NULL) + printf("%d PIOc__inq bcast nvars = %d\n", my_rank, *nvarsp); + } + if(ngattsp) + { mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(unlimdimidp != NULL) + printf("%d PIOc__inq bcast ngatts = %d\n", my_rank, *ngattsp); + } + if(unlimdimidp) + { mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + printf("%d PIOc__inq bcast unlimdimid = %d\n", my_rank, *unlimdimidp); + } + + if(errstr) + free(errstr); + return ierr; } /** - * @ingroup PIOc_inq_dimname - * The PIO-C interface for the NetCDF function nc_inq_dimname. + * @ingroup PIOc_inq_ndims + * The PIO-C interface for the NetCDF function nc_inq_ndims. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -158,72 +169,48 @@ int PIOc_inq (int ncid, int *ndimsp, int *nvarsp, int *ngattsp, * PIOc_openfile() or PIOc_createfile(). * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dimname (int ncid, int dimid, char *name) +int PIOc_inq_ndims (int ncid, int *ndimsp) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_DIMNAME; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d calling PIOc_inq_ndims\n", my_rank); + return PIOc_inq(ncid, ndimsp, NULL, NULL, NULL); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dimname(file->fh, dimid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_dimname(file->fh, dimid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_dimname(file->fh, dimid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } +/** + * @ingroup PIOc_inq_nvars + * The PIO-C interface for the NetCDF function nc_inq_nvars. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_nvars(int ncid, int *nvarsp) +{ + return PIOc_inq(ncid, NULL, nvarsp, NULL, NULL); +} - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (name) - { - int slen; - if(ios->iomaster) - slen = (int) strlen(name) + 1; - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; +/** + * @ingroup PIOc_inq_natts + * The PIO-C interface for the NetCDF function nc_inq_natts. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_natts(int ncid, int *ngattsp) +{ + return PIOc_inq(ncid, NULL, NULL, ngattsp, NULL); } /** @@ -704,32 +691,41 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dim (int ncid, int dimid, char *name, PIO_Offset *lenp) +int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { - int ierr; - int msg; - int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_DIM; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + /* For debugging purposes only... */ + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_dim\n", my_rank); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_DIM; - if(ios->async_interface && ! ios->ioproc){ + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface && !ios->ioproc) + { + char name_present = name ? true : false; + char len_present = lenp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast name_present = %d\n", my_rank, name_present); + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq netcdf Bcast len_present = %d\n", my_rank, len_present); } - + /* Make the call to the netCDF layer. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -755,18 +751,21 @@ int PIOc_inq_dim (int ncid, int dimid, char *name, PIO_Offset *lenp) } } + /* Error handling. */ if(ierr != PIO_NOERR){ errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + + /* BCast the results, if non-null pointers were passed. */ if(name) { int slen; if(ios->iomaster) - slen = (int) strlen(name) + 1; + slen = strlen(name); mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); } if(lenp != NULL) mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); @@ -774,6 +773,43 @@ int PIOc_inq_dim (int ncid, int dimid, char *name, PIO_Offset *lenp) return ierr; } +/** + * @ingroup PIOc_inq_dimname + * The PIO-C interface for the NetCDF function nc_inq_dimname. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_dimname(int ncid, int dimid, char *name) +{ + return PIOc_inq_dim(ncid, dimid, name, NULL); +} + +/** + * @ingroup PIOc_inq_dimlen + * The PIO-C interface for the NetCDF function nc_inq_dimlen. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param lenp a pointer that will get the number of values + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) +{ + return PIOc_inq_dim(ncid, dimid, NULL, lenp); +} + /** * @ingroup PIOc_get_att_uchar * The PIO-C interface for the NetCDF function nc_get_att_uchar. @@ -1413,63 +1449,9 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) */ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_ATTLEN; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attlen(file->fh, varid, name, (size_t *)lenp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_attlen(file->fh, varid, name, (size_t *)lenp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_attlen(file->fh, varid, name, lenp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} + nc_type dummy; + return PIOc_inq_att(ncid, varid, name, &dummy, lenp); +} /** * @ingroup PIOc_inq_atttype @@ -1486,64 +1468,10 @@ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) * @param xtypep a pointer that will get the type of the attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_atttype (int ncid, int varid, const char *name, nc_type *xtypep) +int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_ATTTYPE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_atttype(file->fh, varid, name, xtypep);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_atttype(file->fh, varid, name, xtypep);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_atttype(file->fh, varid, name, xtypep);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(xtypep , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; + PIO_Offset dummy; + return PIOc_inq_att(ncid, varid, name, xtypep, &dummy); } /** @@ -1619,80 +1547,6 @@ int PIOc_rename_var (int ncid, int varid, const char *name) return ierr; } -/** - * @ingroup PIOc_inq_natts - * The PIO-C interface for the NetCDF function nc_inq_natts. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_natts (int ncid, int *ngattsp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_NATTS; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_natts(file->fh, ngattsp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_natts(file->fh, ngattsp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_natts(file->fh, ngattsp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (ngattsp) - mpierr = MPI_Bcast(ngattsp,1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_put_att_ulonglong * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. @@ -2026,36 +1880,40 @@ int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, P * @param idp a pointer that will get the id of the variable or attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dimid (int ncid, const char *name, int *idp) +int PIOc_inq_dimid(int ncid, const char *name, int *idp) { - int ierr; - int msg; - int mpierr; + int msg = PIO_MSG_INQ_DIMID; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ierr = PIO_NOERR; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + /* For debugging purposes only... */ + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_dimid\n", my_rank); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_DIMID; - if(ios->async_interface && ! ios->ioproc){ + /* If using async, and not an IO task, then send parameters. */ + if (ios->async_interface && !ios->ioproc) + { + int namelen; + char id_present = idp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen; - if (ios->iomaster) - namelen = strlen(name); + namelen = strlen(name); mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - + /* IO tasks call the netCDF functions. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -2317,245 +2175,9 @@ int PIOc_inq_format (int ncid, int *formatp) return ierr; } -/** - * @ingroup PIOc_get_att_long - * The PIO-C interface for the NetCDF function nc_get_att_long. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_long(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_long(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_long(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; -} - -/** - * @ingroup PIOc_inq_attname - * The PIO-C interface for the NetCDF function nc_inq_attname. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param attnum the attribute ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_ATTNAME; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attname(file->fh, varid, attnum, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_attname(file->fh, varid, attnum, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(name != NULL){ - int slen; - if(ios->iomaster) - slen = (int) strlen(name) + 1; - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; -} - -/** - * @ingroup PIOc_inq_att - * The PIO-C interface for the NetCDF function nc_inq_att. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @param lenp a pointer that will get the number of values - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, PIO_Offset *lenp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_ATT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(xtypep != NULL) mpierr = MPI_Bcast(xtypep , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(lenp != NULL) mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} - -/** - * @ingroup PIOc_put_att_long - * The PIO-C interface for the NetCDF function nc_put_att_long. +/** + * @ingroup PIOc_get_att_long + * The PIO-C interface for the NetCDF function nc_get_att_long. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2567,7 +2189,7 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, PIO_Of * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long *op) +int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) { int ierr; int msg; @@ -2583,7 +2205,7 @@ int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_LONG; + msg = PIO_MSG_GET_ATT_LONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2597,19 +2219,19 @@ int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_long(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_long(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_long(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_get_att_long(file->fh, varid, name, ip);; break; #endif default: @@ -2618,28 +2240,35 @@ int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_unlimdim - * The PIO-C interface for the NetCDF function nc_inq_unlimdim. + * @ingroup PIOc_inq_attname + * The PIO-C interface for the NetCDF function nc_inq_attname. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param attnum the attribute ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) +int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) { int ierr; int msg; @@ -2655,7 +2284,7 @@ int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_UNLIMDIM; + msg = PIO_MSG_INQ_ATTNAME; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2669,19 +2298,19 @@ int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_unlimdim(file->fh, unlimdimidp);; + ierr = nc_inq_attname(file->fh, varid, attnum, name);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_unlimdim(file->fh, unlimdimidp);; + ierr = nc_inq_attname(file->fh, varid, attnum, name);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_unlimdim(file->fh, unlimdimidp);; + ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; break; #endif default: @@ -2694,15 +2323,20 @@ int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (unlimdimidp) - mpierr = MPI_Bcast(unlimdimidp,1, MPI_INT, ios->ioroot, ios->my_comm); + if(name != NULL){ + int slen; + if(ios->iomaster) + slen = (int) strlen(name) + 1; + mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_get_att_float - * The PIO-C interface for the NetCDF function nc_get_att_float. + * @ingroup PIOc_inq_att + * The PIO-C interface for the NetCDF function nc_inq_att. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2712,9 +2346,12 @@ int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. + * @param xtypep a pointer that will get the type of the attribute. + * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) +int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, + PIO_Offset *lenp) { int ierr; int msg; @@ -2723,40 +2360,47 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) file_desc_t *file; char *errstr; + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d\n", + my_rank, ncid, varid, xtypep, lenp); + errstr = NULL; ierr = PIO_NOERR; - file = pio_get_file_from_id(ncid); - if(file == NULL) + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_FLOAT; + msg = PIO_MSG_INQ_ATT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_float(file->fh, varid, name, ip);; + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_float(file->fh, varid, name, ip);; + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_float(file->fh, varid, name, ip);; + ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);; break; #endif default: @@ -2765,33 +2409,33 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_FLOAT, ios->ioroot, ios->my_comm); - } + if(xtypep) + mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); + if(lenp) + mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_ndims - * The PIO-C interface for the NetCDF function nc_inq_ndims. + * @ingroup PIOc_put_att_long + * The PIO-C interface for the NetCDF function nc_put_att_long. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_ndims (int ncid, int *ndimsp) +int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long *op) { int ierr; int msg; @@ -2807,7 +2451,7 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_NDIMS; + msg = PIO_MSG_PUT_ATT_LONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2821,19 +2465,19 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_ndims(file->fh, ndimsp);; + ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_ndims(file->fh, ndimsp);; + ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_ndims(file->fh, ndimsp);; + ierr = ncmpi_put_att_long(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -2846,15 +2490,31 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (ndimsp) - mpierr = MPI_Bcast(ndimsp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_put_att_int - * The PIO-C interface for the NetCDF function nc_put_att_int. + * @ingroup PIOc_inq_unlimdim + * The PIO-C interface for the NetCDF function nc_inq_unlimdim. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) +{ + return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); +} + +/** + * @ingroup PIOc_get_att_float + * The PIO-C interface for the NetCDF function nc_get_att_float. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2866,7 +2526,7 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const int *op) +int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) { int ierr; int msg; @@ -2874,11 +2534,6 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ iosystem_desc_t *ios; file_desc_t *file; char *errstr; - size_t namelen; - - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name); errstr = NULL; ierr = PIO_NOERR; @@ -2887,24 +2542,12 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_INT; + msg = PIO_MSG_GET_ATT_FLOAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - printf("%d PIOc_put_att_int BCast msg = %d\n", my_rank, msg); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d PIOc_put_att_int about to send name = %s\n", my_rank, name); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_put_att_int sent name = %s\n", my_rank, name); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d PIOc_put_att_int ncid = %d, varid = %d namelen = %d name = %s xtype = %d len = %d\n", - my_rank, file->fh, varid, namelen, name, xtype, len); + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -2913,19 +2556,19 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_float(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_float(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_int(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_get_att_float(file->fh, varid, name, ip);; break; #endif default: @@ -2934,28 +2577,34 @@ int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_ } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_FLOAT, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_nvars - * The PIO-C interface for the NetCDF function nc_inq_nvars. + * @ingroup PIOc_put_att_int + * The PIO-C interface for the NetCDF function nc_put_att_int. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_nvars (int ncid, int *nvarsp) +int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const int *op) { int ierr; int msg; @@ -2963,6 +2612,11 @@ int PIOc_inq_nvars (int ncid, int *nvarsp) iosystem_desc_t *ios; file_desc_t *file; char *errstr; + size_t namelen; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name); errstr = NULL; ierr = PIO_NOERR; @@ -2971,33 +2625,39 @@ int PIOc_inq_nvars (int ncid, int *nvarsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_NVARS; + msg = PIO_MSG_PUT_ATT_INT; if(ios->async_interface && ! ios->ioproc){ - if(!ios->comp_rank) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_nvars(file->fh, nvarsp);; + ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_nvars(file->fh, nvarsp);; + ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_nvars(file->fh, nvarsp);; + ierr = ncmpi_put_att_int(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -3010,8 +2670,6 @@ int PIOc_inq_nvars (int ncid, int *nvarsp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (nvarsp) - mpierr = MPI_Bcast(nvarsp,1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } @@ -3029,7 +2687,7 @@ int PIOc_inq_nvars (int ncid, int *nvarsp) * PIOc_openfile() or PIOc_createfile(). * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_enddef (int ncid) +int PIOc_enddef(int ncid) { int ierr; int msg; @@ -3541,82 +3199,6 @@ int PIOc_del_att (int ncid, int varid, const char *name) return ierr; } -/** - * @ingroup PIOc_inq_dimlen - * The PIO-C interface for the NetCDF function nc_inq_dimlen. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param lenp a pointer that will get the number of values - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_dimlen (int ncid, int dimid, PIO_Offset *lenp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_DIMLEN; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dimlen(file->fh, dimid, (size_t *)lenp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_dimlen(file->fh, dimid, (size_t *)lenp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_dimlen(file->fh, dimid, lenp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (lenp) - mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_get_att_schar * The PIO-C interface for the NetCDF function nc_get_att_schar. @@ -3980,7 +3562,6 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); namelen = strlen(name); - printf("bcasting namelen = %d name = %s len = %d\n", namelen, name, len); mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); @@ -4339,6 +3920,7 @@ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) iosystem_desc_t *ios; file_desc_t *file; char *errstr; + int namelen; errstr = NULL; ierr = PIO_NOERR; @@ -4352,10 +3934,13 @@ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 592b7b5e6ee5..5ba73d633b3e 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -31,6 +31,9 @@ /** The name of the global attribute in the netCDF output file. */ #define ATT_NAME "gatt_test_intercomm" +/** The value of the global attribute in the netCDF output file. */ +#define ATT_VALUE 42 + /** Error code for when things go wrong. */ #define ERR_AWFUL 1111 #define ERR_WRONG 2222 @@ -61,6 +64,144 @@ char err_buffer[MPI_MAX_ERROR_STRING]; * int the global error string. */ int resultlen; +/* Check the file for correctness. */ +int +check_file(int iosysid, int format, char *filename, int my_rank, int verbose) +{ + int ncid; + int ret; + int ndims, nvars, ngatts, unlimdimid; + int ndims2, nvars2, ngatts2, unlimdimid2; + int dimid2; + char dimname[NC_MAX_NAME + 1]; + PIO_Offset dimlen; + char dimname2[NC_MAX_NAME + 1]; + PIO_Offset dimlen2; + char varname[NC_MAX_NAME + 1]; + nc_type vartype; + int varndims, vardimids, varnatts; + char varname2[NC_MAX_NAME + 1]; + nc_type vartype2; + int varndims2, vardimids2, varnatts2; + int varid2; + int att_data; + + /* Re-open the file to check it. */ + if (verbose) + printf("%d test_intercomm opening file %s\n", my_rank, filename); + if ((ret = PIOc_openfile(iosysid, &ncid, &format, filename, + NC_NOWRITE))) + ERR(ret); + + /* Find the number of dimensions, variables, and global attributes.*/ + if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) + ERR(ret); + if (ndims != 1 || nvars != 1 || ngatts != 1 || unlimdimid != -1) + ERR(ERR_WRONG); + + /* This should return PIO_NOERR. */ + if ((ret = PIOc_inq(ncid, NULL, NULL, NULL, NULL))) + ERR(ret); + + /* Check the other functions that get these values. */ + if ((ret = PIOc_inq_ndims(ncid, &ndims2))) + ERR(ret); + if (ndims2 != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_nvars(ncid, &nvars2))) + ERR(ret); + if (nvars2 != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_natts(ncid, &ngatts2))) + ERR(ret); + if (ngatts2 != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) + ERR(ret); + if (unlimdimid != -1) + ERR(ERR_WRONG); + + /* Check out the dimension. */ + if ((ret = PIOc_inq_dim(ncid, 0, dimname, &dimlen))) + ERR(ret); + if (strcmp(dimname, DIM_NAME) || dimlen != DIM_LEN) + ERR(ERR_WRONG); + + /* Check the other functions that get these values. */ + if ((ret = PIOc_inq_dimname(ncid, 0, dimname2))) + ERR(ret); + if (strcmp(dimname2, DIM_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_dimlen(ncid, 0, &dimlen2))) + ERR(ret); + if (dimlen2 != DIM_LEN) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) + ERR(ret); + if (dimid2 != 0) + ERR(ERR_WRONG); + + /* Check out the variable. */ + if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) + ERR(ret); + if (strcmp(varname, VAR_NAME) || vartype != NC_INT || varndims != NDIM || + vardimids != 0 || varnatts != 0) + ERR(ERR_WRONG); + + /* Check the other functions that get these values. */ + if ((ret = PIOc_inq_varname(ncid, 0, varname2))) + ERR(ret); + if (strcmp(varname2, VAR_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_vartype(ncid, 0, &vartype2))) + ERR(ret); + if (vartype2 != NC_INT) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_varndims(ncid, 0, &varndims2))) + ERR(ret); + if (varndims2 != NDIM) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_vardimid(ncid, 0, &vardimids2))) + ERR(ret); + if (vardimids2 != 0) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_varnatts(ncid, 0, &varnatts2))) + ERR(ret); + if (varnatts2 != 0) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) + ERR(ret); + if (varid2 != 0) + ERR(ERR_WRONG); + + /* Check out the global attributes. */ + nc_type atttype; + PIO_Offset attlen; + /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) */ + /* ERR(ret); */ + /* if (atttype != NC_INT || attlen != 1) */ + /* ERR(ERR_WRONG); */ + if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) + ERR(ret); + if (attlen != 1) + ERR(ERR_WRONG); + /* if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) */ + /* ERR(ret); */ + /* sleep(2); */ + /* if (verbose) */ + /* printf("%d test_intercomm att_data = %d\n", my_rank, att_data); */ + /* if (att_data != ATT_VALUE) */ + /* ERR(ERR_WRONG); */ + + /* Close the file. */ + if (verbose) + printf("%d test_intercomm closing file (again) ncid = %d\n", my_rank, ncid); + if ((ret = PIOc_closefile(ncid))) + ERR(ret); + + return 0; +} + /** Run Tests for Init_Intercomm * * @param argc argument count @@ -223,7 +364,7 @@ main(int argc, char **argv) /* Add a global attribute. */ if (verbose) printf("%d test_intercomm writing attribute %s\n", my_rank, ATT_NAME); - int att_data = 42; + int att_data = ATT_VALUE; if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); @@ -248,104 +389,9 @@ main(int argc, char **argv) if ((ret = PIOc_closefile(ncid))) ERR(ret); - /* Re-open the file to check it. */ - if (verbose) - printf("%d test_intercomm opening file %s\n", my_rank, filename[fmt]); - if ((ret = PIOc_openfile(iosysid, &ncid, &format[fmt], filename[fmt], - NC_NOWRITE))) - ERR(ret); - - /* Find the number of dimensions, variables, and global attributes.*/ - int ndims, nvars, ngatts, unlimdimid; - if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) - ERR(ret); - if (ndims != 1 || nvars != 1 || ngatts != 1 || unlimdimid != -1) - ERR(ERR_WRONG); - int ndims2, nvars2, ngatts2, unlimdimid2; - if ((ret = PIOc_inq_ndims(ncid, &ndims2))) - ERR(ret); - if (ndims2 != 1) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_nvars(ncid, &nvars2))) - ERR(ret); - if (nvars2 != 1) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_natts(ncid, &ngatts2))) - ERR(ret); - if (ngatts2 != 1) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) - ERR(ret); - if (unlimdimid != -1) - ERR(ERR_WRONG); - - /* Check out the dimension. */ - char dimname[NC_MAX_NAME + 1]; - PIO_Offset dimlen; - if ((ret = PIOc_inq_dim(ncid, 0, dimname, &dimlen))) - ERR(ret); - printf("%d test_intercomm dim name is %s VAR_NAME is %s\n", my_rank, dimname, VAR_NAME); - if (strcmp(dimname, DIM_NAME) || dimlen != DIM_LEN) - ERR(ERR_WRONG); - char dimname2[NC_MAX_NAME + 1]; - PIO_Offset dimlen2; - if ((ret = PIOc_inq_dimname(ncid, 0, dimname2))) - ERR(ret); - if (strcmp(dimname2, DIM_NAME)) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_dimlen(ncid, 0, &dimlen2))) - ERR(ret); - if (dimlen2 != DIM_LEN) - ERR(ERR_WRONG); - int dimid2; - if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) - ERR(ret); - if (dimid2 != 0) - ERR(ERR_WRONG); - - /* Check out the variable. */ - char varname[NC_MAX_NAME + 1]; - nc_type vartype; - int varndims, vardimids, varnatts; - if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) - ERR(ret); - if (strcmp(varname, VAR_NAME) || vartype != NC_INT || varndims != NDIM || - vardimids != 0 || varnatts != 0) - ERR(ERR_WRONG); - char varname2[NC_MAX_NAME + 1]; - nc_type vartype2; - int varndims2, vardimids2, varnatts2; - if ((ret = PIOc_inq_varname(ncid, 0, varname2))) - ERR(ret); - if (strcmp(varname2, VAR_NAME)) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_vartype(ncid, 0, &vartype2))) - ERR(ret); - if (vartype2 != NC_INT) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_varndims(ncid, 0, &varndims2))) - ERR(ret); - if (varndims2 != NDIM) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_vardimid(ncid, 0, &vardimids2))) - ERR(ret); - if (vardimids2 != 0) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_varnatts(ncid, 0, &varnatts2))) - ERR(ret); - if (varnatts2 != 0) - ERR(ERR_WRONG); - int varid2; - if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) - ERR(ret); - if (varid2 != 0) - ERR(ERR_WRONG); - - /* Close the file. */ - if (verbose) - printf("%d test_intercomm closing file (again) ncid = %d\n", my_rank, ncid); - if ((ret = PIOc_closefile(ncid))) - ERR(ret); + /* Check the file for correctness. */ + if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) + ERR(ret); /* Now delete the file. */ /* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */ From 90c689facbd2e7eabb8591fae6f4b624deb8eaa3 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 9 May 2016 19:29:03 -0400 Subject: [PATCH 07/83] more inq functions working with async --- src/clib/pio_internal.h | 5 - src/clib/pio_msg.c | 64 ++-- src/clib/pio_nc_async.c | 591 ++++++++++-------------------------- tests/unit/test_intercomm.c | 51 ++-- 4 files changed, 219 insertions(+), 492 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 2e9ab413076e..3dbd28b61856 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -166,10 +166,8 @@ enum PIO_MSG{ PIO_MSG_INQ_ATT, PIO_MSG_INQ_FORMAT, PIO_MSG_INQ_VARID, - PIO_MSG_INQ_VARNATTS, PIO_MSG_DEF_VAR, PIO_MSG_INQ_VAR, - PIO_MSG_INQ_VARNAME, PIO_MSG_PUT_ATT_DOUBLE, PIO_MSG_PUT_ATT_INT, PIO_MSG_RENAME_ATT, @@ -193,11 +191,9 @@ enum PIO_MSG{ PIO_MSG_PUT_ATT_SCHAR, PIO_MSG_PUT_ATT_FLOAT, PIO_MSG_RENAME_DIM, - PIO_MSG_INQ_VARNDIMS, PIO_MSG_GET_ATT_LONG, PIO_MSG_INQ_DIM, PIO_MSG_INQ_DIMID, - PIO_MSG_INQ_VARDIMID, PIO_MSG_PUT_ATT_USHORT, PIO_MSG_GET_ATT_FLOAT, PIO_MSG_SYNC, @@ -206,7 +202,6 @@ enum PIO_MSG{ PIO_MSG_GET_ATT_SCHAR, PIO_MSG_INQ_ATTID, PIO_MSG_DEF_DIM, - PIO_MSG_INQ_VARTYPE, PIO_MSG_GET_ATT_INT, PIO_MSG_GET_ATT_DOUBLE, PIO_MSG_PUT_ATT_UCHAR, diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 732b4a2377d2..58cfb9ffba8e 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -373,15 +373,21 @@ int att_handler(iosystem_desc_t *ios, int msg) * @param msg the message sent my the comp root task. * @return PIO_NOERR for success, error code otherwise. */ -int inq_var_handler(iosystem_desc_t *ios, int msg) +int inq_var_handler(iosystem_desc_t *ios) { int ncid; int varid; int mpierr; + char name_present, xtype_present, ndims_present, dimids_present, natts_present; + char name[NC_MAX_NAME + 1], *namep; + nc_type xtype, *xtypep = NULL; + int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; + int ndims, dimids[NC_MAX_DIMS], natts; int ret; int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d inq_var_handler\n", my_rank); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -389,40 +395,31 @@ int inq_var_handler(iosystem_desc_t *ios, int msg) return PIO_EIO; if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_var_handler ncid = %d varid = %d\n", my_rank, ncid, varid); + if ((mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + printf("%d inq_var_handler ncid = %d varid = %d name_present = %d xtype_present = %d ndims_present = %d " + "dimids_present = %d natts_present = %d\n", + my_rank, ncid, varid, name_present, xtype_present, ndims_present, dimids_present, natts_present); - /* Call the inq_var function. */ - char name[NC_MAX_NAME + 1], *namep; - nc_type xtype, *xtypep = NULL; - int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; - int ndims, dimids[NC_MAX_DIMS], natts; - switch (msg) - { - case PIO_MSG_INQ_VAR: + /* Set the non-NULL pointers. */ + if (name_present) namep = name; + if (xtype_present) xtypep = &xtype; + if (ndims_present) ndimsp = &ndims; + if (dimids_present) dimidsp = dimids; + if (natts_present) nattsp = &natts; - break; - case PIO_MSG_INQ_VARNATTS: - nattsp = &natts; - break; - case PIO_MSG_INQ_VARNAME: - namep = name; - break; - case PIO_MSG_INQ_VARNDIMS: - ndimsp = &ndims; - break; - case PIO_MSG_INQ_VARDIMID: - dimidsp = dimids; - break; - case PIO_MSG_INQ_VARTYPE: - xtypep = &xtype; - break; - default: - return PIO_EINVAL; - } /* Call the inq function to get the values. */ if ((ret = PIOc_inq_var(ncid, varid, namep, xtypep, ndimsp, dimidsp, nattsp))) @@ -931,12 +928,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) inq_dimid_handler(my_iosys); break; case PIO_MSG_INQ_VAR: - case PIO_MSG_INQ_VARNATTS: - case PIO_MSG_INQ_VARNAME: - case PIO_MSG_INQ_VARNDIMS: - case PIO_MSG_INQ_VARDIMID: - case PIO_MSG_INQ_VARTYPE: - inq_var_handler(my_iosys, msg); + inq_var_handler(my_iosys); break; case PIO_MSG_GET_ATT_INT: case PIO_MSG_PUT_ATT_INT: diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 12a208d7f3d8..f0830c17a078 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -736,7 +736,7 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ + if (ios->io_rank == 0){ ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; } break; @@ -1037,83 +1037,6 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) return ierr; } -/** - * @ingroup PIOc_inq_vartype - * The PIO-C interface for the NetCDF function nc_inq_vartype. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_VARTYPE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh,1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_vartype(file->fh, varid, xtypep);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_vartype(file->fh, varid, xtypep);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_vartype(file->fh, varid, xtypep);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (xtypep) - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_put_att_schar * The PIO-C interface for the NetCDF function nc_put_att_schar. @@ -1187,86 +1110,6 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI return ierr; } -/** - * @ingroup PIOc_inq_vardimid - * The PIO-C interface for the NetCDF function nc_inq_vardimid. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_vardimid (int ncid, int varid, int *dimidsp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_VARDIMID; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_vardimid(file->fh, varid, dimidsp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_vardimid(file->fh, varid, dimidsp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_vardimid(file->fh, varid, dimidsp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (!ierr && dimidsp) - { - int ndims; - PIOc_inq_varndims(file->fh, varid, &ndims); - mpierr = MPI_Bcast(dimidsp , ndims, MPI_INT, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_get_att_ushort * The PIO-C interface for the NetCDF function nc_get_att_ushort. @@ -1636,50 +1479,75 @@ int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype * @param nattsp a pointer that will get the number of attributes * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_var (int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, - int *dimidsp, int *nattsp) +int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, + int *dimidsp, int *nattsp) { - int ierr; - int msg; - int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ndims; /** The number of dimensions for this variable. */ + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_VAR; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + /* For debugging purposes only... */ + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_var\n", my_rank); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VAR; + printf("%d PIOc_inq_var got file\n", my_rank); - if(ios->async_interface && ! ios->ioproc){ + /* If using async, and this is not an IO task, send the parameters to the IO task. */ + if (ios->async_interface && !ios->ioproc) + { + char name_present = name ? true : false; + char xtype_present = xtypep ? true : false; + char ndims_present = ndimsp ? true : false; + char dimids_present = dimidsp ? true : false; + char natts_present = nattsp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq_var ncid = %d\n", my_rank, ncid); mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d dimids_present = %d, natts_present = %d nattsp = %d\n", + my_rank, name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp); } + printf("%d PIOc_inq_var ios->ioproc = %d nattsp = %d\n", my_rank, ios->ioproc, nattsp); - if(ios->ioproc){ + /* Call the netCDF layer. */ + if (ios->ioproc) + { switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; + ierr = nc_inq_varndims(file->fh, varid, &ndims); + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ + if (ios->io_rank == 0) + { + ierr = nc_inq_varndims(file->fh, varid, &ndims); ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; break; #endif @@ -1693,33 +1561,144 @@ int PIOc_inq_var (int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (xtypep) - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); - if (ndimsp) - { - mpierr = MPI_Bcast(ndimsp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - file->varlist[varid].ndims = (*ndimsp); - } - if (nattsp) - mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d called netcdf nc_inq_var ierr = %d\n", my_rank, ierr); + + /* Broadcast the results for non-null pointers. */ if (name) { int slen; if(ios->iomaster) - slen = (int) strlen(name) + 1; + slen = strlen(name); + printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); + mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var name = %s\n", my_rank, name); + } + if (xtypep) + { + mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var xtype = %d\n", my_rank, *xtypep); + } + if (ndimsp) + { + printf("%d PIOc_inq_var ndims = %d\n", my_rank, *ndimsp); + mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + file->varlist[varid].ndims = (*ndimsp); + printf("%d PIOc_inq_var bcast complete ndims = %d\n", my_rank, *ndimsp); } if (dimidsp) { - int ndims; - PIOc_inq_varndims(file->fh, varid, &ndims); + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm); mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm); } + if (nattsp) + { + printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); + mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); + } if(errstr != NULL) free(errstr); return ierr; } +/** + * @ingroup PIOc_inq_varname + * The PIO-C interface for the NetCDF function nc_inq_varname. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_varname (int ncid, int varid, char *name) +{ + return PIOc_inq_var(ncid, varid, name, NULL, NULL, NULL, NULL); +} + +/** + * @ingroup PIOc_inq_vartype + * The PIO-C interface for the NetCDF function nc_inq_vartype. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param xtypep a pointer that will get the type of the attribute. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) +{ + return PIOc_inq_var(ncid, varid, NULL, xtypep, NULL, NULL, NULL); +} + +/** + * @ingroup PIOc_inq_varndims + * The PIO-C interface for the NetCDF function nc_inq_varndims. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL); +} + +/** + * @ingroup PIOc_inq_vardimid + * The PIO-C interface for the NetCDF function nc_inq_vardimid. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_vardimid(int ncid, int varid, int *dimidsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, dimidsp, NULL); +} + +/** + * @ingroup PIOc_inq_varnatts + * The PIO-C interface for the NetCDF function nc_inq_varnatts. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param nattsp a pointer that will get the number of attributes + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, NULL, nattsp); +} + /** * @ingroup PIOc_rename_att * The PIO-C interface for the NetCDF function nc_rename_att. @@ -2893,82 +2872,6 @@ int PIOc_put_att_longlong (int ncid, int varid, const char *name, nc_type xtype, return ierr; } -/** - * @ingroup PIOc_inq_varnatts - * The PIO-C interface for the NetCDF function nc_inq_varnatts. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param nattsp a pointer that will get the number of attributes - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_VARNATTS; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varnatts(file->fh, varid, nattsp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_varnatts(file->fh, varid, nattsp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varnatts(file->fh, varid, nattsp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (nattsp) - mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} /** * @ingroup PIOc_get_att_ubyte @@ -3355,170 +3258,6 @@ int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long return ierr; } -/** - * @ingroup PIOc_inq_varndims - * The PIO-C interface for the NetCDF function nc_inq_varndims. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_VARNDIMS; - if(file->varlist[varid].ndims > 0){ - (*ndimsp) = file->varlist[varid].ndims; - return PIO_NOERR; - } - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh,1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid,1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varndims(file->fh, varid, ndimsp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_varndims(file->fh, varid, ndimsp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varndims(file->fh, varid, ndimsp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (ndimsp) - { - mpierr = MPI_Bcast(ndimsp,1, MPI_INT, ios->ioroot, ios->my_comm); - file->varlist[varid].ndims = (*ndimsp); - } - if(errstr != NULL) free(errstr); - return ierr; -} - -/** - * @ingroup PIOc_inq_varname - * The PIO-C interface for the NetCDF function nc_inq_varname. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_varname (int ncid, int varid, char *name) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_VARNAME; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh,1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varname(file->fh, varid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_varname(file->fh, varid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varname(file->fh, varid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(name != NULL){ - int slen; - if(ios->iomaster) - slen = (int) strlen(name) + 1; - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_def_dim * The PIO-C interface for the NetCDF function nc_def_dim. diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 5ba73d633b3e..dbbc6c39e93f 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -88,7 +88,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Re-open the file to check it. */ if (verbose) - printf("%d test_intercomm opening file %s\n", my_rank, filename); + printf("%d test_intercomm opening file %s format %d\n", my_rank, filename, format); if ((ret = PIOc_openfile(iosysid, &ncid, &format, filename, NC_NOWRITE))) ERR(ret); @@ -143,36 +143,36 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Check out the variable. */ if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) - ERR(ret); + ERR(ret); if (strcmp(varname, VAR_NAME) || vartype != NC_INT || varndims != NDIM || - vardimids != 0 || varnatts != 0) - ERR(ERR_WRONG); + vardimids != 0 || varnatts != 0) + ERR(ERR_WRONG); /* Check the other functions that get these values. */ if ((ret = PIOc_inq_varname(ncid, 0, varname2))) - ERR(ret); + ERR(ret); if (strcmp(varname2, VAR_NAME)) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_vartype(ncid, 0, &vartype2))) - ERR(ret); + ERR(ret); if (vartype2 != NC_INT) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_varndims(ncid, 0, &varndims2))) - ERR(ret); + ERR(ret); if (varndims2 != NDIM) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_vardimid(ncid, 0, &vardimids2))) - ERR(ret); + ERR(ret); if (vardimids2 != 0) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_varnatts(ncid, 0, &varnatts2))) - ERR(ret); + ERR(ret); if (varnatts2 != 0) - ERR(ERR_WRONG); + ERR(ERR_WRONG); if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) - ERR(ret); + ERR(ret); if (varid2 != 0) - ERR(ERR_WRONG); + ERR(ERR_WRONG); /* Check out the global attributes. */ nc_type atttype; @@ -181,10 +181,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* ERR(ret); */ /* if (atttype != NC_INT || attlen != 1) */ /* ERR(ERR_WRONG); */ - if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) - ERR(ret); - if (attlen != 1) - ERR(ERR_WRONG); + /* if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) */ + /* ERR(ret); */ + /* if (attlen != 1) */ + /* ERR(ERR_WRONG); */ /* if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) */ /* ERR(ret); */ /* sleep(2); */ @@ -225,10 +225,10 @@ main(int argc, char **argv) PIO_IOTYPE_NETCDF4P}; /** Names for the output files. */ - char filename[NUM_NETCDF_FLAVORS][NC_MAX_NAME + 1] = {"test_nc4_pnetcdf.nc", - "test_nc4_classic.nc", - "test_nc4_serial4.nc", - "test_nc4_parallel4.nc"}; + char filename[NUM_NETCDF_FLAVORS][NC_MAX_NAME + 1] = {"test_intercomm_pnetcdf.nc", + "test_intercomm_classic.nc", + "test_intercomm_serial4.nc", + "test_intercomm_parallel4.nc"}; /** The ID for the parallel I/O system. */ int iosysid; @@ -334,7 +334,8 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { - for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) + /*for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ + for (int fmt = 0; fmt < 1; fmt++) { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; From 8600910b76ef546407bb85e920419b065a4bd922 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 10 May 2016 11:40:23 -0400 Subject: [PATCH 08/83] removed some unneeded msg constants --- src/clib/pio_nc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/clib/pio_nc.c b/src/clib/pio_nc.c index f511475a4f6c..52a376f0c266 100644 --- a/src/clib/pio_nc.c +++ b/src/clib/pio_nc.c @@ -122,7 +122,7 @@ int PIOc_inq_dimname (int ncid, int dimid, char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_DIMNAME; + msg = PIO_MSG_INQ_DIM; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -961,7 +961,7 @@ int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARTYPE; + msg = PIO_MSG_INQ_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1108,7 +1108,7 @@ int PIOc_inq_vardimid (int ncid, int varid, int *dimidsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARDIMID; + msg = PIO_MSG_INQ_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1340,7 +1340,7 @@ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTLEN; + msg = PIO_MSG_INQ_ATT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1415,7 +1415,7 @@ int PIOc_inq_atttype (int ncid, int varid, const char *name, nc_type *xtypep) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTTYPE; + msg = PIO_MSG_INQ_ATT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1561,7 +1561,7 @@ int PIOc_inq_natts (int ncid, int *ngattsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_NATTS; + msg = PIO_MSG_INQ; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2322,7 +2322,7 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTNAME; + msg = PIO_MSG_INQ_ATT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2551,7 +2551,7 @@ int PIOc_inq_unlimdim (int ncid, int *unlimdimidp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_UNLIMDIM; + msg = PIO_MSG_INQ; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2702,7 +2702,7 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_NDIMS; + msg = PIO_MSG_INQ; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2848,7 +2848,7 @@ int PIOc_inq_nvars (int ncid, int *nvarsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_NVARS; + msg = PIO_MSG_INQ; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -3141,7 +3141,7 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARNATTS; + msg = PIO_MSG_INQ_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -3444,7 +3444,7 @@ int PIOc_inq_dimlen (int ncid, int dimid, PIO_Offset *lenp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_DIMLEN; + msg = PIO_MSG_INQ_DIM; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -3674,7 +3674,7 @@ int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARNDIMS; + msg = PIO_MSG_INQ_VAR; if(file->varlist[varid].ndims > 0){ (*ndimsp) = file->varlist[varid].ndims; return PIO_NOERR; @@ -3753,7 +3753,7 @@ int PIOc_inq_varname (int ncid, int varid, char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARNAME; + msg = PIO_MSG_INQ_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) From b312291c23c62b2f8773c7819ea84eeb9411a7c6 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 10 May 2016 13:11:14 -0400 Subject: [PATCH 09/83] added logging --- CMakeLists.txt | 9 +++ src/clib/config.h.in | 3 + src/clib/pio.h | 2 +- src/clib/pio_internal.h | 6 ++ src/clib/pio_msg.c | 6 ++ src/clib/pio_nc_async.c | 126 +++++++++++++++++++++++++----------- tests/unit/test_intercomm.c | 7 +- 7 files changed, 118 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b284128d2da6..b13a09dbebb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,18 +15,27 @@ mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH) option (PIO_ENABLE_FORTRAN "Enable the Fortran library builds" ON) option (PIO_ENABLE_TIMING "Enable the use of the GPTL timing library" ON) option (PIO_ENABLE_ASYNC "Enable the use of asychronus IO operations" OFF) +option (PIO_ENABLE_LOGGING "Enable debug logging (large output possible)" OFF) option (PIO_TEST_BIG_ENDIAN "Enable test to see if machine is big endian" ON) option (PIO_USE_MPIIO "Enable support for MPI-IO auto detect" ON) option (PIO_USE_MPISERIAL "Enable mpi-serial support (instead of MPI)" OFF) option (PIO_USE_MALLOC "Use native malloc (instead of bget package)" OFF) option (WITH_PNETCDF "Require the use of PnetCDF" ON) +# Set a variable that appears in the config.h.in file. if(PIO_USE_MALLOC) set(USE_MALLOC 1) else() set(USE_MALLOC 0) endif() +# Set a variable that appears in the config.h.in file. +if(PIO_ENABLE_LOGGING) + set(ENABLE_LOGGING 1) +else() + set(ENABLE_LOGGING 0) +endif() + #===== Library Variables ===== set (PIO_FILESYSTEM_HINTS IGNORE CACHE STRING "Filesystem hints (lustre or gpfs)") diff --git a/src/clib/config.h.in b/src/clib/config.h.in index e4be61d9e0c7..1722872c3056 100644 --- a/src/clib/config.h.in +++ b/src/clib/config.h.in @@ -19,4 +19,7 @@ * will use the included bget() package for memory management. */ #define PIO_USE_MALLOC @USE_MALLOC@ +/** Set to non-zero to turn on logging. Output may be large. */ +#define PIO_ENABLE_LOGGING @ENABLE_LOGGING@ + #endif /* _PIO_CONFIG_ */ diff --git a/src/clib/pio.h b/src/clib/pio.h index e96f754e57e7..44507edcdc71 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -647,7 +647,7 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_get_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned long long *buf); int PIOc_get_var_schar (int ncid, int varid, signed char *buf); int PIOc_iotype_available(const int iotype); - + int PIOc_set_log_level(int level); #if defined(__cplusplus) } #endif diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 3dbd28b61856..78297f54f9e7 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -17,6 +17,12 @@ #include #endif +#ifdef PIO_ENABLE_LOGGING +void nc_log(int severity, const char *fmt, ...); +#define LOG(e) pio_log e +#else +#define LOG(e) +#endif /* PIO_ENABLE_LOGGING */ #define max(a,b) \ ({ __typeof__ (a) _a = (a); \ diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 58cfb9ffba8e..e29c6b769af6 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -7,9 +7,15 @@ * @see http://code.google.com/p/parallelio/ */ +#include #include #include +#ifdef PIO_ENABLE_LOGGING +extern int my_rank; +extern int pio_log_level; +#endif /* PIO_ENABLE_LOGGING */ + /** This function is run on the IO tasks to create a netCDF file. */ int create_file_handler(iosystem_desc_t *ios) { diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index f0830c17a078..144a5a2095fa 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -15,9 +15,80 @@ * @date Feburary 2014, April 2016 */ +#include +#ifdef PIO_ENABLE_LOGGING +#include +#endif /* PIO_ENABLE_LOGGING */ #include #include +#ifdef PIO_ENABLE_LOGGING +int pio_log_level = 0; +int my_rank; +#endif /* PIO_ENABLE_LOGGING */ + +/** Set the logging level. Set to -1 for nothing, 0 for errors only, 1 + * for important logging, and so on. Log levels below 1 are only + * printed on the io/component root. If the library is not built with + * logging, this function does nothing. */ +int PIOc_set_log_level(int level) +{ +#ifdef PIO_ENABLE_LOGGING + printf("setting log level to %d\n", level); + pio_log_level = level; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + return PIO_NOERR; +#endif /* PIO_ENABLE_LOGGING */ +} + +#ifdef PIO_ENABLE_LOGGING +/** This function prints out a message, if the severity of the message + is lower than the global pio_log_level. To use it, do something + like this: + + pio_log(0, "this computer will explode in %d seconds", i); + + After the first arg (the severity), use the rest like a normal + printf statement. Output will appear on stdout. + This function is heavily based on the function in section 15.5 of + the C FAQ. +*/ +void +pio_log(int severity, const char *fmt, ...) +{ + va_list argp; + int t; + + /* If the severity is greater than the log level, we don't print + this message. */ + if (severity > pio_log_level) + return; + + /* If the severity is 1 or less, only print on rank 0. */ + if (severity < 2 && my_rank != 0) + return; + + /* If the severity is zero, this is an error. Otherwise insert that + many tabs before the message. */ + if (!severity) + fprintf(stdout, "ERROR: "); + for (t = 0; t < severity; t++) + fprintf(stdout, "\t"); + + /* Show the rank. */ + fprintf(stdout, "%d ", my_rank); + + /* Print out the variable list of args with vprintf. */ + va_start(argp, fmt); + vfprintf(stdout, fmt, argp); + va_end(argp); + + /* Put on a final linefeed. */ + fprintf(stdout, "\n"); + fflush(stdout); +} +#endif /* PIO_ENABLE_LOGGING */ + /** * @ingroup PIOc_inq * The PIO-C interface for the NetCDF function nc_inq. @@ -44,10 +115,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr; /** Return code from MPI function codes. */ - /* For debugging purposes. */ - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq ncid = %d\n", my_rank, ncid); + LOG((1, "PIOc_inq ncid = %d", ncid)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) @@ -67,15 +135,11 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast ncid = %d\n", my_rank, file->fh); mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast ndims_present = %d\n", my_rank, ndims_present); mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast nvars_present = %d\n", my_rank, nvars_present); mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast ngatts_present = %d\n", my_rank, ngatts_present); mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast unlimdimid_present = %d\n", my_rank, unlimdimid_present); + LOG((2, "PIOc_inq netcdf Bcast unlimdimid_present = %d", unlimdimid_present)); } /* If this is an IO task, then call the netCDF function. */ @@ -132,22 +196,22 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, if (ndimsp) { mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc__inq bcast ndims = %d\n", my_rank, *ndimsp); + LOG((2, "PIOc__inq bcast ndims = %d\n", *ndimsp)); } if(nvarsp) { mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc__inq bcast nvars = %d\n", my_rank, *nvarsp); + LOG((2, "%d PIOc__inq bcast nvars = %d\n", my_rank, *nvarsp)); } if(ngattsp) { mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc__inq bcast ngatts = %d\n", my_rank, *ngattsp); + LOG((2, "%d PIOc__inq bcast ngatts = %d\n", my_rank, *ngattsp)); } if(unlimdimidp) { mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc__inq bcast unlimdimid = %d\n", my_rank, *unlimdimidp); + LOG((2, "%d PIOc__inq bcast unlimdimid = %d\n", my_rank, *unlimdimidp)); } if(errstr) @@ -171,9 +235,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, */ int PIOc_inq_ndims (int ncid, int *ndimsp) { - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d calling PIOc_inq_ndims\n", my_rank); + LOG((1, "PIOc_inq_ndims")); return PIOc_inq(ncid, ndimsp, NULL, NULL, NULL); } @@ -552,7 +614,7 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); namelen = strlen(name); - printf("bcasting namelen = %d name = %s\n", namelen, name); + LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); if (!ios->compmaster) ios->compmaster = MPI_PROC_NULL; mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); @@ -700,10 +762,7 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) int msg = PIO_MSG_INQ_DIM; int mpierr; - /* For debugging purposes only... */ - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_dim\n", my_rank); + LOG((1, "PIOc_inq_dim")); /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) @@ -720,9 +779,9 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast name_present = %d\n", my_rank, name_present); + LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq netcdf Bcast len_present = %d\n", my_rank, len_present); + LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); } /* Make the call to the netCDF layer. */ @@ -1221,9 +1280,7 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) ios = file->iosystem; msg = PIO_MSG_INQ_VARID; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name); + LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1232,11 +1289,8 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); int namelen; namelen = strlen(name); - printf("%d PIOc_inq_varid BCast namelen = %d\n", my_rank, namelen); mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq_varid BCast name = %s\n", my_rank, name); mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq_varid BCast done\n", my_rank); } if(ios->ioproc){ @@ -1490,16 +1544,12 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int msg = PIO_MSG_INQ_VAR; int mpierr; - /* For debugging purposes only... */ - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_var\n", my_rank); + LOG((1, "PIOc_inq_var\n")); /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - printf("%d PIOc_inq_var got file\n", my_rank); /* If using async, and this is not an IO task, send the parameters to the IO task. */ if (ios->async_interface && !ios->ioproc) @@ -1512,19 +1562,17 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq_var ncid = %d\n", my_rank, ncid); mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - printf("%d PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d dimids_present = %d, natts_present = %d nattsp = %d\n", - my_rank, name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp); + LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " + "dimids_present = %d, natts_present = %d nattsp = %d", + name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); } - printf("%d PIOc_inq_var ios->ioproc = %d nattsp = %d\n", my_rank, ios->ioproc, nattsp); - /* Call the netCDF layer. */ if (ios->ioproc) { diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index dbbc6c39e93f..6ab8cb03186c 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -321,7 +321,12 @@ main(int argc, char **argv) comp_task = 0; } - + + /* Turn on logging. */ + if ((ret = PIOc_set_log_level(2))) + ERR(ret); + + /* Initialize the async setup. */ if ((ret = PIOc_Init_Intercomm(COMPONENT_COUNT, MPI_COMM_WORLD, &comp_comms, io_comm, &iosysid))) ERR(ret); From bb17ac4d96745de164f72c1f80421d400065b398 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 10 May 2016 15:00:47 -0400 Subject: [PATCH 10/83] rearranged order of functions, started to use LOG in pio_msg --- src/clib/pio_internal.h | 2 +- src/clib/pio_msg.c | 101 ++- src/clib/pio_nc_async.c | 1334 ++++++++++++++++++++------------------- 3 files changed, 713 insertions(+), 724 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 78297f54f9e7..9efa132843d5 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -18,7 +18,7 @@ #endif #ifdef PIO_ENABLE_LOGGING -void nc_log(int severity, const char *fmt, ...); +void pio_log(int severity, const char *fmt, ...); #define LOG(e) pio_log e #else #define LOG(e) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index e29c6b769af6..76a1f69ab6eb 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -27,15 +27,13 @@ int create_file_handler(iosystem_desc_t *ios) int mpierr; int ret; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d create_file_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "create_file_handler comproot = %d\n", ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d create_file_handler got parameter len = %d\n", my_rank, len); + LOG((1, "create_file_handler got parameter len = %d\n", len)); if (!(filename = malloc(len + 1 * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, @@ -45,9 +43,9 @@ int create_file_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&mode, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d create_file_handler got parameters len = %d " + LOG((1, "create_file_handler got parameters len = %d " "filename = %s iotype = %d mode = %d\n", - my_rank, len, filename, iotype, mode); + len, filename, iotype, mode)); /* Call the create file function. */ if ((ret = PIOc_createfile(ios->iosysid, &ncid, &iotype, filename, mode))) @@ -56,7 +54,7 @@ int create_file_handler(iosystem_desc_t *ios) /* Free resources. */ free(filename); - printf("%d create_file_handler succeeded!\n", my_rank); + LOG((1, "create_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -74,19 +72,19 @@ int close_file_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d close_file_handler\n", my_rank); + LOG((1, "%d close_file_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d create_file_handler got parameter ncid = %d\n", my_rank, ncid); + LOG((1, "%d create_file_handler got parameter ncid = %d\n", ncid)); /* Call the close file function. */ if ((ret = PIOc_closefile(ncid))) return ret; - printf("%d close_file_handler succeeded!\n", my_rank); + LOG((1, "close_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -107,26 +105,22 @@ int inq_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_handler\n", my_rank); + LOG((1, "%d inq_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_handler1\n", my_rank); if ((mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_handler2\n", my_rank); if ((mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_handler3\n", my_rank); if ((mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_handler4\n", my_rank); if ((mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_handler ndims_present = %d nvars_present = %d ngatts_present = %d unlimdimid_present = %d\n", - my_rank, ndims_present, nvars_present, ngatts_present, unlimdimid_present); + LOG((1, "%d inq_handler ndims_present = %d nvars_present = %d ngatts_present = %d unlimdimid_present = %d\n", + ndims_present, nvars_present, ngatts_present, unlimdimid_present)); /* NULLs passed in to any of the pointers in the original call * need to be matched with NULLs here. Assign pointers where @@ -169,7 +163,7 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_dim_handler\n", my_rank); + LOG((1, "inq_dim_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -182,7 +176,7 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) if ((mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; printf("%d inq_handler name_present = %d len_present = %d\n", - my_rank, name_present, len_present); + name_present, len_present); /* Set the non-null pointers. */ if (name_present) @@ -215,26 +209,22 @@ int inq_dimid_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_dimid_handler\n", my_rank); + LOG((1, "inq_dimid_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_dimid_handler ncid = %d\n", my_rank, ncid); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_dimid_handler ncid = %d namelen = %d\n", my_rank, ncid, namelen); if (!(name = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_dimid_handler ncid = %d namelen = %d name = %s\n", - my_rank, ncid, namelen, name); if ((mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d\n", - my_rank, ncid, namelen, name, id_present); + LOG((1, "%d inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d\n", + ncid, namelen, name, id_present)); /* Set non-null pointer. */ if (id_present) @@ -271,7 +261,7 @@ int inq_att_handler(iosystem_desc_t *ios, int msg) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_att_handler\n", my_rank); + LOG((1, "inq_att_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -312,7 +302,7 @@ int att_handler(iosystem_desc_t *ios, int msg) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d att_handler\n", my_rank); + LOG((1, "%d att_handler\n", my_rank)); if (msg == PIO_MSG_PUT_ATT_INT) { @@ -362,7 +352,6 @@ int att_handler(iosystem_desc_t *ios, int msg) /* Call the function to read the attribute. */ if ((ret = PIOc_get_att_int(ncid, varid, name5, ip))) return ret; - printf("%d att_handler got att with first element %d\n", my_rank, ip[0]); /* Free resources. */ free(name5); @@ -393,7 +382,7 @@ int inq_var_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d inq_var_handler\n", my_rank); + LOG((1, "%d inq_var_handler\n", my_rank)); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -483,13 +472,13 @@ int sync_file_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d sync_file_handler\n", my_rank); + LOG((1, "%d sync_file_handler\n", my_rank)); /* Get the parameters for this function that the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d sync_file_handler got parameter ncid = %d\n", my_rank, ncid); + LOG((1, "%d sync_file_handler got parameter ncid = %d\n", my_rank, ncid)); /* Call the sync file function. */ if ((ret = PIOc_sync(ncid))) @@ -512,19 +501,18 @@ int enddef_file_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d enddef_file_handler\n", my_rank); + LOG((1, "%d enddef_file_handler\n", my_rank)); /* Get the parameters for this function that the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d enddef_file_handler got parameter ncid = %d\n", my_rank, ncid); /* Call the sync file function. */ if ((ret = PIOc_enddef(ncid))) return ret; - printf("%d enddef_file_handler succeeded!\n", my_rank); + LOG((1, "%d enddef_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -546,7 +534,7 @@ int def_var_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d def_var_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "%d def_var_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ @@ -567,9 +555,9 @@ int def_var_handler(iosystem_desc_t *ios) return PIO_ENOMEM; if ((mpierr = MPI_Bcast(dimids, ndims, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_var_handler got parameters namelen = %d " + LOG((1, "%d def_var_handler got parameters namelen = %d " "name = %s len = %d ncid = %d\n", - my_rank, namelen, name, len, ncid); + my_rank, namelen, name, len, ncid)); /* Call the create file function. */ if ((ret = PIOc_def_var(ncid, name, xtype, ndims, dimids, &varid))) @@ -579,7 +567,7 @@ int def_var_handler(iosystem_desc_t *ios) free(name); free(dimids); - printf("%d def_var_handler succeeded!\n", my_rank); + LOG((1, "%d def_var_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -598,7 +586,7 @@ int def_dim_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d def_dim_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "%d def_dim_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ @@ -626,7 +614,7 @@ int def_dim_handler(iosystem_desc_t *ios) /* Free resources. */ free(name); - printf("%d def_dim_handler succeeded!\n", my_rank); + LOG((1, "%d def_dim_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -656,7 +644,7 @@ int vara_handler(iosystem_desc_t *ios, int msg) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d def_var_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "%d def_var_handler comproot = %d\n", my_rank, ios->comproot)); if (msg == PIO_MSG_PUT_VARA) { @@ -703,7 +691,7 @@ int vara_handler(iosystem_desc_t *ios, int msg) } - printf("%d vara_handler succeeded!\n", my_rank); + LOG((1, "%d vara_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -724,7 +712,7 @@ int open_file_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d open_file_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "%d open_file_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ @@ -740,9 +728,9 @@ int open_file_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&mode, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d open_file_handler got parameters len = %d " + LOG((1, "%d open_file_handler got parameters len = %d " "filename = %s iotype = %d mode = %d\n", - my_rank, len, filename, iotype, mode); + my_rank, len, filename, iotype, mode)); /* Call the open file function. */ if ((ret = PIOc_openfile(ios->iosysid, &ncid, &iotype, filename, mode))) @@ -751,7 +739,7 @@ int open_file_handler(iosystem_desc_t *ios) /* Free resources. */ free(filename); - printf("%d open_file_handler succeeded!\n", my_rank); + LOG((1, "%d open_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -770,20 +758,19 @@ int delete_file_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d delete_file_handler comproot = %d\n", my_rank, ios->comproot); + LOG((1, "%d delete_file_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d open_file_handler got parameter len = %d\n", my_rank, len); if (!(filename = malloc(len + 1 * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - printf("%d delete_file_handler got parameters len = %d filename = %s\n", - my_rank, len, filename); + LOG((1, "%d delete_file_handler got parameters len = %d filename = %s\n", + my_rank, len, filename)); /* Call the delete file function. */ if ((ret = PIOc_deletefile(ios->iosysid, filename))) @@ -792,7 +779,7 @@ int delete_file_handler(iosystem_desc_t *ios) /* Free resources. */ free(filename); - printf("%d delete_file_handler succeeded!\n", my_rank); + LOG((1, "%d delete_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -830,7 +817,7 @@ int finalize_handler(iosystem_desc_t *ios) { int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d finalize_handler called\n", my_rank); + LOG((1, "%d finalize_handler called\n", my_rank)); return PIO_NOERR; } @@ -853,7 +840,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d pio_msg_handler called\n", my_rank); + LOG((1, "%d pio_msg_handler called\n", my_rank)); /* Have IO comm rank 0 (the ioroot) register to receive * (non-blocking) for a message from each of the comproots. */ @@ -862,7 +849,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) for (int cmp = 0; cmp < component_count; cmp++) { my_iosys = &iosys[cmp]; - printf("%d about to call MPI_Irecv\n", my_rank); + LOG((1, "%d about to call MPI_Irecv\n", my_rank)); mpierr = MPI_Irecv(&msg, 1, MPI_INT, my_iosys->comproot, MPI_ANY_TAG, my_iosys->union_comm, &req[cmp]); CheckMPIReturn(mpierr, __FILE__, __LINE__); @@ -875,8 +862,8 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) /* Wait until any one of the requests are complete. */ if (!io_rank) { - printf("%d about to call MPI_Waitany req[0] = %d MPI_REQUEST_NULL = %d\n", - my_rank, req[0], MPI_REQUEST_NULL); + LOG((1, "%d about to call MPI_Waitany req[0] = %d MPI_REQUEST_NULL = %d\n", + my_rank, req[0], MPI_REQUEST_NULL)); mpierr = MPI_Waitany(component_count, req, &index, &status); CheckMPIReturn(mpierr, __FILE__, __LINE__); printf("%d Waitany returned index = %d req[%d] = %d\n", my_rank, diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 144a5a2095fa..45dd6c4ea38e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -276,62 +276,69 @@ int PIOc_inq_natts(int ncid, int *ngattsp) } /** - * @ingroup PIOc_put_att_short - * The PIO-C interface for the NetCDF function nc_put_att_short. + * @ingroup PIOc_inq_dim + * The PIO-C interface for the NetCDF function nc_inq_dim. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. + * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) +int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { - int ierr; - int msg; - int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_DIM; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq_dim")); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SHORT; - if(ios->async_interface && ! ios->ioproc){ + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface && !ios->ioproc) + { + char name_present = name ? true : false; + char len_present = lenp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); } - + /* Make the call to the netCDF layer. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; + if (ios->io_rank == 0){ + ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_short(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; break; #endif default: @@ -339,18 +346,31 @@ int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PI } } + /* Error handling. */ if(ierr != PIO_NOERR){ errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + + /* BCast the results, if non-null pointers were passed. */ + if(name) + { + int slen; + if(ios->iomaster) + slen = strlen(name); + mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); + } + if(lenp != NULL) + mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_rename_dim - * The PIO-C interface for the NetCDF function nc_rename_dim. + * @ingroup PIOc_inq_dimname + * The PIO-C interface for the NetCDF function nc_inq_dimname. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -361,49 +381,96 @@ int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PI * PIOc_openfile() or PIOc_createfile(). * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_dim (int ncid, int dimid, const char *name) +int PIOc_inq_dimname(int ncid, int dimid, char *name) { - int ierr; - int msg; - int mpierr; + return PIOc_inq_dim(ncid, dimid, name, NULL); +} + +/** + * @ingroup PIOc_inq_dimlen + * The PIO-C interface for the NetCDF function nc_inq_dimlen. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param lenp a pointer that will get the number of values + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) +{ + return PIOc_inq_dim(ncid, dimid, NULL, lenp); +} + +/** + * @ingroup PIOc_inq_dimid + * The PIO-C interface for the NetCDF function nc_inq_dimid. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param idp a pointer that will get the id of the variable or attribute. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_dimid(int ncid, const char *name, int *idp) +{ + int msg = PIO_MSG_INQ_DIMID; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ierr = PIO_NOERR; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + /* For debugging purposes only... */ + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_dimid\n", my_rank); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_DIM; - if(ios->async_interface && ! ios->ioproc){ + /* If using async, and not an IO task, then send parameters. */ + if (ios->async_interface && !ios->ioproc) + { + int namelen; + char id_present = idp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - + /* IO tasks call the netCDF functions. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_dim(file->fh, dimid, name);; + ierr = nc_inq_dimid(file->fh, name, idp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_rename_dim(file->fh, dimid, name);; + ierr = nc_inq_dimid(file->fh, name, idp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_dim(file->fh, dimid, name);; + ierr = ncmpi_inq_dimid(file->fh, name, idp);; break; #endif default: @@ -416,67 +483,92 @@ int PIOc_rename_dim (int ncid, int dimid, const char *name) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if (idp) + mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_get_att_double - * The PIO-C interface for the NetCDF function nc_get_att_double. + * @ingroup PIOc_inq_var + * The PIO-C interface for the NetCDF function nc_inq_var. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. + * @param xtypep a pointer that will get the type of the attribute. + * @param nattsp a pointer that will get the number of attributes * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) +int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, + int *dimidsp, int *nattsp) { - int ierr; - int msg; - int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + char *errstr = NULL; + int ndims; /** The number of dimensions for this variable. */ + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_VAR; + int mpierr; - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq_var\n")); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get the file info, based on the ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_DOUBLE; - if(ios->async_interface && ! ios->ioproc){ + /* If using async, and this is not an IO task, send the parameters to the IO task. */ + if (ios->async_interface && !ios->ioproc) + { + char name_present = name ? true : false; + char xtype_present = xtypep ? true : false; + char ndims_present = ndimsp ? true : false; + char dimids_present = dimidsp ? true : false; + char natts_present = nattsp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " + "dimids_present = %d, natts_present = %d nattsp = %d", + name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); } - - if(ios->ioproc){ + /* Call the netCDF layer. */ + if (ios->ioproc) + { switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_double(file->fh, varid, name, ip);; + ierr = nc_inq_varndims(file->fh, varid, &ndims); + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_double(file->fh, varid, name, ip);; + if (ios->io_rank == 0) + { + ierr = nc_inq_varndims(file->fh, varid, &ndims); + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_double(file->fh, varid, name, ip);; + ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); + ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; break; #endif default: @@ -485,94 +577,73 @@ int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_DOUBLE, ios->ioroot, ios->my_comm); + printf("%d called netcdf nc_inq_var ierr = %d\n", my_rank, ierr); + + /* Broadcast the results for non-null pointers. */ + if (name) + { + int slen; + if(ios->iomaster) + slen = strlen(name); + printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); + mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); + mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var name = %s\n", my_rank, name); + } + if (xtypep) + { + mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var xtype = %d\n", my_rank, *xtypep); + } + if (ndimsp) + { + printf("%d PIOc_inq_var ndims = %d\n", my_rank, *ndimsp); + mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + file->varlist[varid].ndims = (*ndimsp); + printf("%d PIOc_inq_var bcast complete ndims = %d\n", my_rank, *ndimsp); + } + if (dimidsp) + { + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm); + } + if (nattsp) + { + printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); + mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_set_fill - * The PIO-C interface for the NetCDF function nc_set_fill. + * @ingroup PIOc_inq_varname + * The PIO-C interface for the NetCDF function nc_inq_varname. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_set_fill (int ncid, int fillmode, int *old_modep) +int PIOc_inq_varname (int ncid, int varid, char *name) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_SET_FILL; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_set_fill(file->fh, fillmode, old_modep);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_set_fill(file->fh, fillmode, old_modep);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_set_fill(file->fh, fillmode, old_modep);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_inq_var(ncid, varid, name, NULL, NULL, NULL, NULL); } /** - * @ingroup PIOc_def_var - * The PIO-C interface for the NetCDF function nc_def_var. + * @ingroup PIOc_inq_vartype + * The PIO-C interface for the NetCDF function nc_inq_vartype. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -582,105 +653,88 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @param varidp a pointer that will get the variable id - * @return PIO_NOERR for success, error code otherwise. See - * PIOc_Set_File_Error_Handling + * @param xtypep a pointer that will get the type of the attribute. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, - const int *dimidsp, int *varidp) +int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - int namelen; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_DEF_VAR; + return PIOc_inq_var(ncid, varid, NULL, xtypep, NULL, NULL, NULL); +} - /* If async is in use, and this is not an IO tasks, then bcast the - * function parameters to the intercomm, where it will be read by - * the IO root task. */ - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); - if (!ios->compmaster) - ios->compmaster = MPI_PROC_NULL; - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); - } +/** + * @ingroup PIOc_inq_varndims + * The PIO-C interface for the NetCDF function nc_inq_varndims. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp);; - break; - case PIO_IOTYPE_NETCDF4C: - if(ios->io_rank==0){ - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); - if(ierr == PIO_NOERR){ - ierr = nc_def_var_deflate(file->fh, *varidp, 0,1,1); - } - } - break; -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_def_var(file->fh, name, xtype, ndims, dimidsp, varidp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } +/** + * @ingroup PIOc_inq_vardimid + * The PIO-C interface for the NetCDF function nc_inq_vardimid. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_vardimid(int ncid, int varid, int *dimidsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, dimidsp, NULL); +} - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; +/** + * @ingroup PIOc_inq_varnatts + * The PIO-C interface for the NetCDF function nc_inq_varnatts. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param nattsp a pointer that will get the number of attributes + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) +{ + return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, NULL, nattsp); } /** - * @ingroup PIOc_put_att_double - * The PIO-C interface for the NetCDF function nc_put_att_double. + * @ingroup PIOc_inq_varid + * The PIO-C interface for the NetCDF function nc_inq_varid. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. + * @param varidp a pointer that will get the variable id * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) +int PIOc_inq_varid (int ncid, const char *name, int *varidp) { int ierr; int msg; @@ -696,33 +750,39 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_DOUBLE; + msg = PIO_MSG_INQ_VARID; + + LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + printf("%d PIOc_inq_varid BCast ncid = %d\n", my_rank, ncid); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen; + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_inq_varid(file->fh, name, varidp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_inq_varid(file->fh, name, varidp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_double(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_inq_varid(file->fh, name, varidp);; break; #endif default: @@ -735,74 +795,79 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if (varidp) + mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_dim - * The PIO-C interface for the NetCDF function nc_inq_dim. + * @ingroup PIOc_inq_att + * The PIO-C interface for the NetCDF function nc_inq_att. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param xtypep a pointer that will get the type of the attribute. * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) +int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, + PIO_Offset *lenp) { + int ierr; + int msg; + int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; - int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_DIM; - int mpierr; + char *errstr; - LOG((1, "PIOc_inq_dim")); + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d\n", + my_rank, ncid, varid, xtypep, lenp); + + errstr = NULL; + ierr = PIO_NOERR; - /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; + msg = PIO_MSG_INQ_ATT; - /* If async is in use, and this is not an IO task, bcast the parameters. */ - if (ios->async_interface && !ios->ioproc) - { - char name_present = name ? true : false; - char len_present = lenp ? true : false; + if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); - mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - /* Make the call to the netCDF layer. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0){ - ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; + if(ios->io_rank==0){ + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; + ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);; break; #endif default: @@ -810,68 +875,64 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) } } - /* Error handling. */ if(ierr != PIO_NOERR){ errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - - /* BCast the results, if non-null pointers were passed. */ - if(name) - { - int slen; - if(ios->iomaster) - slen = strlen(name); - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(lenp != NULL) - mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); + if(xtypep) + mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); + if(lenp) + mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_dimname - * The PIO-C interface for the NetCDF function nc_inq_dimname. + * @ingroup PIOc_inq_attlen + * The PIO-C interface for the NetCDF function nc_inq_attlen. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dimname(int ncid, int dimid, char *name) +int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) { - return PIOc_inq_dim(ncid, dimid, name, NULL); + nc_type dummy; + return PIOc_inq_att(ncid, varid, name, &dummy, lenp); } /** - * @ingroup PIOc_inq_dimlen - * The PIO-C interface for the NetCDF function nc_inq_dimlen. + * @ingroup PIOc_inq_atttype + * The PIO-C interface for the NetCDF function nc_inq_atttype. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param lenp a pointer that will get the number of values + * @param varid the variable ID. + * @param xtypep a pointer that will get the type of the attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) +int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) { - return PIOc_inq_dim(ncid, dimid, NULL, lenp); + PIO_Offset dummy; + return PIOc_inq_att(ncid, varid, name, xtypep, &dummy); } /** - * @ingroup PIOc_get_att_uchar - * The PIO-C interface for the NetCDF function nc_get_att_uchar. + * @ingroup PIOc_inq_attname + * The PIO-C interface for the NetCDF function nc_inq_attname. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -881,9 +942,10 @@ int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. + * @param attnum the attribute ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) +int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) { int ierr; int msg; @@ -899,7 +961,7 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UCHAR; + msg = PIO_MSG_INQ_ATTNAME; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -913,19 +975,19 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; + ierr = nc_inq_attname(file->fh, varid, attnum, name);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; + ierr = nc_inq_attname(file->fh, varid, attnum, name);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_uchar(file->fh, varid, name, ip);; + ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; break; #endif default: @@ -934,34 +996,37 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_CHAR, ios->ioroot, ios->my_comm); + if(name != NULL){ + int slen; + if(ios->iomaster) + slen = (int) strlen(name) + 1; + mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_var_fill - * The PIO-C interface for the NetCDF function nc_inq_var_fill. + * @ingroup PIOc_inq_attid + * The PIO-C interface for the NetCDF function nc_inq_attid. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. + * @param idp a pointer that will get the id of the variable or attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) +int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) { int ierr; int msg; @@ -977,7 +1042,7 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VAR_FILL; + msg = PIO_MSG_INQ_ATTID; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -991,19 +1056,19 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = nc_inq_attid(file->fh, varid, name, idp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = nc_inq_attid(file->fh, varid, name, idp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = ncmpi_inq_attid(file->fh, varid, name, idp);; break; #endif default: @@ -1016,14 +1081,14 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_attid - * The PIO-C interface for the NetCDF function nc_inq_attid. + * @ingroup PIOc_put_att_short + * The PIO-C interface for the NetCDF function nc_put_att_short. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1033,10 +1098,9 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @param idp a pointer that will get the id of the variable or attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) +int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) { int ierr; int msg; @@ -1052,7 +1116,7 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTID; + msg = PIO_MSG_PUT_ATT_SHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1066,19 +1130,19 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attid(file->fh, varid, name, idp);; + ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_attid(file->fh, varid, name, idp);; + ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_attid(file->fh, varid, name, idp);; + ierr = ncmpi_put_att_short(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1091,26 +1155,24 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_put_att_schar - * The PIO-C interface for the NetCDF function nc_put_att_schar. + * @ingroup PIOc_rename_dim + * The PIO-C interface for the NetCDF function nc_rename_dim. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) +int PIOc_rename_dim (int ncid, int dimid, const char *name) { int ierr; int msg; @@ -1126,7 +1188,7 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SCHAR; + msg = PIO_MSG_RENAME_DIM; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1140,19 +1202,19 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_rename_dim(file->fh, dimid, name);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_rename_dim(file->fh, dimid, name);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_schar(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_rename_dim(file->fh, dimid, name);; break; #endif default: @@ -1170,8 +1232,8 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI } /** - * @ingroup PIOc_get_att_ushort - * The PIO-C interface for the NetCDF function nc_get_att_ushort. + * @ingroup PIOc_get_att_double + * The PIO-C interface for the NetCDF function nc_get_att_double. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1183,7 +1245,7 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) +int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) { int ierr; int msg; @@ -1199,7 +1261,7 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_USHORT; + msg = PIO_MSG_GET_ATT_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1213,19 +1275,19 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + ierr = nc_get_att_double(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + ierr = nc_get_att_double(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_ushort(file->fh, varid, name, ip);; + ierr = ncmpi_get_att_double(file->fh, varid, name, ip);; break; #endif default: @@ -1241,28 +1303,26 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * if(ierr == PIO_NOERR){ PIO_Offset attlen; PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_SHORT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_DOUBLE, ios->ioroot, ios->my_comm); } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_varid - * The PIO-C interface for the NetCDF function nc_inq_varid. + * @ingroup PIOc_set_fill + * The PIO-C interface for the NetCDF function nc_set_fill. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param varidp a pointer that will get the variable id * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_varid (int ncid, const char *name, int *varidp) +int PIOc_set_fill (int ncid, int fillmode, int *old_modep) { int ierr; int msg; @@ -1278,39 +1338,33 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARID; - - LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); + msg = PIO_MSG_SET_FILL; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - printf("%d PIOc_inq_varid BCast ncid = %d\n", my_rank, ncid); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen; - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } + if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varid(file->fh, name, varidp);; + ierr = nc_set_fill(file->fh, fillmode, old_modep);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_varid(file->fh, name, varidp);; + ierr = nc_set_fill(file->fh, fillmode, old_modep);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varid(file->fh, name, varidp);; + ierr = ncmpi_set_fill(file->fh, fillmode, old_modep);; break; #endif default: @@ -1323,69 +1377,123 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (varidp) - mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_attlen - * The PIO-C interface for the NetCDF function nc_inq_attlen. + * @ingroup PIOc_def_var + * The PIO-C interface for the NetCDF function nc_def_var. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @param lenp a pointer that will get the number of values - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + * @param varidp a pointer that will get the variable id + * @return PIO_NOERR for success, error code otherwise. See + * PIOc_Set_File_Error_Handling */ -int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) +int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, + const int *dimidsp, int *varidp) { - nc_type dummy; - return PIOc_inq_att(ncid, varid, name, &dummy, lenp); -} + int msg = PIO_MSG_DEF_VAR; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + int ierr = PIO_NOERR; + char *errstr = NULL; + int namelen; -/** - * @ingroup PIOc_inq_atttype - * The PIO-C interface for the NetCDF function nc_inq_atttype. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) -{ - PIO_Offset dummy; - return PIOc_inq_att(ncid, varid, name, xtypep, &dummy); + /* Get the file information. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* If async is in use, and this is not an IO tasks, then bcast the + * function parameters to the intercomm, where it will be read by + * the IO root task. */ + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); + if (!ios->compmaster) + ios->compmaster = MPI_PROC_NULL; + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); + } + + if(ios->ioproc){ + switch(file->iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp);; + break; + case PIO_IOTYPE_NETCDF4C: + if (ios->io_rank == 0) + { + ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); + if (!ierr) + ierr = nc_def_var_deflate(file->fh, *varidp, 0,1,1); + } + break; +#endif + case PIO_IOTYPE_NETCDF: + if (ios->io_rank == 0) + ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + /* Handle errors. */ + if (ierr) + { + errstr = (char *)malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr, "in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm); + + /* Free error string if allocated. */ + if(errstr) + free(errstr); + + return ierr; } /** - * @ingroup PIOc_rename_var - * The PIO-C interface for the NetCDF function nc_rename_var. + * @ingroup PIOc_put_att_double + * The PIO-C interface for the NetCDF function nc_put_att_double. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_var (int ncid, int varid, const char *name) +int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) { int ierr; int msg; @@ -1401,7 +1509,7 @@ int PIOc_rename_var (int ncid, int varid, const char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_VAR; + msg = PIO_MSG_PUT_ATT_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1415,19 +1523,19 @@ int PIOc_rename_var (int ncid, int varid, const char *name) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_var(file->fh, varid, name);; + ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_rename_var(file->fh, varid, name);; + ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_var(file->fh, varid, name);; + ierr = ncmpi_put_att_double(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1445,8 +1553,8 @@ int PIOc_rename_var (int ncid, int varid, const char *name) } /** - * @ingroup PIOc_put_att_ulonglong - * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. + * @ingroup PIOc_get_att_uchar + * The PIO-C interface for the NetCDF function nc_get_att_uchar. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1458,7 +1566,7 @@ int PIOc_rename_var (int ncid, int varid, const char *name) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned long long *op) +int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) { int ierr; int msg; @@ -1474,7 +1582,7 @@ int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_ULONGLONG; + msg = PIO_MSG_GET_ATT_UCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1488,19 +1596,19 @@ int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_uchar(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_get_att_uchar(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_ulonglong(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_get_att_uchar(file->fh, varid, name, ip);; break; #endif default: @@ -1509,17 +1617,22 @@ int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_CHAR, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_var - * The PIO-C interface for the NetCDF function nc_inq_var. + * @ingroup PIOc_inq_var_fill + * The PIO-C interface for the NetCDF function nc_inq_var_fill. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1529,74 +1642,51 @@ int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @param nattsp a pointer that will get the number of attributes * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, - int *dimidsp, int *nattsp) +int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) { + int ierr; + int msg; + int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; - int ndims; /** The number of dimensions for this variable. */ - int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_VAR; - int mpierr; + char *errstr; - LOG((1, "PIOc_inq_var\n")); + errstr = NULL; + ierr = PIO_NOERR; - /* Get the file info, based on the ncid. */ - if (!(file = pio_get_file_from_id(ncid))) + file = pio_get_file_from_id(ncid); + if(file == NULL) return PIO_EBADID; ios = file->iosystem; + msg = PIO_MSG_INQ_VAR_FILL; - /* If using async, and this is not an IO task, send the parameters to the IO task. */ - if (ios->async_interface && !ios->ioproc) - { - char name_present = name ? true : false; - char xtype_present = xtypep ? true : false; - char ndims_present = ndimsp ? true : false; - char dimids_present = dimidsp ? true : false; - char natts_present = nattsp ? true : false; + if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " - "dimids_present = %d, natts_present = %d nattsp = %d", - name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - /* Call the netCDF layer. */ - if (ios->ioproc) - { + + if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varndims(file->fh, varid, &ndims); - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - { - ierr = nc_inq_varndims(file->fh, varid, &ndims); - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; + if(ios->io_rank==0){ + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); - ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; + ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_value);; break; #endif default: @@ -1609,147 +1699,87 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - printf("%d called netcdf nc_inq_var ierr = %d\n", my_rank, ierr); - - /* Broadcast the results for non-null pointers. */ - if (name) - { - int slen; - if(ios->iomaster) - slen = strlen(name); - printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); - mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var name = %s\n", my_rank, name); - } - if (xtypep) - { - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var xtype = %d\n", my_rank, *xtypep); - } - if (ndimsp) - { - printf("%d PIOc_inq_var ndims = %d\n", my_rank, *ndimsp); - mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - file->varlist[varid].ndims = (*ndimsp); - printf("%d PIOc_inq_var bcast complete ndims = %d\n", my_rank, *ndimsp); - } - if (dimidsp) - { - mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm); - } - if (nattsp) - { - printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); - mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); - } + mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_varname - * The PIO-C interface for the NetCDF function nc_inq_varname. + * @ingroup PIOc_put_att_schar + * The PIO-C interface for the NetCDF function nc_put_att_schar. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_varname (int ncid, int varid, char *name) +int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) { - return PIOc_inq_var(ncid, varid, name, NULL, NULL, NULL, NULL); -} + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; -/** - * @ingroup PIOc_inq_vartype - * The PIO-C interface for the NetCDF function nc_inq_vartype. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) -{ - return PIOc_inq_var(ncid, varid, NULL, xtypep, NULL, NULL, NULL); -} + errstr = NULL; + ierr = PIO_NOERR; -/** - * @ingroup PIOc_inq_varndims - * The PIO-C interface for the NetCDF function nc_inq_varndims. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) -{ - return PIOc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL); -} + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_ATT_SCHAR; -/** - * @ingroup PIOc_inq_vardimid - * The PIO-C interface for the NetCDF function nc_inq_vardimid. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_vardimid(int ncid, int varid, int *dimidsp) -{ - return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, dimidsp, NULL); -} + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } -/** - * @ingroup PIOc_inq_varnatts - * The PIO-C interface for the NetCDF function nc_inq_varnatts. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param nattsp a pointer that will get the number of attributes - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) -{ - return PIOc_inq_var(ncid, varid, NULL, NULL, NULL, NULL, nattsp); + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_put_att_schar(file->fh, varid, name, xtype, len, op);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(errstr != NULL) free(errstr); + return ierr; } /** - * @ingroup PIOc_rename_att - * The PIO-C interface for the NetCDF function nc_rename_att. + * @ingroup PIOc_get_att_ushort + * The PIO-C interface for the NetCDF function nc_get_att_ushort. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1761,7 +1791,7 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) +int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) { int ierr; int msg; @@ -1777,7 +1807,7 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_ATT; + msg = PIO_MSG_GET_ATT_USHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1791,19 +1821,19 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_att(file->fh, varid, name, newname);; + ierr = nc_get_att_ushort(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_rename_att(file->fh, varid, name, newname);; + ierr = nc_get_att_ushort(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_att(file->fh, varid, name, newname);; + ierr = ncmpi_get_att_ushort(file->fh, varid, name, ip);; break; #endif default: @@ -1812,29 +1842,34 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_SHORT, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_put_att_ushort - * The PIO-C interface for the NetCDF function nc_put_att_ushort. + * @ingroup PIOc_rename_var + * The PIO-C interface for the NetCDF function nc_rename_var. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned short *op) +int PIOc_rename_var (int ncid, int varid, const char *name) { int ierr; int msg; @@ -1850,7 +1885,7 @@ int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_USHORT; + msg = PIO_MSG_RENAME_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1864,19 +1899,19 @@ int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, P #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_rename_var(file->fh, varid, name);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_rename_var(file->fh, varid, name);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_ushort(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_rename_var(file->fh, varid, name);; break; #endif default: @@ -1894,71 +1929,62 @@ int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, P } /** - * @ingroup PIOc_inq_dimid - * The PIO-C interface for the NetCDF function nc_inq_dimid. + * @ingroup PIOc_put_att_ulonglong + * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param idp a pointer that will get the id of the variable or attribute. + * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_dimid(int ncid, const char *name, int *idp) +int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned long long *op) { - int msg = PIO_MSG_INQ_DIMID; + int ierr; + int msg; + int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; - int ierr = PIO_NOERR; - int mpierr; + char *errstr; - /* For debugging purposes only... */ - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_dimid\n", my_rank); + errstr = NULL; + ierr = PIO_NOERR; - /* Get the file info, based on the ncid. */ - if (!(file = pio_get_file_from_id(ncid))) + file = pio_get_file_from_id(ncid); + if(file == NULL) return PIO_EBADID; ios = file->iosystem; + msg = PIO_MSG_PUT_ATT_ULONGLONG; - /* If using async, and not an IO task, then send parameters. */ - if (ios->async_interface && !ios->ioproc) - { - int namelen; - char id_present = idp ? true : false; + if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - /* IO tasks call the netCDF functions. */ + if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dimid(file->fh, name, idp);; + ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_dimid(file->fh, name, idp);; + ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_dimid(file->fh, name, idp);; + ierr = ncmpi_put_att_ulonglong(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1971,15 +1997,13 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if (idp) - mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_put_att_text - * The PIO-C interface for the NetCDF function nc_put_att_text. + * @ingroup PIOc_rename_att + * The PIO-C interface for the NetCDF function nc_rename_att. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1991,7 +2015,7 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, const char *op) +int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) { int ierr; int msg; @@ -2007,7 +2031,7 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_TEXT; + msg = PIO_MSG_RENAME_ATT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2021,19 +2045,19 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; + ierr = nc_rename_att(file->fh, varid, name, newname);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; + ierr = nc_rename_att(file->fh, varid, name, newname);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_text(file->fh, varid, name, len, op);; + ierr = ncmpi_rename_att(file->fh, varid, name, newname);; break; #endif default: @@ -2051,8 +2075,8 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co } /** - * @ingroup PIOc_get_att_uint - * The PIO-C interface for the NetCDF function nc_get_att_uint. + * @ingroup PIOc_put_att_ushort + * The PIO-C interface for the NetCDF function nc_put_att_ushort. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2064,7 +2088,7 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) +int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned short *op) { int ierr; int msg; @@ -2080,7 +2104,7 @@ int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UINT; + msg = PIO_MSG_PUT_ATT_USHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2094,19 +2118,19 @@ int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_uint(file->fh, varid, name, ip);; + ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_uint(file->fh, varid, name, ip);; + ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_uint(file->fh, varid, name, ip);; + ierr = ncmpi_put_att_ushort(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -2115,34 +2139,29 @@ int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED, ios->ioroot, ios->my_comm); - } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_format - * The PIO-C interface for the NetCDF function nc_inq_format. + * @ingroup PIOc_put_att_text + * The PIO-C interface for the NetCDF function nc_put_att_text. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param formatp a pointer that will get the file format + * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_format (int ncid, int *formatp) +int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, const char *op) { int ierr; int msg; @@ -2158,7 +2177,7 @@ int PIOc_inq_format (int ncid, int *formatp) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_FORMAT; + msg = PIO_MSG_PUT_ATT_TEXT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2172,19 +2191,19 @@ int PIOc_inq_format (int ncid, int *formatp) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_format(file->fh, formatp);; + ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_format(file->fh, formatp);; + ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_format(file->fh, formatp);; + ierr = ncmpi_put_att_text(file->fh, varid, name, len, op);; break; #endif default: @@ -2197,14 +2216,13 @@ int PIOc_inq_format (int ncid, int *formatp) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_get_att_long - * The PIO-C interface for the NetCDF function nc_get_att_long. + * @ingroup PIOc_get_att_uint + * The PIO-C interface for the NetCDF function nc_get_att_uint. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2216,7 +2234,7 @@ int PIOc_inq_format (int ncid, int *formatp) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) +int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) { int ierr; int msg; @@ -2232,7 +2250,7 @@ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_LONG; + msg = PIO_MSG_GET_ATT_UINT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2246,19 +2264,19 @@ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_long(file->fh, varid, name, ip);; + ierr = nc_get_att_uint(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_long(file->fh, varid, name, ip);; + ierr = nc_get_att_uint(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_long(file->fh, varid, name, ip);; + ierr = ncmpi_get_att_uint(file->fh, varid, name, ip);; break; #endif default: @@ -2274,28 +2292,27 @@ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) if(ierr == PIO_NOERR){ PIO_Offset attlen; PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED, ios->ioroot, ios->my_comm); } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_attname - * The PIO-C interface for the NetCDF function nc_inq_attname. + * @ingroup PIOc_inq_format + * The PIO-C interface for the NetCDF function nc_inq_format. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param attnum the attribute ID. + * @param formatp a pointer that will get the file format * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) +int PIOc_inq_format (int ncid, int *formatp) { int ierr; int msg; @@ -2311,7 +2328,7 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTNAME; + msg = PIO_MSG_INQ_FORMAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2325,19 +2342,19 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attname(file->fh, varid, attnum, name);; + ierr = nc_inq_format(file->fh, formatp);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_attname(file->fh, varid, attnum, name);; + ierr = nc_inq_format(file->fh, formatp);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; + ierr = ncmpi_inq_format(file->fh, formatp);; break; #endif default: @@ -2350,20 +2367,14 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(name != NULL){ - int slen; - if(ios->iomaster) - slen = (int) strlen(name) + 1; - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); - } + mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_att - * The PIO-C interface for the NetCDF function nc_inq_att. + * @ingroup PIOc_get_att_long + * The PIO-C interface for the NetCDF function nc_get_att_long. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -2373,12 +2384,9 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, - PIO_Offset *lenp) +int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) { int ierr; int msg; @@ -2387,47 +2395,40 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, file_desc_t *file; char *errstr; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d\n", - my_rank, ncid, varid, xtypep, lenp); - errstr = NULL; ierr = PIO_NOERR; - if (!(file = pio_get_file_from_id(ncid))) + file = pio_get_file_from_id(ncid); + if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATT; + msg = PIO_MSG_GET_ATT_LONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } + if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; + ierr = nc_get_att_long(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; + ierr = nc_get_att_long(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);; + ierr = ncmpi_get_att_long(file->fh, varid, name, ip);; break; #endif default: @@ -2436,14 +2437,15 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(xtypep) - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(lenp) - mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } From b16d251b1798f3607c9a2ab19e38bde22aa781e6 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 10 May 2016 16:55:44 -0400 Subject: [PATCH 11/83] cleaning up error handling --- src/clib/pio_msg.c | 323 ++++++++++++++--------------- src/clib/pio_nc_async.c | 444 +++++++++++++++++++++------------------- 2 files changed, 401 insertions(+), 366 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 76a1f69ab6eb..e30dc8dce2b6 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -1,5 +1,5 @@ /** - * @file + * @file * @author Ed Hartnett * @date 2016 * @brief PIO async msg handling @@ -26,7 +26,7 @@ int create_file_handler(iosystem_desc_t *ios) int mode; int mpierr; int ret; - + LOG((1, "create_file_handler comproot = %d\n", ios->comproot)); /* Get the parameters for this function that the he comp master @@ -50,28 +50,28 @@ int create_file_handler(iosystem_desc_t *ios) /* Call the create file function. */ if ((ret = PIOc_createfile(ios->iosysid, &ncid, &iotype, filename, mode))) return ret; - + /* Free resources. */ free(filename); - + LOG((1, "create_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } /** This function is run on the IO tasks to close a netCDF file. It is - * only ever run on the IO tasks. + * only ever run on the IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int close_file_handler(iosystem_desc_t *ios) { int ncid; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d close_file_handler\n", my_rank)); /* Get the parameters for this function that the the comp master @@ -83,16 +83,16 @@ int close_file_handler(iosystem_desc_t *ios) /* Call the close file function. */ if ((ret = PIOc_closefile(ncid))) return ret; - + LOG((1, "close_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } /** This function is run on the IO tasks to inq a netCDF file. It is - * only ever run on the IO tasks. + * only ever run on the IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int inq_handler(iosystem_desc_t *ios) { @@ -102,9 +102,9 @@ int inq_handler(iosystem_desc_t *ios) char ndims_present, nvars_present, ngatts_present, unlimdimid_present; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d inq_handler\n", my_rank)); /* Get the parameters for this function that the the comp master @@ -137,22 +137,22 @@ int inq_handler(iosystem_desc_t *ios) /* Call the inq function to get the values. */ if ((ret = PIOc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp))) return ret; - + return PIO_NOERR; } /** Do an inq_dim on a netCDF dimension. This function is only run on * IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @param msg the message sent my the comp root task. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. */ int inq_dim_handler(iosystem_desc_t *ios, int msg) { int ncid; int dimid; - char name_present, len_present; + char name_present, len_present; char *dimnamep = NULL; PIO_Offset *dimlenp = NULL; char dimname[NC_MAX_NAME + 1]; @@ -160,9 +160,9 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "inq_dim_handler\n", my_rank)); /* Get the parameters for this function that the the comp master @@ -187,15 +187,15 @@ int inq_dim_handler(iosystem_desc_t *ios, int msg) /* Call the inq function to get the values. */ if ((ret = PIOc_inq_dim(ncid, dimid, dimnamep, dimlenp))) return ret; - + return PIO_NOERR; } /** Do an inq_dimid on a netCDF dimension name. This function is only * run on IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int inq_dimid_handler(iosystem_desc_t *ios) { @@ -206,9 +206,9 @@ int inq_dimid_handler(iosystem_desc_t *ios) int ret; int namelen; char *name; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "inq_dimid_handler\n", my_rank)); /* Get the parameters for this function that the the comp master @@ -224,7 +224,7 @@ int inq_dimid_handler(iosystem_desc_t *ios) if ((mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; LOG((1, "%d inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d\n", - ncid, namelen, name, id_present)); + ncid, namelen, name, id_present)); /* Set non-null pointer. */ if (id_present) @@ -236,18 +236,18 @@ int inq_dimid_handler(iosystem_desc_t *ios) /* Free resources. */ free(name); - + return PIO_NOERR; } /** Handle attribute inquiry operations. This code only runs on IO * tasks. * - * @param ios pointer to the iosystem_desc_t. - * @param msg the message sent my the comp root task. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. */ -int inq_att_handler(iosystem_desc_t *ios, int msg) +int inq_att_handler(iosystem_desc_t *ios) { int ncid; int varid; @@ -256,12 +256,12 @@ int inq_att_handler(iosystem_desc_t *ios, int msg) char *name5; int namelen; PIO_Offset attlen; - nc_type xtype; int *op, *ip; - - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - LOG((1, "inq_att_handler\n", my_rank)); + nc_type xtype, *xtypep = NULL; + PIO_Offset len, *lenp = NULL; + char xtype_present, len_present; + + LOG((1, "inq_att_handler")); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -269,14 +269,26 @@ int inq_att_handler(iosystem_desc_t *ios, int msg) return PIO_EIO; if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm))) + return PIO_EIO; if (!(name5 = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; - mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, - ios->intercomm); - + if ((mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, + ios->intercomm))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + + /* Match NULLs in collective function call. */ + if (xtype_present) + xtypep = &xtype; + if (len_present) + lenp = &len; + /* Call the function to learn about the attribute. */ - if ((ret = PIOc_inq_att(ncid, varid, name5, &xtype, &attlen))) + if ((ret = PIOc_inq_att(ncid, varid, name5, xtypep, lenp))) return ret; return PIO_NOERR; @@ -284,9 +296,9 @@ int inq_att_handler(iosystem_desc_t *ios, int msg) /** Handle attribute operations. This code only runs on IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @param msg the message sent my the comp root task. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. */ int att_handler(iosystem_desc_t *ios, int msg) { @@ -299,7 +311,7 @@ int att_handler(iosystem_desc_t *ios, int msg) PIO_Offset len; nc_type xtype; int *op, *ip; - + int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d att_handler\n", my_rank)); @@ -321,7 +333,7 @@ int att_handler(iosystem_desc_t *ios, int msg) if (!(op = malloc(len * sizeof(int)))) return PIO_ENOMEM; mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); - + /* Call the function to write the attribute. */ if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, len, op))) return ret; @@ -348,7 +360,7 @@ int att_handler(iosystem_desc_t *ios, int msg) return ret; if (!(ip = malloc(len * sizeof(int)))) return PIO_ENOMEM; - + /* Call the function to read the attribute. */ if ((ret = PIOc_get_att_int(ncid, varid, name5, ip))) return ret; @@ -364,9 +376,9 @@ int att_handler(iosystem_desc_t *ios, int msg) /** Do an inq_var on a netCDF variable. This function is only run on * IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @param msg the message sent my the comp root task. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. */ int inq_var_handler(iosystem_desc_t *ios) { @@ -376,10 +388,10 @@ int inq_var_handler(iosystem_desc_t *ios) char name_present, xtype_present, ndims_present, dimids_present, natts_present; char name[NC_MAX_NAME + 1], *namep; nc_type xtype, *xtypep = NULL; - int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; - int ndims, dimids[NC_MAX_DIMS], natts; + int *ndimsp = NULL, *dimidsp = NULL, *nattsp = NULL; + int ndims, dimids[NC_MAX_DIMS], natts; int ret; - + int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d inq_var_handler\n", my_rank)); @@ -419,15 +431,15 @@ int inq_var_handler(iosystem_desc_t *ios) /* Call the inq function to get the values. */ if ((ret = PIOc_inq_var(ncid, varid, namep, xtypep, ndimsp, dimidsp, nattsp))) return ret; - + return PIO_NOERR; } /** Do an inq_varid on a netCDF variable name. This function is only * run on IO tasks. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int inq_varid_handler(iosystem_desc_t *ios) { @@ -437,7 +449,7 @@ int inq_varid_handler(iosystem_desc_t *ios) int ret; int namelen; char *name; - + /* Get the parameters for this function that the the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) @@ -455,23 +467,23 @@ int inq_varid_handler(iosystem_desc_t *ios) /* Free resources. */ free(name); - + return PIO_NOERR; } -/** This function is run on the IO tasks to sync a netCDF file. +/** This function is run on the IO tasks to sync a netCDF file. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int sync_file_handler(iosystem_desc_t *ios) { int ncid; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d sync_file_handler\n", my_rank)); /* Get the parameters for this function that the comp master @@ -483,24 +495,24 @@ int sync_file_handler(iosystem_desc_t *ios) /* Call the sync file function. */ if ((ret = PIOc_sync(ncid))) return ret; - + printf("%d sync_file_handler succeeded!\n", my_rank); return PIO_NOERR; } -/** This function is run on the IO tasks to enddef a netCDF file. +/** This function is run on the IO tasks to enddef a netCDF file. * - * @param ios pointer to the iosystem_desc_t. - * @return PIO_NOERR for success, error code otherwise. + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. */ int enddef_file_handler(iosystem_desc_t *ios) { int ncid; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d enddef_file_handler\n", my_rank)); /* Get the parameters for this function that the comp master @@ -511,7 +523,7 @@ int enddef_file_handler(iosystem_desc_t *ios) /* Call the sync file function. */ if ((ret = PIOc_enddef(ncid))) return ret; - + LOG((1, "%d enddef_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -531,9 +543,9 @@ int def_var_handler(iosystem_desc_t *ios) nc_type xtype; int ndims; int *dimids; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d def_var_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master @@ -562,11 +574,11 @@ int def_var_handler(iosystem_desc_t *ios) /* Call the create file function. */ if ((ret = PIOc_def_var(ncid, name, xtype, ndims, dimids, &varid))) return ret; - + /* Free resources. */ free(name); free(dimids); - + LOG((1, "%d def_var_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -583,19 +595,19 @@ int def_dim_handler(iosystem_desc_t *ios) int mpierr; int ret; int dimid; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d def_dim_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_dim_handler ncid = %d\n", my_rank, ncid); + printf("%d def_dim_handler ncid = %d\n", my_rank, ncid); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_dim_handler ncid = %d namelen %d\n", my_rank, ncid, namelen); + printf("%d def_dim_handler ncid = %d namelen %d\n", my_rank, ncid, namelen); if (!(name = malloc(namelen + 1 * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, @@ -610,19 +622,19 @@ int def_dim_handler(iosystem_desc_t *ios) /* Call the create file function. */ if ((ret = PIOc_def_dim(ncid, name, len, &dimid))) return ret; - + /* Free resources. */ free(name); - + LOG((1, "%d def_dim_handler succeeded!\n", my_rank)); return PIO_NOERR; } /** This function is run on the IO tasks. It reads or writes an array - * of data to a netCDF variable. + * of data to a netCDF variable. * * @param ios pointer to the iosystem_desc_t data. - * @param msg the message sent my the comp root task. + * @param msg the message sent my the comp root task. * * @return PIO_NOERR for success, error code otherwise. */ int vara_handler(iosystem_desc_t *ios, int msg) @@ -641,9 +653,9 @@ int vara_handler(iosystem_desc_t *ios, int msg) void *data; int size_in_bytes; PIO_Offset *count, *start; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d def_var_handler comproot = %d\n", my_rank, ios->comproot)); if (msg == PIO_MSG_PUT_VARA) @@ -669,7 +681,7 @@ int vara_handler(iosystem_desc_t *ios, int msg) size *= count[d]; size_in_bytes = size * sizeof(int); if (!(data = malloc(size_in_bytes))) - return PIO_ENOMEM; + return PIO_ENOMEM; if ((mpierr = MPI_Bcast(data, size_in_bytes, MPI_INT, 0, ios->intercomm))) return PIO_EIO; @@ -680,7 +692,7 @@ int vara_handler(iosystem_desc_t *ios, int msg) /* Call the create file function. */ if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) return ret; - + /* Free resources. */ free(start); free(count); @@ -688,14 +700,14 @@ int vara_handler(iosystem_desc_t *ios, int msg) } else { - + } LOG((1, "%d vara_handler succeeded!\n", my_rank)); return PIO_NOERR; } -/** This function is run on the IO tasks to open a netCDF file. +/** This function is run on the IO tasks to open a netCDF file. * * @param ios pointer to the iosystem_desc_t data. * @@ -709,16 +721,16 @@ int open_file_handler(iosystem_desc_t *ios) int mode; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d open_file_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d open_file_handler got parameter len = %d\n", my_rank, len); + LOG((2, "open_file_handler got parameter len = %d", len)); if (!(filename = malloc(len + 1 * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, 0, @@ -735,15 +747,15 @@ int open_file_handler(iosystem_desc_t *ios) /* Call the open file function. */ if ((ret = PIOc_openfile(ios->iosysid, &ncid, &iotype, filename, mode))) return ret; - + /* Free resources. */ free(filename); - + LOG((1, "%d open_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } -/** This function is run on the IO tasks to delete a netCDF file. +/** This function is run on the IO tasks to delete a netCDF file. * * @param ios pointer to the iosystem_desc_t data. * @@ -755,9 +767,9 @@ int delete_file_handler(iosystem_desc_t *ios) char *filename; int mpierr; int ret; - + int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d delete_file_handler comproot = %d\n", my_rank, ios->comproot)); /* Get the parameters for this function that the he comp master @@ -775,10 +787,10 @@ int delete_file_handler(iosystem_desc_t *ios) /* Call the delete file function. */ if ((ret = PIOc_deletefile(ios->iosysid, filename))) return ret; - + /* Free resources. */ free(filename); - + LOG((1, "%d delete_file_handler succeeded!\n", my_rank)); return PIO_NOERR; } @@ -830,7 +842,7 @@ int pio_callback_handler(iosystem_desc_t *ios, int msg) return, unless there is an error. */ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) { - iosystem_desc_t *my_iosys; + iosystem_desc_t *my_iosys; int msg = 0; MPI_Request req[component_count]; MPI_Status status; @@ -841,7 +853,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); LOG((1, "%d pio_msg_handler called\n", my_rank)); - + /* Have IO comm rank 0 (the ioroot) register to receive * (non-blocking) for a message from each of the comproots. */ if (!io_rank) @@ -849,7 +861,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) for (int cmp = 0; cmp < component_count; cmp++) { my_iosys = &iosys[cmp]; - LOG((1, "%d about to call MPI_Irecv\n", my_rank)); + LOG((1, "%d about to call MPI_Irecv\n", my_rank)); mpierr = MPI_Irecv(&msg, 1, MPI_INT, my_iosys->comproot, MPI_ANY_TAG, my_iosys->union_comm, &req[cmp]); CheckMPIReturn(mpierr, __FILE__, __LINE__); @@ -863,26 +875,25 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) if (!io_rank) { LOG((1, "%d about to call MPI_Waitany req[0] = %d MPI_REQUEST_NULL = %d\n", - my_rank, req[0], MPI_REQUEST_NULL)); + my_rank, req[0], MPI_REQUEST_NULL)); mpierr = MPI_Waitany(component_count, req, &index, &status); CheckMPIReturn(mpierr, __FILE__, __LINE__); - printf("%d Waitany returned index = %d req[%d] = %d\n", my_rank, - index, index, req[index]); + LOG((3, "Waitany returned index = %d req[%d] = %d", + index, index, req[index])); } /* Broadcast the index of the computational component that * originated the request to the rest of the IO tasks. */ - printf("%d about to call index MPI_Bcast index = %d\n", my_rank, index); mpierr = MPI_Bcast(&index, 1, MPI_INT, 0, iosys->io_comm); CheckMPIReturn(mpierr, __FILE__, __LINE__); my_iosys = &iosys[index]; - printf("%d index MPI_Bcast complete index = %d\n", my_rank, index); + LOG((3, "index MPI_Bcast complete index = %d", index)); /* Broadcast the msg value to the rest of the IO tasks. */ - printf("%d about to call msg MPI_Bcast\n", my_rank); + LOG((3, "about to call msg MPI_Bcast")); mpierr = MPI_Bcast(&msg, 1, MPI_INT, 0, my_iosys->io_comm); CheckMPIReturn(mpierr, __FILE__, __LINE__); - printf("%d msg MPI_Bcast complete msg = %d\n", my_rank, msg); + LOG((3, "msg MPI_Bcast complete msg = %d", msg)); /* Handle the message. This code is run on all IO tasks. */ switch (msg) @@ -926,13 +937,12 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_GET_ATT_INT: case PIO_MSG_PUT_ATT_INT: ret = att_handler(my_iosys, msg); - printf("att_handler returned %d\n", ret); break; case PIO_MSG_INQ_VARID: inq_varid_handler(my_iosys); break; case PIO_MSG_INQ_ATT: - inq_att_handler(my_iosys, msg); + inq_att_handler(my_iosys); break; case PIO_MSG_INITDECOMP_DOF: initdecomp_dof_handler(my_iosys); @@ -969,7 +979,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) /* If an error was returned by the handler, do something! */ if (ret) { - printf("hander returned error code %d\n", ret); + LOG((0, "hander returned error code %d", ret)); MPI_Finalize(); } @@ -980,10 +990,10 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) my_iosys = &iosys[index]; mpierr = MPI_Irecv(&msg, 1, MPI_INT, my_iosys->comproot, MPI_ANY_TAG, my_iosys->union_comm, &req[index]); - printf("%d pio_msg_handler called MPI_Irecv req[%d] = %d\n", my_rank, index, req[index]); + LOG((3, "pio_msg_handler called MPI_Irecv req[%d] = %d\n", index, req[index])); CheckMPIReturn(mpierr, __FILE__, __LINE__); } - + } return PIO_NOERR; @@ -997,22 +1007,22 @@ pio_iosys_print(int my_rank, iosystem_desc_t *iosys) printf("%d union_comm: MPI_COMM_NULL ", my_rank); else printf("%d union_comm: %d ", my_rank, iosys->union_comm); - + if (iosys->comp_comm == MPI_COMM_NULL) printf("comp_comm: MPI_COMM_NULL "); else printf("comp_comm: %d ", iosys->comp_comm); - + if (iosys->io_comm == MPI_COMM_NULL) printf("io_comm: MPI_COMM_NULL "); else printf("io_comm: %d ", iosys->io_comm); - + if (iosys->intercomm == MPI_COMM_NULL) printf("intercomm: MPI_COMM_NULL\n"); else printf("intercomm: %d\n", iosys->intercomm); - + printf("%d num_iotasks=%d num_comptasks=%d union_rank=%d, comp_rank=%d, " "io_rank=%d async_interface=%d\n", my_rank, iosys->num_iotasks, iosys->num_comptasks, iosys->union_rank, @@ -1029,7 +1039,7 @@ pio_iosys_print(int my_rank, iosystem_desc_t *iosys) return PIO_NOERR; } -/** @ingroup PIO_init +/** @ingroup PIO_init * Library initialization used when IO tasks are distinct from compute * tasks. * @@ -1105,7 +1115,7 @@ pio_iosys_print(int my_rank, iosystem_desc_t *iosys) * Return or Not * ------------- * - * The io_comm tasks do not return from the init_intercomm routine. + * The io_comm tasks do not return from the init_intercomm routine. * * Sequence of Events to do Asynch I/O * ----------------------------------- @@ -1179,7 +1189,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Get a pointer to the iosys struct */ my_iosys = &iosys[cmp]; - + /* Create an MPI info object. */ CheckMPIReturn(MPI_Info_create(&(my_iosys->info)),__FILE__,__LINE__); @@ -1188,32 +1198,32 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, { /* Copy the computation communicator. */ mpierr = MPI_Comm_dup(comp_comms[cmp], &my_iosys->comp_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Create an MPI group with the computation tasks. */ mpierr = MPI_Comm_group(my_iosys->comp_comm, &my_iosys->compgroup); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Find out how many tasks are in this communicator. */ mpierr = MPI_Comm_size(iosys->comp_comm, &my_iosys->num_comptasks); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Set the rank within the comp_comm. */ mpierr = MPI_Comm_rank(my_iosys->comp_comm, &my_iosys->comp_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Find the rank of the io leader in peer_comm. */ iam = -1; mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; @@ -1221,7 +1231,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, if (!my_iosys->comp_rank) { mpierr = MPI_Comm_rank(peer_comm, &iam); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; } @@ -1230,7 +1240,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Find the lucky comp_leader task. */ mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; @@ -1242,17 +1252,17 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, } else my_iosys->compmaster = MPI_PROC_NULL; - + /* Set up the intercomm from the computation side. */ mpierr = MPI_Intercomm_create(my_iosys->comp_comm, 0, peer_comm, io_leader, cmp, &my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Create the union communicator. */ mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; } @@ -1269,25 +1279,25 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, { /* Copy the IO communicator. */ mpierr = MPI_Comm_dup(io_comm, &my_iosys->io_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Get an MPI group that includes the io tasks. */ mpierr = MPI_Comm_group(my_iosys->io_comm, &my_iosys->iogroup); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Find out how many tasks are in this communicator. */ mpierr = MPI_Comm_size(iosys->io_comm, &my_iosys->num_iotasks); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Set the rank within the io_comm. */ mpierr = MPI_Comm_rank(my_iosys->io_comm, &my_iosys->io_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; @@ -1295,7 +1305,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, if (!my_iosys->io_rank) { mpierr = MPI_Comm_rank(peer_comm, &iam); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; } @@ -1304,17 +1314,17 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Find the lucky io_leader task. */ mpierr = MPI_Allreduce(&iam, &io_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Find the rank of the comp leader in peer_comm. */ iam = -1; mpierr = MPI_Allreduce(&iam, &comp_leader, 1, MPI_INT, MPI_MAX, peer_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; - + /* This is an io task. */ my_iosys->ioproc = true; @@ -1325,18 +1335,18 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, io_master = MPI_ROOT; } else - my_iosys->iomaster = 0; + my_iosys->iomaster = 0; /* Set up the intercomm from the I/O side. */ mpierr = MPI_Intercomm_create(my_iosys->io_comm, 0, peer_comm, comp_leader, cmp, &my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; /* Create the union communicator. */ mpierr = MPI_Intercomm_merge(my_iosys->intercomm, 0, &my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; @@ -1358,7 +1368,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Find rank in union communicator. */ mpierr = MPI_Comm_rank(my_iosys->union_comm, &my_iosys->union_rank); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; @@ -1371,11 +1381,11 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Distribute the answer to all tasks. */ mpierr = MPI_Allreduce(&my_iosys->ioroot, &root, 1, MPI_INT, MPI_MAX, my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; my_iosys->ioroot = root; - + /* Find the rank of the computation leader in the union * communicator. */ if (!my_iosys->comp_rank) @@ -1386,7 +1396,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Distribute the answer to all tasks. */ mpierr = MPI_Allreduce(&my_iosys->comproot, &root, 1, MPI_INT, MPI_MAX, my_iosys->union_comm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); if (mpierr) ierr = PIO_EIO; my_iosys->comproot = root; @@ -1403,7 +1413,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, comp_master = 0; mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, my_iosys->intercomm); CheckMPIReturn(mpierr, __FILE__, __LINE__); @@ -1413,7 +1423,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, io_master = 0; mpierr = MPI_Bcast(&my_iosys->num_comptasks, 1, MPI_INT, comp_master, my_iosys->intercomm); - CheckMPIReturn(mpierr, __FILE__, __LINE__); + CheckMPIReturn(mpierr, __FILE__, __LINE__); mpierr = MPI_Bcast(&my_iosys->num_iotasks, 1, MPI_INT, io_master, my_iosys->intercomm); CheckMPIReturn(mpierr, __FILE__, __LINE__); @@ -1421,11 +1431,9 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Allocate an array to hold the ranks of the IO tasks * within the union communicator. */ - printf("%d allocating for %d iotasks\n", my_rank, my_iosys->num_iotasks); if (!(my_iosys->ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) return PIO_ENOMEM; - printf("%d allocated\n", my_rank); - + /* Allocate a temp array to help get the IO ranks. */ int *tmp_ioranks; if (!(tmp_ioranks = malloc(my_iosys->num_iotasks * sizeof(int)))) @@ -1434,7 +1442,7 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Init array, then have IO tasks set their values, then * use allreduce to distribute results to all tasks. */ for (int cnt = 0 ; cnt < my_iosys->num_iotasks; cnt++) - tmp_ioranks[cnt] = -1; + tmp_ioranks[cnt] = -1; if (io_comm != MPI_COMM_NULL) tmp_ioranks[my_iosys->io_rank] = my_iosys->union_rank; mpierr = MPI_Allreduce(tmp_ioranks, my_iosys->ioranks, my_iosys->num_iotasks, MPI_INT, MPI_MAX, @@ -1460,17 +1468,13 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, /* Add this id to the list of PIO iosystem ids. */ iosysidp[cmp] = pio_add_to_iosystem_list(my_iosys); - printf("%d added to iosystem_list iosysid = %d\n", my_rank, iosysidp[cmp]); + LOG((2, "added to iosystem_list iosysid = %d", iosysidp[cmp])); /* Now call the function from which the IO tasks will not * return until the PIO_MSG_EXIT message is sent. */ if (io_comm != MPI_COMM_NULL) - { - printf("%d about to call pio_msg_handler\n", my_rank); if ((ierr = pio_msg_handler(my_iosys->io_rank, component_count, iosys))) return ierr; - } - } /* If there was an error, make sure all tasks see it. */ @@ -1482,7 +1486,6 @@ int PIOc_Init_Intercomm(int component_count, MPI_Comm peer_comm, if (mpierr) ierr = PIO_EIO; } - + return ierr; } - diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 45dd6c4ea38e..b2e6bc31a7ae 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -89,6 +89,24 @@ pio_log(int severity, const char *fmt, ...) } #endif /* PIO_ENABLE_LOGGING */ +/** + ** @brief Wrapper for MPI calls to print the Error string on error + */ +void check_mpi(file_desc_t *file, const int ierr, const char *filename, const int line) +{ + if (ierr != MPI_SUCCESS) + { + char errstring[MPI_MAX_ERROR_STRING]; + int errstrlen; + int mpierr = MPI_Error_string(ierr, errstring, &errstrlen); + + fprintf(stderr, "MPI ERROR: %s in file %s at line %d\n", + errstring, filename, line); + + check_netcdf(file, PIO_EIO, filename, line); + } +} + /** * @ingroup PIOc_inq * The PIO-C interface for the NetCDF function nc_inq. @@ -111,7 +129,6 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int msg = PIO_MSG_INQ; /** Message for async notification. */ iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ - char *errstr = NULL; /** String for error messages. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr; /** Return code from MPI function codes. */ @@ -125,23 +142,36 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* For async, on non-IO tasks, send the necessary information to * the IO tasks over the intercomm. Whether or not the pointers * are NULL are passed as integers, either true or false. */ - if (ios->async_interface && ! ios->ioproc) + if (ios->async_interface) { - char ndims_present = ndimsp ? true : false; - char nvars_present = nvarsp ? true : false; - char ngatts_present = ngattsp ? true : false; - char unlimdimid_present = unlimdimidp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast unlimdimid_present = %d", unlimdimid_present)); - } + if (!ios->ioproc) + { + char ndims_present = ndimsp ? true : false; + char nvars_present = nvarsp ? true : false; + char ngatts_present = ngattsp ? true : false; + char unlimdimid_present = unlimdimidp ? true : false; + + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast unlimdimid_present = %d", unlimdimid_present)); + } + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { @@ -182,41 +212,31 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, ierr = iotype_error(file->iotype,__FILE__,__LINE__); } - if(ierr != PIO_NOERR) - { - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - printf("%d PIOc_inq netcdf call returned %d\n", my_rank, ierr); - ierr = check_netcdf(file, ierr, errstr,__LINE__); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } - /* Broadcast results to all tasks. If pointers were NULL, then - * ignore that parameter. */ + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ if (ndimsp) - { - mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - LOG((2, "PIOc__inq bcast ndims = %d\n", *ndimsp)); - } + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if(nvarsp) - { - mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - LOG((2, "%d PIOc__inq bcast nvars = %d\n", my_rank, *nvarsp)); - } + if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if(ngattsp) - { - mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - LOG((2, "%d PIOc__inq bcast ngatts = %d\n", my_rank, *ngattsp)); - } + if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if(unlimdimidp) - { - mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm); - LOG((2, "%d PIOc__inq bcast unlimdimid = %d\n", my_rank, *unlimdimidp)); - } + if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; - if(errstr) - free(errstr); - return ierr; } @@ -293,9 +313,8 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; - int ierr = PIO_NOERR; int msg = PIO_MSG_INQ_DIM; + int ierr = PIO_NOERR; int mpierr; LOG((1, "PIOc_inq_dim")); @@ -306,18 +325,29 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ - if (ios->async_interface && !ios->ioproc) + if (ios->async_interface) { - char name_present = name ? true : false; - char len_present = lenp ? true : false; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); - mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); + if (!ios->ioproc) + { + char name_present = name ? true : false; + char len_present = lenp ? true : false; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); + if (!mpierr) + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); + } + + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* Make the call to the netCDF layer. */ @@ -346,25 +376,27 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) } } - /* Error handling. */ - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); - /* BCast the results, if non-null pointers were passed. */ - if(name) + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (name) { int slen; - if(ios->iomaster) + if (ios->iomaster) slen = strlen(name); - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return PIO_EIO; } - if(lenp != NULL) - mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + + if (lenp) + if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + return PIO_EIO; + return ierr; } @@ -424,14 +456,14 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) int msg = PIO_MSG_INQ_DIMID; iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; int ierr = PIO_NOERR; int mpierr; - /* For debugging purposes only... */ - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_dimid\n", my_rank); + /* Name must be provided. */ + if (!name) + return PIO_EINVAL; + + LOG((1, "PIOc_inq_dimid name = %s", name)); /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) @@ -478,14 +510,16 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results. */ if (idp) - mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + return ierr; } @@ -510,13 +544,12 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, { iosystem_desc_t *ios; file_desc_t *file; - char *errstr = NULL; int ndims; /** The number of dimensions for this variable. */ int ierr = PIO_NOERR; int msg = PIO_MSG_INQ_VAR; int mpierr; - LOG((1, "PIOc_inq_var\n")); + LOG((1, "PIOc_inq_var ncid = %d varid = %d", ncid, varid)); /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) @@ -576,12 +609,10 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - printf("%d called netcdf nc_inq_var ierr = %d\n", my_rank, ierr); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ if (name) @@ -589,36 +620,32 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int slen; if(ios->iomaster) slen = strlen(name); - printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var slen = %d\n", my_rank, slen); - mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var name = %s\n", my_rank, name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return PIO_EIO; } if (xtypep) - { - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var xtype = %d\n", my_rank, *xtypep); - } + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if (ndimsp) { - printf("%d PIOc_inq_var ndims = %d\n", my_rank, *ndimsp); - mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; file->varlist[varid].ndims = (*ndimsp); - printf("%d PIOc_inq_var bcast complete ndims = %d\n", my_rank, *ndimsp); } if (dimidsp) { - mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; } if (nattsp) - { - printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); - mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm); - printf("%d PIOc_inq_var natts = %d\n", my_rank, *nattsp); - } - if(errstr != NULL) free(errstr); + if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + return ierr; } @@ -736,36 +763,48 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) */ int PIOc_inq_varid (int ncid, const char *name, int *varidp) { - int ierr; - int msg; - int mpierr; + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_VARID; + int mpierr = 0; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; - errstr = NULL; - ierr = PIO_NOERR; + /* Caller must provide name. */ + if (!name) + return PIO_EINVAL; - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Get file info based on ncid. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VARID; LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - printf("%d PIOc_inq_varid BCast ncid = %d\n", my_rank, ncid); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen; - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (ios->async_interface) + { + if (!ios->ioproc) + { + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen; + namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ios->ioproc){ + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 @@ -790,14 +829,16 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ if (varidp) - mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + if ((mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + return ierr; } @@ -817,30 +858,34 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) * @param lenp a pointer that will get the number of values * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, - PIO_Offset *lenp) +int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, + PIO_Offset *lenp) { - int ierr; - int msg; - int mpierr; + int msg = PIO_MSG_INQ_ATT; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; + int mpierr; + int ierr = PIO_NOERR; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d\n", - my_rank, ncid, varid, xtypep, lenp); + /* Caller must provide a name. */ + if (!name) + return PIO_EINVAL; - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d", + ncid, varid, xtypep, lenp)); + /* Find file based on ncid. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATT; - if(ios->async_interface && ! ios->ioproc){ + /* If using async and this is not an IO task, send parameter data + * over the intercomm. */ + if(ios->async_interface && !ios->ioproc) + { + char xtype_present = xtypep ? true : false; + char len_present = lenp ? true : false; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); @@ -848,26 +893,29 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, int namelen = strlen(name); mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ - switch(file->iotype){ + if (ios->ioproc) + { + switch (file->iotype) + { #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp);; - } + if (ios->io_rank == 0) + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp);; + ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp); break; #endif default: @@ -875,16 +923,19 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Handle errors. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results. */ if(xtypep) - mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; if(lenp) - mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + return PIO_EIO; + return ierr; } @@ -905,8 +956,7 @@ int PIOc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, */ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) { - nc_type dummy; - return PIOc_inq_att(ncid, varid, name, &dummy, lenp); + return PIOc_inq_att(ncid, varid, name, NULL, lenp); } /** @@ -926,8 +976,7 @@ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) */ int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) { - PIO_Offset dummy; - return PIOc_inq_att(ncid, varid, name, xtypep, &dummy); + return PIOc_inq_att(ncid, varid, name, xtypep, NULL); } /** @@ -947,21 +996,15 @@ int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) */ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) { - int ierr; - int msg; + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_ATTNAME; int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - file = pio_get_file_from_id(ncid); - if(file == NULL) + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTNAME; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -969,7 +1012,6 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -995,19 +1037,16 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(name != NULL){ + check_netcdf(file, ierr, __FILE__, __LINE__); + if (name) + { int slen; if(ios->iomaster) - slen = (int) strlen(name) + 1; + slen = (int) strlen(name); mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen, MPI_CHAR, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); } - if(errstr != NULL) free(errstr); + return ierr; } @@ -1028,21 +1067,15 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) */ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) { - int ierr; - int msg; + int ierr = PIO_NOERR; + int msg = PIO_MSG_INQ_ATTID; int mpierr; iosystem_desc_t *ios; file_desc_t *file; - char *errstr; - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_ATTID; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1050,7 +1083,6 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -1076,13 +1108,13 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + /* Handle errors. */ + mpierr = MPI_Bcast(&ierr , 1, MPI_INT, ios->ioroot, ios->my_comm); + check_netcdf(file, ierr, __FILE__, __LINE__); + + if (idp) + mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); + return ierr; } From af76675fa258385227c30b0ea9fdedb9cf4db0be Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 09:25:27 -0400 Subject: [PATCH 12/83] further async development --- src/clib/pio_file.c | 115 +++++++++++++++++++++++------------- src/clib/pio_internal.h | 2 + src/clib/pio_nc_async.c | 101 ++++++++++++++++++------------- tests/unit/test_intercomm.c | 16 ++--- 4 files changed, 145 insertions(+), 89 deletions(-) diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index c4ccb4d0fbc9..fac23a4146a5 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -13,28 +13,33 @@ */ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, - const char filename[], const int mode) + const char *filename, const int mode) { - int ierr; - int msg; - int mpierr; + int msg = PIO_MSG_OPEN_FILE; size_t len; iosystem_desc_t *ios; file_desc_t *file; + int ierr = PIO_NOERR; + int mpierr = MPI_SUCCESS; + + /* Get the IO system info from the iosysid. */ + if (!(ios = pio_get_iosystem_from_id(iosysid))) + { + printf("bad iosysid %d\n",iosysid); + return PIO_EBADID; + } - ierr = PIO_NOERR; + /* User must provide valid input for these parameters. */ + if (!ncidp || !iotype || !filename) + return PIO_EINVAL; + if (*iotype < PIO_IOTYPE_PNETCDF || *iotype > PIO_IOTYPE_NETCDF4P) + return PIO_ENOMEM; - msg = PIO_MSG_OPEN_FILE; - ios = pio_get_iosystem_from_id(iosysid); - if(ios==NULL){ - printf("bad iosysid %d\n",iosysid); - return PIO_EBADID; - } + /* Allocate space for the file info. */ + if (!(file = (file_desc_t *) malloc(sizeof(*file)))) + return PIO_ENOMEM; - file = (file_desc_t *) malloc(sizeof(*file)); - if(file==NULL){ - return PIO_ENOMEM; - } + /* Fill in some file values. */ file->iotype = *iotype; file->next = NULL; file->iosystem = ios; @@ -57,19 +62,35 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, file->buffer.frame=NULL; file->buffer.fillvalue=NULL; - if(ios->async_interface && ! ios->ioproc){ - if(ios->comp_rank==0) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - len = strlen(filename); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + if(ios->comp_rank==0) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + len = strlen(filename); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); + } - if(ios->ioproc){ + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); + } - switch(file->iotype){ + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { + switch (file->iotype) + { #ifdef _NETCDF #ifdef _NETCDF4 @@ -78,7 +99,7 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, ierr = nc_open(filename, file->mode, &(file->fh)); #else file->mode = file->mode | NC_MPIIO; - ierr = nc_open_par(filename, file->mode, ios->io_comm,ios->info, &(file->fh)); + ierr = nc_open_par(filename, file->mode, ios->io_comm, ios->info, &file->fh); #endif break; @@ -89,18 +110,20 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_open(filename, file->mode, &(file->fh)); + ierr = nc_open(filename, file->mode, &file->fh); } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_open(ios->io_comm, filename, file->mode, ios->info, &(file->fh)); + ierr = ncmpi_open(ios->io_comm, filename, file->mode, ios->info, &file->fh); // This should only be done with a file opened to append - if(ierr == PIO_NOERR && (file->mode & PIO_WRITE)){ - if(ios->iomaster) printf("%d Setting IO buffer %ld\n",__LINE__,PIO_BUFFER_SIZE_LIMIT); + if (ierr == PIO_NOERR && (file->mode & PIO_WRITE)) + { + if(ios->iomaster) + printf("%d Setting IO buffer %ld\n",__LINE__,PIO_BUFFER_SIZE_LIMIT); ierr = ncmpi_buffer_attach(file->fh, PIO_BUFFER_SIZE_LIMIT ); } break; @@ -129,19 +152,29 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, /* #endif */ } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if (!ierr) { - mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->ioroot, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->ioroot, ios->union_comm); - *ncidp = file->fh; - pio_add_to_file_list(file); - *ncidp = file->fh; + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + { + if ((mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->ioroot, ios->union_comm))) + return PIO_EIO; + + if ((mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->ioroot, ios->union_comm))) + return PIO_EIO; + + *ncidp = file->fh; + pio_add_to_file_list(file); } - if(ios->io_rank==0){ - printf("Open file %s %d\n",filename,file->fh); //,file->fh,file->id,ios->io_rank,ierr); + + if (ios->io_rank==0){ + printf("Open file %s %d\n",filename,file->fh); //,file->fh,file->id,ios->io_rank,ierr); // if(file->fh==5) print_trace(stdout); } + return ierr; } diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 9efa132843d5..16e5120ead11 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -152,6 +152,8 @@ typedef struct pio_swapm_defaults void flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk); void piomemerror(iosystem_desc_t ios, size_t req, char *fname, const int line); void compute_maxaggregate_bytes(const iosystem_desc_t ios, io_desc_t *iodesc); + void check_mpi(file_desc_t *file, const int mpierr, const char *filename, + const int line); #ifdef BGQ void identity(MPI_Comm comm, int *iotask); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b2e6bc31a7ae..ea5d3ec1c8f6 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -89,20 +89,28 @@ pio_log(int severity, const char *fmt, ...) } #endif /* PIO_ENABLE_LOGGING */ -/** - ** @brief Wrapper for MPI calls to print the Error string on error +/** Handle MPI errors. An error message is sent to stderr, then the + check_netcdf() function is called with PIO_EIO. + + @param file pointer to the file_desc_t info + @param mpierr the MPI return code to handle + @param filename the name of the code file where error occured. + @param line the line of code where error occured. */ -void check_mpi(file_desc_t *file, const int ierr, const char *filename, const int line) +void check_mpi(file_desc_t *file, const int mpierr, const char *filename, + const int line) { - if (ierr != MPI_SUCCESS) + if (mpierr) { char errstring[MPI_MAX_ERROR_STRING]; int errstrlen; - int mpierr = MPI_Error_string(ierr, errstring, &errstrlen); - fprintf(stderr, "MPI ERROR: %s in file %s at line %d\n", - errstring, filename, line); + /* If we can get an error string from MPI, print it to stderr. */ + if (!MPI_Error_string(mpierr, errstring, &errstrlen)) + fprintf(stderr, "MPI ERROR: %s in file %s at line %d\n", + errstring, filename, line); + /* Handle all MPI errors as PIO_EIO. */ check_netcdf(file, PIO_EIO, filename, line); } } @@ -130,7 +138,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ - int mpierr; /** Return code from MPI function codes. */ + int mpierr = MPI_SUCCESS; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq ncid = %d", ncid)); @@ -139,9 +147,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, return PIO_EBADID; ios = file->iosystem; - /* For async, on non-IO tasks, send the necessary information to - * the IO tasks over the intercomm. Whether or not the pointers - * are NULL are passed as integers, either true or false. */ + /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { if (!ios->ioproc) @@ -221,22 +227,25 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ - if (ndimsp) - if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; - - if(nvarsp) - if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; - - if(ngattsp) - if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; - - if(unlimdimidp) - if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + if (!ierr) + { + if (ndimsp) + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if (nvarsp) + if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + + if (ngattsp) + if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + + if (unlimdimidp) + if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + return ierr; } @@ -471,22 +480,35 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) ios = file->iosystem; /* If using async, and not an IO task, then send parameters. */ - if (ios->async_interface && !ios->ioproc) + if (ios->async_interface) { - int namelen; - char id_present = idp ? true : false; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!ios->ioproc) + { + char id_present = idp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* IO tasks call the netCDF functions. */ - if(ios->ioproc){ - switch(file->iotype){ + if (ios->ioproc) + { + switch(file->iotype) + { #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: @@ -495,9 +517,8 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ + if (ios->io_rank == 0) ierr = nc_inq_dimid(file->fh, name, idp);; - } break; #endif #ifdef _PNETCDF diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 6ab8cb03186c..cfddf1e600a0 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -177,14 +177,14 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Check out the global attributes. */ nc_type atttype; PIO_Offset attlen; - /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) */ - /* ERR(ret); */ - /* if (atttype != NC_INT || attlen != 1) */ - /* ERR(ERR_WRONG); */ - /* if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) */ - /* ERR(ret); */ - /* if (attlen != 1) */ - /* ERR(ERR_WRONG); */ + if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) + ERR(ret); + if (atttype != NC_INT || attlen != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) + ERR(ret); + if (attlen != 1) + ERR(ERR_WRONG); /* if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) */ /* ERR(ret); */ /* sleep(2); */ From fc48722e78d2f59d24a7c88dfac4dd5c25eb7856 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 09:32:57 -0400 Subject: [PATCH 13/83] better error handling --- src/clib/pio_nc_async.c | 84 +++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index ea5d3ec1c8f6..6006905181b3 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -391,21 +391,24 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ - if (name) - { - int slen; - if (ios->iomaster) - slen = strlen(name); - if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return PIO_EIO; + if (!ierr) + { + if (name) + { + int slen; + if (ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + if (lenp) + if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } - - if (lenp) - if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - return PIO_EIO; - + return ierr; } @@ -533,13 +536,13 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (idp) if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -632,7 +635,7 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ @@ -642,30 +645,30 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, if(ios->iomaster) slen = strlen(name); if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); } if (xtypep) if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); if (ndimsp) { if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); file->varlist[varid].ndims = (*ndimsp); } if (dimidsp) { if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); } if (nattsp) if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -852,13 +855,13 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (varidp) if ((mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -946,16 +949,19 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, /* Handle errors. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ - if(xtypep) - if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; - if(lenp) - if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - return PIO_EIO; + if (!ierr) + { + if(xtypep) + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if(lenp) + if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } return ierr; } @@ -1130,11 +1136,17 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) } /* Handle errors. */ - mpierr = MPI_Bcast(&ierr , 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); - if (idp) - mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); + /* Broadcast results. */ + if (!ierr) + { + if (idp) + if ((mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } return ierr; } From 90f714e087eff15da7e3f413cf175dee8e629d0a Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 10:28:00 -0400 Subject: [PATCH 14/83] continued development of async --- src/clib/pio.h | 2 + src/clib/pio_nc_async.c | 411 +++++++++++++++++++++++----------------- src/clib/pioc_support.c | 26 +++ 3 files changed, 269 insertions(+), 170 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 44507edcdc71..2be57ca845c9 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -648,6 +648,8 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_get_var_schar (int ncid, int varid, signed char *buf); int PIOc_iotype_available(const int iotype); int PIOc_set_log_level(int level); + int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op); + int PIOc_get_att(int ncid, int varid, const char *name, void *ip); #if defined(__cplusplus) } #endif diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 6006905181b3..dcaf033ed3ef 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -89,32 +89,6 @@ pio_log(int severity, const char *fmt, ...) } #endif /* PIO_ENABLE_LOGGING */ -/** Handle MPI errors. An error message is sent to stderr, then the - check_netcdf() function is called with PIO_EIO. - - @param file pointer to the file_desc_t info - @param mpierr the MPI return code to handle - @param filename the name of the code file where error occured. - @param line the line of code where error occured. - */ -void check_mpi(file_desc_t *file, const int mpierr, const char *filename, - const int line) -{ - if (mpierr) - { - char errstring[MPI_MAX_ERROR_STRING]; - int errstrlen; - - /* If we can get an error string from MPI, print it to stderr. */ - if (!MPI_Error_string(mpierr, errstring, &errstrlen)) - fprintf(stderr, "MPI ERROR: %s in file %s at line %d\n", - errstring, filename, line); - - /* Handle all MPI errors as PIO_EIO. */ - check_netcdf(file, PIO_EIO, filename, line); - } -} - /** * @ingroup PIOc_inq * The PIO-C interface for the NetCDF function nc_inq. @@ -1151,79 +1125,6 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) return ierr; } -/** - * @ingroup PIOc_put_att_short - * The PIO-C interface for the NetCDF function nc_put_att_short. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_short(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_rename_dim * The PIO-C interface for the NetCDF function nc_rename_dim. @@ -1297,20 +1198,20 @@ int PIOc_rename_dim (int ncid, int dimid, const char *name) } /** - * @ingroup PIOc_get_att_double - * The PIO-C interface for the NetCDF function nc_get_att_double. + * @ingroup PIOc_rename_var + * The PIO-C interface for the NetCDF function nc_rename_var. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) +int PIOc_rename_var (int ncid, int varid, const char *name) { int ierr; int msg; @@ -1326,7 +1227,7 @@ int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_DOUBLE; + msg = PIO_MSG_RENAME_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1340,19 +1241,19 @@ int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_double(file->fh, varid, name, ip);; + ierr = nc_rename_var(file->fh, varid, name);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_double(file->fh, varid, name, ip);; + ierr = nc_rename_var(file->fh, varid, name);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_double(file->fh, varid, name, ip);; + ierr = ncmpi_rename_var(file->fh, varid, name);; break; #endif default: @@ -1361,15 +1262,10 @@ int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_DOUBLE, ios->ioroot, ios->my_comm); - } if(errstr != NULL) free(errstr); return ierr; } @@ -1545,20 +1441,20 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, } /** - * @ingroup PIOc_put_att_double - * The PIO-C interface for the NetCDF function nc_put_att_double. + * @ingroup PIOc_inq_var_fill + * The PIO-C interface for the NetCDF function nc_inq_var_fill. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) +int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) { int ierr; int msg; @@ -1574,7 +1470,7 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_DOUBLE; + msg = PIO_MSG_INQ_VAR_FILL; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1588,19 +1484,19 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_double(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_value);; break; #endif default: @@ -1613,13 +1509,111 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); + mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_get_att_uchar - * The PIO-C interface for the NetCDF function nc_get_att_uchar. + * @ingroup PIOc_get_att + * The PIO-C interface for the NetCDF function nc_get_att. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See + * PIOc_Set_File_Error_Handling + */ +int PIOc_get_att(int ncid, int varid, const char *name, void *ip) +{ + int msg = PIO_MSG_GET_ATT_INT; + iosystem_desc_t *ios; + file_desc_t *file; + int ierr = PIO_NOERR; + int mpierr = MPI_SUCCESS; + + /* User must provide a name and destination pointer. */ + if (!name || !ip) + return PIO_EINVAL; + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { + switch (file->iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_att(file->fh, varid, name, ip); + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if (ios->io_rank == 0) + ierr = nc_get_att(file->fh, varid, name, ip); + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_get_att(file->fh, varid, name, ip); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. */ + if (!ierr) + { + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_INT, ios->ioroot, ios->my_comm); + } + return ierr; +} + +/** + * @ingroup PIOc_put_att_short + * The PIO-C interface for the NetCDF function nc_put_att_short. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1631,7 +1625,7 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) +int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) { int ierr; int msg; @@ -1647,7 +1641,7 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UCHAR; + msg = PIO_MSG_PUT_ATT_SHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1661,19 +1655,19 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; + ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; + ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_uchar(file->fh, varid, name, ip);; + ierr = ncmpi_put_att_short(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1682,34 +1676,29 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_CHAR, ios->ioroot, ios->my_comm); - } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_inq_var_fill - * The PIO-C interface for the NetCDF function nc_inq_var_fill. + * @ingroup PIOc_get_att_double + * The PIO-C interface for the NetCDF function nc_get_att_double. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) +int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) { int ierr; int msg; @@ -1725,7 +1714,7 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VAR_FILL; + msg = PIO_MSG_GET_ATT_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1739,19 +1728,19 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = nc_get_att_double(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = nc_get_att_double(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_value);; + ierr = ncmpi_get_att_double(file->fh, varid, name, ip);; break; #endif default: @@ -1760,18 +1749,22 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) } if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); } ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_DOUBLE, ios->ioroot, ios->my_comm); + } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_put_att_schar - * The PIO-C interface for the NetCDF function nc_put_att_schar. + * @ingroup PIOc_put_att_double + * The PIO-C interface for the NetCDF function nc_put_att_double. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1783,7 +1776,7 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) +int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) { int ierr; int msg; @@ -1799,7 +1792,7 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SCHAR; + msg = PIO_MSG_PUT_ATT_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1813,19 +1806,19 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; + ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_schar(file->fh, varid, name, xtype, len, op);; + ierr = ncmpi_put_att_double(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1843,8 +1836,8 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI } /** - * @ingroup PIOc_get_att_ushort - * The PIO-C interface for the NetCDF function nc_get_att_ushort. + * @ingroup PIOc_get_att_uchar + * The PIO-C interface for the NetCDF function nc_get_att_uchar. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand @@ -1856,7 +1849,7 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) +int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) { int ierr; int msg; @@ -1872,7 +1865,7 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_ATT_USHORT; + msg = PIO_MSG_GET_ATT_UCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1886,19 +1879,19 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + ierr = nc_get_att_uchar(file->fh, varid, name, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + ierr = nc_get_att_uchar(file->fh, varid, name, ip);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_ushort(file->fh, varid, name, ip);; + ierr = ncmpi_get_att_uchar(file->fh, varid, name, ip);; break; #endif default: @@ -1914,27 +1907,27 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * if(ierr == PIO_NOERR){ PIO_Offset attlen; PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_SHORT, ios->ioroot, ios->my_comm); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_CHAR, ios->ioroot, ios->my_comm); } if(errstr != NULL) free(errstr); return ierr; } /** - * @ingroup PIOc_rename_var - * The PIO-C interface for the NetCDF function nc_rename_var. + * @ingroup PIOc_put_att_schar + * The PIO-C interface for the NetCDF function nc_put_att_schar. * * This routine is called collectively by all tasks in the communicator * ios.union_comm. For more information on the underlying NetCDF commmand * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html * * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_var (int ncid, int varid, const char *name) +int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) { int ierr; int msg; @@ -1950,7 +1943,7 @@ int PIOc_rename_var (int ncid, int varid, const char *name) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_VAR; + msg = PIO_MSG_PUT_ATT_SCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1964,19 +1957,19 @@ int PIOc_rename_var (int ncid, int varid, const char *name) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_var(file->fh, varid, name);; + ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_rename_var(file->fh, varid, name);; + ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_var(file->fh, varid, name);; + ierr = ncmpi_put_att_schar(file->fh, varid, name, xtype, len, op);; break; #endif default: @@ -1993,6 +1986,84 @@ int PIOc_rename_var (int ncid, int varid, const char *name) return ierr; } +/** + * @ingroup PIOc_get_att_ushort + * The PIO-C interface for the NetCDF function nc_get_att_ushort. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_ATT_USHORT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_get_att_ushort(file->fh, varid, name, ip);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_get_att_ushort(file->fh, varid, name, ip);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); + sprintf(errstr,"name %s in file %s",name,__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(ierr == PIO_NOERR){ + PIO_Offset attlen; + PIOc_inq_attlen(file->fh, varid, name, &attlen); + mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_SHORT, ios->ioroot, ios->my_comm); + } + if(errstr != NULL) free(errstr); + return ierr; +} + /** * @ingroup PIOc_put_att_ulonglong * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index 0a5cc4baa461..bd16fa0aff5c 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -114,6 +114,32 @@ void pioassert(_Bool expression, const char *msg, const char *fname, const int l } +/** Handle MPI errors. An error message is sent to stderr, then the + check_netcdf() function is called with PIO_EIO. + + @param file pointer to the file_desc_t info + @param mpierr the MPI return code to handle + @param filename the name of the code file where error occured. + @param line the line of code where error occured. + */ +void check_mpi(file_desc_t *file, const int mpierr, const char *filename, + const int line) +{ + if (mpierr) + { + char errstring[MPI_MAX_ERROR_STRING]; + int errstrlen; + + /* If we can get an error string from MPI, print it to stderr. */ + if (!MPI_Error_string(mpierr, errstring, &errstrlen)) + fprintf(stderr, "MPI ERROR: %s in file %s at line %d\n", + errstring, filename, line); + + /* Handle all MPI errors as PIO_EIO. */ + check_netcdf(file, PIO_EIO, filename, line); + } +} + /** Check the result of a netCDF API call. * * @param file pointer to the PIO structure describing this file. From fb378ca2acc95d5ef4de45309d345f17a546a14b Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 14:58:49 -0400 Subject: [PATCH 15/83] added log message --- src/clib/pio_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index fac23a4146a5..b68ce0237680 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -1,3 +1,4 @@ +#include #include #include /** @@ -22,6 +23,8 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, int ierr = PIO_NOERR; int mpierr = MPI_SUCCESS; + LOG((1, "PIOc_openfile iosysid = %d", iosysid)); + /* Get the IO system info from the iosysid. */ if (!(ios = pio_get_iosystem_from_id(iosysid))) { From 07830738067c7de55c2687329ba2738acb814971 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 15:08:38 -0400 Subject: [PATCH 16/83] further development --- src/clib/pio_msg.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index e30dc8dce2b6..3b26f1f598bb 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -308,7 +308,7 @@ int att_handler(iosystem_desc_t *ios, int msg) int ret; char *name5; int namelen; - PIO_Offset len; + PIO_Offset attlen; nc_type xtype; int *op, *ip; @@ -329,13 +329,13 @@ int att_handler(iosystem_desc_t *ios, int msg) return PIO_ENOMEM; mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - if (!(op = malloc(len * sizeof(int)))) + mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!(op = malloc(attlen * sizeof(int)))) return PIO_ENOMEM; - mpierr = MPI_Bcast(op, len, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(op, attlen, MPI_INT, ios->compmaster, ios->intercomm); /* Call the function to write the attribute. */ - if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, len, op))) + if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, attlen, op))) return ret; /* Free resources. */ @@ -356,9 +356,9 @@ int att_handler(iosystem_desc_t *ios, int msg) mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); /* Allocate space for the attribute data. */ - if ((ret = PIOc_inq_attlen(ncid, varid, name5, &len))) + if ((ret = PIOc_inq_attlen(ncid, varid, name5, &attlen))) return ret; - if (!(ip = malloc(len * sizeof(int)))) + if (!(ip = malloc(attlen * sizeof(int)))) return PIO_ENOMEM; /* Call the function to read the attribute. */ @@ -496,7 +496,7 @@ int sync_file_handler(iosystem_desc_t *ios) if ((ret = PIOc_sync(ncid))) return ret; - printf("%d sync_file_handler succeeded!\n", my_rank); + LOG((2, "sync_file_handler succeeded!")); return PIO_NOERR; } @@ -598,16 +598,14 @@ int def_dim_handler(iosystem_desc_t *ios) int my_rank; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - LOG((1, "%d def_dim_handler comproot = %d\n", my_rank, ios->comproot)); + LOG((1, "def_dim_handler comproot = %d", ios->comproot)); /* Get the parameters for this function that the he comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_dim_handler ncid = %d\n", my_rank, ncid); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_dim_handler ncid = %d namelen %d\n", my_rank, ncid, namelen); if (!(name = malloc(namelen + 1 * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, @@ -615,9 +613,8 @@ int def_dim_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&len, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_dim_handler got parameters namelen = %d " - "name = %s len = %d ncid = %d\n", - my_rank, namelen, name, len, ncid); + LOG((2, "def_dim_handler got parameters namelen = %d " + "name = %s len = %d ncid = %d", namelen, name, len, ncid)); /* Call the create file function. */ if ((ret = PIOc_def_dim(ncid, name, len, &dimid))) @@ -685,9 +682,8 @@ int vara_handler(iosystem_desc_t *ios, int msg) if ((mpierr = MPI_Bcast(data, size_in_bytes, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - printf("%d def_var_handler got parameters namelen = %d " - "name = %s len = %d ncid = %d\n", - my_rank, namelen, name, len, ncid); + LOG((2, " def_var_handler got parameters namelen = %d " + "name = %s len = %d ncid = %d", namelen, name, len, ncid)); /* Call the create file function. */ if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) @@ -893,7 +889,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) LOG((3, "about to call msg MPI_Bcast")); mpierr = MPI_Bcast(&msg, 1, MPI_INT, 0, my_iosys->io_comm); CheckMPIReturn(mpierr, __FILE__, __LINE__); - LOG((3, "msg MPI_Bcast complete msg = %d", msg)); + LOG((1, "msg MPI_Bcast complete msg = %d", msg)); /* Handle the message. This code is run on all IO tasks. */ switch (msg) From e2504bb0be58ef296156f3ad8454f1fd38d8d693 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 15:27:00 -0400 Subject: [PATCH 17/83] further development of async --- src/clib/pio_internal.h | 4 +- src/clib/pio_msg.c | 106 ++++++++++++++++++++++++++++------------ src/clib/pio_nc_async.c | 2 + 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 16e5120ead11..a288a15de1da 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -370,7 +370,9 @@ enum PIO_MSG{ PIO_MSG_FREEDECOMP, PIO_MSG_CLOSE_FILE, PIO_MSG_DELETE_FILE, - PIO_MSG_EXIT + PIO_MSG_EXIT, + PIO_MSG_GET_ATT, + PIO_MSG_PUT_ATT }; #endif diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 3b26f1f598bb..c8fb89e9d2d4 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -255,7 +255,6 @@ int inq_att_handler(iosystem_desc_t *ios) int ret; char *name5; int namelen; - PIO_Offset attlen; int *op, *ip; nc_type xtype, *xtypep = NULL; PIO_Offset len, *lenp = NULL; @@ -309,12 +308,10 @@ int att_handler(iosystem_desc_t *ios, int msg) char *name5; int namelen; PIO_Offset attlen; - nc_type xtype; + nc_type atttype; int *op, *ip; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - LOG((1, "%d att_handler\n", my_rank)); + LOG((1, "att_handler msg = %d", msg)); if (msg == PIO_MSG_PUT_ATT_INT) { @@ -328,47 +325,94 @@ int att_handler(iosystem_desc_t *ios, int msg) if (!(name5 = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!(op = malloc(attlen * sizeof(int)))) return PIO_ENOMEM; mpierr = MPI_Bcast(op, attlen, MPI_INT, ios->compmaster, ios->intercomm); /* Call the function to write the attribute. */ - if ((ret = PIOc_put_att_int(ncid, varid, name5, xtype, attlen, op))) + if ((ret = PIOc_put_att_int(ncid, varid, name5, atttype, attlen, op))) return ret; /* Free resources. */ free(name5); free(op); } - else if (msg = PIO_MSG_GET_ATT_INT) - { - /* Get the parameters for this function that the the comp master - * task is broadcasting. */ - if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) - return PIO_EIO; - if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) - return PIO_EIO; - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!(name5 = malloc((namelen + 1) * sizeof(char)))) - return PIO_ENOMEM; - mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - /* Allocate space for the attribute data. */ - if ((ret = PIOc_inq_attlen(ncid, varid, name5, &attlen))) - return ret; - if (!(ip = malloc(attlen * sizeof(int)))) - return PIO_ENOMEM; + return PIO_NOERR; +} - /* Call the function to read the attribute. */ - if ((ret = PIOc_get_att_int(ncid, varid, name5, ip))) - return ret; +/** Handle attribute operations. This code only runs on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int att_get_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int mpierr; + int ierr; + char *name; + int namelen; + PIO_Offset attlen; + nc_type atttype; + int *op, *ip; + int iotype; - /* Free resources. */ - free(name5); - free(ip); + LOG((1, "att_get_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, + ios->intercomm); + if ((mpierr = MPI_Bcast(&iotype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + + /* Get the length and the type of the attribute. */ + switch (iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_inq_att(ncid, varid, name, &atttype, (size_t *)&attlen); + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if (ios->io_rank == 0) + ierr = nc_inq_att(ncid, varid, name, &atttype, (size_t *)&attlen); + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_inq_att(ncid, varid, name, &atttype, &attlen); + break; +#endif + default: + ierr = iotype_error(iotype,__FILE__,__LINE__); } + + /* Allocate space for the attribute data. */ + if (!(ip = malloc(attlen * sizeof(int)))) + return PIO_ENOMEM; + + /* Call the function to read the attribute. */ + if ((ierr = PIOc_get_att_int(ncid, varid, name, ip))) + return ierr; + + /* Free resources. */ + free(name); + free(ip); return PIO_NOERR; } @@ -931,6 +975,8 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) inq_var_handler(my_iosys); break; case PIO_MSG_GET_ATT_INT: + ret = att_get_handler(my_iosys); + break; case PIO_MSG_PUT_ATT_INT: ret = att_handler(my_iosys, msg); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index dcaf033ed3ef..13e0c002376f 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1562,6 +1562,8 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ From 2a77fe14cfb275e7ccf6522c59576a8d918eab9e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 16:18:15 -0400 Subject: [PATCH 18/83] further development of async --- src/clib/pio_msg.c | 8 +- src/clib/pio_nc_async.c | 827 ++---------------------------------- tests/unit/test_intercomm.c | 44 +- 3 files changed, 65 insertions(+), 814 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index c8fb89e9d2d4..f04eda2ecd0d 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -377,8 +377,11 @@ int att_get_handler(iosystem_desc_t *ios) ios->intercomm); if ((mpierr = MPI_Bcast(&iotype, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + LOG((1, "att_get_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d", + ncid, varid, namelen, name, iotype)); /* Get the length and the type of the attribute. */ + LOG((1, "att_get_handler magic iotype = %d", iotype)); switch (iotype) { #ifdef _NETCDF @@ -780,9 +783,8 @@ int open_file_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&mode, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - LOG((1, "%d open_file_handler got parameters len = %d " - "filename = %s iotype = %d mode = %d\n", - my_rank, len, filename, iotype, mode)); + LOG((2, "open_file_handler got parameters len = %d filename = %s iotype = %d mode = %d\n", + len, filename, iotype, mode)); /* Call the open file function. */ if ((ret = PIOc_openfile(ios->iosysid, &ncid, &iotype, filename, mode))) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 13e0c002376f..fbd0313206b1 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -18,6 +18,7 @@ #include #ifdef PIO_ENABLE_LOGGING #include +#include #endif /* PIO_ENABLE_LOGGING */ #include #include @@ -64,8 +65,8 @@ pio_log(int severity, const char *fmt, ...) if (severity > pio_log_level) return; - /* If the severity is 1 or less, only print on rank 0. */ - if (severity < 2 && my_rank != 0) + /* If the severity is 0, only print on rank 0. */ + if (severity < 1 && my_rank != 0) return; /* If the severity is zero, this is an error. Otherwise insert that @@ -1534,6 +1535,8 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) int msg = PIO_MSG_GET_ATT_INT; iosystem_desc_t *ios; file_desc_t *file; + PIO_Offset attlen; + nc_type atttype; int ierr = PIO_NOERR; int mpierr = MPI_SUCCESS; @@ -1541,6 +1544,8 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) if (!name || !ip) return PIO_EINVAL; + LOG((1, "PIOc_get_att ncid %d varid %d name %s", ncid, varid, name)); + /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; @@ -1564,6 +1569,7 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); + LOG((2, "broadcast iotype = %d", file->iotype)); } /* Handle MPI errors. */ @@ -1580,23 +1586,32 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_get_att(file->fh, varid, name, ip); + if (!ierr) + ierr = nc_inq_att(file->fh, varid, name, &atttype, (size_t *)&attlen); break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if (ios->io_rank == 0) + { ierr = nc_get_att(file->fh, varid, name, ip); + if (!ierr) + ierr = nc_inq_att(file->fh, varid, name, &atttype, (size_t *)&attlen); + } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: ierr = ncmpi_get_att(file->fh, varid, name, ip); + if (!ierr) + ierr = ncmpi_inq_att(file->fh, varid, name, &atttype, &attlen); break; #endif default: ierr = iotype_error(file->iotype,__FILE__,__LINE__); } } + LOG((2, "PIOc_get_att called netcdf layer ierr = %d", ierr)); /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) @@ -1606,9 +1621,12 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* Broadcast results to all tasks. */ if (!ierr) { - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_INT, ios->ioroot, ios->my_comm); + LOG((2, "PIOc_get_att broadcasting attlen = %d", attlen)); + mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); + LOG((2, "PIOc_get_att done broadcasting attlen = %d", attlen)); + LOG((2, "PIOc_get_att broadcasting att data")); + mpierr = MPI_Bcast(ip, (int)attlen, MPI_INT, ios->ioroot, ios->my_comm); + LOG((2, "PIOc_get_att done broadcasting att data")); } return ierr; } @@ -1700,68 +1718,9 @@ int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PI * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_get_att_double (int ncid, int varid, const char *name, double *ip) +int PIOc_get_att_double(int ncid, int varid, const char *name, double *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_double(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_double(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_double(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_DOUBLE, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -1853,66 +1812,7 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P */ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_uchar(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_uchar(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -2004,66 +1904,7 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI */ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_USHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_ushort(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_ushort(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_SHORT, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -2374,66 +2215,7 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co */ int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_uint(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_uint(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_uint(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -2526,66 +2308,7 @@ int PIOc_inq_format (int ncid, int *formatp) */ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_long(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_long(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_long(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -2695,66 +2418,7 @@ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) */ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_float(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_float(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_float(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_FLOAT, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3077,66 +2741,7 @@ int PIOc_put_att_longlong (int ncid, int varid, const char *name, nc_type xtype, */ int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_UBYTE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_ubyte(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_ubyte(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_ubyte(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_BYTE, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3155,66 +2760,7 @@ int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip */ int PIOc_get_att_text (int ncid, int varid, const char *name, char *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_text(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_text(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_text(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3306,66 +2852,7 @@ int PIOc_del_att (int ncid, int varid, const char *name) */ int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_schar(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_schar(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_schar(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_CHAR, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3384,66 +2871,7 @@ int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) */ int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_ulonglong(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_ulonglong(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_ulonglong(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_UNSIGNED_LONG_LONG, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3618,66 +3046,7 @@ int PIOc_put_att_uint (int ncid, int varid, const char *name, nc_type xtype, PIO */ int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_short(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_short(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_short(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_SHORT, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3841,70 +3210,7 @@ int PIOc_put_att_ubyte (int ncid, int varid, const char *name, nc_type xtype, PI */ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - int namelen; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_int(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_int(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_int(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_INT, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** @@ -3923,66 +3229,7 @@ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) */ int PIOc_get_att_longlong (int ncid, int varid, const char *name, long long *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_ATT_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att_longlong(file->fh, varid, name, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_get_att_longlong(file->fh, varid, name, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_get_att_longlong(file->fh, varid, name, ip);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(name)+strlen(__FILE__) + 40)* sizeof(char)); - sprintf(errstr,"name %s in file %s",name,__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(ierr == PIO_NOERR){ - PIO_Offset attlen; - PIOc_inq_attlen(file->fh, varid, name, &attlen); - mpierr = MPI_Bcast(ip , (int) attlen, MPI_LONG_LONG, ios->ioroot, ios->my_comm); - } - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index cfddf1e600a0..cf99c672a058 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -92,6 +92,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) if ((ret = PIOc_openfile(iosysid, &ncid, &format, filename, NC_NOWRITE))) ERR(ret); + sleep(2); /* Find the number of dimensions, variables, and global attributes.*/ if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) @@ -136,10 +137,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (dimlen2 != DIM_LEN) ERR(ERR_WRONG); - if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) - ERR(ret); - if (dimid2 != 0) - ERR(ERR_WRONG); + /* if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) */ + /* ERR(ret); */ + /* if (dimid2 != 0) */ + /* ERR(ERR_WRONG); */ /* Check out the variable. */ if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) @@ -169,29 +170,30 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (varnatts2 != 0) ERR(ERR_WRONG); - if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) - ERR(ret); - if (varid2 != 0) - ERR(ERR_WRONG); + /* if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) */ + /* ERR(ret); */ + /* if (varid2 != 0) */ + /* ERR(ERR_WRONG); */ /* Check out the global attributes. */ nc_type atttype; PIO_Offset attlen; - if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) - ERR(ret); - if (atttype != NC_INT || attlen != 1) - ERR(ERR_WRONG); - if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) - ERR(ret); - if (attlen != 1) - ERR(ERR_WRONG); - /* if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) */ + /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) */ + /* ERR(ret); */ + /* if (atttype != NC_INT || attlen != 1) */ + /* ERR(ERR_WRONG); */ + /* if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) */ /* ERR(ret); */ - /* sleep(2); */ - /* if (verbose) */ - /* printf("%d test_intercomm att_data = %d\n", my_rank, att_data); */ - /* if (att_data != ATT_VALUE) */ + /* if (attlen != 1) */ /* ERR(ERR_WRONG); */ + sleep(2); + if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) + ERR(ret); + sleep(2); + if (verbose) + printf("%d test_intercomm att_data = %d\n", my_rank, att_data); + if (att_data != ATT_VALUE) + ERR(ERR_WRONG); /* Close the file. */ if (verbose) From f028866a1d06ccede498ac4a785cca97e254aa21 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 16:18:32 -0400 Subject: [PATCH 19/83] further development of async --- tests/unit/test_intercomm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index cf99c672a058..e36a508f6ecd 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -178,18 +178,16 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Check out the global attributes. */ nc_type atttype; PIO_Offset attlen; - /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) */ - /* ERR(ret); */ - /* if (atttype != NC_INT || attlen != 1) */ - /* ERR(ERR_WRONG); */ - /* if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) */ - /* ERR(ret); */ - /* if (attlen != 1) */ - /* ERR(ERR_WRONG); */ - sleep(2); + if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) + ERR(ret); + if (atttype != NC_INT || attlen != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &attlen))) + ERR(ret); + if (attlen != 1) + ERR(ERR_WRONG); if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) ERR(ret); - sleep(2); if (verbose) printf("%d test_intercomm att_data = %d\n", my_rank, att_data); if (att_data != ATT_VALUE) From 891b29c28370d1f2c41e68531407c635872e7155 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 16:19:25 -0400 Subject: [PATCH 20/83] further development of async --- tests/unit/test_intercomm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index e36a508f6ecd..7e46d59d0930 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -170,10 +170,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (varnatts2 != 0) ERR(ERR_WRONG); - /* if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) */ - /* ERR(ret); */ - /* if (varid2 != 0) */ - /* ERR(ERR_WRONG); */ + if ((ret = PIOc_inq_varid(ncid, VAR_NAME, &varid2))) + ERR(ret); + if (varid2 != 0) + ERR(ERR_WRONG); /* Check out the global attributes. */ nc_type atttype; From 8b460808550218894b1f719a55641ad350103284 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 11 May 2016 16:28:09 -0400 Subject: [PATCH 21/83] further development of async --- src/clib/pio_msg.c | 6 ++---- src/clib/pio_nc_async.c | 5 +++-- tests/unit/test_intercomm.c | 10 ++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index f04eda2ecd0d..530ea5c26930 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -207,9 +207,7 @@ int inq_dimid_handler(iosystem_desc_t *ios) int namelen; char *name; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - LOG((1, "inq_dimid_handler\n", my_rank)); + LOG((1, "inq_dimid_handler")); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -223,7 +221,7 @@ int inq_dimid_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - LOG((1, "%d inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d\n", + LOG((1, "inq_dimid_handler ncid = %d namelen = %d name = %s id_present = %d", ncid, namelen, name, id_present)); /* Set non-null pointer. */ diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index fbd0313206b1..f92c81924ef1 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -440,11 +440,10 @@ int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) */ int PIOc_inq_dimid(int ncid, const char *name, int *idp) { - int msg = PIO_MSG_INQ_DIMID; iosystem_desc_t *ios; file_desc_t *file; int ierr = PIO_NOERR; - int mpierr; + int mpierr = MPI_SUCCESS; /* Name must be provided. */ if (!name) @@ -462,10 +461,12 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) { if (!ios->ioproc) { + int msg = PIO_MSG_INQ_DIMID; char id_present = idp ? true : false; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); int namelen = strlen(name); diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 7e46d59d0930..b427ab7b4667 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -137,10 +137,12 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (dimlen2 != DIM_LEN) ERR(ERR_WRONG); - /* if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) */ - /* ERR(ret); */ - /* if (dimid2 != 0) */ - /* ERR(ERR_WRONG); */ + sleep(2); + if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) + ERR(ret); + if (dimid2 != 0) + ERR(ERR_WRONG); + sleep(2); /* Check out the variable. */ if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) From 80a361f60384d27934a1a6f7b7f40716ea1e991b Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:11:10 -0400 Subject: [PATCH 22/83] further async development --- src/clib/pio.h | 2 +- src/clib/pio_nc_async.c | 381 +++++++++++++++++++++++++----------- tests/unit/test_intercomm.c | 2 +- 3 files changed, 268 insertions(+), 117 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 2be57ca845c9..5dc08cedee2c 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -648,7 +648,7 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_get_var_schar (int ncid, int varid, signed char *buf); int PIOc_iotype_available(const int iotype); int PIOc_set_log_level(int level); - int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op); + int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const void *op); int PIOc_get_att(int ncid, int varid, const char *name, void *ip); #if defined(__cplusplus) } diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index f92c81924ef1..e5bd7fc693c5 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -113,7 +113,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ - int mpierr = MPI_SUCCESS; /** Return code from MPI function codes. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq ncid = %d", ncid)); @@ -149,7 +149,8 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, } /* Handle MPI errors. */ - mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -297,9 +298,8 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { iosystem_desc_t *ios; file_desc_t *file; - int msg = PIO_MSG_INQ_DIM; int ierr = PIO_NOERR; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq_dim")); @@ -313,10 +313,13 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { if (!ios->ioproc) { + int msg = PIO_MSG_INQ_DIM; char name_present = name ? true : false; - char len_present = lenp ? true : false; + char len_present = lenp ? true : false; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -330,7 +333,8 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) } /* Handle MPI errors. */ - mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -443,7 +447,7 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) iosystem_desc_t *ios; file_desc_t *file; int ierr = PIO_NOERR; - int mpierr = MPI_SUCCESS; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ /* Name must be provided. */ if (!name) @@ -479,7 +483,8 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) } /* Handle MPI errors. */ - mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -516,9 +521,10 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ - if (idp) - if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ierr) + if (idp) + if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -546,8 +552,7 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, file_desc_t *file; int ndims; /** The number of dimensions for this variable. */ int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_VAR; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq_var ncid = %d varid = %d", ncid, varid)); @@ -556,32 +561,51 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, return PIO_EBADID; ios = file->iosystem; - /* If using async, and this is not an IO task, send the parameters to the IO task. */ - if (ios->async_interface && !ios->ioproc) + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) { - char name_present = name ? true : false; - char xtype_present = xtypep ? true : false; - char ndims_present = ndimsp ? true : false; - char dimids_present = dimidsp ? true : false; - char natts_present = nattsp ? true : false; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_VAR; + char name_present = name ? true : false; + char xtype_present = xtypep ? true : false; + char ndims_present = ndimsp ? true : false; + char dimids_present = dimidsp ? true : false; + char natts_present = nattsp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " "dimids_present = %d, natts_present = %d nattsp = %d", name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); - } + } + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + /* Call the netCDF layer. */ if (ios->ioproc) { - switch(file->iotype){ + switch(file->iotype) + { #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: @@ -615,36 +639,39 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ - if (name) - { - int slen; - if(ios->iomaster) - slen = strlen(name); - if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - } - if (xtypep) - if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - - if (ndimsp) - { - if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - file->varlist[varid].ndims = (*ndimsp); - } - if (dimidsp) + if (!ierr) { - if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (name) + { + int slen; + if(ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (xtypep) + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + + if (ndimsp) + { + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + file->varlist[varid].ndims = (*ndimsp); + } + if (dimidsp) + { + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (nattsp) + if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } - if (nattsp) - if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -763,11 +790,10 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) */ int PIOc_inq_varid (int ncid, const char *name, int *varidp) { - int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_VARID; - int mpierr = 0; iosystem_desc_t *ios; file_desc_t *file; + int ierr = PIO_NOERR; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ /* Caller must provide name. */ if (!name) @@ -784,6 +810,8 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) { if (!ios->ioproc) { + int msg = PIO_MSG_INQ_VARID; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -798,7 +826,8 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) } /* Handle MPI errors. */ - mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -864,7 +893,7 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, int msg = PIO_MSG_INQ_ATT; iosystem_desc_t *ios; file_desc_t *file; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ int ierr = PIO_NOERR; /* Caller must provide a name. */ @@ -923,10 +952,10 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, } } - /* Handle errors. */ - if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - check_netcdf(file, ierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) @@ -1001,7 +1030,7 @@ int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) { int ierr = PIO_NOERR; int msg = PIO_MSG_INQ_ATTNAME; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; @@ -1072,7 +1101,7 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) { int ierr = PIO_NOERR; int msg = PIO_MSG_INQ_ATTID; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; @@ -1111,10 +1140,10 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) } } - /* Handle errors. */ - if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - check_netcdf(file, ierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) @@ -1144,7 +1173,7 @@ int PIOc_rename_dim (int ncid, int dimid, const char *name) { int ierr; int msg; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; char *errstr; @@ -1217,7 +1246,7 @@ int PIOc_rename_var (int ncid, int varid, const char *name) { int ierr; int msg; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; char *errstr; @@ -1289,7 +1318,7 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) { int ierr; int msg; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; char *errstr; @@ -1363,39 +1392,63 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp) { - int msg = PIO_MSG_DEF_VAR; - int mpierr; iosystem_desc_t *ios; file_desc_t *file; int ierr = PIO_NOERR; - char *errstr = NULL; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ int namelen; + /* User must provide name and storage for varid. */ + if (!name || !varidp) + { + check_netcdf(file, PIO_EINVAL, __FILE__, __LINE__); + return PIO_EINVAL; + } + /* Get the file information. */ if (!(file = pio_get_file_from_id(ncid))) + { + check_netcdf(file, PIO_EBADID, __FILE__, __LINE__); return PIO_EBADID; + } ios = file->iosystem; - /* If async is in use, and this is not an IO tasks, then bcast the - * function parameters to the intercomm, where it will be read by - * the IO root task. */ - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); - if (!ios->compmaster) - ios->compmaster = MPI_PROC_NULL; - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); + /* If using async, and not an IO task, then send parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_DEF_VAR; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); + if (!ios->compmaster) + ios->compmaster = MPI_PROC_NULL; + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ios->ioproc){ - switch(file->iotype) + /* IO tasks call the netCDF functions. */ + if (ios->ioproc) + { + switch (file->iotype) { #ifdef _NETCDF #ifdef _NETCDF4 @@ -1426,19 +1479,16 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, } } - /* Handle errors. */ - if (ierr) - { - errstr = (char *)malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr, "in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results. */ + if (!ierr) + if (varidp) + mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm); - /* Free error string if allocated. */ - if(errstr) - free(errstr); - return ierr; } @@ -1460,7 +1510,7 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) { int ierr; int msg; - int mpierr; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ iosystem_desc_t *ios; file_desc_t *file; char *errstr; @@ -1533,13 +1583,12 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) */ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { - int msg = PIO_MSG_GET_ATT_INT; iosystem_desc_t *ios; file_desc_t *file; PIO_Offset attlen; nc_type atttype; int ierr = PIO_NOERR; - int mpierr = MPI_SUCCESS; + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ /* User must provide a name and destination pointer. */ if (!name || !ip) @@ -1557,8 +1606,11 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { if (!ios->ioproc) { + int msg = PIO_MSG_GET_ATT_INT; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -1574,7 +1626,8 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) } /* Handle MPI errors. */ - mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -1632,6 +1685,104 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) return ierr; } +/** + * @ingroup PIOc_put_att + * The PIO-C interface for the NetCDF function nc_put_att. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const void *op) +{ + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ + + LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_PUT_ATT; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { + switch (file->iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_put_att(file->fh, varid, name, xtype, len, op); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + return ierr; +} + /** * @ingroup PIOc_put_att_short * The PIO-C interface for the NetCDF function nc_put_att_short. @@ -1650,7 +1801,7 @@ int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PI { int ierr; int msg; - int mpierr; + int mpierr = MPI_SUCCESS; iosystem_desc_t *ios; file_desc_t *file; char *errstr; diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index b427ab7b4667..f6dbfc966c54 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -371,7 +371,7 @@ main(int argc, char **argv) /* Add a global attribute. */ if (verbose) - printf("%d test_intercomm writing attribute %s\n", my_rank, ATT_NAME); + printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME); int att_data = ATT_VALUE; if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); From 10b178ac88a72cb16190b4943398bfdc42d7c840 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:31:51 -0400 Subject: [PATCH 23/83] code cleanup --- src/clib/pio_nc_async.c | 335 ++++++---------------------------------- 1 file changed, 44 insertions(+), 291 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index e5bd7fc693c5..278b19f759f0 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -280,6 +280,24 @@ int PIOc_inq_natts(int ncid, int *ngattsp) return PIOc_inq(ncid, NULL, NULL, ngattsp, NULL); } +/** + * @ingroup PIOc_inq_unlimdim + * The PIO-C interface for the NetCDF function nc_inq_unlimdim. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) +{ + return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); +} + /** * @ingroup PIOc_inq_dim * The PIO-C interface for the NetCDF function nc_inq_dim. @@ -1786,18 +1804,9 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, /** * @ingroup PIOc_put_att_short * The PIO-C interface for the NetCDF function nc_put_att_short. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) +int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const short *op) { int ierr; int msg; @@ -1859,16 +1868,6 @@ int PIOc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, PI /** * @ingroup PIOc_get_att_double * The PIO-C interface for the NetCDF function nc_get_att_double. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_double(int ncid, int varid, const char *name, double *ip) { @@ -1878,18 +1877,9 @@ int PIOc_get_att_double(int ncid, int varid, const char *name, double *ip) /** * @ingroup PIOc_put_att_double * The PIO-C interface for the NetCDF function nc_put_att_double. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) +int PIOc_put_att_double(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const double *op) { int ierr; int msg; @@ -1951,16 +1941,6 @@ int PIOc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, P /** * @ingroup PIOc_get_att_uchar * The PIO-C interface for the NetCDF function nc_get_att_uchar. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip) { @@ -1970,18 +1950,9 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip /** * @ingroup PIOc_put_att_schar * The PIO-C interface for the NetCDF function nc_put_att_schar. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) +int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const signed char *op) { int ierr; int msg; @@ -2043,16 +2014,6 @@ int PIOc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, PI /** * @ingroup PIOc_get_att_ushort * The PIO-C interface for the NetCDF function nc_get_att_ushort. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *ip) { @@ -2062,18 +2023,9 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * /** * @ingroup PIOc_put_att_ulonglong * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned long long *op) +int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned long long *op) { int ierr; int msg; @@ -2208,18 +2160,9 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) /** * @ingroup PIOc_put_att_ushort * The PIO-C interface for the NetCDF function nc_put_att_ushort. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned short *op) +int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned short *op) { int ierr; int msg; @@ -2281,18 +2224,9 @@ int PIOc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, P /** * @ingroup PIOc_put_att_text * The PIO-C interface for the NetCDF function nc_put_att_text. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, const char *op) +int PIOc_put_att_text(int ncid, int varid, const char *name, + PIO_Offset len, const char *op) { int ierr; int msg; @@ -2354,16 +2288,6 @@ int PIOc_put_att_text (int ncid, int varid, const char *name, PIO_Offset len, co /** * @ingroup PIOc_get_att_uint * The PIO-C interface for the NetCDF function nc_get_att_uint. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) { @@ -2447,16 +2371,6 @@ int PIOc_inq_format (int ncid, int *formatp) /** * @ingroup PIOc_get_att_long * The PIO-C interface for the NetCDF function nc_get_att_long. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) { @@ -2466,18 +2380,9 @@ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) /** * @ingroup PIOc_put_att_long * The PIO-C interface for the NetCDF function nc_put_att_long. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long *op) +int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const long *op) { int ierr; int msg; @@ -2536,37 +2441,9 @@ int PIOc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, PIO return ierr; } -/** - * @ingroup PIOc_inq_unlimdim - * The PIO-C interface for the NetCDF function nc_inq_unlimdim. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) -{ - return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); -} - /** * @ingroup PIOc_get_att_float * The PIO-C interface for the NetCDF function nc_get_att_float. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) { @@ -2576,18 +2453,9 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) /** * @ingroup PIOc_put_att_int * The PIO-C interface for the NetCDF function nc_put_att_int. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const int *op) +int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const int *op) { int ierr; int msg; @@ -2733,18 +2601,9 @@ int PIOc_enddef(int ncid) /** * @ingroup PIOc_put_att_uchar * The PIO-C interface for the NetCDF function nc_put_att_uchar. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_uchar (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) +int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned char *op) { int ierr; int msg; @@ -2806,18 +2665,9 @@ int PIOc_put_att_uchar (int ncid, int varid, const char *name, nc_type xtype, PI /** * @ingroup PIOc_put_att_longlong * The PIO-C interface for the NetCDF function nc_put_att_longlong. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_longlong (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long long *op) +int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const long long *op) { int ierr; int msg; @@ -2880,16 +2730,6 @@ int PIOc_put_att_longlong (int ncid, int varid, const char *name, nc_type xtype, /** * @ingroup PIOc_get_att_ubyte * The PIO-C interface for the NetCDF function nc_get_att_ubyte. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip) { @@ -2899,16 +2739,6 @@ int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip /** * @ingroup PIOc_get_att_text * The PIO-C interface for the NetCDF function nc_get_att_text. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_text (int ncid, int varid, const char *name, char *ip) { @@ -2991,16 +2821,6 @@ int PIOc_del_att (int ncid, int varid, const char *name) /** * @ingroup PIOc_get_att_schar * The PIO-C interface for the NetCDF function nc_get_att_schar. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) { @@ -3010,16 +2830,6 @@ int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) /** * @ingroup PIOc_get_att_ulonglong * The PIO-C interface for the NetCDF function nc_get_att_ulonglong. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *ip) { @@ -3112,18 +2922,9 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) /** * @ingroup PIOc_put_att_uint * The PIO-C interface for the NetCDF function nc_put_att_uint. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_uint (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned int *op) +int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned int *op) { int ierr; int msg; @@ -3185,16 +2986,6 @@ int PIOc_put_att_uint (int ncid, int varid, const char *name, nc_type xtype, PIO /** * @ingroup PIOc_get_att_short * The PIO-C interface for the NetCDF function nc_get_att_short. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) { @@ -3276,18 +3067,9 @@ int PIOc_redef (int ncid) /** * @ingroup PIOc_put_att_ubyte * The PIO-C interface for the NetCDF function nc_put_att_ubyte. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_ubyte (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) +int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned char *op) { int ierr; int msg; @@ -3349,16 +3131,6 @@ int PIOc_put_att_ubyte (int ncid, int varid, const char *name, nc_type xtype, PI /** * @ingroup PIOc_get_att_int * The PIO-C interface for the NetCDF function nc_get_att_int. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) { @@ -3368,16 +3140,6 @@ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) /** * @ingroup PIOc_get_att_longlong * The PIO-C interface for the NetCDF function nc_get_att_longlong. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_get_att_longlong (int ncid, int varid, const char *name, long long *ip) { @@ -3387,18 +3149,9 @@ int PIOc_get_att_longlong (int ncid, int varid, const char *name, long long *ip) /** * @ingroup PIOc_put_att_float * The PIO-C interface for the NetCDF function nc_put_att_float. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_put_att_float (int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const float *op) +int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const float *op) { int ierr; int msg; From a0aaea9fe56ef3d092235e9b06d2acef8efce899 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:42:54 -0400 Subject: [PATCH 24/83] further cleanup of async code --- src/clib/pio_nc_async.c | 56 +---------------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 278b19f759f0..b8737990ef0b 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1808,61 +1808,7 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const short *op) { - int ierr; - int msg; - int mpierr = MPI_SUCCESS; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_short(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_short(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** From 96e74980a53a53a7a34a34a8c667f7f61b3a946a Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:46:55 -0400 Subject: [PATCH 25/83] further cleanup of async code --- src/clib/pio_nc_async.c | 448 +--------------------------------------- 1 file changed, 8 insertions(+), 440 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b8737990ef0b..ad646e26573b 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1827,61 +1827,7 @@ int PIOc_get_att_double(int ncid, int varid, const char *name, double *ip) int PIOc_put_att_double(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const double *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_double(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_double(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -1900,61 +1846,7 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const signed char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_schar(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_schar(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -1973,61 +1865,7 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_ulonglong(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_ulonglong(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2110,61 +1948,7 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned short *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_USHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_ushort(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_ushort(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2174,61 +1958,7 @@ int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_text(int ncid, int varid, const char *name, PIO_Offset len, const char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_text(file->fh, varid, name, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_text(file->fh, varid, name, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** @@ -2330,61 +2060,7 @@ int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_long(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_long(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** @@ -2551,61 +2227,7 @@ int PIOc_enddef(int ncid) int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_uchar(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_uchar(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_uchar(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** @@ -2615,61 +2237,7 @@ int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_longlong(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_longlong(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_longlong(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } From f788f6b923e9c502556c640953d8eade88af28a2 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:48:19 -0400 Subject: [PATCH 26/83] further cleanup of async code --- src/clib/pio_nc_async.c | 117 ++-------------------------------------- 1 file changed, 4 insertions(+), 113 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index ad646e26573b..ed62343c8744 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2240,7 +2240,6 @@ int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } - /** * @ingroup PIOc_get_att_ubyte * The PIO-C interface for the NetCDF function nc_get_att_ubyte. @@ -2440,61 +2439,7 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_uint(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_uint(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_uint(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** @@ -2585,68 +2530,14 @@ int PIOc_redef (int ncid) int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_UBYTE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_ubyte(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_ubyte(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_ubyte(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** * @ingroup PIOc_get_att_int * The PIO-C interface for the NetCDF function nc_get_att_int. */ -int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) +int PIOc_get_att_int(int ncid, int varid, const char *name, int *ip) { return PIOc_get_att(ncid, varid, name, (void *)ip); } @@ -2655,7 +2546,7 @@ int PIOc_get_att_int (int ncid, int varid, const char *name, int *ip) * @ingroup PIOc_get_att_longlong * The PIO-C interface for the NetCDF function nc_get_att_longlong. */ -int PIOc_get_att_longlong (int ncid, int varid, const char *name, long long *ip) +int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) { return PIOc_get_att(ncid, varid, name, (void *)ip); } From 0a6fb4f902cc3a76bf62e01f5c29eb398687d939 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:50:30 -0400 Subject: [PATCH 27/83] further cleanup of async code --- src/clib/pio_nc_async.c | 110 ++++++++++------------------------------ 1 file changed, 28 insertions(+), 82 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index ed62343c8744..e1075701e480 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2349,6 +2349,33 @@ int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long return PIOc_get_att(ncid, varid, name, (void *)ip); } +/** + * @ingroup PIOc_get_att_short + * The PIO-C interface for the NetCDF function nc_get_att_short. + */ +int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) +{ + return PIOc_get_att(ncid, varid, name, (void *)ip); +} + +/** + * @ingroup PIOc_get_att_int + * The PIO-C interface for the NetCDF function nc_get_att_int. + */ +int PIOc_get_att_int(int ncid, int varid, const char *name, int *ip) +{ + return PIOc_get_att(ncid, varid, name, (void *)ip); +} + +/** + * @ingroup PIOc_get_att_longlong + * The PIO-C interface for the NetCDF function nc_get_att_longlong. + */ +int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) +{ + return PIOc_get_att(ncid, varid, name, (void *)ip); +} + /** * @ingroup PIOc_def_dim * The PIO-C interface for the NetCDF function nc_def_dim. @@ -2442,15 +2469,6 @@ int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } -/** - * @ingroup PIOc_get_att_short - * The PIO-C interface for the NetCDF function nc_get_att_short. - */ -int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - /** * @ingroup PIOc_redef * The PIO-C interface for the NetCDF function nc_redef. @@ -2533,24 +2551,6 @@ int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } -/** - * @ingroup PIOc_get_att_int - * The PIO-C interface for the NetCDF function nc_get_att_int. - */ -int PIOc_get_att_int(int ncid, int varid, const char *name, int *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - -/** - * @ingroup PIOc_get_att_longlong - * The PIO-C interface for the NetCDF function nc_get_att_longlong. - */ -int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - /** * @ingroup PIOc_put_att_float * The PIO-C interface for the NetCDF function nc_put_att_float. @@ -2558,60 +2558,6 @@ int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const float *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_float(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_float(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_float(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } From 54c8287f32cb3378cf78dded89367656316e69f1 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 12:53:36 -0400 Subject: [PATCH 28/83] further cleanup of async code --- src/clib/pio_nc_async.c | 456 ++++++++++++++++++++-------------------- 1 file changed, 228 insertions(+), 228 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index e1075701e480..e3e1de1b9b1e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1391,6 +1391,234 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) return ierr; } +/** + * @ingroup PIOc_enddef + * The PIO-C interface for the NetCDF function nc_enddef. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_enddef(int ncid) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_ENDDEF; + + if(ios->async_interface && ! ios->ioproc){ + if(!ios->comp_rank) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + printf("PIOc_enddef file->fh = %d\n", file->fh); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_enddef(file->fh);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_enddef(file->fh);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_enddef(file->fh);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(errstr != NULL) free(errstr); + return ierr; +} + +/** + * @ingroup PIOc_redef + * The PIO-C interface for the NetCDF function nc_redef. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_redef (int ncid) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_REDEF; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_redef(file->fh);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_redef(file->fh);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_redef(file->fh);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(errstr != NULL) free(errstr); + return ierr; +} + +/** + * @ingroup PIOc_def_dim + * The PIO-C interface for the NetCDF function nc_def_dim. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param idp a pointer that will get the id of the variable or attribute. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + int namelen; + + errstr = NULL; + ierr = PIO_NOERR; + + int my_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + printf("%d PIOc_def_dim ncid = %d name = %s len = %d\n", my_rank, + ncid, name, len); + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_DEF_DIM; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + namelen = strlen(name); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + } + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_def_dim(file->fh, name, len, idp);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); + if(errstr != NULL) free(errstr); + return ierr; +} + /** * @ingroup PIOc_def_var * The PIO-C interface for the NetCDF function nc_def_var. @@ -2147,79 +2375,6 @@ int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, return ierr; } -/** - * @ingroup PIOc_enddef - * The PIO-C interface for the NetCDF function nc_enddef. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_enddef(int ncid) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_ENDDEF; - - if(ios->async_interface && ! ios->ioproc){ - if(!ios->comp_rank) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - printf("PIOc_enddef file->fh = %d\n", file->fh); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_enddef(file->fh);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_enddef(file->fh);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_enddef(file->fh);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_put_att_uchar * The PIO-C interface for the NetCDF function nc_put_att_uchar. @@ -2376,89 +2531,6 @@ int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) return PIOc_get_att(ncid, varid, name, (void *)ip); } -/** - * @ingroup PIOc_def_dim - * The PIO-C interface for the NetCDF function nc_def_dim. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param idp a pointer that will get the id of the variable or attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - int namelen; - - errstr = NULL; - ierr = PIO_NOERR; - - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_def_dim ncid = %d name = %s len = %d\n", my_rank, - ncid, name, len); - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_DEF_DIM; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_def_dim(file->fh, name, len, idp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_put_att_uint * The PIO-C interface for the NetCDF function nc_put_att_uint. @@ -2469,78 +2541,6 @@ int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } -/** - * @ingroup PIOc_redef - * The PIO-C interface for the NetCDF function nc_redef. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_redef (int ncid) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_REDEF; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_redef(file->fh);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_redef(file->fh);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_redef(file->fh);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; -} - /** * @ingroup PIOc_put_att_ubyte * The PIO-C interface for the NetCDF function nc_put_att_ubyte. From 19ea32285ecf07e4033f86cd18f7f05015c71afa Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 14:08:21 -0400 Subject: [PATCH 29/83] further development of async code --- src/clib/pio_nc_async.c | 582 ++++++++++++++++++++-------------------- 1 file changed, 291 insertions(+), 291 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index e3e1de1b9b1e..51bb7f7813aa 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -298,6 +298,80 @@ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); } +/** + * @ingroup PIOc_inq_format + * The PIO-C interface for the NetCDF function nc_inq_format. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param formatp a pointer that will get the file format + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_inq_format (int ncid, int *formatp) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_INQ_FORMAT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_inq_format(file->fh, formatp);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_inq_format(file->fh, formatp);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_inq_format(file->fh, formatp);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm); + if(errstr != NULL) free(errstr); + return ierr; +} + /** * @ingroup PIOc_inq_dim * The PIO-C interface for the NetCDF function nc_inq_dim. @@ -1319,6 +1393,152 @@ int PIOc_rename_var (int ncid, int varid, const char *name) return ierr; } +/** + * @ingroup PIOc_rename_att + * The PIO-C interface for the NetCDF function nc_rename_att. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_RENAME_ATT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_rename_att(file->fh, varid, name, newname);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_rename_att(file->fh, varid, name, newname);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_rename_att(file->fh, varid, name, newname);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(errstr != NULL) free(errstr); + return ierr; +} + +/** + * @ingroup PIOc_del_att + * The PIO-C interface for the NetCDF function nc_del_att. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @param varid the variable ID. + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_del_att (int ncid, int varid, const char *name) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + char *errstr; + + errstr = NULL; + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_DEL_ATT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_del_att(file->fh, varid, name);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_del_att(file->fh, varid, name);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + ierr = ncmpi_del_att(file->fh, varid, name);; + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + if(ierr != PIO_NOERR){ + errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); + sprintf(errstr,"in file %s",__FILE__); + } + ierr = check_netcdf(file, ierr, errstr,__LINE__); + if(errstr != NULL) free(errstr); + return ierr; +} + /** * @ingroup PIOc_set_fill * The PIO-C interface for the NetCDF function nc_set_fill. @@ -2087,196 +2307,82 @@ int PIOc_get_att_ushort (int ncid, int varid, const char *name, unsigned short * } /** - * @ingroup PIOc_put_att_ulonglong - * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. + * @ingroup PIOc_get_att_uint + * The PIO-C interface for the NetCDF function nc_get_att_uint. */ -int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned long long *op) +int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) { - return PIOc_put_att(ncid, varid, name, xtype, len, op); + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_rename_att - * The PIO-C interface for the NetCDF function nc_rename_att. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + * @ingroup PIOc_get_att_long + * The PIO-C interface for the NetCDF function nc_get_att_long. */ -int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) +int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; + return PIOc_get_att(ncid, varid, name, (void *)ip); +} - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_RENAME_ATT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_att(file->fh, varid, name, newname);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_rename_att(file->fh, varid, name, newname);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_att(file->fh, varid, name, newname);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; +/** + * @ingroup PIOc_get_att_ubyte + * The PIO-C interface for the NetCDF function nc_get_att_ubyte. + */ +int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip) +{ + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_put_att_ushort - * The PIO-C interface for the NetCDF function nc_put_att_ushort. + * @ingroup PIOc_get_att_text + * The PIO-C interface for the NetCDF function nc_get_att_text. */ -int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned short *op) +int PIOc_get_att_text (int ncid, int varid, const char *name, char *ip) { - return PIOc_put_att(ncid, varid, name, xtype, len, op); + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_put_att_text - * The PIO-C interface for the NetCDF function nc_put_att_text. + * @ingroup PIOc_get_att_schar + * The PIO-C interface for the NetCDF function nc_get_att_schar. */ -int PIOc_put_att_text(int ncid, int varid, const char *name, - PIO_Offset len, const char *op) +int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_get_att_uint - * The PIO-C interface for the NetCDF function nc_get_att_uint. + * @ingroup PIOc_get_att_ulonglong + * The PIO-C interface for the NetCDF function nc_get_att_ulonglong. */ -int PIOc_get_att_uint (int ncid, int varid, const char *name, unsigned int *ip) +int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *ip) { return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_inq_format - * The PIO-C interface for the NetCDF function nc_inq_format. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param formatp a pointer that will get the file format - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + * @ingroup PIOc_get_att_short + * The PIO-C interface for the NetCDF function nc_get_att_short. */ -int PIOc_inq_format (int ncid, int *formatp) +int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_INQ_FORMAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_format(file->fh, formatp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_format(file->fh, formatp);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_format(file->fh, formatp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_get_att(ncid, varid, name, (void *)ip); +} - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); - return ierr; +/** + * @ingroup PIOc_get_att_int + * The PIO-C interface for the NetCDF function nc_get_att_int. + */ +int PIOc_get_att_int(int ncid, int varid, const char *name, int *ip) +{ + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_get_att_long - * The PIO-C interface for the NetCDF function nc_get_att_long. + * @ingroup PIOc_get_att_longlong + * The PIO-C interface for the NetCDF function nc_get_att_longlong. */ -int PIOc_get_att_long (int ncid, int varid, const char *name, long *ip) +int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) { return PIOc_get_att(ncid, varid, name, (void *)ip); } @@ -2396,167 +2502,61 @@ int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, } /** - * @ingroup PIOc_get_att_ubyte - * The PIO-C interface for the NetCDF function nc_get_att_ubyte. - */ -int PIOc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - -/** - * @ingroup PIOc_get_att_text - * The PIO-C interface for the NetCDF function nc_get_att_text. - */ -int PIOc_get_att_text (int ncid, int varid, const char *name, char *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - -/** - * @ingroup PIOc_del_att - * The PIO-C interface for the NetCDF function nc_del_att. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_del_att (int ncid, int varid, const char *name) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_DEL_ATT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_del_att(file->fh, varid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_del_att(file->fh, varid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_del_att(file->fh, varid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; -} - -/** - * @ingroup PIOc_get_att_schar - * The PIO-C interface for the NetCDF function nc_get_att_schar. - */ -int PIOc_get_att_schar (int ncid, int varid, const char *name, signed char *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - -/** - * @ingroup PIOc_get_att_ulonglong - * The PIO-C interface for the NetCDF function nc_get_att_ulonglong. - */ -int PIOc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *ip) -{ - return PIOc_get_att(ncid, varid, name, (void *)ip); -} - -/** - * @ingroup PIOc_get_att_short - * The PIO-C interface for the NetCDF function nc_get_att_short. + * @ingroup PIOc_put_att_uint + * The PIO-C interface for the NetCDF function nc_put_att_uint. */ -int PIOc_get_att_short (int ncid, int varid, const char *name, short *ip) +int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned int *op) { - return PIOc_get_att(ncid, varid, name, (void *)ip); + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** - * @ingroup PIOc_get_att_int - * The PIO-C interface for the NetCDF function nc_get_att_int. + * @ingroup PIOc_put_att_ubyte + * The PIO-C interface for the NetCDF function nc_put_att_ubyte. */ -int PIOc_get_att_int(int ncid, int varid, const char *name, int *ip) +int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned char *op) { - return PIOc_get_att(ncid, varid, name, (void *)ip); + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** - * @ingroup PIOc_get_att_longlong - * The PIO-C interface for the NetCDF function nc_get_att_longlong. + * @ingroup PIOc_put_att_float + * The PIO-C interface for the NetCDF function nc_put_att_float. */ -int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) +int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const float *op) { - return PIOc_get_att(ncid, varid, name, (void *)ip); + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** - * @ingroup PIOc_put_att_uint - * The PIO-C interface for the NetCDF function nc_put_att_uint. + * @ingroup PIOc_put_att_ulonglong + * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. */ -int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned int *op) +int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned long long *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** - * @ingroup PIOc_put_att_ubyte - * The PIO-C interface for the NetCDF function nc_put_att_ubyte. + * @ingroup PIOc_put_att_ushort + * The PIO-C interface for the NetCDF function nc_put_att_ushort. */ -int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned char *op) +int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const unsigned short *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** - * @ingroup PIOc_put_att_float - * The PIO-C interface for the NetCDF function nc_put_att_float. + * @ingroup PIOc_put_att_text + * The PIO-C interface for the NetCDF function nc_put_att_text. */ -int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const float *op) +int PIOc_put_att_text(int ncid, int varid, const char *name, + PIO_Offset len, const char *op) { return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } From 8938469e6b5749b3e8621cf6f4537b532a2be119 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 14:25:34 -0400 Subject: [PATCH 30/83] further async development --- src/clib/pio_nc_async.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 51bb7f7813aa..e4c4cb21c0a4 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2074,6 +2074,13 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { int msg = PIO_MSG_GET_ATT_INT; + /* Get the type and length of the attribute. */ + if ((ierr = PIOc_inq_att(file->fh, varid, name, &atttype, &attlen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); From 6e7e780a23b5739cd6481ecbafc59e51cddf19c8 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 14:26:39 -0400 Subject: [PATCH 31/83] further async development --- src/clib/pio_msg.c | 4 ++++ src/clib/pio_nc_async.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 530ea5c26930..25d106e9c3cd 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -375,6 +375,10 @@ int att_get_handler(iosystem_desc_t *ios) ios->intercomm); if ((mpierr = MPI_Bcast(&iotype, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + if ((mpierr = MPI_Bcast(&atttype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; LOG((1, "att_get_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d", ncid, varid, namelen, name, iotype)); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index e4c4cb21c0a4..dbaeb017af35 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2095,7 +2095,10 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); - LOG((2, "broadcast iotype = %d", file->iotype)); + if (!mpierr) + mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ From cd4421f3920293fe59af2dcfc283674ff639970b Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 12 May 2016 14:27:46 -0400 Subject: [PATCH 32/83] further async development --- src/clib/pio_msg.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 25d106e9c3cd..0553cd94ce9b 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -382,31 +382,6 @@ int att_get_handler(iosystem_desc_t *ios) LOG((1, "att_get_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d", ncid, varid, namelen, name, iotype)); - /* Get the length and the type of the attribute. */ - LOG((1, "att_get_handler magic iotype = %d", iotype)); - switch (iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_att(ncid, varid, name, &atttype, (size_t *)&attlen); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - ierr = nc_inq_att(ncid, varid, name, &atttype, (size_t *)&attlen); - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_att(ncid, varid, name, &atttype, &attlen); - break; -#endif - default: - ierr = iotype_error(iotype,__FILE__,__LINE__); - } - /* Allocate space for the attribute data. */ if (!(ip = malloc(attlen * sizeof(int)))) return PIO_ENOMEM; From ae43f4771a108f31804a1cb69cf9e2b371597f94 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 12:43:46 -0400 Subject: [PATCH 33/83] added PIOc_inq_type --- src/clib/pio.h | 1 + src/clib/pio_internal.h | 3 +- src/clib/pio_msg.c | 46 ++++++++++++- src/clib/pio_nc_async.c | 128 ++++++++++++++++++++++++++++++++++++ tests/unit/test_intercomm.c | 22 +++++-- 5 files changed, 192 insertions(+), 8 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 5dc08cedee2c..3b20458f2944 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -650,6 +650,7 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_set_log_level(int level); int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const void *op); int PIOc_get_att(int ncid, int varid, const char *name, void *ip); + int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep); #if defined(__cplusplus) } #endif diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index a288a15de1da..3425517818a3 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -372,7 +372,8 @@ enum PIO_MSG{ PIO_MSG_DELETE_FILE, PIO_MSG_EXIT, PIO_MSG_GET_ATT, - PIO_MSG_PUT_ATT + PIO_MSG_PUT_ATT, + PIO_MSG_INQ_TYPE }; #endif diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 0553cd94ce9b..42444ce13e2d 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -16,6 +16,45 @@ extern int my_rank; extern int pio_log_level; #endif /* PIO_ENABLE_LOGGING */ +/** This function is run on the IO tasks to find netCDF type + * length. */ +int inq_type_handler(iosystem_desc_t *ios) +{ + int ncid; + int xtype; + char name_present, size_present; + char *namep = NULL, name[NC_MAX_NAME + 1]; + PIO_Offset *sizep = NULL, size; + int mpierr; + int ret; + + LOG((1, "typelen_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&xtype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((1, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype)); + + if (name_present) + namep = name; + if (size_present) + sizep = &size; + + /* Call the function. */ + if ((ret = PIOc_inq_type(ncid, xtype, namep, sizep))) + return ret; + + LOG((1, "inq_type_handler succeeded!")); + return PIO_NOERR; +} + /** This function is run on the IO tasks to create a netCDF file. */ int create_file_handler(iosystem_desc_t *ios) { @@ -54,7 +93,7 @@ int create_file_handler(iosystem_desc_t *ios) /* Free resources. */ free(filename); - LOG((1, "create_file_handler succeeded!\n", my_rank)); + LOG((1, "create_file_handler succeeded!")); return PIO_NOERR; } @@ -387,7 +426,7 @@ int att_get_handler(iosystem_desc_t *ios) return PIO_ENOMEM; /* Call the function to read the attribute. */ - if ((ierr = PIOc_get_att_int(ncid, varid, name, ip))) + if ((ierr = PIOc_get_att(ncid, varid, name, ip))) return ierr; /* Free resources. */ @@ -917,6 +956,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) /* Handle the message. This code is run on all IO tasks. */ switch (msg) { + case PIO_MSG_INQ_TYPE: + inq_type_handler(my_iosys); + break; case PIO_MSG_CREATE_FILE: create_file_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index dbaeb017af35..b5ba8022bdc8 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -298,6 +298,134 @@ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); } +/** + * @ingroup PIOc_typelen + * The PIO-C interface for the NetCDF function nctypelen. + */ +int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) +{ + int msg = PIO_MSG_INQ_TYPE; /** Message for async notification. */ + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ + int typelen; + + LOG((1, "PIOc_inq_type ncid = %d xtype = %d", ncid, xtype)); + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + char name_present = name ? true : false; + char size_present = sizep ? true : false; + + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { + switch (file->iotype) + { +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if (!file->iosystem->io_rank) + ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + switch (xtype) + { + case NC_UBYTE: + case NC_BYTE: + case NC_CHAR: + typelen = 1; + break; + case NC_SHORT: + case NC_USHORT: + typelen = 2; + break; + case NC_UINT: + case NC_INT: + case NC_FLOAT: + typelen = 4; + break; + case NC_UINT64: + case NC_INT64: + case NC_DOUBLE: + typelen = 8; + break; + } + + if (sizep) + *sizep = typelen; + if (name) + strcpy(name, "some type"); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + + LOG((2, "PIOc_inq_type netcdf call returned %d", ierr)); + } + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + { + if (name) + { + int slen; + if (ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (sizep) + if ((mpierr = MPI_Bcast(sizep , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + return ierr; +} + /** * @ingroup PIOc_inq_format * The PIO-C interface for the NetCDF function nc_inq_format. diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index f6dbfc966c54..a538e3bdd450 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -92,7 +92,6 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) if ((ret = PIOc_openfile(iosysid, &ncid, &format, filename, NC_NOWRITE))) ERR(ret); - sleep(2); /* Find the number of dimensions, variables, and global attributes.*/ if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) @@ -137,12 +136,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (dimlen2 != DIM_LEN) ERR(ERR_WRONG); - sleep(2); if ((ret = PIOc_inq_dimid(ncid, DIM_NAME, &dimid2))) ERR(ret); if (dimid2 != 0) ERR(ERR_WRONG); - sleep(2); /* Check out the variable. */ if ((ret = PIOc_inq_var(ncid, 0, varname, &vartype, &varndims, &vardimids, &varnatts))) @@ -341,8 +338,7 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { - /*for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ - for (int fmt = 0; fmt < 1; fmt++) + for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; @@ -357,6 +353,22 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm file created ncid = %d\n", my_rank, ncid); + /* Test the inq_type function for atomic types. */ + char type_name[NC_MAX_NAME + 1]; + PIO_Offset type_size; + #define NUM_TYPES 11 + nc_type xtype[NUM_TYPES] = {NC_CHAR, NC_BYTE, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE, + NC_UBYTE, NC_USHORT, NC_UINT, NC_INT64, NC_UINT64}; + int type_len[NUM_TYPES] = {1, 1, 2, 4, 4, 8, 1, 2, 4, 8, 8}; + int max_type = format[fmt] == PIO_IOTYPE_NETCDF ? NC_DOUBLE : NC_UINT64; + for (int i = 0; i < max_type; i++) + { + if ((ret = PIOc_inq_type(ncid, xtype[i], type_name, &type_size))) + ERR(ret); + if (type_size != type_len[i]) + ERR(ERR_AWFUL); + } + /* Define a dimension. */ if (verbose) printf("%d test_intercomm defining dimension %s\n", my_rank, DIM_NAME); From 5912c2a6e39ce23f8d76ba615e3d2155acf89300 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 12:48:01 -0400 Subject: [PATCH 34/83] added PIOc_inq_type --- src/clib/pio_msg.c | 9 ++++++--- src/clib/pio_nc_async.c | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 42444ce13e2d..b14b834215a1 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -394,7 +394,7 @@ int att_get_handler(iosystem_desc_t *ios) int ierr; char *name; int namelen; - PIO_Offset attlen; + PIO_Offset attlen, typelen; nc_type atttype; int *op, *ip; int iotype; @@ -418,8 +418,11 @@ int att_get_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; - LOG((1, "att_get_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d", - ncid, varid, namelen, name, iotype)); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + LOG((1, "att_get_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d" + "atttype = %d attlen = %d typelen = %d", + ncid, varid, namelen, name, iotype, atttype, attlen, typelen)); /* Allocate space for the attribute data. */ if (!(ip = malloc(attlen * sizeof(int)))) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b5ba8022bdc8..7dbce2660c9e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2179,7 +2179,7 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { iosystem_desc_t *ios; file_desc_t *file; - PIO_Offset attlen; + PIO_Offset attlen, typelen; nc_type atttype; int ierr = PIO_NOERR; int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ @@ -2209,9 +2209,18 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) return ierr; } + /* Get the length (in bytes) of the type. */ + if ((ierr = PIOc_inq_type(file->fh, atttype, NULL, &typelen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + + /* Send the message to IO master. */ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - + + /* Send the function parameters. */ if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -2227,6 +2236,8 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ From fed2d0f2fa7e478f4bc60fde23628708613c59b7 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 12:58:16 -0400 Subject: [PATCH 35/83] further development of async get_att --- src/clib/pio_msg.c | 2 +- src/clib/pio_nc_async.c | 43 +++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index b14b834215a1..df51c1149e7c 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -425,7 +425,7 @@ int att_get_handler(iosystem_desc_t *ios) ncid, varid, namelen, name, iotype, atttype, attlen, typelen)); /* Allocate space for the attribute data. */ - if (!(ip = malloc(attlen * sizeof(int)))) + if (!(ip = malloc(attlen * typelen))) return PIO_ENOMEM; /* Call the function to read the attribute. */ diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 7dbce2660c9e..4dfab6de19d5 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2195,27 +2195,34 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) return PIO_EBADID; ios = file->iosystem; - /* If async is in use, and this is not an IO task, bcast the parameters. */ + /* Run these on all tasks if async is not in use, but only on + * non-IO tasks if async is in use. */ + if (!ios->async_interface || !ios->ioproc) + { + /* Get the type and length of the attribute. */ + if ((ierr = PIOc_inq_att(file->fh, varid, name, &atttype, &attlen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + + /* Get the length (in bytes) of the type. */ + if ((ierr = PIOc_inq_type(file->fh, atttype, NULL, &typelen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + } + + + /* If async is in use, and this is not an IO task, bcast the + * parameters and the attribute and type information we fetched. */ if (ios->async_interface) { if (!ios->ioproc) { int msg = PIO_MSG_GET_ATT_INT; - /* Get the type and length of the attribute. */ - if ((ierr = PIOc_inq_att(file->fh, varid, name, &atttype, &attlen))) - { - check_netcdf(file, ierr, __FILE__, __LINE__); - return ierr; - } - - /* Get the length (in bytes) of the type. */ - if ((ierr = PIOc_inq_type(file->fh, atttype, NULL, &typelen))) - { - check_netcdf(file, ierr, __FILE__, __LINE__); - return ierr; - } - /* Send the message to IO master. */ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -2244,6 +2251,12 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); + + /* Broadcast values. */ + if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ From f5b581a6abb54c00121079e708fd8c7fcd793c83 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 13:13:26 -0400 Subject: [PATCH 36/83] now get_att generalized by type --- src/clib/pio_nc_async.c | 30 +++++++++++++----------------- tests/unit/test_intercomm.c | 3 ++- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 4dfab6de19d5..51e7bb25c2cf 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2252,11 +2252,13 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); - /* Broadcast values. */ - if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Broadcast values currently only known on computation tasks to IO tasks. */ + LOG((2, "PIOc_get_att bcast from comproot = %d attlen = %d typelen = %d", ios->comproot, attlen, typelen)); + if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + LOG((2, "PIOc_get_att bcast complete attlen = %d typelen = %d", attlen, typelen)); } /* If this is an IO task, then call the netCDF function. */ @@ -2268,25 +2270,17 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_get_att(file->fh, varid, name, ip); - if (!ierr) - ierr = nc_inq_att(file->fh, varid, name, &atttype, (size_t *)&attlen); break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if (ios->io_rank == 0) - { ierr = nc_get_att(file->fh, varid, name, ip); - if (!ierr) - ierr = nc_inq_att(file->fh, varid, name, &atttype, (size_t *)&attlen); - } break; #endif #ifdef _PNETCDF case PIO_IOTYPE_PNETCDF: ierr = ncmpi_get_att(file->fh, varid, name, ip); - if (!ierr) - ierr = ncmpi_inq_att(file->fh, varid, name, &atttype, &attlen); break; #endif default: @@ -2303,11 +2297,13 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* Broadcast results to all tasks. */ if (!ierr) { - LOG((2, "PIOc_get_att broadcasting attlen = %d", attlen)); - mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->ioroot, ios->my_comm); - LOG((2, "PIOc_get_att done broadcasting attlen = %d", attlen)); LOG((2, "PIOc_get_att broadcasting att data")); - mpierr = MPI_Bcast(ip, (int)attlen, MPI_INT, ios->ioroot, ios->my_comm); + if ((mpierr = MPI_Bcast(ip, (int)attlen * typelen, MPI_BYTE, ios->ioroot, + ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } LOG((2, "PIOc_get_att done broadcasting att data")); } return ierr; diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index a538e3bdd450..fdf85df00941 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -338,7 +338,8 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { - for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) +/* for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ + for (int fmt = 0; fmt < 1; fmt++) { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; From 1c351820a6314a90ec957c210e48e7de0d066d24 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 13:21:33 -0400 Subject: [PATCH 37/83] now get_att generalized by type --- tests/unit/test_intercomm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index fdf85df00941..6d57d58bb5d3 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -338,8 +338,8 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { -/* for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ - for (int fmt = 0; fmt < 1; fmt++) + for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) +/* for (int fmt = 0; fmt < 1; fmt++) */ { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; From e6675619f1513b178bba86fa75378d0f2923f938 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 13:22:38 -0400 Subject: [PATCH 38/83] now get_att generalized by type --- tests/unit/test_intercomm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 6d57d58bb5d3..bf50759815ae 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -338,8 +338,8 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { - for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) -/* for (int fmt = 0; fmt < 1; fmt++) */ +/* for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ + for (int fmt = 0; fmt < 1; fmt++) { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; @@ -386,6 +386,9 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME); int att_data = ATT_VALUE; + short short_att_data = ATT_VALUE; + if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &short_att_data))) + ERR(ret); if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); From 06b279e09da4daa12a29079cfc258b7648151d96 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 18:02:12 -0400 Subject: [PATCH 39/83] got put_att working with async --- src/clib/pio_msg.c | 73 ++++++++++++++++++++----------------- src/clib/pio_nc_async.c | 27 ++++++++++++-- tests/unit/test_intercomm.c | 8 ++-- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index df51c1149e7c..b73a6da02b31 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -336,46 +336,53 @@ int inq_att_handler(iosystem_desc_t *ios) * @param msg the message sent my the comp root task. * @return PIO_NOERR for success, error code otherwise. */ -int att_handler(iosystem_desc_t *ios, int msg) +int att_put_handler(iosystem_desc_t *ios) { int ncid; int varid; int mpierr; - int ret; - char *name5; + int ierr; + char *name; int namelen; - PIO_Offset attlen; + PIO_Offset attlen, typelen; nc_type atttype; int *op, *ip; + int iotype; - LOG((1, "att_handler msg = %d", msg)); - - if (msg == PIO_MSG_PUT_ATT_INT) - { - /* Get the parameters for this function that the the comp master - * task is broadcasting. */ - if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) - return PIO_EIO; - if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) - return PIO_EIO; - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!(name5 = malloc((namelen + 1) * sizeof(char)))) - return PIO_ENOMEM; - mpierr = MPI_Bcast((void *)name5, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - if (!(op = malloc(attlen * sizeof(int)))) - return PIO_ENOMEM; - mpierr = MPI_Bcast(op, attlen, MPI_INT, ios->compmaster, ios->intercomm); + LOG((1, "att_put_handler")); - /* Call the function to write the attribute. */ - if ((ret = PIOc_put_att_int(ncid, varid, name5, atttype, attlen, op))) - return ret; + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, + ios->intercomm); + if ((mpierr = MPI_Bcast(&atttype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if (!(op = malloc(attlen * typelen))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)op, attlen * typelen, MPI_BYTE, 0, ios->intercomm))) + return PIO_EIO; + LOG((1, "att_put_handler ncid = %d varid = %d namelen = %d name = %s iotype = %d" + "atttype = %d attlen = %d typelen = %d", + ncid, varid, namelen, name, iotype, atttype, attlen, typelen)); - /* Free resources. */ - free(name5); - free(op); - } + /* Call the function to read the attribute. */ + if ((ierr = PIOc_put_att(ncid, varid, name, atttype, attlen, op))) + return ierr; + + /* Free resources. */ + free(name); + free(op); return PIO_NOERR; } @@ -998,11 +1005,11 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_INQ_VAR: inq_var_handler(my_iosys); break; - case PIO_MSG_GET_ATT_INT: + case PIO_MSG_GET_ATT: ret = att_get_handler(my_iosys); break; - case PIO_MSG_PUT_ATT_INT: - ret = att_handler(my_iosys, msg); + case PIO_MSG_PUT_ATT: + ret = att_put_handler(my_iosys); break; case PIO_MSG_INQ_VARID: inq_varid_handler(my_iosys); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 51e7bb25c2cf..b755e331fc00 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2221,7 +2221,7 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { if (!ios->ioproc) { - int msg = PIO_MSG_GET_ATT_INT; + int msg = PIO_MSG_GET_ATT; /* Send the message to IO master. */ if(ios->compmaster) @@ -2328,16 +2328,29 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ + PIO_Offset typelen; /** Length (in bytes) of the type. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); + LOG((1, "PIOc_put_att ncid = %d varid = %d name = %s", ncid, varid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; + /* Run these on all tasks if async is not in use, but only on + * non-IO tasks if async is in use. */ + if (!ios->async_interface || !ios->ioproc) + { + /* Get the length (in bytes) of the type. */ + if ((ierr = PIOc_inq_type(file->fh, xtype, NULL, &typelen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + } + /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -2362,13 +2375,21 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, if (!mpierr) mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) - mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)op, len * typelen, MPI_BYTE, ios->compmaster, + ios->intercomm); } /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); + + /* Broadcast values currently only known on computation tasks to IO tasks. */ + LOG((2, "PIOc_put_att bcast from comproot = %d typelen = %d", ios->comproot, typelen)); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index bf50759815ae..c0d7c93c6bec 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -387,8 +387,10 @@ main(int argc, char **argv) printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME); int att_data = ATT_VALUE; short short_att_data = ATT_VALUE; + sleep(2); if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &short_att_data))) ERR(ret); + sleep(2); if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); @@ -413,9 +415,9 @@ main(int argc, char **argv) if ((ret = PIOc_closefile(ncid))) ERR(ret); - /* Check the file for correctness. */ - if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) - ERR(ret); + /* /\* Check the file for correctness. *\/ */ + /* if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) */ + /* ERR(ret); */ /* Now delete the file. */ /* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */ From 99632fd170033056eb337db3ea3003dd0cfacdfb Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 18:37:11 -0400 Subject: [PATCH 40/83] further development of async code --- src/clib/pio_msg.c | 6 ++- src/clib/pio_nc_async.c | 74 +++---------------------------------- tests/unit/test_intercomm.c | 27 +++++++++----- 3 files changed, 28 insertions(+), 79 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index b73a6da02b31..ab4232f68d3b 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -28,7 +28,7 @@ int inq_type_handler(iosystem_desc_t *ios) int mpierr; int ret; - LOG((1, "typelen_handler")); + LOG((1, "inq_type_handler")); /* Get the parameters for this function that the the comp master * task is broadcasting. */ @@ -40,7 +40,7 @@ int inq_type_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - LOG((1, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype)); + LOG((2, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype)); if (name_present) namep = name; @@ -51,6 +51,8 @@ int inq_type_handler(iosystem_desc_t *ios) if ((ret = PIOc_inq_type(ncid, xtype, namep, sizep))) return ret; + if (sizep) + LOG((2, "inq_type_handler size = %d", *sizep)); LOG((1, "inq_type_handler succeeded!")); return PIO_NOERR; } diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b755e331fc00..7977726a09b6 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -402,7 +402,7 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -2344,11 +2344,12 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, if (!ios->async_interface || !ios->ioproc) { /* Get the length (in bytes) of the type. */ - if ((ierr = PIOc_inq_type(file->fh, xtype, NULL, &typelen))) + if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen))) { check_netcdf(file, ierr, __FILE__, __LINE__); return ierr; } + LOG((2, "PIOc_put_att typelen = %d", ncid, typelen)); } /* If async is in use, and this is not an IO task, bcast the parameters. */ @@ -2379,6 +2380,8 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, if (!mpierr) mpierr = MPI_Bcast((void *)op, len * typelen, MPI_BYTE, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_put_att finished bcast ncid = %d varid = %d namelen = %d name = %s " + "len = %d typelen = %d", file->fh, varid, namelen, name, len, typelen)); } /* Handle MPI errors. */ @@ -2592,72 +2595,7 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - size_t namelen; - - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_inq_varid ncid = %d name = %s\n", my_rank, ncid, name); - - errstr = NULL; - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_ATT_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)op, len, MPI_INT, ios->compmaster, ios->intercomm); - } - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att_int(file->fh, varid, name, xtype, (size_t)len, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_put_att_int(file->fh, varid, name, xtype, len, op);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); - return ierr; + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index c0d7c93c6bec..3e4f937fcbac 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -30,6 +30,7 @@ /** The name of the global attribute in the netCDF output file. */ #define ATT_NAME "gatt_test_intercomm" +#define SHORT_ATT_NAME "short_gatt_test_intercomm" /** The value of the global attribute in the netCDF output file. */ #define ATT_VALUE 42 @@ -85,6 +86,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) int varndims2, vardimids2, varnatts2; int varid2; int att_data; + short short_att_data; /* Re-open the file to check it. */ if (verbose) @@ -96,7 +98,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Find the number of dimensions, variables, and global attributes.*/ if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) ERR(ret); - if (ndims != 1 || nvars != 1 || ngatts != 1 || unlimdimid != -1) + if (ndims != 1 || nvars != 1 || ngatts != 2 || unlimdimid != -1) ERR(ERR_WRONG); /* This should return PIO_NOERR. */ @@ -114,7 +116,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ERR_WRONG); if ((ret = PIOc_inq_natts(ncid, &ngatts2))) ERR(ret); - if (ngatts2 != 1) + if (ngatts2 != 2) ERR(ERR_WRONG); if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) ERR(ret); @@ -191,6 +193,15 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) printf("%d test_intercomm att_data = %d\n", my_rank, att_data); if (att_data != ATT_VALUE) ERR(ERR_WRONG); + if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, SHORT_ATT_NAME, &atttype, &attlen))) + ERR(ret); + if (atttype != NC_SHORT || attlen != 1) + ERR(ERR_WRONG); + if ((ret = PIOc_get_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, &short_att_data))) + ERR(ret); + if (short_att_data != ATT_VALUE) + ERR(ERR_WRONG); + /* Close the file. */ if (verbose) @@ -387,12 +398,10 @@ main(int argc, char **argv) printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME); int att_data = ATT_VALUE; short short_att_data = ATT_VALUE; - sleep(2); - if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &short_att_data))) - ERR(ret); - sleep(2); if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); + if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) + ERR(ret); /* End define mode. */ if (verbose) @@ -415,9 +424,9 @@ main(int argc, char **argv) if ((ret = PIOc_closefile(ncid))) ERR(ret); - /* /\* Check the file for correctness. *\/ */ - /* if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) */ - /* ERR(ret); */ + /* Check the file for correctness. */ + if ((ret = check_file(iosysid, format[fmt], filename[fmt], my_rank, verbose))) + ERR(ret); /* Now delete the file. */ /* if ((ret = PIOc_deletefile(iosysid, filename[fmt]))) */ From 4866ec14ec1780a996b6f47ed724a4b640d3023b Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 18:50:25 -0400 Subject: [PATCH 41/83] further development of async code --- src/clib/pio_nc_async.c | 10 +++++----- tests/unit/test_intercomm.c | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 7977726a09b6..25e642a29c6b 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2605,7 +2605,7 @@ int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2615,7 +2615,7 @@ int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const long long *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2625,7 +2625,7 @@ int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned int *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2635,7 +2635,7 @@ int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const unsigned char *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** @@ -2645,7 +2645,7 @@ int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, PIO_Offset len, const float *op) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_put_att(ncid, varid, name, xtype, len, op); } /** diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 3e4f937fcbac..108aa4929a5b 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -31,6 +31,8 @@ /** The name of the global attribute in the netCDF output file. */ #define ATT_NAME "gatt_test_intercomm" #define SHORT_ATT_NAME "short_gatt_test_intercomm" +#define FLOAT_ATT_NAME "float_gatt_test_intercomm" +#define DOUBLE_ATT_NAME "double_gatt_test_intercomm" /** The value of the global attribute in the netCDF output file. */ #define ATT_VALUE 42 @@ -87,6 +89,8 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) int varid2; int att_data; short short_att_data; + float float_att_data; + double double_att_data; /* Re-open the file to check it. */ if (verbose) @@ -98,7 +102,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Find the number of dimensions, variables, and global attributes.*/ if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) ERR(ret); - if (ndims != 1 || nvars != 1 || ngatts != 2 || unlimdimid != -1) + if (ndims != 1 || nvars != 1 || ngatts != 4 || unlimdimid != -1) ERR(ERR_WRONG); /* This should return PIO_NOERR. */ @@ -116,7 +120,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ERR_WRONG); if ((ret = PIOc_inq_natts(ncid, &ngatts2))) ERR(ret); - if (ngatts2 != 2) + if (ngatts2 != 4) ERR(ERR_WRONG); if ((ret = PIOc_inq_unlimdim(ncid, &unlimdimid2))) ERR(ret); @@ -201,6 +205,14 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (short_att_data != ATT_VALUE) ERR(ERR_WRONG); + if ((ret = PIOc_get_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, &float_att_data))) + ERR(ret); + if (float_att_data != ATT_VALUE) + ERR(ERR_WRONG); + if ((ret = PIOc_get_att_double(ncid, NC_GLOBAL, DOUBLE_ATT_NAME, &double_att_data))) + ERR(ret); + if (double_att_data != ATT_VALUE) + ERR(ERR_WRONG); /* Close the file. */ @@ -398,10 +410,16 @@ main(int argc, char **argv) printf("%d test_intercomm writing attributes %s\n", my_rank, ATT_NAME); int att_data = ATT_VALUE; short short_att_data = ATT_VALUE; + float float_att_data = ATT_VALUE; + double double_att_data = ATT_VALUE; if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) ERR(ret); + if ((ret = PIOc_put_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, NC_FLOAT, 1, &float_att_data))) + ERR(ret); + if ((ret = PIOc_put_att_double(ncid, NC_GLOBAL, DOUBLE_ATT_NAME, NC_DOUBLE, 1, &double_att_data))) + ERR(ret); /* End define mode. */ if (verbose) From 9020e2d167b178b6bfc88a077ed5cb6adf81bb14 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 13 May 2016 19:12:23 -0400 Subject: [PATCH 42/83] moved logging code to pioc_support --- src/clib/pio_nc_async.c | 71 ---------------------------------------- src/clib/pioc_support.c | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 71 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 25e642a29c6b..41f36a5742ca 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -16,80 +16,9 @@ */ #include -#ifdef PIO_ENABLE_LOGGING -#include -#include -#endif /* PIO_ENABLE_LOGGING */ #include #include -#ifdef PIO_ENABLE_LOGGING -int pio_log_level = 0; -int my_rank; -#endif /* PIO_ENABLE_LOGGING */ - -/** Set the logging level. Set to -1 for nothing, 0 for errors only, 1 - * for important logging, and so on. Log levels below 1 are only - * printed on the io/component root. If the library is not built with - * logging, this function does nothing. */ -int PIOc_set_log_level(int level) -{ -#ifdef PIO_ENABLE_LOGGING - printf("setting log level to %d\n", level); - pio_log_level = level; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - return PIO_NOERR; -#endif /* PIO_ENABLE_LOGGING */ -} - -#ifdef PIO_ENABLE_LOGGING -/** This function prints out a message, if the severity of the message - is lower than the global pio_log_level. To use it, do something - like this: - - pio_log(0, "this computer will explode in %d seconds", i); - - After the first arg (the severity), use the rest like a normal - printf statement. Output will appear on stdout. - This function is heavily based on the function in section 15.5 of - the C FAQ. -*/ -void -pio_log(int severity, const char *fmt, ...) -{ - va_list argp; - int t; - - /* If the severity is greater than the log level, we don't print - this message. */ - if (severity > pio_log_level) - return; - - /* If the severity is 0, only print on rank 0. */ - if (severity < 1 && my_rank != 0) - return; - - /* If the severity is zero, this is an error. Otherwise insert that - many tabs before the message. */ - if (!severity) - fprintf(stdout, "ERROR: "); - for (t = 0; t < severity; t++) - fprintf(stdout, "\t"); - - /* Show the rank. */ - fprintf(stdout, "%d ", my_rank); - - /* Print out the variable list of args with vprintf. */ - va_start(argp, fmt); - vfprintf(stdout, fmt, argp); - va_end(argp); - - /* Put on a final linefeed. */ - fprintf(stdout, "\n"); - fflush(stdout); -} -#endif /* PIO_ENABLE_LOGGING */ - /** * @ingroup PIOc_inq * The PIO-C interface for the NetCDF function nc_inq. diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index bd16fa0aff5c..579a9e64fc6f 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -1,12 +1,84 @@ /** @file * Support functions. */ +#include +#ifdef PIO_ENABLE_LOGGING +#include +#include +#endif /* PIO_ENABLE_LOGGING */ #include #include #include #define versno 2001 +#ifdef PIO_ENABLE_LOGGING +int pio_log_level = 0; +int my_rank; +#endif /* PIO_ENABLE_LOGGING */ + +/** Set the logging level. Set to -1 for nothing, 0 for errors only, 1 + * for important logging, and so on. Log levels below 1 are only + * printed on the io/component root. If the library is not built with + * logging, this function does nothing. */ +int PIOc_set_log_level(int level) +{ +#ifdef PIO_ENABLE_LOGGING + printf("setting log level to %d\n", level); + pio_log_level = level; + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + return PIO_NOERR; +#endif /* PIO_ENABLE_LOGGING */ +} + +#ifdef PIO_ENABLE_LOGGING +/** This function prints out a message, if the severity of the message + is lower than the global pio_log_level. To use it, do something + like this: + + pio_log(0, "this computer will explode in %d seconds", i); + + After the first arg (the severity), use the rest like a normal + printf statement. Output will appear on stdout. + This function is heavily based on the function in section 15.5 of + the C FAQ. +*/ +void +pio_log(int severity, const char *fmt, ...) +{ + va_list argp; + int t; + + /* If the severity is greater than the log level, we don't print + this message. */ + if (severity > pio_log_level) + return; + + /* If the severity is 0, only print on rank 0. */ + if (severity < 1 && my_rank != 0) + return; + + /* If the severity is zero, this is an error. Otherwise insert that + many tabs before the message. */ + if (!severity) + fprintf(stdout, "ERROR: "); + for (t = 0; t < severity; t++) + fprintf(stdout, "\t"); + + /* Show the rank. */ + fprintf(stdout, "%d ", my_rank); + + /* Print out the variable list of args with vprintf. */ + va_start(argp, fmt); + vfprintf(stdout, fmt, argp); + va_end(argp); + + /* Put on a final linefeed. */ + fprintf(stdout, "\n"); + fflush(stdout); +} +#endif /* PIO_ENABLE_LOGGING */ + static pio_swapm_defaults swapm_defaults; bool PIO_Save_Decomps=false; /** From 0337dbec63b11eb89732872a0d9e087a46340daf Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 06:18:20 -0400 Subject: [PATCH 43/83] cleaning up call to netcdf layer in PIOc_nc_async --- src/clib/pio.h | 4 ++ src/clib/pio_file.c | 61 ++++++++++++----- src/clib/pio_nc_async.c | 129 +++++++++++++----------------------- src/clib/pioc.c | 12 ++-- tests/unit/test_intercomm.c | 4 +- 5 files changed, 101 insertions(+), 109 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 3b20458f2944..596e10c0e29c 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -259,6 +259,10 @@ typedef struct file_desc_t int mode; struct wmulti_buffer buffer; struct file_desc_t *next; + + /** True if this task should participate in IO (only true for one + * task with netcdf serial files. */ + int do_io; } file_desc_t; /** diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index b68ce0237680..03cce3e9c255 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -65,6 +65,14 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, file->buffer.frame=NULL; file->buffer.fillvalue=NULL; + /** Set to true if this task should participate in IO (only true for + * one task with netcdf serial files. */ + if (file->iotype == PIO_IOTYPE_NETCDF4P || file->iotype == PIO_IOTYPE_PNETCDF || + ios->io_rank == 0) + file->do_io = 1; + else + file->do_io = 0; + /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -75,13 +83,13 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, len = strlen(filename); if (!mpierr) - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr) - mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) - mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ @@ -193,7 +201,7 @@ int PIOc_openfile(const int iosysid, int *ncidp, int *iotype, ** @param mode : The netcdf mode for the open operation */ -int PIOc_createfile(const int iosysid, int *ncidp, int *iotype, +int PIOc_createfile(const int iosysid, int *ncidp, int *iotype, const char filename[], const int mode) { int ierr; @@ -235,18 +243,37 @@ int PIOc_createfile(const int iosysid, int *ncidp, int *iotype, msg = PIO_MSG_CREATE_FILE; file->mode = mode; + /** Set to true if this task should participate in IO (only true for + * one task with netcdf serial files. */ + if (file->iotype == PIO_IOTYPE_NETCDF4P || file->iotype == PIO_IOTYPE_PNETCDF || + ios->io_rank == 0) + file->do_io = 1; + else + file->do_io = 0; - if(ios->async_interface && ! ios->ioproc){ - if(ios->comp_rank==0) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - len = strlen(filename); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + if(ios->comp_rank==0) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + len = strlen(filename); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->compmaster, ios->intercomm); + } + /* Handle MPI errors. */ + mpierr = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -288,9 +315,9 @@ int PIOc_createfile(const int iosysid, int *ncidp, int *iotype, ierr = check_netcdf(file, ierr, __FILE__,__LINE__); if(ierr == PIO_NOERR){ - mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->ioroot, ios->union_comm); + mpierr = MPI_Bcast(&file->mode, 1, MPI_INT, ios->ioroot, ios->union_comm); file->mode = file->mode | PIO_WRITE; // This flag is implied by netcdf create functions but we need to know if its set - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->ioroot, ios->union_comm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->ioroot, ios->union_comm); *ncidp = file->fh; pio_add_to_file_list(file); *ncidp = file->fh; @@ -403,7 +430,7 @@ int PIOc_deletefile(const int iosysid, const char filename[]) if(ios->comp_rank==0) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); len = strlen(filename); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); mpierr = MPI_Bcast((void *)filename, len + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } // The barriers are needed to assure that no task is trying to operate on the file while it is being deleted. diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 41f36a5742ca..338cfef612f2 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -38,7 +38,6 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp) { - int msg = PIO_MSG_INQ; /** Message for async notification. */ iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ @@ -56,6 +55,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, { if (!ios->ioproc) { + int msg = PIO_MSG_INQ; /** Message for async notification. */ char ndims_present = ndimsp ? true : false; char nvars_present = nvarsp ? true : false; char ngatts_present = ngattsp ? true : false; @@ -86,43 +86,29 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (!file->iosystem->io_rank) - { - /* Should not be necessary to do this - nc_inq should - * handle null pointers. This has been reported as a bug - * to netCDF developers. */ - int tmp_ndims, tmp_nvars, tmp_ngatts, tmp_unlimdimid; - ierr = nc_inq(ncid, &tmp_ndims, &tmp_nvars, &tmp_ngatts, &tmp_unlimdimid); - if (ndimsp) - *ndimsp = tmp_ndims; - if (nvarsp) - *nvarsp = tmp_nvars; - if (ngattsp) - *ngattsp = tmp_ngatts; - if (unlimdimidp) - *unlimdimidp = tmp_unlimdimid; - } - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype == PIO_IOTYPE_NETCDF && file->do_io) + { + /* Should not be necessary to do this - nc_inq should + * handle null pointers. This has been reported as a bug + * to netCDF developers. */ + int tmp_ndims, tmp_nvars, tmp_ngatts, tmp_unlimdimid; + ierr = nc_inq(ncid, &tmp_ndims, &tmp_nvars, &tmp_ngatts, &tmp_unlimdimid); + if (ndimsp) + *ndimsp = tmp_ndims; + if (nvarsp) + *nvarsp = tmp_nvars; + if (ngattsp) + *ngattsp = tmp_ngatts; + if (unlimdimidp) + *unlimdimidp = tmp_unlimdimid; + } else if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); +#endif /* _NETCDF */ LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } @@ -274,25 +260,13 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) check_mpi(file, mpierr, __FILE__, __LINE__); } + /* If this is an IO task, then call the netCDF function. */ /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (!file->iosystem->io_rank) - ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) + { switch (xtype) { case NC_UBYTE: @@ -320,12 +294,12 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) *sizep = typelen; if (name) strcpy(name, "some type"); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - + } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); +#endif /* _NETCDF */ LOG((2, "PIOc_inq_type netcdf call returned %d", ierr)); } @@ -445,9 +419,9 @@ int PIOc_inq_format (int ncid, int *formatp) */ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) { - iosystem_desc_t *ios; - file_desc_t *file; - int ierr = PIO_NOERR; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq_dim")); @@ -487,30 +461,17 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) check_mpi(file, mpierr, __FILE__, __LINE__); } - /* Make the call to the netCDF layer. */ - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0){ - ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; - } - break; -#endif + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ diff --git a/src/clib/pioc.c b/src/clib/pioc.c index afe7e85d9819..612d99bde7ca 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -350,10 +350,9 @@ int PIOc_InitDecomp_bc(const int iosysid, const int basetype,const int ndims, co ** @param rearr the rearranger to use by default, this may be overriden in the @ref PIO_initdecomp ** @param iosysidp index of the defined system descriptor */ - -int PIOc_Init_Intracomm(const MPI_Comm comp_comm, - const int num_iotasks, const int stride, - const int base,const int rearr, int *iosysidp) +int PIOc_Init_Intracomm(const MPI_Comm comp_comm, const int num_iotasks, + const int stride, const int base, const int rearr, + int *iosysidp) { iosystem_desc_t *iosys; int ierr = PIO_NOERR; @@ -437,10 +436,11 @@ int PIOc_Init_Intracomm(const MPI_Comm comp_comm, &(iosys->iogroup)),__FILE__,__LINE__); /* Create an MPI communicator for the IO tasks. */ - CheckMPIReturn(MPI_Comm_create(iosys->comp_comm, iosys->iogroup, &(iosys->io_comm)),__FILE__,__LINE__); + CheckMPIReturn(MPI_Comm_create(iosys->comp_comm, iosys->iogroup, &(iosys->io_comm)) + ,__FILE__,__LINE__); /* For the tasks that are doing IO, get their rank. */ - if(iosys->ioproc) + if (iosys->ioproc) CheckMPIReturn(MPI_Comm_rank(iosys->io_comm, &(iosys->io_rank)),__FILE__,__LINE__); else iosys->io_rank = -1; diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 108aa4929a5b..18f3f3238ab9 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -361,8 +361,8 @@ main(int argc, char **argv) * and when the do, they should go straight to finalize. */ if (comp_task) { -/* for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) */ - for (int fmt = 0; fmt < 1; fmt++) + for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) +/* for (int fmt = 0; fmt < 1; fmt++) */ { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; From ddaa30a8049a3e89bb643b8a2023e2eb5d0d80ab Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 06:30:01 -0400 Subject: [PATCH 44/83] cleaning up call to netcdf layer in PIOc_nc_async --- src/clib/pio_nc_async.c | 305 +++++++++------------------------------- 1 file changed, 63 insertions(+), 242 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 338cfef612f2..da6bd4a872c0 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -143,15 +143,6 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /** * @ingroup PIOc_inq_ndims * The PIO-C interface for the NetCDF function nc_inq_ndims. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_ndims (int ncid, int *ndimsp) { @@ -162,15 +153,6 @@ int PIOc_inq_ndims (int ncid, int *ndimsp) /** * @ingroup PIOc_inq_nvars * The PIO-C interface for the NetCDF function nc_inq_nvars. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_nvars(int ncid, int *nvarsp) { @@ -180,15 +162,6 @@ int PIOc_inq_nvars(int ncid, int *nvarsp) /** * @ingroup PIOc_inq_natts * The PIO-C interface for the NetCDF function nc_inq_natts. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_natts(int ncid, int *ngattsp) { @@ -198,15 +171,6 @@ int PIOc_inq_natts(int ncid, int *ngattsp) /** * @ingroup PIOc_inq_unlimdim * The PIO-C interface for the NetCDF function nc_inq_unlimdim. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) { @@ -332,16 +296,6 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /** * @ingroup PIOc_inq_format * The PIO-C interface for the NetCDF function nc_inq_format. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param formatp a pointer that will get the file format - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_format (int ncid, int *formatp) { @@ -504,15 +458,6 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) /** * @ingroup PIOc_inq_dimname * The PIO-C interface for the NetCDF function nc_inq_dimname. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_dimname(int ncid, int dimid, char *name) { @@ -522,16 +467,6 @@ int PIOc_inq_dimname(int ncid, int dimid, char *name) /** * @ingroup PIOc_inq_dimlen * The PIO-C interface for the NetCDF function nc_inq_dimlen. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__dimensions.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param lenp a pointer that will get the number of values - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_dimlen(int ncid, int dimid, PIO_Offset *lenp) { @@ -601,28 +536,14 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* IO tasks call the netCDF functions. */ if (ios->ioproc) { - switch(file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_dimid(file->fh, name, idp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - ierr = nc_inq_dimid(file->fh, name, idp);; - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_inq_dimid(file->fh, name, idp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_dimid(file->fh, name, idp);; +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ @@ -714,33 +635,20 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /* Call the netCDF layer. */ if (ios->ioproc) { - switch(file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varndims(file->fh, varid, &ndims); - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - { - ierr = nc_inq_varndims(file->fh, varid, &ndims); - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; - } - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) + { ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + { + ierr = nc_inq_varndims(file->fh, varid, &ndims); + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); + } +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ @@ -789,16 +697,6 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /** * @ingroup PIOc_inq_varname * The PIO-C interface for the NetCDF function nc_inq_varname. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_varname (int ncid, int varid, char *name) { @@ -808,17 +706,6 @@ int PIOc_inq_varname (int ncid, int varid, char *name) /** * @ingroup PIOc_inq_vartype * The PIO-C interface for the NetCDF function nc_inq_vartype. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) { @@ -828,16 +715,6 @@ int PIOc_inq_vartype (int ncid, int varid, nc_type *xtypep) /** * @ingroup PIOc_inq_varndims * The PIO-C interface for the NetCDF function nc_inq_varndims. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) { @@ -847,16 +724,6 @@ int PIOc_inq_varndims (int ncid, int varid, int *ndimsp) /** * @ingroup PIOc_inq_vardimid * The PIO-C interface for the NetCDF function nc_inq_vardimid. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_vardimid(int ncid, int varid, int *dimidsp) { @@ -866,17 +733,6 @@ int PIOc_inq_vardimid(int ncid, int varid, int *dimidsp) /** * @ingroup PIOc_inq_varnatts * The PIO-C interface for the NetCDF function nc_inq_varnatts. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__variables.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param nattsp a pointer that will get the number of attributes - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) { @@ -944,28 +800,14 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_varid(file->fh, name, varidp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_varid(file->fh, name, varidp);; - } - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_varid(file->fh, name, varidp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_varid(file->fh, name, varidp);; +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_varid(file->fh, name, varidp); +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ @@ -1084,17 +926,6 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, /** * @ingroup PIOc_inq_attlen * The PIO-C interface for the NetCDF function nc_inq_attlen. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param lenp a pointer that will get the number of values - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) { @@ -1104,17 +935,6 @@ int PIOc_inq_attlen (int ncid, int varid, const char *name, PIO_Offset *lenp) /** * @ingroup PIOc_inq_atttype * The PIO-C interface for the NetCDF function nc_inq_atttype. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @param varid the variable ID. - * @param xtypep a pointer that will get the type of the attribute. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) { @@ -2321,16 +2141,6 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, return ierr; } -/** - * @ingroup PIOc_put_att_short - * The PIO-C interface for the NetCDF function nc_put_att_short. - */ -int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const short *op) -{ - return PIOc_put_att(ncid, varid, name, xtype, len, op); -} - /** * @ingroup PIOc_get_att_double * The PIO-C interface for the NetCDF function nc_get_att_double. @@ -2340,16 +2150,6 @@ int PIOc_get_att_double(int ncid, int varid, const char *name, double *ip) return PIOc_get_att(ncid, varid, name, (void *)ip); } -/** - * @ingroup PIOc_put_att_double - * The PIO-C interface for the NetCDF function nc_put_att_double. - */ -int PIOc_put_att_double(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const double *op) -{ - return PIOc_put_att(ncid, varid, name, xtype, len, op); -} - /** * @ingroup PIOc_get_att_uchar * The PIO-C interface for the NetCDF function nc_get_att_uchar. @@ -2359,16 +2159,6 @@ int PIOc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *ip return PIOc_get_att(ncid, varid, name, (void *)ip); } -/** - * @ingroup PIOc_put_att_schar - * The PIO-C interface for the NetCDF function nc_put_att_schar. - */ -int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const signed char *op) -{ - return PIOc_put_att(ncid, varid, name, xtype, len, op); -} - /** * @ingroup PIOc_get_att_ushort * The PIO-C interface for the NetCDF function nc_get_att_ushort. @@ -2460,22 +2250,32 @@ int PIOc_get_att_longlong(int ncid, int varid, const char *name, long long *ip) } /** - * @ingroup PIOc_put_att_long - * The PIO-C interface for the NetCDF function nc_put_att_long. + * @ingroup PIOc_get_att_float + * The PIO-C interface for the NetCDF function nc_get_att_float. */ -int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const long *op) +int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) { - return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); + return PIOc_get_att(ncid, varid, name, (void *)ip); } /** - * @ingroup PIOc_get_att_float - * The PIO-C interface for the NetCDF function nc_get_att_float. + * @ingroup PIOc_put_att_schar + * The PIO-C interface for the NetCDF function nc_put_att_schar. */ -int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) +int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const signed char *op) { - return PIOc_get_att(ncid, varid, name, (void *)ip); + return PIOc_put_att(ncid, varid, name, xtype, len, op); +} + +/** + * @ingroup PIOc_put_att_long + * The PIO-C interface for the NetCDF function nc_put_att_long. + */ +int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const long *op) +{ + return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } /** @@ -2568,3 +2368,24 @@ int PIOc_put_att_text(int ncid, int varid, const char *name, return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } +/** + * @ingroup PIOc_put_att_short + * The PIO-C interface for the NetCDF function nc_put_att_short. + */ +int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const short *op) +{ + return PIOc_put_att(ncid, varid, name, xtype, len, op); +} + +/** + * @ingroup PIOc_put_att_double + * The PIO-C interface for the NetCDF function nc_put_att_double. + */ +int PIOc_put_att_double(int ncid, int varid, const char *name, nc_type xtype, + PIO_Offset len, const double *op) +{ + return PIOc_put_att(ncid, varid, name, xtype, len, op); +} + + From 16e37990aa5f6d40d53bdd0f9bae045db1c1b039 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 07:02:03 -0400 Subject: [PATCH 45/83] got inq_format working with async --- src/clib/pio_msg.c | 39 +++++++++++++++ src/clib/pio_nc_async.c | 95 ++++++++++++++++++++----------------- tests/unit/test_intercomm.c | 11 +++++ 3 files changed, 101 insertions(+), 44 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index ab4232f68d3b..fc49680c74bb 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -57,6 +57,42 @@ int inq_type_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** This function is run on the IO tasks to find netCDF file + * format. */ +int inq_format_handler(iosystem_desc_t *ios) +{ + int ncid; + int *formatp = NULL, format; + char format_present; + int mpierr; + int ret; + + LOG((1, "inq_format_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&format_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "inq_format_handler got parameters ncid = %d format_present = %d", + ncid, format_present)); + + /* Manage NULL pointers. */ + if (format_present) + formatp = &format; + + /* Call the function. */ + if ((ret = PIOc_inq_format(ncid, formatp))) + return ret; + + if (formatp) + LOG((2, "inq_format_handler format = %d", *formatp)); + LOG((1, "inq_format_handler succeeded!")); + + return PIO_NOERR; +} + /** This function is run on the IO tasks to create a netCDF file. */ int create_file_handler(iosystem_desc_t *ios) { @@ -971,6 +1007,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_INQ_TYPE: inq_type_handler(my_iosys); break; + case PIO_MSG_INQ_FORMAT: + inq_format_handler(my_iosys); + break; case PIO_MSG_CREATE_FILE: create_file_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index da6bd4a872c0..04f48d91f07a 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -299,61 +299,68 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) */ int PIOc_inq_format (int ncid, int *formatp) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_FORMAT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_FORMAT; + char format_present = formatp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&format_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_format(file->fh, formatp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_format(file->fh, formatp);; - } - break; -#endif + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_format(file->fh, formatp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_format(file->fh, formatp); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_format(file->fh, formatp); +#endif /* _NETCDF */ + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + { + if (formatp) + if ((mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + return ierr; } diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 18f3f3238ab9..686ad181c096 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -377,6 +377,17 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm file created ncid = %d\n", my_rank, ncid); + /* Test the inq_format function. */ + int myformat; + if ((ret = PIOc_inq_format(ncid, &myformat))) + ERR(ret); + if ((format[fmt] == PIO_IOTYPE_PNETCDF || format[fmt] == PIO_IOTYPE_NETCDF) && + myformat != 1) + ERR(ERR_AWFUL); + else if ((format[fmt] == PIO_IOTYPE_NETCDF4C || format[fmt] == PIO_IOTYPE_NETCDF4P) && + myformat != 3) + ERR(ERR_AWFUL); + /* Test the inq_type function for atomic types. */ char type_name[NC_MAX_NAME + 1]; PIO_Offset type_size; From 2a250cfe947a264e9c57a4ecf4aaec6e6d08d208 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 07:32:41 -0400 Subject: [PATCH 46/83] got inq_attname working with async --- src/clib/pio_msg.c | 46 +++++++++++++ src/clib/pio_nc_async.c | 124 +++++++++++++++++++----------------- tests/unit/test_intercomm.c | 5 ++ 3 files changed, 117 insertions(+), 58 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index fc49680c74bb..3640d201c0cd 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -368,6 +368,49 @@ int inq_att_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** Handle attribute inquiry operations. This code only runs on IO + * tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_attname_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int attnum; + char name[NC_MAX_NAME + 1], *namep = NULL; + char name_present; + int mpierr; + int ret; + + LOG((1, "inq_att_name_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "inq_attname_handler got ncid = %d varid = %d attnum = %d name_present = %d", + ncid, varid, attnum, name_present)); + + /* Match NULLs in collective function call. */ + if (name_present) + namep = name; + + /* Call the function to learn about the attribute. */ + if ((ret = PIOc_inq_attname(ncid, varid, attnum, namep))) + return ret; + + return PIO_NOERR; +} + /** Handle attribute operations. This code only runs on IO tasks. * * @param ios pointer to the iosystem_desc_t. @@ -1058,6 +1101,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_INQ_ATT: inq_att_handler(my_iosys); break; + case PIO_MSG_INQ_ATTNAME: + inq_attname_handler(my_iosys); + break; case PIO_MSG_INITDECOMP_DOF: initdecomp_dof_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 04f48d91f07a..34f0141ef8df 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -885,30 +885,18 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); } + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); +#endif /* _NETCDF */ + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Handle MPI errors. */ @@ -963,58 +951,78 @@ int PIOc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep) * @param attnum the attribute ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_attname (int ncid, int varid, int attnum, char *name) +int PIOc_inq_attname(int ncid, int varid, int attnum, char *name) { - int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_ATTNAME; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; + LOG((1, "PIOc_inq_attname ncid = %d varid = %d attnum = %d", ncid, varid, + attnum)); + + /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_ATTNAME; + char name_present = name ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attname(file->fh, varid, attnum, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_attname(file->fh, varid, attnum, name);; - } - break; -#endif + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_attname(file->fh, varid, attnum, name);; +#endif /* _NETCDF */ + LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); } + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; check_netcdf(file, ierr, __FILE__, __LINE__); - if (name) - { - int slen; - if(ios->iomaster) - slen = (int) strlen(name); - mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm); - mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm); - } + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + if (name) + { + int namelen = strlen(name); + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->ioroot, + ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } return ierr; } diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 686ad181c096..3587a5e03daa 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -183,6 +183,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) /* Check out the global attributes. */ nc_type atttype; PIO_Offset attlen; + char myattname[NC_MAX_NAME + 1]; if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) ERR(ret); if (atttype != NC_INT || attlen != 1) @@ -191,6 +192,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (attlen != 1) ERR(ERR_WRONG); + if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, myattname))) + ERR(ret); + if (strcmp(ATT_NAME, myattname)) + ERR(ERR_WRONG); if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) ERR(ret); if (verbose) From 5b140219be69862622ad1246fcba4bfe7ff308dd Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 07:49:01 -0400 Subject: [PATCH 47/83] got inq_attid working for async --- src/clib/pio_msg.c | 55 +++++++++++++++++++++++++ src/clib/pio_nc_async.c | 81 +++++++++++++++++++++++-------------- tests/unit/test_intercomm.c | 5 +++ 3 files changed, 110 insertions(+), 31 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 3640d201c0cd..51575f697bce 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -411,6 +411,58 @@ int inq_attname_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** Handle attribute inquiry operations. This code only runs on IO + * tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @param msg the message sent my the comp root task. + * @return PIO_NOERR for success, error code otherwise. +*/ +int inq_attid_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int attnum; + char *name; + int namelen; + int id, *idp = NULL; + char id_present; + int mpierr; + int ret; + + LOG((1, "inq_attid_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "inq_attid_handler got ncid = %d varid = %d attnum = %d id_present = %d", + ncid, varid, attnum, id_present)); + + /* Match NULLs in collective function call. */ + if (id_present) + idp = &id; + + /* Call the function to learn about the attribute. */ + if ((ret = PIOc_inq_attid(ncid, varid, name, idp))) + return ret; + + /* Free resources. */ + free(name); + + return PIO_NOERR; +} + /** Handle attribute operations. This code only runs on IO tasks. * * @param ios pointer to the iosystem_desc_t. @@ -1104,6 +1156,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_INQ_ATTNAME: inq_attname_handler(my_iosys); break; + case PIO_MSG_INQ_ATTID: + inq_attid_handler(my_iosys); + break; case PIO_MSG_INITDECOMP_DOF: initdecomp_dof_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 34f0141ef8df..0a9fe0d8d209 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1042,47 +1042,66 @@ int PIOc_inq_attname(int ncid, int varid, int attnum, char *name) * @param idp a pointer that will get the id of the variable or attribute. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) +int PIOc_inq_attid(int ncid, int varid, const char *name, int *idp) { - int ierr = PIO_NOERR; - int msg = PIO_MSG_INQ_ATTID; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; + /* User must provide name shorter than NC_MAX_NAME +1. */ + if (!name || strlen(name) > NC_MAX_NAME) + return PIO_EINVAL; + + LOG((1, "PIOc_inq_attid ncid = %d varid = %d name = %s", ncid, varid, name)); + + /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_ATTID; + int namelen = strlen(name); + char id_present = idp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_attid(file->fh, varid, name, idp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_attid(file->fh, varid, name, idp);; - } - break; -#endif + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_inq_attid(file->fh, varid, name, idp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_attid(file->fh, varid, name, idp);; +#endif /* _NETCDF */ + LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); } /* Handle MPI errors. */ @@ -1094,7 +1113,7 @@ int PIOc_inq_attid (int ncid, int varid, const char *name, int *idp) if (!ierr) { if (idp) - if ((mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) check_mpi(file, mpierr, __FILE__, __LINE__); } diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 3587a5e03daa..30d06d9e3923 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -184,6 +184,7 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) nc_type atttype; PIO_Offset attlen; char myattname[NC_MAX_NAME + 1]; + int myid; if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &atttype, &attlen))) ERR(ret); if (atttype != NC_INT || attlen != 1) @@ -196,6 +197,10 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) ERR(ret); if (strcmp(ATT_NAME, myattname)) ERR(ERR_WRONG); + if ((ret = PIOc_inq_attid(ncid, NC_GLOBAL, ATT_NAME, &myid))) + ERR(ret); + if (myid != 0) + ERR(ERR_WRONG); if ((ret = PIOc_get_att_int(ncid, NC_GLOBAL, ATT_NAME, &att_data))) ERR(ret); if (verbose) From 10ff1436da7f206c88b4b69261fe041b5e323694 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 07:58:53 -0400 Subject: [PATCH 48/83] got inq_attid working for async --- src/clib/pio_msg.c | 45 +++++++++++++++++++ src/clib/pio_nc_async.c | 95 ++++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 43 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 51575f697bce..1a65d67f5ea8 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -833,6 +833,48 @@ int def_dim_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** This function is run on the IO tasks to rename a netCDF + * dimension. */ +int rename_dim_handler(iosystem_desc_t *ios) +{ + int ncid; + int len, namelen; + int iotype; + char *name; + int mode; + int mpierr; + int ret; + int dimid; + + LOG((1, "rename_dim_handler")); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&dimid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc(namelen + 1 * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, + ios->intercomm))) + return PIO_EIO; + LOG((2, "rename_dim_handler got parameters namelen = %d " + "name = %s ncid = %d varid = %d", namelen, name, ncid, varid)); + + /* Call the create file function. */ + if ((ret = PIOc_rename_dim(ncid, dimid, name))) + return ret; + + /* Free resources. */ + free(name); + + LOG((1, "%d rename_dim_handler succeeded!\n", my_rank)); + return PIO_NOERR; +} + /** This function is run on the IO tasks. It reads or writes an array * of data to a netCDF variable. * @@ -1123,6 +1165,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_DELETE_FILE: delete_file_handler(my_iosys); break; + case PIO_MSG_RENAME_DIM: + rename_dim_handler(my_iosys); + break; case PIO_MSG_DEF_DIM: def_dim_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 0a9fe0d8d209..13f5b310bd9e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1133,62 +1133,71 @@ int PIOc_inq_attid(int ncid, int varid, const char *name, int *idp) * PIOc_openfile() or PIOc_createfile(). * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_dim (int ncid, int dimid, const char *name) +int PIOc_rename_dim(int ncid, int dimid, const char *name) { - int ierr; - int msg; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* User must provide name of correct length. */ + if (!name || strlen(name) > NC_MAX_NAME) + return PIO_EINVAL; + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_DIM; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_DIM; /** Message for async notification. */ + int namelen = strlen(name); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_dim(file->fh, dimid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_rename_dim(file->fh, dimid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_dim(file->fh, dimid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_dim(file->fh, dimid, name); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_dim(file->fh, dimid, name);; +#endif /* _NETCDF */ + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; } From 6c0ee7b3783040a22246790562c8c2998e6e916c Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 08:17:31 -0400 Subject: [PATCH 49/83] got rename_dim working --- src/clib/pio_msg.c | 12 ++++++------ src/clib/pio_nc_async.c | 6 ++++-- tests/unit/test_intercomm.c | 12 +++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 1a65d67f5ea8..c1b8aa42ab26 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -845,6 +845,7 @@ int rename_dim_handler(iosystem_desc_t *ios) int mpierr; int ret; int dimid; + char name1[NC_MAX_NAME + 1]; LOG((1, "rename_dim_handler")); @@ -856,13 +857,12 @@ int rename_dim_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - if (!(name = malloc(namelen + 1 * sizeof(char)))) - return PIO_ENOMEM; - if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, - ios->intercomm))) - return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; LOG((2, "rename_dim_handler got parameters namelen = %d " - "name = %s ncid = %d varid = %d", namelen, name, ncid, varid)); + "name = %s ncid = %d dimid = %d", namelen, name, ncid, dimid)); /* Call the create file function. */ if ((ret = PIOc_rename_dim(ncid, dimid, name))) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 13f5b310bd9e..aa67d8b42e35 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1167,9 +1167,11 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) if (!mpierr) mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) - mpierr = MPI_Bcast(&name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_rename_dim Bcast file->fh = %d dimid = %d namelen = %d name = %s", + file->fh, dimid, namelen, name)); } /* Handle MPI errors. */ diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 30d06d9e3923..c4d2bc375476 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -23,12 +23,15 @@ #define LOCAL_DIM_LEN 2 /** The name of the dimension in the netCDF output file. */ +#define FIRST_DIM_NAME "jojo" #define DIM_NAME "dim_test_intercomm" /** The name of the variable in the netCDF output file. */ +#define FIRST_VAR_NAME "bill" #define VAR_NAME "var_test_intercomm" /** The name of the global attribute in the netCDF output file. */ +#define FIRST_ATT_NAME "willy" #define ATT_NAME "gatt_test_intercomm" #define SHORT_ATT_NAME "short_gatt_test_intercomm" #define FLOAT_ATT_NAME "float_gatt_test_intercomm" @@ -415,9 +418,16 @@ main(int argc, char **argv) } /* Define a dimension. */ + char dimname2[NC_MAX_NAME + 1]; if (verbose) printf("%d test_intercomm defining dimension %s\n", my_rank, DIM_NAME); - if ((ret = PIOc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid))) + if ((ret = PIOc_def_dim(ncid, FIRST_DIM_NAME, DIM_LEN, &dimid))) + ERR(ret); + if ((ret = PIOc_inq_dimname(ncid, 0, dimname2))) + ERR(ret); + if (strcmp(dimname2, FIRST_DIM_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_rename_dim(ncid, 0, DIM_NAME))) ERR(ret); /* Define a 1-D variable. */ From f44671845e06f2f512cd4b011f82938f25ccbb3a Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 08:24:58 -0400 Subject: [PATCH 50/83] got rename_var working with async --- src/clib/pio_msg.c | 45 ++++++++++++++++ src/clib/pio_nc_async.c | 101 ++++++++++++++++++++---------------- tests/unit/test_intercomm.c | 9 +++- 3 files changed, 109 insertions(+), 46 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index c1b8aa42ab26..a4b663fe1367 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -875,6 +875,48 @@ int rename_dim_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** This function is run on the IO tasks to rename a netCDF + * dimension. */ +int rename_var_handler(iosystem_desc_t *ios) +{ + int ncid; + int len, namelen; + int iotype; + char *name; + int mode; + int mpierr; + int ret; + int varid; + char name1[NC_MAX_NAME + 1]; + + LOG((1, "rename_var_handler")); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "rename_var_handler got parameters namelen = %d " + "name = %s ncid = %d varid = %d", namelen, name, ncid, varid)); + + /* Call the create file function. */ + if ((ret = PIOc_rename_var(ncid, varid, name))) + return ret; + + /* Free resources. */ + free(name); + + LOG((1, "%d rename_var_handler succeeded!\n", my_rank)); + return PIO_NOERR; +} + /** This function is run on the IO tasks. It reads or writes an array * of data to a netCDF variable. * @@ -1168,6 +1210,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_RENAME_DIM: rename_dim_handler(my_iosys); break; + case PIO_MSG_RENAME_VAR: + rename_var_handler(my_iosys); + break; case PIO_MSG_DEF_DIM: def_dim_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index aa67d8b42e35..6c15bf74758e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1140,12 +1140,12 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - LOG((1, "PIOc_inq ncid = %d", ncid)); - /* User must provide name of correct length. */ if (!name || strlen(name) > NC_MAX_NAME) return PIO_EINVAL; + LOG((1, "PIOc_rename_dim ncid = %d dimid = %d name = %s", ncid, dimid, name)); + /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; @@ -1217,62 +1217,73 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_rename_var (int ncid, int varid, const char *name) +int PIOc_rename_var(int ncid, int varid, const char *name) { - int ierr; - int msg; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - errstr = NULL; - ierr = PIO_NOERR; + /* User must provide name of correct length. */ + if (!name || strlen(name) > NC_MAX_NAME) + return PIO_EINVAL; - file = pio_get_file_from_id(ncid); - if(file == NULL) + LOG((1, "PIOc_rename_var ncid = %d varid = %d name = %s", ncid, varid, name)); + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_VAR; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_VAR; /** Message for async notification. */ + int namelen = strlen(name); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_var(file->fh, varid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_rename_var(file->fh, varid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_var(file->fh, varid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_rename_var Bcast file->fh = %d varid = %d namelen = %d name = %s", + file->fh, varid, namelen, name)); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_var(file->fh, varid, name); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_var(file->fh, varid, name);; +#endif /* _NETCDF */ + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; } diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index c4d2bc375476..dfce3827c1f5 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -431,9 +431,16 @@ main(int argc, char **argv) ERR(ret); /* Define a 1-D variable. */ + char varname2[NC_MAX_NAME + 1]; if (verbose) printf("%d test_intercomm defining variable %s\n", my_rank, VAR_NAME); - if ((ret = PIOc_def_var(ncid, VAR_NAME, NC_INT, NDIM, &dimid, &varid))) + if ((ret = PIOc_def_var(ncid, FIRST_VAR_NAME, NC_INT, NDIM, &dimid, &varid))) + ERR(ret); + if ((ret = PIOc_inq_varname(ncid, 0, varname2))) + ERR(ret); + if (strcmp(varname2, FIRST_VAR_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_rename_var(ncid, 0, VAR_NAME))) ERR(ret); /* Add a global attribute. */ From 0ce232fd523cb6ec39018a2d5dbc0e29f9f68775 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 14 May 2016 09:01:59 -0400 Subject: [PATCH 51/83] got rename_var working with async --- src/clib/pio_msg.c | 49 +++++++++++++++++++ src/clib/pio_nc_async.c | 105 ++++++++++++++++++++++++---------------- 2 files changed, 111 insertions(+), 43 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index a4b663fe1367..cdd7dd84e6cd 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -917,6 +917,52 @@ int rename_var_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** This function is run on the IO tasks to rename a netCDF + * attribute. */ +int rename_att_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int namelen, newnamelen; + char *name, *newname; + int mpierr; + int ret; + + LOG((1, "rename_att_handler")); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(newname = malloc((newnamelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(newname, newnamelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "rename_var_handler got parameters namelen = %d name = %s ncid = %d varid = %d" + "newnamelen = %d newname = %s", namelen, name, ncid, varid, newnamelen, newname)); + + /* Call the create file function. */ + if ((ret = PIOc_rename_att(ncid, varid, name, newname))) + return ret; + + /* Free resources. */ + free(name); + free(newname); + + LOG((1, "%d rename_att_handler succeeded!\n", my_rank)); + return PIO_NOERR; +} + /** This function is run on the IO tasks. It reads or writes an array * of data to a netCDF variable. * @@ -1213,6 +1259,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_RENAME_VAR: rename_var_handler(my_iosys); break; + case PIO_MSG_RENAME_ATT: + rename_att_handler(my_iosys); + break; case PIO_MSG_DEF_DIM: def_dim_handler(my_iosys); break; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 6c15bf74758e..87927295a5f8 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1303,60 +1303,79 @@ int PIOc_rename_var(int ncid, int varid, const char *name) */ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; +{ + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - errstr = NULL; - ierr = PIO_NOERR; + /* User must provide names of correct length. */ + if (!name || strlen(name) > NC_MAX_NAME || + !newname || strlen(newname) > NC_MAX_NAME) + return PIO_EINVAL; - file = pio_get_file_from_id(ncid); - if(file == NULL) + LOG((1, "PIOc_rename_att ncid = %d varid = %d name = %s newname = %s", + ncid, varid, name, newname)); + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_RENAME_ATT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_ATT; /** Message for async notification. */ + int namelen = strlen(name); + int newnamelen = strlen(newname); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_rename_att(file->fh, varid, name, newname);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_rename_att(file->fh, varid, name, newname);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_rename_att(file->fh, varid, name, newname);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_rename_att Bcast file->fh = %d varid = %d namelen = %d name = %s" + "newnamelen = %s newname = %s", file->fh, varid, namelen, name, newnamelen, newname)); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_att(file->fh, varid, name, newname); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_att(file->fh, varid, name, newname); +#endif /* _NETCDF */ + LOG((2, "PIOc_rename_att netcdf call returned %d", ierr)); } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; } From a055a395115b65458fbd74538a6b8dbf1ba40967 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 07:09:51 -0400 Subject: [PATCH 52/83] fixed rename_att function for async --- src/clib/pio_msg.c | 15 +++++++++++++-- src/clib/pio_nc_async.c | 30 +++++++++++++++++++++--------- tests/unit/test_intercomm.c | 21 ++++++++++++++++++--- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index cdd7dd84e6cd..86fd5d04f53d 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -929,31 +929,41 @@ int rename_att_handler(iosystem_desc_t *ios) int ret; LOG((1, "rename_att_handler")); + LOG((1, "rename_att_handler2")); /* Get the parameters for this function that the he comp master * task is broadcasting. */ + LOG((1, "rename_att_handler about to get ncid")); if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + LOG((2, "rename_att_handler ncid = %d", ncid)); if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + LOG((2, "rename_att_handler varid = %d", varid)); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + LOG((2, "rename_att_handler namelen = %d", namelen)); if (!(name = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; + LOG((2, "rename_att_handler name = %s", name)); if ((mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; + LOG((2, "rename_att_handler newnamelen = %d", newnamelen)); if (!(newname = malloc((newnamelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast(newname, newnamelen + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_var_handler got parameters namelen = %d name = %s ncid = %d varid = %d" + LOG((2, "rename_att_handler got parameters namelen = %d name = %s ncid = %d varid = %d " "newnamelen = %d newname = %s", namelen, name, ncid, varid, newnamelen, newname)); /* Call the create file function. */ if ((ret = PIOc_rename_att(ncid, varid, name, newname))) + { + LOG((2, "rename_att_handler rename_att returned %d", ret)); return ret; + } /* Free resources. */ free(name); @@ -1224,7 +1234,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) LOG((3, "about to call msg MPI_Bcast")); mpierr = MPI_Bcast(&msg, 1, MPI_INT, 0, my_iosys->io_comm); CheckMPIReturn(mpierr, __FILE__, __LINE__); - LOG((1, "msg MPI_Bcast complete msg = %d", msg)); + LOG((1, "pio_msg_handler msg MPI_Bcast complete msg = %d", msg)); /* Handle the message. This code is run on all IO tasks. */ switch (msg) @@ -1261,6 +1271,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) break; case PIO_MSG_RENAME_ATT: rename_att_handler(my_iosys); + LOG((1, "rename_att_handler returned")); break; case PIO_MSG_DEF_DIM: def_dim_handler(my_iosys); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 87927295a5f8..e80f80bc3db5 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1299,15 +1299,16 @@ int PIOc_rename_var(int ncid, int varid, const char *name) * @param ncid the ncid of the open file, obtained from * PIOc_openfile() or PIOc_createfile(). * @param varid the variable ID. - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + * @return PIO_NOERR for success, error code otherwise. See + * PIOc_Set_File_Error_Handling */ -int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) -{ +int PIOc_rename_att (int ncid, int varid, const char *name, + const char *newname) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ - int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ /* User must provide names of correct length. */ if (!name || strlen(name) > NC_MAX_NAME || @@ -1322,6 +1323,8 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) return PIO_EBADID; ios = file->iosystem; + LOG((2, "PIOc_rename_att2 ncid = %d varid = %d name = %s newname = %s", + ncid, varid, name, newname)); /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -1331,9 +1334,12 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) int namelen = strlen(name); int newnamelen = strlen(newname); - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + LOG((2, "PIOc_rename_att sending msg")); + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + LOG((2, "PIOc_rename_att done sending msg")); if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -1346,18 +1352,19 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_rename_att Bcast file->fh = %d varid = %d namelen = %d name = %s" - "newnamelen = %s newname = %s", file->fh, varid, namelen, name, newnamelen, newname)); } + /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } + LOG((2, "PIOc_rename_att calling netcdf function")); /* If this is an IO task, then call the netCDF function. */ + LOG((2, "PIOc_rename_att calling netcdf function")); if (ios->ioproc) { #ifdef _PNETCDF @@ -1372,10 +1379,15 @@ int PIOc_rename_att (int ncid, int varid, const char *name, const char *newname) } /* Broadcast and check the return code. */ + LOG((2, "PIOc_rename_att Bcasting %d", ierr)); if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + LOG((2, "PIOc_rename_att ERROR")); return PIO_EIO; + } + LOG((2, "PIOc_rename_att Bcast complete")); check_netcdf(file, ierr, __FILE__, __LINE__); - + LOG((2, "PIOc_rename_att succeeded")); return ierr; } diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index dfce3827c1f5..d2253fc6f30e 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -31,7 +31,7 @@ #define VAR_NAME "var_test_intercomm" /** The name of the global attribute in the netCDF output file. */ -#define FIRST_ATT_NAME "willy" +#define FIRST_ATT_NAME "willy_gatt_test_intercomm" #define ATT_NAME "gatt_test_intercomm" #define SHORT_ATT_NAME "short_gatt_test_intercomm" #define FLOAT_ATT_NAME "float_gatt_test_intercomm" @@ -450,8 +450,23 @@ main(int argc, char **argv) short short_att_data = ATT_VALUE; float float_att_data = ATT_VALUE; double double_att_data = ATT_VALUE; - if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) - ERR(ret); + char attname2[NC_MAX_NAME + 1]; + if (fmt == 0) + { + if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) + ERR(ret); + } + else + { + if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) + ERR(ret); + if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, attname2))) + ERR(ret); + if (strcmp(attname2, FIRST_ATT_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_rename_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, ATT_NAME))) + ERR(ret); + } if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) ERR(ret); if ((ret = PIOc_put_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, NC_FLOAT, 1, &float_att_data))) From 01679e5be991eb12c35e1fc7839d6c0d161d8a20 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 08:19:42 -0400 Subject: [PATCH 53/83] more cleanup --- src/clib/pio_nc_async.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index e80f80bc3db5..4e9544a17dcb 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1323,8 +1323,6 @@ int PIOc_rename_att (int ncid, int varid, const char *name, return PIO_EBADID; ios = file->iosystem; - LOG((2, "PIOc_rename_att2 ncid = %d varid = %d name = %s newname = %s", - ncid, varid, name, newname)); /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -1334,8 +1332,6 @@ int PIOc_rename_att (int ncid, int varid, const char *name, int namelen = strlen(name); int newnamelen = strlen(newname); - LOG((2, "PIOc_rename_att sending msg")); - if (ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -1354,17 +1350,13 @@ int PIOc_rename_att (int ncid, int varid, const char *name, mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } - /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } - LOG((2, "PIOc_rename_att calling netcdf function")); - /* If this is an IO task, then call the netCDF function. */ - LOG((2, "PIOc_rename_att calling netcdf function")); if (ios->ioproc) { #ifdef _PNETCDF @@ -1375,18 +1367,13 @@ int PIOc_rename_att (int ncid, int varid, const char *name, if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) ierr = nc_rename_att(file->fh, varid, name, newname); #endif /* _NETCDF */ - LOG((2, "PIOc_rename_att netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ - LOG((2, "PIOc_rename_att Bcasting %d", ierr)); if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - LOG((2, "PIOc_rename_att ERROR")); - return PIO_EIO; - } - LOG((2, "PIOc_rename_att Bcast complete")); + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); + LOG((2, "PIOc_rename_att succeeded")); return ierr; } From 1728b3e9e3270f3ba069cc84d024c5675209938c Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 08:33:10 -0400 Subject: [PATCH 54/83] continued async development --- src/clib/pio_nc_async.c | 341 ++++++++++++++++++++-------------------- 1 file changed, 167 insertions(+), 174 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 4e9544a17dcb..0bc417c5f0a0 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1392,62 +1392,63 @@ int PIOc_rename_att (int ncid, int varid, const char *name, * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_del_att (int ncid, int varid, const char *name) +int PIOc_del_att(int ncid, int varid, const char *name) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - errstr = NULL; - ierr = PIO_NOERR; + /* User must provide name of correct length. */ + if (!name || strlen(name) > NC_MAX_NAME) + return PIO_EINVAL; - file = pio_get_file_from_id(ncid); - if(file == NULL) + LOG((1, "PIOc_del_att ncid = %d varid = %d name = %s", ncid, varid, name)); + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_DEL_ATT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_DEL_ATT; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_del_att(file->fh, varid, name);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_del_att(file->fh, varid, name);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_del_att(file->fh, varid, name);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_del_att(file->fh, varid, name); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_del_att(file->fh, varid, name); +#endif /* _NETCDF */ } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + check_netcdf(file, ierr, __FILE__, __LINE__); + + LOG((2, "PIOc_del_att succeeded")); return ierr; } @@ -1466,60 +1467,59 @@ int PIOc_del_att (int ncid, int varid, const char *name) */ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) { - int ierr; - int msg; - int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_set_fill ncid = %d fillmode = %d old_modep = %d", ncid, fillmode, + old_modep)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_SET_FILL; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_SET_FILL; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_set_fill(file->fh, fillmode, old_modep);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_set_fill(file->fh, fillmode, old_modep);; - } - break; -#endif + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_set_fill(file->fh, fillmode, old_modep);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_set_fill(file->fh, fillmode, old_modep); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_set_fill(file->fh, fillmode, old_modep); +#endif /* _NETCDF */ } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + check_netcdf(file, ierr, __FILE__, __LINE__); + + LOG((2, "PIOc_set_fill succeeded")); return ierr; } @@ -1538,61 +1538,57 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) */ int PIOc_enddef(int ncid) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_enddef ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_ENDDEF; - if(ios->async_interface && ! ios->ioproc){ - if(!ios->comp_rank) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - printf("PIOc_enddef file->fh = %d\n", file->fh); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_ENDDEF; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_enddef(file->fh);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_enddef(file->fh);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_enddef(file->fh);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_enddef(file->fh); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_enddef(file->fh); +#endif /* _NETCDF */ } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + check_netcdf(file, ierr, __FILE__, __LINE__); + + LOG((2, "PIOc_enddef succeeded")); return ierr; } @@ -1611,60 +1607,57 @@ int PIOc_enddef(int ncid) */ int PIOc_redef (int ncid) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_redef ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_REDEF; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_ENDDEF; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_redef(file->fh);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_redef(file->fh);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_redef(file->fh);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_redef(file->fh); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_redef(file->fh); +#endif /* _NETCDF */ } - ierr = check_netcdf(file, ierr, errstr,__LINE__); - if(errstr != NULL) free(errstr); + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + check_netcdf(file, ierr, __FILE__, __LINE__); + + LOG((2, "PIOc_redef succeeded")); return ierr; } From 2e1746024e2ebde549e8e1fe23e0ef6c210f7f28 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:05:05 -0400 Subject: [PATCH 55/83] continued async development --- tests/unit/test_intercomm.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index d2253fc6f30e..57968c48aad2 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -451,22 +451,14 @@ main(int argc, char **argv) float float_att_data = ATT_VALUE; double double_att_data = ATT_VALUE; char attname2[NC_MAX_NAME + 1]; - if (fmt == 0) - { - if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, ATT_NAME, NC_INT, 1, &att_data))) - ERR(ret); - } - else - { - if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) - ERR(ret); - if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, attname2))) - ERR(ret); - if (strcmp(attname2, FIRST_ATT_NAME)) - ERR(ERR_WRONG); - if ((ret = PIOc_rename_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, ATT_NAME))) - ERR(ret); - } + if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) + ERR(ret); + if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, attname2))) + ERR(ret); + if (strcmp(attname2, FIRST_ATT_NAME)) + ERR(ERR_WRONG); + if ((ret = PIOc_rename_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, ATT_NAME))) + ERR(ret); if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) ERR(ret); if ((ret = PIOc_put_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, NC_FLOAT, 1, &float_att_data))) From f60fe9656657acc133759bc5a1909e739488acd3 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:11:50 -0400 Subject: [PATCH 56/83] continued async development --- tests/unit/test_intercomm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 57968c48aad2..b2c2d2d3d70d 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -451,6 +451,7 @@ main(int argc, char **argv) float float_att_data = ATT_VALUE; double double_att_data = ATT_VALUE; char attname2[NC_MAX_NAME + 1]; + /* Write an att and rename it. */ if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) ERR(ret); if ((ret = PIOc_inq_attname(ncid, NC_GLOBAL, 0, attname2))) @@ -459,6 +460,16 @@ main(int argc, char **argv) ERR(ERR_WRONG); if ((ret = PIOc_rename_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, ATT_NAME))) ERR(ret); + + /* Write an att and delete it. */ + /* if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) */ + /* ERR(ret); */ + /* if ((ret = PIOc_del_att(ncid, NC_GLOBAL, FIRST_ATT_NAME))) */ + /* ERR(ret); */ + /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, NULL, NULL)) != PIO_ENOTATT) */ + /* ERR(ERR_AWFUL); */ + + /* Write some atts of different types. */ if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) ERR(ret); if ((ret = PIOc_put_att_float(ncid, NC_GLOBAL, FLOAT_ATT_NAME, NC_FLOAT, 1, &float_att_data))) From 149d94e58e1742310394bb0ceb7d7e4d499b6a76 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:29:27 -0400 Subject: [PATCH 57/83] continued async development --- src/clib/pio_msg.c | 53 +++++++++++++++++++++++++++++-------- src/clib/pio_nc_async.c | 52 ++++++++++++++++++++---------------- tests/unit/test_intercomm.c | 12 ++++++--- 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 86fd5d04f53d..5c2f511da501 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -929,28 +929,21 @@ int rename_att_handler(iosystem_desc_t *ios) int ret; LOG((1, "rename_att_handler")); - LOG((1, "rename_att_handler2")); /* Get the parameters for this function that the he comp master * task is broadcasting. */ - LOG((1, "rename_att_handler about to get ncid")); if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_att_handler ncid = %d", ncid)); if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_att_handler varid = %d", varid)); if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_att_handler namelen = %d", namelen)); if (!(name = malloc((namelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_att_handler name = %s", name)); if ((mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "rename_att_handler newnamelen = %d", newnamelen)); if (!(newname = malloc((newnamelen + 1) * sizeof(char)))) return PIO_ENOMEM; if ((mpierr = MPI_Bcast(newname, newnamelen + 1, MPI_CHAR, 0, ios->intercomm))) @@ -960,10 +953,7 @@ int rename_att_handler(iosystem_desc_t *ios) /* Call the create file function. */ if ((ret = PIOc_rename_att(ncid, varid, name, newname))) - { - LOG((2, "rename_att_handler rename_att returned %d", ret)); return ret; - } /* Free resources. */ free(name); @@ -973,6 +963,45 @@ int rename_att_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** This function is run on the IO tasks to delete a netCDF + * attribute. */ +int delete_att_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int namelen, newnamelen; + char *name, *newname; + int mpierr; + int ret; + + LOG((1, "delete_att_handler")); + + /* Get the parameters for this function that the he comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if (!(name = malloc((namelen + 1) * sizeof(char)))) + return PIO_ENOMEM; + if ((mpierr = MPI_Bcast(name, namelen + 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + LOG((2, "delete_att_handler namelen = %d name = %s ncid = %d varid = %d ", + namelen, name, ncid, varid)); + + /* Call the create file function. */ + if ((ret = PIOc_del_att(ncid, varid, name))) + return ret; + + /* Free resources. */ + free(name); + + LOG((1, "delete_att_handler succeeded!")); + return PIO_NOERR; +} + /** This function is run on the IO tasks. It reads or writes an array * of data to a netCDF variable. * @@ -1271,7 +1300,9 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) break; case PIO_MSG_RENAME_ATT: rename_att_handler(my_iosys); - LOG((1, "rename_att_handler returned")); + break; + case PIO_MSG_DEL_ATT: + delete_att_handler(my_iosys); break; case PIO_MSG_DEF_DIM: def_dim_handler(my_iosys); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 0bc417c5f0a0..7271cae2bd71 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -899,11 +899,11 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + /* Broadcast results. */ if (!ierr) { @@ -1104,11 +1104,11 @@ int PIOc_inq_attid(int ncid, int varid, const char *name, int *idp) LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + /* Broadcast results. */ if (!ierr) { @@ -1335,7 +1335,6 @@ int PIOc_rename_att (int ncid, int varid, const char *name, if (ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - LOG((2, "PIOc_rename_att done sending msg")); if (!mpierr) mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -1398,9 +1397,10 @@ int PIOc_del_att(int ncid, int varid, const char *name) file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ + int namelen = strlen(name); /** Length of name string. */ /* User must provide name of correct length. */ - if (!name || strlen(name) > NC_MAX_NAME) + if (!name || namelen > NC_MAX_NAME) return PIO_EINVAL; LOG((1, "PIOc_del_att ncid = %d varid = %d name = %s", ncid, varid, name)); @@ -1421,7 +1421,13 @@ int PIOc_del_att(int ncid, int varid, const char *name) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); if (!mpierr) - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ @@ -1734,11 +1740,11 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; @@ -1927,11 +1933,11 @@ int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) } } - if(ierr != PIO_NOERR){ - errstr = (char *) malloc((strlen(__FILE__) + 20)* sizeof(char)); - sprintf(errstr,"in file %s",__FILE__); - } - ierr = check_netcdf(file, ierr, errstr,__LINE__); + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return PIO_EIO; + check_netcdf(file, ierr, __FILE__, __LINE__); + mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); if(errstr != NULL) free(errstr); return ierr; diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index b2c2d2d3d70d..d45e14431ae9 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -462,12 +462,16 @@ main(int argc, char **argv) ERR(ret); /* Write an att and delete it. */ - /* if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) */ - /* ERR(ret); */ - /* if ((ret = PIOc_del_att(ncid, NC_GLOBAL, FIRST_ATT_NAME))) */ - /* ERR(ret); */ + nc_type myatttype; + if ((ret = PIOc_put_att_int(ncid, NC_GLOBAL, FIRST_ATT_NAME, NC_INT, 1, &att_data))) + ERR(ret); + if ((ret = PIOc_del_att(ncid, NC_GLOBAL, FIRST_ATT_NAME))) + ERR(ret); /* if ((ret = PIOc_inq_att(ncid, NC_GLOBAL, FIRST_ATT_NAME, NULL, NULL)) != PIO_ENOTATT) */ + /* { */ + /* printf("ret = %d\n", ret); */ /* ERR(ERR_AWFUL); */ + /* } */ /* Write some atts of different types. */ if ((ret = PIOc_put_att_short(ncid, NC_GLOBAL, SHORT_ATT_NAME, NC_SHORT, 1, &short_att_data))) From 28107470cb939ca087cbfb0c3f67b5c82e3c9930 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:32:14 -0400 Subject: [PATCH 58/83] continued async development --- src/clib/pio_nc_async.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 7271cae2bd71..0a3e1b1ec18b 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1769,14 +1769,14 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp) { - iosystem_desc_t *ios; - file_desc_t *file; - int ierr = PIO_NOERR; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - int namelen; + int namelen = strlen(name); /* User must provide name and storage for varid. */ - if (!name || !varidp) + if (!name || !varidp || namelen > NC_MAX_NAME) { check_netcdf(file, PIO_EINVAL, __FILE__, __LINE__); return PIO_EINVAL; @@ -1796,14 +1796,12 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, if (!ios->ioproc) { int msg = PIO_MSG_DEF_VAR; + if(ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - LOG((2, "bcasting namelen = %d name = %s\n", namelen, name)); - if (!ios->compmaster) - ios->compmaster = MPI_PROC_NULL; if (!mpierr) mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -1864,8 +1862,9 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, /* Broadcast results. */ if (!ierr) if (varidp) - mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm); - + if ((mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + return ierr; } From d9ef4b998257a38ad69ce47c03ddd40d26467591 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:42:43 -0400 Subject: [PATCH 59/83] more async changes --- src/clib/pio_nc_async.c | 74 +++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 0a3e1b1ec18b..d95b70594f1f 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1683,38 +1683,52 @@ int PIOc_redef (int ncid) */ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - int namelen; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - errstr = NULL; - ierr = PIO_NOERR; + /* User must provide name. */ + if (!name || strlen(name) > NC_MAX_NAME) + return PIO_EINVAL; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - printf("%d PIOc_def_dim ncid = %d name = %s len = %d\n", my_rank, - ncid, name, len); + LOG((1, "PIOc_def_dim ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_DEF_DIM; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_DEF_DIM; + int namelen = strlen(name); + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ if(ios->ioproc){ switch(file->iotype){ #ifdef _NETCDF @@ -1744,9 +1758,13 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) return PIO_EIO; check_netcdf(file, ierr, __FILE__, __LINE__); - - mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + if (idp) + if ((mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + return ierr; } From 7417325ae9e0393cf688e86c3639b022c675708e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:47:20 -0400 Subject: [PATCH 60/83] more async changes --- src/clib/pio_nc_async.c | 44 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index d95b70594f1f..bc1033958a93 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1791,10 +1791,9 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - int namelen = strlen(name); /* User must provide name and storage for varid. */ - if (!name || !varidp || namelen > NC_MAX_NAME) + if (!name || !varidp || strlen(name) > NC_MAX_NAME) { check_netcdf(file, PIO_EINVAL, __FILE__, __LINE__); return PIO_EINVAL; @@ -1814,6 +1813,7 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, if (!ios->ioproc) { int msg = PIO_MSG_DEF_VAR; + int namelen = strlen(name); if(ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -1838,38 +1838,22 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, check_mpi(file, mpierr, __FILE__, __LINE__); } - /* IO tasks call the netCDF functions. */ + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp);; - break; - case PIO_IOTYPE_NETCDF4C: - if (ios->io_rank == 0) - { - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); - if (!ierr) - ierr = nc_def_var_deflate(file->fh, *varidp, 0,1,1); - } - break; -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); +#ifdef _NETCDF4 + /* For netCDF-4 serial files, turn on compression for this variable. */ + if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C) + ierr = nc_def_var_deflate(file->fh, *varidp, 0, 1, 1); +#endif /* _NETCDF4 */ +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ From b3d7b94b5b195ef55937d1b8d510b010f6e856e8 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:49:54 -0400 Subject: [PATCH 61/83] more async changes --- src/clib/pio_nc_async.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index bc1033958a93..b4d2430cfba8 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1692,7 +1692,7 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) if (!name || strlen(name) > NC_MAX_NAME) return PIO_EINVAL; - LOG((1, "PIOc_def_dim ncid = %d", ncid)); + LOG((1, "PIOc_def_dim ncid = %d name = %s len = %d", ncid, name, len)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) @@ -1729,29 +1729,17 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) } /* If this is an IO task, then call the netCDF function. */ - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_def_dim(file->fh, name, (size_t)len, idp);; - } - break; -#endif + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_def_dim(file->fh, name, len, idp);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_def_dim(file->fh, name, len, idp);; +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_def_dim(file->fh, name, (size_t)len, idp); +#endif /* _NETCDF */ + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ From a4be288dfb0a073d76dbe667956224d5a1468559 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:54:45 -0400 Subject: [PATCH 62/83] more async changes --- src/clib/pio_nc_async.c | 86 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b4d2430cfba8..66d77d1c5518 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -114,7 +114,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -1739,7 +1739,6 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) ierr = nc_def_dim(file->fh, name, (size_t)len, idp); #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ @@ -1872,63 +1871,64 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, * @param varid the variable ID. * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_inq_var_fill (int ncid, int varid, int *no_fill, void *fill_value) +int PIOc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep) { - int ierr; - int msg; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ - iosystem_desc_t *ios; - file_desc_t *file; - char *errstr; - errstr = NULL; - ierr = PIO_NOERR; + LOG((1, "PIOc_inq ncid = %d", ncid)); - file = pio_get_file_from_id(ncid); - if(file == NULL) + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_INQ_VAR_FILL; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_VAR_FILL; + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_value);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_value);; - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_valuep); +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_valuep); +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Broadcast results to all tasks. Ignore NULL parameters. */ + if (!ierr) + if (fill_valuep) + if ((mpierr = MPI_Bcast(fill_valuep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); - mpierr = MPI_Bcast(fill_value, 1, MPI_INT, ios->ioroot, ios->my_comm); - if(errstr != NULL) free(errstr); return ierr; } From b61b5a3818c196b9de102b3af70d81c35edfd8eb Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 10:58:22 -0400 Subject: [PATCH 63/83] more async changes --- src/clib/pio_nc_async.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 66d77d1c5518..dd3ec9775afb 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1949,15 +1949,15 @@ int PIOc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep) */ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) { - iosystem_desc_t *ios; - file_desc_t *file; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ PIO_Offset attlen, typelen; nc_type atttype; - int ierr = PIO_NOERR; - int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ /* User must provide a name and destination pointer. */ - if (!name || !ip) + if (!name || !ip || strlen(name) > NC_MAX_NAME) return PIO_EINVAL; LOG((1, "PIOc_get_att ncid %d varid %d name %s", ncid, varid, name)); @@ -1985,7 +1985,6 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) return ierr; } } - /* If async is in use, and this is not an IO task, bcast the * parameters and the attribute and type information we fetched. */ From a5d6df3304a6bf5ab09e155685cc86864de31c12 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:00:09 -0400 Subject: [PATCH 64/83] more async changes --- src/clib/pio_nc_async.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index dd3ec9775afb..37a828dd6a63 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2035,30 +2035,15 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_att(file->fh, varid, name, ip); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if (ios->io_rank == 0) - ierr = nc_get_att(file->fh, varid, name, ip); - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_get_att(file->fh, varid, name, ip); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_get_att(file->fh, varid, name, ip); +#endif /* _NETCDF */ } - LOG((2, "PIOc_get_att called netcdf layer ierr = %d", ierr)); /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) @@ -2068,14 +2053,12 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* Broadcast results to all tasks. */ if (!ierr) { - LOG((2, "PIOc_get_att broadcasting att data")); if ((mpierr = MPI_Bcast(ip, (int)attlen * typelen, MPI_BYTE, ios->ioroot, ios->my_comm))) { check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; } - LOG((2, "PIOc_get_att done broadcasting att data")); } return ierr; } From 7ec04777fedd1ae3ada51dbe435d7487841eae96 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:01:56 -0400 Subject: [PATCH 65/83] more async changes --- src/clib/pio_nc_async.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 37a828dd6a63..7ac27d02f9d9 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -2152,34 +2152,22 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { - switch (file->iotype) - { -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); - } - break; -#endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) ierr = ncmpi_put_att(file->fh, varid, name, xtype, len, op); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); +#endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); return ierr; From be7b7b41e1477f3b0fa42c08ea9147d016bf25c6 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:11:02 -0400 Subject: [PATCH 66/83] more async changes --- src/clib/pio_nc_async.c | 46 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 7ac27d02f9d9..7498c426b1f1 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -867,24 +867,38 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, return PIO_EBADID; ios = file->iosystem; - /* If using async and this is not an IO task, send parameter data - * over the intercomm. */ - if(ios->async_interface && !ios->ioproc) + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) { - char xtype_present = xtypep ? true : false; - char len_present = lenp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen = strlen(name); - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } + if (!ios->ioproc) + { + char xtype_present = xtypep ? true : false; + char len_present = lenp ? true : false; + int namelen = strlen(name); + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { From cf375e13249a4de38018ee84448038043fe01396 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:31:52 -0400 Subject: [PATCH 67/83] more async changes --- src/clib/pio.h | 4 +- src/clib/pio_file.c | 2 +- src/clib/pio_nc_async.c | 194 ++++++++++++++++++++++------------------ 3 files changed, 112 insertions(+), 88 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 596e10c0e29c..ffcb2385566a 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -413,8 +413,8 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp); int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp); int PIOc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_level); -int PIOc_inq_var_deflate(int ncid, int varid, int *shufflep, - int *deflatep, int *deflate_levelp); +int PIOc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, + int *deflate_levelp); int PIOc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp); int PIOc_def_var_chunking(int ncid, int varid, int storage, const PIO_Offset *chunksizesp); int PIOc_inq_var_chunking(int ncid, int varid, int *storagep, PIO_Offset *chunksizesp); diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index 03cce3e9c255..b3e8f9dc021e 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -462,7 +462,7 @@ int PIOc_deletefile(const int iosysid, const char filename[]) /** * @name PIOc_sync */ -int PIOc_sync (int ncid) +int PIOc_sync(int ncid) { int ierr; int msg; diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 7498c426b1f1..b3e31fa57ffe 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -114,7 +114,10 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -269,7 +272,10 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -350,7 +356,10 @@ int PIOc_inq_format (int ncid, int *formatp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -437,7 +446,10 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -555,7 +567,10 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ @@ -660,7 +675,10 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ @@ -819,7 +837,10 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -915,7 +936,10 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ @@ -1023,7 +1047,10 @@ int PIOc_inq_attname(int ncid, int varid, int attnum, char *name) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -1120,7 +1147,10 @@ int PIOc_inq_attid(int ncid, int varid, const char *name, int *idp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ @@ -1211,7 +1241,10 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); return ierr; @@ -1295,7 +1328,10 @@ int PIOc_rename_var(int ncid, int varid, const char *name) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); return ierr; @@ -1384,7 +1420,10 @@ int PIOc_rename_att (int ncid, int varid, const char *name, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); LOG((2, "PIOc_rename_att succeeded")); @@ -1411,10 +1450,9 @@ int PIOc_del_att(int ncid, int varid, const char *name) file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - int namelen = strlen(name); /** Length of name string. */ /* User must provide name of correct length. */ - if (!name || namelen > NC_MAX_NAME) + if (!name || strlen(name) > NC_MAX_NAME) return PIO_EINVAL; LOG((1, "PIOc_del_att ncid = %d varid = %d name = %s", ncid, varid, name)); @@ -1430,6 +1468,7 @@ int PIOc_del_att(int ncid, int varid, const char *name) if (!ios->ioproc) { int msg = PIO_MSG_DEL_ATT; + int namelen = strlen(name); /** Length of name string. */ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -1465,7 +1504,10 @@ int PIOc_del_att(int ncid, int varid, const char *name) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); LOG((2, "PIOc_del_att succeeded")); @@ -1536,34 +1578,29 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); LOG((2, "PIOc_set_fill succeeded")); return ierr; } -/** - * @ingroup PIOc_enddef - * The PIO-C interface for the NetCDF function nc_enddef. - * - * This routine is called collectively by all tasks in the communicator - * ios.union_comm. For more information on the underlying NetCDF commmand - * please read about this function in the NetCDF documentation at: - * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html - * - * @param ncid the ncid of the open file, obtained from - * PIOc_openfile() or PIOc_createfile(). - * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling - */ -int PIOc_enddef(int ncid) +/** This is an internal function that handles both PIOc_enddef and + * PIOc_redef. + * @param ncid the ncid of the file to enddef or redef + * @param is_enddef set to non-zero for enddef, 0 for redef. + * @returns PIO_NOERR on success, error code on failure. */ +int pioc_change_def(int ncid, int is_enddef) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - LOG((1, "PIOc_enddef ncid = %d", ncid)); + LOG((1, "pioc_change_def ncid = %d is_enddef = %d", ncid, is_enddef)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) @@ -1575,7 +1612,7 @@ int PIOc_enddef(int ncid) { if (!ios->ioproc) { - int msg = PIO_MSG_ENDDEF; + int msg = is_enddef ? PIO_MSG_ENDDEF : PIO_MSG_REDEF; if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); @@ -1595,23 +1632,49 @@ int PIOc_enddef(int ncid) { #ifdef _PNETCDF if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_enddef(file->fh); + if (is_enddef) + ierr = ncmpi_enddef(file->fh); + else + ierr = ncmpi_redef(file->fh); #endif /* _PNETCDF */ #ifdef _NETCDF if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_enddef(file->fh); + if (is_enddef) + ierr = nc_enddef(file->fh); + else + ierr = nc_redef(file->fh); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); - LOG((2, "PIOc_enddef succeeded")); return ierr; } +/** + * @ingroup PIOc_enddef + * The PIO-C interface for the NetCDF function nc_enddef. + * + * This routine is called collectively by all tasks in the communicator + * ios.union_comm. For more information on the underlying NetCDF commmand + * please read about this function in the NetCDF documentation at: + * http://www.unidata.ucar.edu/software/netcdf/docs/group__datasets.html + * + * @param ncid the ncid of the open file, obtained from + * PIOc_openfile() or PIOc_createfile(). + * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling + */ +int PIOc_enddef(int ncid) +{ + return pioc_change_def(ncid, 1); +} + /** * @ingroup PIOc_redef * The PIO-C interface for the NetCDF function nc_redef. @@ -1625,60 +1688,9 @@ int PIOc_enddef(int ncid) * PIOc_openfile() or PIOc_createfile(). * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ -int PIOc_redef (int ncid) +int PIOc_redef(int ncid) { - iosystem_desc_t *ios; /** Pointer to io system information. */ - file_desc_t *file; /** Pointer to file information. */ - int ierr = PIO_NOERR; /** Return code from function calls. */ - int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ - - LOG((1, "PIOc_redef ncid = %d", ncid)); - - /* Find the info about this file. */ - if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; - ios = file->iosystem; - - /* If async is in use, and this is not an IO task, bcast the parameters. */ - if (ios->async_interface) - { - if (!ios->ioproc) - { - int msg = PIO_MSG_ENDDEF; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - } - - /* If this is an IO task, then call the netCDF function. */ - if (ios->ioproc) - { -#ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_redef(file->fh); -#endif /* _PNETCDF */ -#ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_redef(file->fh); -#endif /* _NETCDF */ - } - - /* Broadcast and check the return code. */ - if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - check_netcdf(file, ierr, __FILE__, __LINE__); - - LOG((2, "PIOc_redef succeeded")); - return ierr; + return pioc_change_def(ncid, 0); } /** @@ -1757,7 +1769,10 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr2, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -1859,7 +1874,10 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ @@ -1934,7 +1952,10 @@ int PIOc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -2061,7 +2082,10 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); return PIO_EIO; + } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. */ From 7e01a846314168cbe3a55977baa8531f794aaa82 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:41:33 -0400 Subject: [PATCH 68/83] got redef function working with async --- src/clib/pio_msg.c | 16 +++++++--------- tests/unit/test_intercomm.c | 8 ++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 5c2f511da501..be2b75ea8cea 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -711,26 +711,23 @@ int sync_file_handler(iosystem_desc_t *ios) * @param ios pointer to the iosystem_desc_t. * @return PIO_NOERR for success, error code otherwise. */ -int enddef_file_handler(iosystem_desc_t *ios) +int change_def_file_handler(iosystem_desc_t *ios, int msg) { int ncid; int mpierr; int ret; - int my_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - LOG((1, "%d enddef_file_handler\n", my_rank)); + LOG((1, "change_def_file_handler")); /* Get the parameters for this function that the comp master * task is broadcasting. */ if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; - /* Call the sync file function. */ - if ((ret = PIOc_enddef(ncid))) - return ret; + /* Call the function. */ + ret = (msg == PIO_MSG_ENDDEF) ? PIOc_enddef(ncid) : PIOc_redef(ncid); - LOG((1, "%d enddef_file_handler succeeded!\n", my_rank)); + LOG((1, "change_def_file_handler succeeded!")); return PIO_NOERR; } @@ -1281,7 +1278,8 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) sync_file_handler(my_iosys); break; case PIO_MSG_ENDDEF: - enddef_file_handler(my_iosys); + case PIO_MSG_REDEF: + change_def_file_handler(my_iosys, msg); break; case PIO_MSG_OPEN_FILE: open_file_handler(my_iosys); diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index d45e14431ae9..172c3ca760bf 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -390,6 +390,14 @@ main(int argc, char **argv) if (verbose) printf("%d test_intercomm file created ncid = %d\n", my_rank, ncid); + /* /\* End define mode, then re-enter it. *\/ */ + if ((ret = PIOc_enddef(ncid))) + ERR(ret); + if (verbose) + printf("%d test_intercomm calling redef\n", my_rank); + if ((ret = PIOc_redef(ncid))) + ERR(ret); + /* Test the inq_format function. */ int myformat; if ((ret = PIOc_inq_format(ncid, &myformat))) From 68c3068a99f9a1b3f4771cac34418053e3516f0e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 11:50:18 -0400 Subject: [PATCH 69/83] created internal function because pnetcdf does not have inq_type() --- src/clib/pio_nc_async.c | 70 +++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index b3e31fa57ffe..30046e929aa1 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -180,6 +180,45 @@ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) return PIOc_inq(ncid, NULL, NULL, unlimdimidp, NULL); } +/** Internal function to provide inq_type function for pnetcdf. */ +int pioc_pnetcdf_inq_type(int ncid, nc_type xtype, char *name, + PIO_Offset *sizep) +{ + int typelen; + char typename[NC_MAX_NAME + 1]; + + switch (xtype) + { + case NC_UBYTE: + case NC_BYTE: + case NC_CHAR: + typelen = 1; + break; + case NC_SHORT: + case NC_USHORT: + typelen = 2; + break; + case NC_UINT: + case NC_INT: + case NC_FLOAT: + typelen = 4; + break; + case NC_UINT64: + case NC_INT64: + case NC_DOUBLE: + typelen = 8; + break; + } + + /* If pointers were supplied, copy results. */ + if (sizep) + *sizep = typelen; + if (name) + strcpy(name, "some type"); + + return PIO_NOERR; +} + /** * @ingroup PIOc_typelen * The PIO-C interface for the NetCDF function nctypelen. @@ -227,41 +266,12 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) check_mpi(file, mpierr, __FILE__, __LINE__); } - /* If this is an IO task, then call the netCDF function. */ /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF if (file->iotype == PIO_IOTYPE_PNETCDF) - { - switch (xtype) - { - case NC_UBYTE: - case NC_BYTE: - case NC_CHAR: - typelen = 1; - break; - case NC_SHORT: - case NC_USHORT: - typelen = 2; - break; - case NC_UINT: - case NC_INT: - case NC_FLOAT: - typelen = 4; - break; - case NC_UINT64: - case NC_INT64: - case NC_DOUBLE: - typelen = 8; - break; - } - - if (sizep) - *sizep = typelen; - if (name) - strcpy(name, "some type"); - } + ierr = pioc_pnetcdf_inq_type(ncid, xtype, name, sizep); #endif /* _PNETCDF */ #ifdef _NETCDF if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) From 5f597a8b3813f9859654034f86796f3577407f40 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 12:03:08 -0400 Subject: [PATCH 70/83] further development of async code --- src/clib/pio_internal.h | 4 ++-- src/clib/pio_nc_async.c | 42 ++++++++++++++++------------------------- src/clib/pioc_support.c | 5 ++++- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 3425517818a3..412b3d990557 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -152,8 +152,8 @@ typedef struct pio_swapm_defaults void flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk); void piomemerror(iosystem_desc_t ios, size_t req, char *fname, const int line); void compute_maxaggregate_bytes(const iosystem_desc_t ios, io_desc_t *iodesc); - void check_mpi(file_desc_t *file, const int mpierr, const char *filename, - const int line); + int check_mpi(file_desc_t *file, const int mpierr, const char *filename, + const int line); #ifdef BGQ void identity(MPI_Comm comm, int *iotask); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 30046e929aa1..c8e856006229 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -74,12 +74,11 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast unlimdimid_present = %d", unlimdimid_present)); } /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -114,10 +113,7 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -125,19 +121,19 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, { if (ndimsp) if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if (nvarsp) if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if (ngattsp) if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if (unlimdimidp) if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -225,7 +221,6 @@ int pioc_pnetcdf_inq_type(int ncid, nc_type xtype, char *name, */ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) { - int msg = PIO_MSG_INQ_TYPE; /** Message for async notification. */ iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ int ierr = PIO_NOERR; /** Return code from function calls. */ @@ -244,6 +239,7 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) { if (!ios->ioproc) { + int msg = PIO_MSG_INQ_TYPE; /** Message for async notification. */ char name_present = name ? true : false; char size_present = sizep ? true : false; @@ -262,7 +258,7 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -282,10 +278,7 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -297,13 +290,13 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) if (ios->iomaster) slen = strlen(name); if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } if (sizep) if ((mpierr = MPI_Bcast(sizep , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -339,14 +332,14 @@ int PIOc_inq_format (int ncid, int *formatp) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); if (!mpierr) - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&format_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); } /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -366,10 +359,7 @@ int PIOc_inq_format (int ncid, int *formatp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -377,7 +367,7 @@ int PIOc_inq_format (int ncid, int *formatp) { if (formatp) if ((mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index 579a9e64fc6f..e08a019c5179 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -193,8 +193,9 @@ void pioassert(_Bool expression, const char *msg, const char *fname, const int l @param mpierr the MPI return code to handle @param filename the name of the code file where error occured. @param line the line of code where error occured. + @return PIO_NOERR for no error, otherwise PIO_EIO. */ -void check_mpi(file_desc_t *file, const int mpierr, const char *filename, +int check_mpi(file_desc_t *file, const int mpierr, const char *filename, const int line) { if (mpierr) @@ -209,7 +210,9 @@ void check_mpi(file_desc_t *file, const int mpierr, const char *filename, /* Handle all MPI errors as PIO_EIO. */ check_netcdf(file, PIO_EIO, filename, line); + return PIO_EIO; } + return PIO_NOERR; } /** Check the result of a netCDF API call. From 46ba2cc6131823451225bd06044c3c5907acad60 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 17 May 2016 12:06:45 -0400 Subject: [PATCH 71/83] further development of async code --- src/clib/pio_nc_async.c | 57 ++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index c8e856006229..5d303a90be25 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -427,7 +427,7 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -446,10 +446,7 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ @@ -461,14 +458,14 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) if (ios->iomaster) slen = strlen(name); if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } if (lenp) if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -548,7 +545,7 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -567,17 +564,14 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) if (idp) if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -650,7 +644,7 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -661,24 +655,23 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, if (file->iotype == PIO_IOTYPE_PNETCDF) { ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); - ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; + if (!ierr) + ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; } #endif /* _PNETCDF */ #ifdef _NETCDF if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) { ierr = nc_inq_varndims(file->fh, varid, &ndims); - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); + if (!ierr) + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); } #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ @@ -690,30 +683,30 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, if(ios->iomaster) slen = strlen(name); if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } if (xtypep) if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if (ndimsp) { if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); file->varlist[varid].ndims = (*ndimsp); } if (dimidsp) { if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } if (nattsp) if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -781,13 +774,13 @@ int PIOc_inq_varnatts (int ncid, int varid, int *nattsp) */ int PIOc_inq_varid (int ncid, const char *name, int *varidp) { - iosystem_desc_t *ios; - file_desc_t *file; - int ierr = PIO_NOERR; + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ /* Caller must provide name. */ - if (!name) + if (!name || strlen(name) > NC_MAX_NAME) return PIO_EINVAL; /* Get file info based on ncid. */ From cea8e392d6d2af0f398b1f8897d36ca1bbe8bea3 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 18 May 2016 10:08:20 -0400 Subject: [PATCH 72/83] first pass at PIOc_put_vars_tc() --- src/clib/pio.h | 4 +- src/clib/pio_nc_async.c | 12 +- src/clib/pio_put_nc_async.c | 436 +++++++++++++++++++++++++++++------- 3 files changed, 362 insertions(+), 90 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index ffcb2385566a..d7710f9f4aed 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -592,10 +592,11 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_put_vars_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const long long *op); int PIOc_put_vara_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const double *op); int PIOc_put_vars (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype); + int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], nc_type xtype, const void *buf); int PIOc_put_var_uchar (int ncid, int varid, const unsigned char *op); int PIOc_put_var_long (int ncid, int varid, const long *op); int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const long long *op); - int PIOc_get_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], int *buf); + int PIOc_get_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], int *buf); int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset index[], float *buf); int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset index[], short *buf); int PIOc_get_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], int *buf); @@ -647,6 +648,7 @@ int PIOc_set_blocksize(const int newblocksize); int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], char *buf); int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset index[], unsigned char *buf); int PIOc_get_vars (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype); + int PIOc_get_vars_tc(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], nc_type xtype, void *buf); int PIOc_get_varm_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], short *buf); int PIOc_get_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned long long *buf); int PIOc_get_var_schar (int ncid, int varid, signed char *buf); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 5d303a90be25..a8db152c91ff 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -1828,7 +1828,7 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); if (!mpierr) - mpierr = MPI_Bcast(&(file->fh), 1, MPI_INT, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast(&(ncid), 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -1852,15 +1852,19 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, { #ifdef _PNETCDF if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); + ierr = ncmpi_def_var(ncid, name, xtype, ndims, dimidsp, varidp); #endif /* _PNETCDF */ #ifdef _NETCDF if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_def_var(file->fh, name, xtype, ndims, dimidsp, varidp); + ierr = nc_def_var(ncid, name, xtype, ndims, dimidsp, varidp); #ifdef _NETCDF4 /* For netCDF-4 serial files, turn on compression for this variable. */ if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C) - ierr = nc_def_var_deflate(file->fh, *varidp, 0, 1, 1); + ierr = nc_def_var_deflate(ncid, *varidp, 0, 1, 1); + + /* For netCDF-4 parallel files, set parallel access to collective. */ + if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4P) + ierr = nc_var_par_access(ncid, *varidp, NC_COLLECTIVE); #endif /* _NETCDF4 */ #endif /* _NETCDF */ } diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index dd9693a3abe2..74a52328eebb 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -1,14 +1,357 @@ #include #include -/// -/// PIO interface to nc_put_vars_uchar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned char *op) +/** + * Internal PIO function which provides a type-neutral interface to + * nc_put_vars + * + * This routine is called collectively by all tasks in the + * communicator ios.union_comm. + * + * @param ncid identifies the netCDF file + * @param varid the variable ID number + + * @param start[] an array of start indicies (must have same number of + * entries as variable has dimensions). If NULL, indices of 0 will be + * used. + * + * @param count[] an array of counts (must have same number of entries + * as variable has dimensions). If NULL, counts matching the size of + * the variable will be used. + * + * @param stride[] an array of strides (must have same number of + * entries as variable has dimensions). If NULL, strides of 1 will be + * used. + * + * @param xtype the netCDF type of the data being passed in buf. Data + * will be automatically covnerted from this type to the type of the + * variable being written to. + * + * @param buf pointer to the data to be written. + * + * @return PIO_NOERR on success, error code otherwise. + */ +int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, nc_type xtype, const void *buf) +{ + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ + int ndims; /** The number of dimensions in the variable. */ + int *dimids; /** The IDs of the dimensions for this variable. */ + PIO_Offset typelen; /** Size (in bytes) of the data type of data in buf. */ + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + LOG((1, "PIOc_put_vars_tc ncid = %d varid = %d start = %d count = %d " + "stride = %d xtype = %d", ncid, start, count, stride, xtype)); + + /* User must provide some data. */ + if (!buf) + return PIO_EINVAL; + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* Run these on all tasks if async is not in use, but only on + * non-IO tasks if async is in use. */ + if (!ios->async_interface || !ios->ioproc) + { + /* Get the length of the data type. */ + if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Get the number of dims for this var. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + PIO_Offset dimlen[ndims]; + + /* If no count array was passed, we need to know the dimlens + * so we can calculate how many data elements are in the + * buf. */ + if (!count) + { + int dimid[ndims]; + + /* Get the dimids for this var. */ + if ((ierr = PIOc_inq_vardimid(ncid, varid, dimid))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Get the length of each dimension. */ + for (int vd = 0; vd < ndims; vd++) + if ((ierr = PIOc_inq_dimlen(ncid, dimid[vd], &dimlen[vd]))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + } + + /* Figure out the real start, count, and stride arrays. (The + * user may have passed in NULLs.) */ + PIO_Offset rstart[ndims], rcount[ndims], rstride[ndims]; + for (int vd = 0; vd < ndims; vd++) + { + rstart[vd] = start ? start[vd] : 0; + rcount[vd] = count ? count[vd] : dimlen[vd]; + rstride[vd] = stride ? stride[vd] : 1; + } + + /* How many elements in buf? */ + size_t num_elem = 1; + for (int vd = 0; vd < ndims; vd++) + num_elem *= (rcount[vd] - rstart[vd])/rstride[vd]; + LOG((2, "PIOc_put_vars_tc num_elem = %d", num_elem)); + } + + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_PUT_VARS; + char start_present = start ? true : false; + char count_present = count ? true : false; + char stride_present = stride ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&ncid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && start_present) + mpierr = MPI_Bcast(&start, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && count_present) + mpierr = MPI_Bcast(&count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && stride_present) + mpierr = MPI_Bcast(&stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + + /* /\* Broadcast values currently only known on computation tasks to IO tasks. *\/ */ + /* if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->comproot, ios->my_comm))) */ + /* check_mpi(file, mpierr, __FILE__, __LINE__); */ + /* if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) */ + /* check_mpi(file, mpierr, __FILE__, __LINE__); */ + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { +#ifdef _PNETCDF + if (file->iotype == PIO_IOTYPE_PNETCDF) + { + vdesc = file->varlist + varid; + if (vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0) + vdesc->request = realloc(vdesc->request, + sizeof(int) * (vdesc->nreqs + PIO_REQUEST_ALLOC_CHUNK)); + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank == 0) + switch(xtype) + { + case NC_BYTE: + ierr = ncmpi_bput_vars_schar(ncid, varid, start, count, stride, buf, request); + break; + case NC_CHAR: + ierr = ncmpi_bput_vars_text(ncid, varid, start, count, stride, buf, request); + break; + case NC_SHORT: + ierr = ncmpi_bput_vars_short(ncid, varid, start, count, stride, buf, request); + break; + case NC_INT: + ierr = ncmpi_bput_vars_int(ncid, varid, start, count, stride, buf, request); + break; + case NC_FLOAT: + ierr = ncmpi_bput_vars_float(ncid, varid, start, count, stride, buf, request); + break; + case NC_DOUBLE: + ierr = ncmpi_bput_vars_double(ncid, varid, start, count, stride, buf, request); + break; + case NC_INT64: + ierr = ncmpi_bput_vars_longlong(ncid, varid, start, count, stride, buf, request); + break; + default: + LOG((0, "Unknown type for pnetcdf file! xtype = %d", xtype)); + + } + else + *request = PIO_REQ_NULL; + + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + switch(xtype) + { + case NC_BYTE: + ierr = nc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_CHAR: + ierr = nc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_SHORT: + ierr = nc_put_vars_short(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT: + ierr = nc_put_vars_int(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_FLOAT: + ierr = nc_put_vars_float(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_DOUBLE: + ierr = nc_put_vars_double(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; +#ifdef _NETCDF4 + case NC_UBYTE: + ierr = nc_put_vars_uchar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_USHORT: + ierr = nc_put_vars_ushort(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT: + ierr = nc_put_vars_uint(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT64: + ierr = nc_put_vars_longlong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT64: + ierr = nc_put_vars_ulonglong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + /* case NC_STRING: */ + /* ierr = nc_put_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ + /* (ptrdiff_t *)stride, (void *)buf); */ + /* break; */ + default: + ierr = nc_put_vars(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); +#endif /* _NETCDF4 */ + } +#endif /* _NETCDF */ + } + + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if (ierr) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + return ierr; +} + +/** + * PIO interface to nc_put_vars + * + * This routine is called collectively by all tasks in the + * communicator ios.union_comm. + + * Refer to the + * netcdf documentation. */ +int PIOc_put_vars(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const PIO_Offset stride[], const void *buf, PIO_Offset bufcount, + MPI_Datatype buftype) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARS; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], + const PIO_Offset count[], const PIO_Offset stride[], + const unsigned char *op) { int ierr; int msg; @@ -4771,83 +5114,6 @@ int PIOc_put_vara_double (int ncid, int varid, const PIO_Offset start[], const P return ierr; } -/// -/// PIO interface to nc_put_vars -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} /// /// PIO interface to nc_put_var_uchar From 58b9466f8c56fb5c67823a4999eed5c10cda4609 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 18 May 2016 13:17:21 -0400 Subject: [PATCH 73/83] put_vars with async --- src/clib/pio_msg.c | 154 +++++++++++++++++++++++++++++++++--- src/clib/pio_put_nc_async.c | 13 ++- 2 files changed, 157 insertions(+), 10 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index be2b75ea8cea..ce26b78154ec 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -579,6 +579,145 @@ int att_get_handler(iosystem_desc_t *ios) return PIO_NOERR; } +/** Handle var put operations. This code only runs on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int put_vars_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int mpierr; + int ierr; + char *name; + int namelen; + PIO_Offset typelen; /** Length (in bytes) of this type. */ + nc_type xtype; /** Type of the data being written. */ + char start_present, count_present, stride_present; + PIO_Offset *startp = NULL, *countp = NULL, *stridep = NULL; + int ndims; /** Number of dimensions. */ + void *buf; /** Buffer for data storage. */ + size_t num_elem; /** Number of data elements in the buffer. */ + + LOG((1, "put_vars_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + + /* Now we know how big to make these arrays. */ + PIO_Offset start[ndims], count[ndims], stride[ndims]; + + if ((mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && start_present) + if ((mpierr = MPI_Bcast(start, ndims, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && count_present) + if ((mpierr = MPI_Bcast(count, ndims, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && stride_present) + if ((mpierr = MPI_Bcast(stride, ndims, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&xtype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + + /* Allocate room for our data. */ + if (!(buf = malloc(num_elem * typelen))) + return PIO_ENOMEM; + + /* Get the data. */ + if ((mpierr = MPI_Bcast(buf, num_elem * typelen, MPI_BYTE, 0, ios->intercomm))) + return PIO_EIO; + + LOG((1, "att_vars_handler ncid = %d varid = %d ndims = %d start_present = %d " + "count_present = %d stride_present = %d xtype = %d num_elem = %d typelen = %d", + ncid, varid, ndims, start_present, count_present, stride_present, xtype, + num_elem, typelen)); + + /* Set the non-NULL pointers. */ + if (start_present) + startp = start; + if (count_present) + countp = count; + if (stride_present) + stridep = stride; + + /* Call the function to write the data. */ + switch(xtype) + { + case NC_BYTE: + ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_CHAR: + ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_SHORT: + ierr = PIOc_put_vars_short(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT: + ierr = PIOc_put_vars_int(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_FLOAT: + ierr = PIOc_put_vars_float(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_DOUBLE: + ierr = PIOc_put_vars_double(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; +#ifdef _NETCDF4 + case NC_UBYTE: + ierr = PIOc_put_vars_uchar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_USHORT: + ierr = PIOc_put_vars_ushort(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT: + ierr = PIOc_put_vars_uint(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT64: + ierr = PIOc_put_vars_longlong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT64: + ierr = PIOc_put_vars_ulonglong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + /* case NC_STRING: */ + /* ierr = PIOc_put_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ + /* (ptrdiff_t *)stride, (void *)buf); */ + /* break; */ + /* default:*/ + /* ierr = PIOc_put_vars(ncid, varid, (size_t *)start, (size_t *)count, */ + /* (ptrdiff_t *)stride, buf); */ +#endif /* _NETCDF4 */ + } + + return PIO_NOERR; +} + /** Do an inq_var on a netCDF variable. This function is only run on * IO tasks. * @@ -1338,6 +1477,12 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_INQ_ATTID: inq_attid_handler(my_iosys); break; + case PIO_MSG_GET_VARS: + var_handler(my_iosys, msg); + break; + case PIO_MSG_PUT_VARS: + put_vars_handler(my_iosys); + break; case PIO_MSG_INITDECOMP_DOF: initdecomp_dof_handler(my_iosys); break; @@ -1350,15 +1495,6 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) case PIO_MSG_SETERRORHANDLING: seterrorhandling_handler(my_iosys); break; - case PIO_MSG_GET_VAR1: - var_handler(my_iosys, msg); - break; - case PIO_MSG_PUT_VAR1: - var_handler(my_iosys, msg); - break; - case PIO_MSG_PUT_VARA: - vara_handler(my_iosys, msg); - break; case PIO_MSG_FREEDECOMP: freedecomp_handler(my_iosys); break; diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index 74a52328eebb..e5ae038a4c3a 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -41,6 +41,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off int ndims; /** The number of dimensions in the variable. */ int *dimids; /** The IDs of the dimensions for this variable. */ PIO_Offset typelen; /** Size (in bytes) of the data type of data in buf. */ + size_t num_elem = 1; /** Number of data elements in the buffer. */ var_desc_t *vdesc; PIO_Offset usage; int *request; @@ -99,7 +100,6 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off } /* How many elements in buf? */ - size_t num_elem = 1; for (int vd = 0; vd < ndims; vd++) num_elem *= (rcount[vd] - rstart[vd])/rstride[vd]; LOG((2, "PIOc_put_vars_tc num_elem = %d", num_elem)); @@ -122,6 +122,8 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off mpierr = MPI_Bcast(&ncid, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && start_present) @@ -136,6 +138,15 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off mpierr = MPI_Bcast(&stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + + /* Send the data. */ + if (!mpierr) + mpierr = MPI_Bcast(buf, num_elem * typelen, MPI_BYTE, ios->compmaster, + ios->intercomm); } /* Handle MPI errors. */ From fdd7d8b966562352e88e775958d9175217516358 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 23 May 2016 16:45:30 -0400 Subject: [PATCH 74/83] more development of async code --- src/clib/pio_msg.c | 18 ++++++++++-------- src/clib/pio_put_nc_async.c | 7 ++++++- tests/unit/test_intercomm.c | 6 ++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index ce26b78154ec..126efaace43c 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -617,17 +617,17 @@ int put_vars_handler(iosystem_desc_t *ios) if ((mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; if (!mpierr && start_present) - if ((mpierr = MPI_Bcast(start, ndims, MPI_CHAR, 0, ios->intercomm))) + if ((mpierr = MPI_Bcast(start, ndims, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; if ((mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; if (!mpierr && count_present) - if ((mpierr = MPI_Bcast(count, ndims, MPI_CHAR, 0, ios->intercomm))) + if ((mpierr = MPI_Bcast(count, ndims, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; if ((mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; if (!mpierr && stride_present) - if ((mpierr = MPI_Bcast(stride, ndims, MPI_CHAR, 0, ios->intercomm))) + if ((mpierr = MPI_Bcast(stride, ndims, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; if ((mpierr = MPI_Bcast(&xtype, 1, MPI_INT, 0, ios->intercomm))) return PIO_EIO; @@ -635,6 +635,10 @@ int put_vars_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; + LOG((1, "put_vars_handler ncid = %d varid = %d ndims = %d start_present = %d " + "count_present = %d stride_present = %d xtype = %d num_elem = %d typelen = %d", + ncid, varid, ndims, start_present, count_present, stride_present, xtype, + num_elem, typelen)); /* Allocate room for our data. */ if (!(buf = malloc(num_elem * typelen))) @@ -643,12 +647,10 @@ int put_vars_handler(iosystem_desc_t *ios) /* Get the data. */ if ((mpierr = MPI_Bcast(buf, num_elem * typelen, MPI_BYTE, 0, ios->intercomm))) return PIO_EIO; - - LOG((1, "att_vars_handler ncid = %d varid = %d ndims = %d start_present = %d " - "count_present = %d stride_present = %d xtype = %d num_elem = %d typelen = %d", - ncid, varid, ndims, start_present, count_present, stride_present, xtype, - num_elem, typelen)); + for (int e = 0; e < num_elem; e++) + LOG((2, "element %d = %d", e, ((int *)buf)[e])); + /* Set the non-NULL pointers. */ if (start_present) startp = start; diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index e5ae038a4c3a..9938ba09548f 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -104,7 +104,8 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off num_elem *= (rcount[vd] - rstart[vd])/rstride[vd]; LOG((2, "PIOc_put_vars_tc num_elem = %d", num_elem)); } - + + sleep(2); /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -142,6 +143,9 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_put_vars_tc ncid = %d varid = %d ndims = %d start_present = %d " + "count_present = %d stride_present = %d xtype = %d num_elem = %d", ncid, varid, + ndims, start_present, count_present, stride_present, xtype, num_elem)); /* Send the data. */ if (!mpierr) @@ -149,6 +153,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off ios->intercomm); } + sleep(2); /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) return check_mpi(file, mpierr2, __FILE__, __LINE__); diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 172c3ca760bf..ca8f7aa7a3a4 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -495,13 +495,15 @@ main(int argc, char **argv) if ((ret = PIOc_enddef(ncid))) ERR(ret); - /* Write some data. */ + /* /\* Write some data. *\/ */ /* for (int i = 0; i < LOCAL_DIM_LEN; i++) */ /* data[i] = my_rank; */ /* if (verbose) */ /* printf("%d test_intercomm writing data\n", my_rank); */ /* start[0] = !my_rank ? 0 : 2; */ - /* if ((ret = PIOc_put_vara_int(ncid, varid, start, count, data))) */ + /* count[0] = 2; */ + /* sleep(2); */ + /* if ((ret = PIOc_put_vars_tc(ncid, varid, start, count, NULL, NC_INT, data))) */ /* ERR(ret); */ /* Close the file. */ From d6bfc031bd36ccd98f9a1c8ecfad6eab9b542484 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 23 May 2016 18:10:33 -0400 Subject: [PATCH 75/83] more development of async changes --- src/clib/CMakeLists.txt | 2 +- src/clib/pio_msg.c | 65 +- src/clib/pio_put_nc_async.c | 2514 +++++------------------------------ tests/unit/test_intercomm.c | 30 +- 4 files changed, 383 insertions(+), 2228 deletions(-) diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 475aa6196a41..4344261aa281 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -23,7 +23,7 @@ set (PIO_GENNC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/pio_put_nc.c ${CMAKE_CURRENT_BINARY_DIR}/pio_nc.c) if (PIO_ENABLE_ASYNC) - set (PIO_ADDL_SRCS pio_nc_async.c pio_put_nc_async.c pio_get_nc_async.c pio_msg.c) + set (PIO_ADDL_SRCS pio_nc_async.c pio_put_nc_async.c pio_get_nc_async.c pio_msg.c pio_varm.c) else () set (PIO_ADDL_SRCS ${PIO_GENNC_SRCS}) endif () diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 126efaace43c..9c509398ca2a 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -617,8 +617,11 @@ int put_vars_handler(iosystem_desc_t *ios) if ((mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; if (!mpierr && start_present) + { if ((mpierr = MPI_Bcast(start, ndims, MPI_OFFSET, 0, ios->intercomm))) return PIO_EIO; + LOG((1, "put_vars_handler getting start[0] = %d ndims = %d", start[0], ndims)); + } if ((mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; if (!mpierr && count_present) @@ -640,6 +643,16 @@ int put_vars_handler(iosystem_desc_t *ios) ncid, varid, ndims, start_present, count_present, stride_present, xtype, num_elem, typelen)); + for (int d = 0; d < ndims; d++) + { + if (start_present) + LOG((2, "start[%d] = %d\n", d, start[d])); + if (count_present) + LOG((2, "count[%d] = %d\n", d, count[d])); + if (stride_present) + LOG((2, "stride[%d] = %d\n", d, stride[d])); + } + /* Allocate room for our data. */ if (!(buf = malloc(num_elem * typelen))) return PIO_ENOMEM; @@ -663,57 +676,57 @@ int put_vars_handler(iosystem_desc_t *ios) switch(xtype) { case NC_BYTE: - ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_CHAR: - ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_SHORT: - ierr = PIOc_put_vars_short(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_short(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_INT: - ierr = PIOc_put_vars_int(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_int(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_FLOAT: - ierr = PIOc_put_vars_float(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_float(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_DOUBLE: - ierr = PIOc_put_vars_double(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_double(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; #ifdef _NETCDF4 case NC_UBYTE: - ierr = PIOc_put_vars_uchar(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_uchar(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_USHORT: - ierr = PIOc_put_vars_ushort(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_ushort(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_UINT: - ierr = PIOc_put_vars_uint(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_uint(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_INT64: - ierr = PIOc_put_vars_longlong(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_longlong(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; case NC_UINT64: - ierr = PIOc_put_vars_ulonglong(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + ierr = PIOc_put_vars_ulonglong(ncid, varid, (size_t *)startp, (size_t *)countp, + (ptrdiff_t *)stridep, buf); break; /* case NC_STRING: */ - /* ierr = PIOc_put_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ - /* (ptrdiff_t *)stride, (void *)buf); */ + /* ierr = PIOc_put_vars_string(ncid, varid, (size_t *)startp, (size_t *)countp, */ + /* (ptrdiff_t *)stridep, (void *)buf); */ /* break; */ /* default:*/ - /* ierr = PIOc_put_vars(ncid, varid, (size_t *)start, (size_t *)count, */ - /* (ptrdiff_t *)stride, buf); */ + /* ierr = PIOc_put_vars(ncid, varid, (size_t *)startp, (size_t *)countp, */ + /* (ptrdiff_t *)stridep, buf); */ #endif /* _NETCDF4 */ } diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index 9938ba09548f..95d31c826ce6 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -1,3 +1,4 @@ +#include #include #include @@ -47,7 +48,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off int *request; LOG((1, "PIOc_put_vars_tc ncid = %d varid = %d start = %d count = %d " - "stride = %d xtype = %d", ncid, start, count, stride, xtype)); + "stride = %d xtype = %d", ncid, varid, start, count, stride, xtype)); /* User must provide some data. */ if (!buf) @@ -105,7 +106,6 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off LOG((2, "PIOc_put_vars_tc num_elem = %d", num_elem)); } - sleep(2); /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { @@ -119,6 +119,8 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off if(ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + /* Send the function parameters and associated informaiton + * to the msg handler. */ if (!mpierr) mpierr = MPI_Bcast(&ncid, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -128,15 +130,15 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off if (!mpierr) mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && start_present) - mpierr = MPI_Bcast(&start, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((PIO_Offset *)start, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && count_present) - mpierr = MPI_Bcast(&count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((PIO_Offset *)count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && stride_present) - mpierr = MPI_Bcast(&stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((PIO_Offset *)stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -146,14 +148,16 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off LOG((2, "PIOc_put_vars_tc ncid = %d varid = %d ndims = %d start_present = %d " "count_present = %d stride_present = %d xtype = %d num_elem = %d", ncid, varid, ndims, start_present, count_present, stride_present, xtype, num_elem)); + + for (int e = 0; e < num_elem; e++) + LOG((2, "PIOc_put_vars_tc element %d = %d", e, ((int *)buf)[e])); /* Send the data. */ if (!mpierr) - mpierr = MPI_Bcast(buf, num_elem * typelen, MPI_BYTE, ios->compmaster, + mpierr = MPI_Bcast((void *)buf, num_elem * typelen, MPI_BYTE, ios->compmaster, ios->intercomm); } - sleep(2); /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) return check_mpi(file, mpierr2, __FILE__, __LINE__); @@ -365,9 +369,48 @@ int PIOc_put_vars(int ncid, int varid, const PIO_Offset start[], const PIO_Offse return ierr; } +/** Interface to netCDF data write function. */ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned char *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UBYTE, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_ushort(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const PIO_Offset stride[], const unsigned short *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_USHORT, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_ulonglong(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const PIO_Offset stride[], const unsigned long long *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT64, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_uint(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned int *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_ushort(int ncid, int varid, const unsigned short *op) +{ + return PIOc_put_vars_tc(ncid, varid, NULL, NULL, NULL, NC_USHORT, op); +} + +/// +/// PIO interface to nc_put_var1_longlong +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) { int ierr; int msg; @@ -384,7 +427,7 @@ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_UCHAR; + msg = PIO_MSG_PUT_VAR1_LONGLONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -399,13 +442,13 @@ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -420,7 +463,7 @@ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_uchar(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var1_longlong(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -438,14 +481,16 @@ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], return ierr; } -/// -/// PIO interface to nc_put_vars_ushort -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset start[], + const PIO_Offset count[], const unsigned char *op) +{ + return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); +} + + +/** Interface to netCDF data write function. */ +int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset index[], const long *ip) { int ierr; int msg; @@ -462,7 +507,7 @@ int PIOc_put_vars_ushort (int ncid, int varid, const PIO_Offset start[], const P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_USHORT; + msg = PIO_MSG_PUT_VAR1_LONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -477,13 +522,13 @@ int PIOc_put_vars_ushort (int ncid, int varid, const PIO_Offset start[], const P #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; } break; #endif @@ -498,7 +543,7 @@ int PIOc_put_vars_ushort (int ncid, int varid, const PIO_Offset start[], const P request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_ushort(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var1_long(file->fh, varid, index, ip, request);; }else{ *request = PIO_REQ_NULL; } @@ -516,14 +561,33 @@ int PIOc_put_vars_ushort (int ncid, int varid, const PIO_Offset start[], const P return ierr; } +/** Interface to netCDF data write function. */ +int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const long *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_short(int ncid, int varid, const short *op) +{ + return PIOc_put_vars_short(ncid, varid, NULL, NULL, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const int *op) +{ + return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); +} + /// -/// PIO interface to nc_put_vars_ulonglong +/// PIO interface to nc_put_var1_ushort /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned long long *op) +int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const unsigned short *op) { int ierr; int msg; @@ -540,12 +604,12 @@ int PIOc_put_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], cons if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_ULONGLONG; + msg = PIO_MSG_PUT_VAR1_USHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -555,13 +619,13 @@ int PIOc_put_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], cons #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -576,7 +640,7 @@ int PIOc_put_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], cons request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_ulonglong(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var1_ushort(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -595,13 +659,37 @@ int PIOc_put_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], cons } /// -/// PIO interface to nc_put_varm +/// PIO interface to nc_put_vara_text +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const char *op) +{ + return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); +} + +/// +/// PIO interface to nc_put_var_ulonglong +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) +{ + return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); +} + +/// +/// PIO interface to nc_put_var_int /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_put_var_int (int ncid, int varid, const int *op) { int ierr; int msg; @@ -618,12 +706,12 @@ int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offs if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM; + msg = PIO_MSG_PUT_VAR_INT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -633,13 +721,13 @@ int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offs #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + ierr = nc_put_var_int(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + ierr = nc_put_var_int(file->fh, varid, op);; } break; #endif @@ -654,7 +742,7 @@ int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offs request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype, request);; + ierr = ncmpi_bput_var_int(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -673,13 +761,13 @@ int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offs } /// -/// PIO interface to nc_put_vars_uint +/// PIO interface to nc_put_var_longlong /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned int *op) +int PIOc_put_var_longlong (int ncid, int varid, const long long *op) { int ierr; int msg; @@ -696,12 +784,12 @@ int PIOc_put_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_UINT; + msg = PIO_MSG_PUT_VAR_LONGLONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -711,13 +799,13 @@ int PIOc_put_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var_longlong(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var_longlong(file->fh, varid, op);; } break; #endif @@ -732,7 +820,7 @@ int PIOc_put_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_uint(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var_longlong(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -751,13 +839,13 @@ int PIOc_put_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO } /// -/// PIO interface to nc_put_varm_uchar +/// PIO interface to nc_put_var_schar /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned char *op) +int PIOc_put_var_schar (int ncid, int varid, const signed char *op) { int ierr; int msg; @@ -774,12 +862,12 @@ int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_UCHAR; + msg = PIO_MSG_PUT_VAR_SCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -789,13 +877,13 @@ int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var_schar(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var_schar(file->fh, varid, op);; } break; #endif @@ -810,7 +898,7 @@ int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_uchar(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_var_schar(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -829,13 +917,13 @@ int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PI } /// -/// PIO interface to nc_put_var_ushort +/// PIO interface to nc_put_var_uint /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_ushort (int ncid, int varid, const unsigned short *op) +int PIOc_put_var_uint (int ncid, int varid, const unsigned int *op) { int ierr; int msg; @@ -852,12 +940,12 @@ int PIOc_put_var_ushort (int ncid, int varid, const unsigned short *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_USHORT; + msg = PIO_MSG_PUT_VAR_UINT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -867,13 +955,13 @@ int PIOc_put_var_ushort (int ncid, int varid, const unsigned short *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_ushort(file->fh, varid, op);; + ierr = nc_put_var_uint(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_ushort(file->fh, varid, op);; + ierr = nc_put_var_uint(file->fh, varid, op);; } break; #endif @@ -888,7 +976,7 @@ int PIOc_put_var_ushort (int ncid, int varid, const unsigned short *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_ushort(file->fh, varid, op, request);; + ierr = ncmpi_bput_var_uint(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -907,13 +995,13 @@ int PIOc_put_var_ushort (int ncid, int varid, const unsigned short *op) } /// -/// PIO interface to nc_put_var1_longlong +/// PIO interface to nc_put_var /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) +int PIOc_put_var (int ncid, int varid, const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -930,12 +1018,12 @@ int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONGLONG; + msg = PIO_MSG_PUT_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -945,13 +1033,13 @@ int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var(file->fh, varid, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var(file->fh, varid, buf);; } break; #endif @@ -966,7 +1054,7 @@ int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_longlong(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -985,13 +1073,13 @@ int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const } /// -/// PIO interface to nc_put_vara_uchar +/// PIO interface to nc_put_vara_ushort /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned char *op) +int PIOc_put_vara_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned short *op) { int ierr; int msg; @@ -1008,12 +1096,12 @@ int PIOc_put_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_UCHAR; + msg = PIO_MSG_PUT_VARA_USHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1023,13 +1111,13 @@ int PIOc_put_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -1044,7 +1132,7 @@ int PIOc_put_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_uchar(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_vara_ushort(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1063,13 +1151,13 @@ int PIOc_put_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PI } /// -/// PIO interface to nc_put_varm_short +/// PIO interface to nc_put_vars_short /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const short *op) +int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const short *op) { int ierr; int msg; @@ -1086,12 +1174,12 @@ int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_SHORT; + msg = PIO_MSG_PUT_VARS_SHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1101,13 +1189,13 @@ int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; } break; #endif @@ -1122,7 +1210,7 @@ int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_short(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_vars_short(file->fh, varid, start, count, stride, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1141,13 +1229,13 @@ int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PI } /// -/// PIO interface to nc_put_var1_long +/// PIO interface to nc_put_vara_uint /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_long (int ncid, int varid, const PIO_Offset index[], const long *ip) +int PIOc_put_vara_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned int *op) { int ierr; int msg; @@ -1164,12 +1252,12 @@ int PIOc_put_var1_long (int ncid, int varid, const PIO_Offset index[], const lon if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONG; + msg = PIO_MSG_PUT_VARA_UINT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1179,13 +1267,13 @@ int PIOc_put_var1_long (int ncid, int varid, const PIO_Offset index[], const lon #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; + ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; + ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -1200,7 +1288,7 @@ int PIOc_put_var1_long (int ncid, int varid, const PIO_Offset index[], const lon request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_long(file->fh, varid, index, ip, request);; + ierr = ncmpi_bput_vara_uint(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1219,13 +1307,13 @@ int PIOc_put_var1_long (int ncid, int varid, const PIO_Offset index[], const lon } /// -/// PIO interface to nc_put_vars_long +/// PIO interface to nc_put_vara_schar /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const long *op) +int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const signed char *op) { int ierr; int msg; @@ -1242,12 +1330,12 @@ int PIOc_put_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_LONG; + msg = PIO_MSG_PUT_VARA_SCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1257,13 +1345,13 @@ int PIOc_put_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -1278,7 +1366,7 @@ int PIOc_put_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_long(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_vara_schar(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1296,14 +1384,15 @@ int PIOc_put_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO return ierr; } + /// -/// PIO interface to nc_put_var_short +/// PIO interface to nc_put_var1_uchar /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_short (int ncid, int varid, const short *op) +int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], const unsigned char *op) { int ierr; int msg; @@ -1320,12 +1409,12 @@ int PIOc_put_var_short (int ncid, int varid, const short *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_SHORT; + msg = PIO_MSG_PUT_VAR1_UCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1335,13 +1424,13 @@ int PIOc_put_var_short (int ncid, int varid, const short *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_short(file->fh, varid, op);; + ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_short(file->fh, varid, op);; + ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -1356,7 +1445,7 @@ int PIOc_put_var_short (int ncid, int varid, const short *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_short(file->fh, varid, op, request);; + ierr = ncmpi_bput_var1_uchar(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1374,15 +1463,15 @@ int PIOc_put_var_short (int ncid, int varid, const short *op) return ierr; } + /// -/// PIO interface to nc_put_vara_int +/// PIO interface to nc_put_vars_schar /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], - const int *op) +int PIOc_put_vars_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const signed char *op) { int ierr; int msg; @@ -1392,9 +1481,6 @@ int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_O var_desc_t *vdesc; PIO_Offset usage; int *request; - int size; - int ret; - int ndims; ierr = PIO_NOERR; @@ -1402,20 +1488,12 @@ int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_O if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_INT; + msg = PIO_MSG_PUT_VARS_SCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if ((ret = PIOc_inq_varndims(ncid, varid, &ndims))) - return ret; - mpierr = MPI_Bcast((void *)start, ndims, MPI_INT, ios->compmaster, ios->intercomm); - mpierr = MPI_Bcast((void *)count, ndims, MPI_INT, ios->compmaster, ios->intercomm); - for (int d = 0, size = 1; d < ndims; d++) - size *= count[d]; - mpierr = MPI_Bcast((void *)op, size, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1425,13 +1503,13 @@ int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_O #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; } break; #endif @@ -1446,7 +1524,7 @@ int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_O request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_int(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_vars_schar(file->fh, varid, start, count, stride, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1465,13 +1543,13 @@ int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_O } /// -/// PIO interface to nc_put_var1_ushort +/// PIO interface to nc_put_var1 /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const unsigned short *op) +int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -1488,7 +1566,7 @@ int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const u if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_USHORT; + msg = PIO_MSG_PUT_VAR1; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1503,13 +1581,13 @@ int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const u #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -1524,7 +1602,7 @@ int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const u request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ushort(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -1543,13 +1621,13 @@ int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const u } /// -/// PIO interface to nc_put_vara_text +/// PIO interface to nc_put_vara_float /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const char *op) +int PIOc_put_vara_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const float *op) { int ierr; int msg; @@ -1566,7 +1644,7 @@ int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_TEXT; + msg = PIO_MSG_PUT_VARA_FLOAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1581,13 +1659,13 @@ int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -1602,7 +1680,7 @@ int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_text(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_vara_float(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1621,13 +1699,13 @@ int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO } /// -/// PIO interface to nc_put_varm_text +/// PIO interface to nc_put_var1_float /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const char *op) +int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], const float *op) { int ierr; int msg; @@ -1644,7 +1722,7 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_TEXT; + msg = PIO_MSG_PUT_VAR1_FLOAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1659,13 +1737,13 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -1680,7 +1758,7 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_text(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_var1_float(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1698,14 +1776,15 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO return ierr; } + /// -/// PIO interface to nc_put_varm_ushort +/// PIO interface to nc_put_var1_text /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned short *op) +int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) { int ierr; int msg; @@ -1722,7 +1801,7 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_USHORT; + msg = PIO_MSG_PUT_VAR1_TEXT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1737,13 +1816,13 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -1758,7 +1837,7 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_ushort(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_var1_text(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1777,13 +1856,13 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P } /// -/// PIO interface to nc_put_var_ulonglong +/// PIO interface to nc_put_vars_text /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) +int PIOc_put_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const char *op) { int ierr; int msg; @@ -1800,7 +1879,7 @@ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_ULONGLONG; + msg = PIO_MSG_PUT_VARS_TEXT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1815,13 +1894,13 @@ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_ulonglong(file->fh, varid, op);; + ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_ulonglong(file->fh, varid, op);; + ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; } break; #endif @@ -1836,7 +1915,7 @@ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_ulonglong(file->fh, varid, op, request);; + ierr = ncmpi_bput_vars_text(file->fh, varid, start, count, stride, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1854,14 +1933,15 @@ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) return ierr; } + /// -/// PIO interface to nc_put_var_int +/// PIO interface to nc_put_vars_double /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_int (int ncid, int varid, const int *op) +int PIOc_put_vars_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const double *op) { int ierr; int msg; @@ -1878,7 +1958,7 @@ int PIOc_put_var_int (int ncid, int varid, const int *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_INT; + msg = PIO_MSG_PUT_VARS_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1893,13 +1973,13 @@ int PIOc_put_var_int (int ncid, int varid, const int *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_int(file->fh, varid, op);; + ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_int(file->fh, varid, op);; + ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; } break; #endif @@ -1914,7 +1994,7 @@ int PIOc_put_var_int (int ncid, int varid, const int *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_int(file->fh, varid, op, request);; + ierr = ncmpi_bput_vars_double(file->fh, varid, start, count, stride, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -1933,13 +2013,13 @@ int PIOc_put_var_int (int ncid, int varid, const int *op) } /// -/// PIO interface to nc_put_var_longlong +/// PIO interface to nc_put_vara_longlong /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_longlong (int ncid, int varid, const long long *op) +int PIOc_put_vara_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long long *op) { int ierr; int msg; @@ -1956,7 +2036,7 @@ int PIOc_put_var_longlong (int ncid, int varid, const long long *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_LONGLONG; + msg = PIO_MSG_PUT_VARA_LONGLONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1971,13 +2051,13 @@ int PIOc_put_var_longlong (int ncid, int varid, const long long *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_longlong(file->fh, varid, op);; + ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_longlong(file->fh, varid, op);; + ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -1992,7 +2072,7 @@ int PIOc_put_var_longlong (int ncid, int varid, const long long *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_longlong(file->fh, varid, op, request);; + ierr = ncmpi_bput_vara_longlong(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -2011,13 +2091,13 @@ int PIOc_put_var_longlong (int ncid, int varid, const long long *op) } /// -/// PIO interface to nc_put_var_schar +/// PIO interface to nc_put_var_double /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_schar (int ncid, int varid, const signed char *op) +int PIOc_put_var_double (int ncid, int varid, const double *op) { int ierr; int msg; @@ -2034,7 +2114,7 @@ int PIOc_put_var_schar (int ncid, int varid, const signed char *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_SCHAR; + msg = PIO_MSG_PUT_VAR_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -2049,1885 +2129,13 @@ int PIOc_put_var_schar (int ncid, int varid, const signed char *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_schar(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_schar(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_schar(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_uint (int ncid, int varid, const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_uint(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_uint(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_uint(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var (int ncid, int varid, const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_ushort -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned short *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_USHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_ushort(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vars_short -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const short *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_short(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_uint(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const signed char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_schar(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_varm_ulonglong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_ulonglong(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1_uchar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], const unsigned char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uchar(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_varm_int -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_int(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vars_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const signed char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_schar(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1 -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_float(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_float(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_varm_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_float(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_text(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vars_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_text(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_varm_long -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_long(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vars_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const double *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_double(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_longlong(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_double (int ncid, int varid, const double *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_double(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_double(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_double(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_float (int ncid, int varid, const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_float(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_float(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_float(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1_ulonglong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ulonglong(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_varm_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_uint(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_var1_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var_double(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var_double(file->fh, varid, op);; } break; #endif @@ -3942,7 +2150,7 @@ int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const uns request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uint(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var_double(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -3961,13 +2169,13 @@ int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const uns } /// -/// PIO interface to nc_put_var1_int +/// PIO interface to nc_put_var_float /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int *op) +int PIOc_put_var_float (int ncid, int varid, const float *op) { int ierr; int msg; @@ -3984,7 +2192,7 @@ int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_INT; + msg = PIO_MSG_PUT_VAR_FLOAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -3999,13 +2207,13 @@ int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var_float(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var_float(file->fh, varid, op);; } break; #endif @@ -4020,7 +2228,7 @@ int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_int(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var_float(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4039,13 +2247,13 @@ int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int } /// -/// PIO interface to nc_put_vars_float +/// PIO interface to nc_put_var1_ulonglong /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const float *op) +int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) { int ierr; int msg; @@ -4062,7 +2270,7 @@ int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_FLOAT; + msg = PIO_MSG_PUT_VAR1_ULONGLONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4077,13 +2285,13 @@ int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -4098,7 +2306,7 @@ int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_float(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var1_ulonglong(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4116,14 +2324,15 @@ int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PI return ierr; } + /// -/// PIO interface to nc_put_vara_short +/// PIO interface to nc_put_var1_uint /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const short *op) +int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const unsigned int *op) { int ierr; int msg; @@ -4140,7 +2349,7 @@ int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_SHORT; + msg = PIO_MSG_PUT_VAR1_UINT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4155,13 +2364,13 @@ int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -4176,7 +2385,7 @@ int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_short(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_var1_uint(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4195,13 +2404,13 @@ int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PI } /// -/// PIO interface to nc_put_var1_schar +/// PIO interface to nc_put_var1_int /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const signed char *op) +int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int *op) { int ierr; int msg; @@ -4218,7 +2427,7 @@ int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const si if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_SCHAR; + msg = PIO_MSG_PUT_VAR1_INT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4233,13 +2442,13 @@ int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const si #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -4254,7 +2463,7 @@ int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const si request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_schar(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var1_int(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4273,13 +2482,13 @@ int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const si } /// -/// PIO interface to nc_put_vara_ulonglong +/// PIO interface to nc_put_vars_float /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned long long *op) +int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const float *op) { int ierr; int msg; @@ -4296,7 +2505,7 @@ int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], cons if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_ULONGLONG; + msg = PIO_MSG_PUT_VARS_FLOAT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4311,13 +2520,13 @@ int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], cons #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; } break; #endif @@ -4332,7 +2541,7 @@ int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], cons request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_ulonglong(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_vars_float(file->fh, varid, start, count, stride, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4351,13 +2560,13 @@ int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], cons } /// -/// PIO interface to nc_put_varm_double +/// PIO interface to nc_put_vara_short /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const double *op) +int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const short *op) { int ierr; int msg; @@ -4374,7 +2583,7 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_DOUBLE; + msg = PIO_MSG_PUT_VARA_SHORT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4389,13 +2598,13 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -4410,7 +2619,7 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_double(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_vara_short(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4429,13 +2638,13 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P } /// -/// PIO interface to nc_put_vara +/// PIO interface to nc_put_var1_schar /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const signed char *op) { int ierr; int msg; @@ -4452,7 +2661,7 @@ int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offs if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA; + msg = PIO_MSG_PUT_VAR1_SCHAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4467,13 +2676,13 @@ int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offs #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -4488,7 +2697,7 @@ int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offs request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; + ierr = ncmpi_bput_var1_schar(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4507,13 +2716,13 @@ int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offs } /// -/// PIO interface to nc_put_vara_long +/// PIO interface to nc_put_vara_ulonglong /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long *op) +int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned long long *op) { int ierr; int msg; @@ -4530,7 +2739,7 @@ int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_LONG; + msg = PIO_MSG_PUT_VARA_ULONGLONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4545,13 +2754,13 @@ int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; + ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -4566,7 +2775,7 @@ int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_long(file->fh, varid, start, count, op, request);; + ierr = ncmpi_bput_vara_ulonglong(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4584,14 +2793,15 @@ int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO return ierr; } + /// -/// PIO interface to nc_put_var1_double +/// PIO interface to nc_put_vara /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const double *op) +int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -4608,7 +2818,7 @@ int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const d if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_DOUBLE; + msg = PIO_MSG_PUT_VARA; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4623,13 +2833,13 @@ int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const d #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; } break; #endif @@ -4644,7 +2854,7 @@ int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const d request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_double(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -4663,13 +2873,13 @@ int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const d } /// -/// PIO interface to nc_put_varm_schar +/// PIO interface to nc_put_vara_long /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const signed char *op) +int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long *op) { int ierr; int msg; @@ -4686,7 +2896,7 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_SCHAR; + msg = PIO_MSG_PUT_VARA_LONG; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4701,13 +2911,13 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; } break; #endif @@ -4722,7 +2932,7 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_schar(file->fh, varid, start, count, stride, imap, op, request);; + ierr = ncmpi_bput_vara_long(file->fh, varid, start, count, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4741,13 +2951,13 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI } /// -/// PIO interface to nc_put_var_text +/// PIO interface to nc_put_var1_double /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_var_text (int ncid, int varid, const char *op) +int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const double *op) { int ierr; int msg; @@ -4764,7 +2974,7 @@ int PIOc_put_var_text (int ncid, int varid, const char *op) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_TEXT; + msg = PIO_MSG_PUT_VAR1_DOUBLE; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4779,13 +2989,13 @@ int PIOc_put_var_text (int ncid, int varid, const char *op) #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_text(file->fh, varid, op);; + ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var_text(file->fh, varid, op);; + ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; } break; #endif @@ -4800,7 +3010,7 @@ int PIOc_put_var_text (int ncid, int varid, const char *op) request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var_text(file->fh, varid, op, request);; + ierr = ncmpi_bput_var1_double(file->fh, varid, index, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4819,13 +3029,13 @@ int PIOc_put_var_text (int ncid, int varid, const char *op) } /// -/// PIO interface to nc_put_vars_int +/// PIO interface to nc_put_var_text /// /// This routine is called collectively by all tasks in the communicator ios.union_comm. /// /// Refer to the netcdf documentation. /// -int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const int *op) +int PIOc_put_var_text (int ncid, int varid, const char *op) { int ierr; int msg; @@ -4842,7 +3052,7 @@ int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_ if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_INT; + msg = PIO_MSG_PUT_VAR_TEXT; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -4857,13 +3067,13 @@ int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_ #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var_text(file->fh, varid, op);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vars_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; + ierr = nc_put_var_text(file->fh, varid, op);; } break; #endif @@ -4878,7 +3088,7 @@ int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_ request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_int(file->fh, varid, start, count, stride, op, request);; + ierr = ncmpi_bput_var_text(file->fh, varid, op, request);; }else{ *request = PIO_REQ_NULL; } @@ -4896,6 +3106,13 @@ int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_ return ierr; } +/** PIO interface to nc_put_vars_int */ +int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], + const PIO_Offset stride[], const int *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); +} + /// /// PIO interface to nc_put_var1_short /// @@ -5287,81 +3504,4 @@ int PIOc_put_var_long (int ncid, int varid, const long *op) return ierr; } -/// -/// PIO interface to nc_put_varm_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARM_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_varm_longlong(file->fh, varid, start, count, stride, imap, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index ca8f7aa7a3a4..6cb671b6ec31 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -19,9 +19,6 @@ /** The length of our test data. */ #define DIM_LEN 4 -/** The length of data on each (of 2) computational task. */ -#define LOCAL_DIM_LEN 2 - /** The name of the dimension in the netCDF output file. */ #define FIRST_DIM_NAME "jojo" #define DIM_NAME "dim_test_intercomm" @@ -379,7 +376,7 @@ main(int argc, char **argv) { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; - int data[LOCAL_DIM_LEN]; + int data[DIM_LEN]; /* Create a netCDF file with one dimension and one variable. */ if (verbose) @@ -495,16 +492,21 @@ main(int argc, char **argv) if ((ret = PIOc_enddef(ncid))) ERR(ret); - /* /\* Write some data. *\/ */ - /* for (int i = 0; i < LOCAL_DIM_LEN; i++) */ - /* data[i] = my_rank; */ - /* if (verbose) */ - /* printf("%d test_intercomm writing data\n", my_rank); */ - /* start[0] = !my_rank ? 0 : 2; */ - /* count[0] = 2; */ - /* sleep(2); */ - /* if ((ret = PIOc_put_vars_tc(ncid, varid, start, count, NULL, NC_INT, data))) */ - /* ERR(ret); */ + /* Write some data. For the PIOc_put/get functions, all + * data must be on compmaster before the function is + * called. Only compmaster's arguments are passed to the + * async msg handler. All other computation tasks are + * ignored. */ + for (int i = 0; i < DIM_LEN; i++) + data[i] = i; + if (verbose) + printf("%d test_intercomm writing data\n", my_rank); + if (verbose) + printf("%d test_intercomm writing data\n", my_rank); + start[0] = 0; + count[0] = DIM_LEN; + if ((ret = PIOc_put_vars_tc(ncid, varid, start, count, NULL, NC_INT, data))) + ERR(ret); /* Close the file. */ if (verbose) From 32e3165ce27d7b0010631313afbb110427197cfc Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 23 May 2016 18:48:02 -0400 Subject: [PATCH 76/83] further development of async --- src/clib/pio_put_nc_async.c | 3996 ++++++++++------------------------- 1 file changed, 1100 insertions(+), 2896 deletions(-) diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index 95d31c826ce6..3a10a6dd2d5f 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -12,15 +12,15 @@ * @param ncid identifies the netCDF file * @param varid the variable ID number - * @param start[] an array of start indicies (must have same number of + * @param *start an array of start indicies (must have same number of * entries as variable has dimensions). If NULL, indices of 0 will be * used. * - * @param count[] an array of counts (must have same number of entries + * @param *count an array of counts (must have same number of entries * as variable has dimensions). If NULL, counts matching the size of * the variable will be used. * - * @param stride[] an array of strides (must have same number of + * @param *stride an array of strides (must have same number of * entries as variable has dimensions). If NULL, strides of 1 will be * used. * @@ -235,7 +235,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off break; case NC_INT: ierr = nc_put_vars_int(ncid, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf); + (ptrdiff_t *)stride, buf); break; case NC_FLOAT: ierr = nc_put_vars_float(ncid, varid, (size_t *)start, (size_t *)count, @@ -266,10 +266,10 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off ierr = nc_put_vars_ulonglong(ncid, varid, (size_t *)start, (size_t *)count, (ptrdiff_t *)stride, buf); break; - /* case NC_STRING: */ - /* ierr = nc_put_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ - /* (ptrdiff_t *)stride, (void *)buf); */ - /* break; */ + /* case NC_STRING: */ + /* ierr = nc_put_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ + /* (ptrdiff_t *)stride, (void *)buf); */ + /* break; */ default: ierr = nc_put_vars(ncid, varid, (size_t *)start, (size_t *)count, (ptrdiff_t *)stride, buf); @@ -296,103 +296,106 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off * Refer to the * netcdf documentation. */ -int PIOc_put_vars(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], - const PIO_Offset stride[], const void *buf, PIO_Offset bufcount, +int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARS; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_vars(file->fh, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, + bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } /** Interface to netCDF data write function. */ -int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset start[], - const PIO_Offset count[], const PIO_Offset stride[], +int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, const unsigned char *op) { return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UBYTE, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_ushort(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], - const PIO_Offset stride[], const unsigned short *op) +int PIOc_put_vars_ushort(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const unsigned short *op) { return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_USHORT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_ulonglong(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], - const PIO_Offset stride[], const unsigned long long *op) +int PIOc_put_vars_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const unsigned long long *op) { return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT64, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_uint(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const unsigned int *op) +int PIOc_put_vars_uint(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const unsigned int *op) { return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT, op); } @@ -412,78 +415,78 @@ int PIOc_put_var_ushort(int ncid, int varid, const unsigned short *op) /// int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_LONGLONG; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_longlong(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_longlong(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } /** Interface to netCDF data write function. */ -int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset start[], - const PIO_Offset count[], const unsigned char *op) +int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned char *op) { return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); } @@ -492,77 +495,78 @@ int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset start[], /** Interface to netCDF data write function. */ int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset index[], const long *ip) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_LONG; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_long(file->fh, varid, index, ip, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_long(file->fh, varid, index, ip, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } /** Interface to netCDF data write function. */ -int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const long *op) +int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long *op) { return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); } @@ -574,2934 +578,1134 @@ int PIOc_put_var_short(int ncid, int varid, const short *op) } /** Interface to netCDF data write function. */ -int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], +int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const int *op) { return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); } -/// -/// PIO interface to nc_put_var1_ushort -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], const unsigned short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], + const unsigned short *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_USHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_USHORT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ushort(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_ushort(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_vara_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const char *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const char *op) { return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); } -/// -/// PIO interface to nc_put_var_ulonglong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// +/** Interface to netCDF data write function. */ int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) { return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); } -/// -/// PIO interface to nc_put_var_int -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_int (int ncid, int varid, const int *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_int(int ncid, int varid, const int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_int(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_int(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_int(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_int(ncid, varid, NULL, NULL, NULL, op); } -/// -/// PIO interface to nc_put_var_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_longlong (int ncid, int varid, const long long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_longlong(int ncid, int varid, const long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_longlong(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_longlong(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_longlong(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_put_vars_longlong(ncid, varid, NULL, NULL, NULL, op); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +/** Interface to netCDF data write function. */ +int PIOc_put_var_schar(int ncid, int varid, const signed char *op) +{ + return PIOc_put_vars_schar(ncid, varid, NULL, NULL, NULL, op); +} - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var_uint(int ncid, int varid, const unsigned int *op) +{ + return PIOc_put_vars_uint(ncid, varid, NULL, NULL, NULL, op); } -/// -/// PIO interface to nc_put_var_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_schar (int ncid, int varid, const signed char *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, + MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_schar(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_schar(file->fh, varid, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_schar(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_var_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_uint (int ncid, int varid, const unsigned int *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_ushort(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned short *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_uint(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_uint(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_uint(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_put_vars_ushort(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, const short *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_SHORT, op); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +/** Interface to netCDF data write function. */ +int PIOc_put_vara_uint(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned int *op) +{ + return PIOc_put_vars_uint(ncid, varid, start, count, NULL, op); +} - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const signed char *op) +{ + return PIOc_put_vars_schar(ncid, varid, start, count, NULL, op); } -/// -/// PIO interface to nc_put_var -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var (int ncid, int varid, const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) + +/** Interface to netCDF data write function. */ +int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], + const unsigned char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_UCHAR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_uchar(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_vara_ushort -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vars_schar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const signed char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_USHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_ushort(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_BYTE, op); } -/// -/// PIO interface to nc_put_vars_short -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, + PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_short(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = PIO_NOERR; - return ierr; -} + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1; -/// -/// PIO interface to nc_put_vara_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_uint(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; -} -/// -/// PIO interface to nc_put_vara_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const signed char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_schar(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - - -/// -/// PIO interface to nc_put_var1_uchar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], const unsigned char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uchar(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; -/// -/// PIO interface to nc_put_vars_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const signed char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_schar(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_var1 -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_float(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const float *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_float(ncid, varid, start, count, NULL, op); } -/// -/// PIO interface to nc_put_vara_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const float *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], + const float *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_float(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = PIO_NOERR; - return ierr; -} + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_FLOAT; -/// -/// PIO interface to nc_put_var1_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_float(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; -} - - -/// -/// PIO interface to nc_put_var1_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_text(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; - return ierr; -} + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; -/// -/// PIO interface to nc_put_vars_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_text(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_float(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_vars_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const double *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_double(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/// -/// PIO interface to nc_put_vara_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_longlong(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = PIO_NOERR; - return ierr; -} + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_TEXT; -/// -/// PIO interface to nc_put_var_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_double (int ncid, int varid, const double *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_double(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_double(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_double(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; -} - -/// -/// PIO interface to nc_put_var_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_float (int ncid, int varid, const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_float(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_float(file->fh, varid, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_float(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; - return ierr; -} + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; -/// -/// PIO interface to nc_put_var1_ulonglong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ulonglong(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_text(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } - -/// -/// PIO interface to nc_put_var1_uint -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const unsigned int *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vars_text(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uint(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_CHAR, op); } -/// -/// PIO interface to nc_put_var1_int -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vars_double(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const double *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_int(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_DOUBLE, op); } -/// -/// PIO interface to nc_put_vars_float -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const float *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_float(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_longlong(ncid, varid, start, count, NULL, op); } -/// -/// PIO interface to nc_put_vara_short -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_double (int ncid, int varid, const double *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_short(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_double(ncid, varid, NULL, NULL, NULL, op); } -/// -/// PIO interface to nc_put_var1_schar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_schar (int ncid, int varid, const PIO_Offset index[], const signed char *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_float(int ncid, int varid, const float *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_SCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_schar(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_float(ncid, varid, NULL, NULL, NULL, op); } -/// -/// PIO interface to nc_put_vara_ulonglong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const unsigned long long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_ulonglong(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; - return ierr; -} + ierr = PIO_NOERR; + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_ULONGLONG; -/// -/// PIO interface to nc_put_vara -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; -} - -/// -/// PIO interface to nc_put_vara_long -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_long(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_ulonglong(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_var1_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_double (int ncid, int varid, const PIO_Offset index[], const double *op) + +/** Interface to netCDF data write function. */ +int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const unsigned int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_UINT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_double(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_uint(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_var_text -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_text (int ncid, int varid, const char *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_INT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_text(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_text(file->fh, varid, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_text(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_int(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/** PIO interface to nc_put_vars_int */ -int PIOc_put_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], - const PIO_Offset stride[], const int *op) +int PIOc_put_vars_float(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const float *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, op); } -/// -/// PIO interface to nc_put_var1_short -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_short (int ncid, int varid, const PIO_Offset index[], const short *op) +int PIOc_put_vara_short(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const short *op) +{ + return PIOc_put_vars_short(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const signed char *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_SHORT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_SCHAR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_short(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_schar(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_vars_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vars_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const long long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const unsigned long long *op) +{ + return PIOc_put_vars_ulonglong(ncid, varid, start, count, NULL, op); +} + + +/** Interface to netCDF data write function. */ +int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const void *buf, + PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARA; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars_longlong(file->fh, varid, start, count, stride, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_vara_double -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_vara_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const double *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vara_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const long *op) +{ + return PIOc_put_vars_long(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const double *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARA_DOUBLE; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_DOUBLE; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vara_double(file->fh, varid, start, count, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_double(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var_text(int ncid, int varid, const char *op) +{ + return PIOc_put_vars_text(ncid, varid, NULL, NULL, NULL, op); } +/** PIO interface to nc_put_vars_int */ +int PIOc_put_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const int *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); +} -/// -/// PIO interface to nc_put_var_uchar -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_uchar (int ncid, int varid, const unsigned char *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const short *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VAR1_SHORT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_uchar(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_uchar(file->fh, varid, op);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_uchar(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_var1_short(file->fh, varid, index, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; + return ierr; } -/// -/// PIO interface to nc_put_var_long -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var_long (int ncid, int varid, const long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_vars_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long long *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR_LONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var_long(file->fh, varid, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var_long(file->fh, varid, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var_long(file->fh, varid, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT64, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_double(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const double *op) +{ + return PIOc_put_vars_double(ncid, varid, start, count, NULL, op); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var_uchar(int ncid, int varid, const unsigned char *op) +{ + return PIOc_put_vars_uchar(ncid, varid, NULL, NULL, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_long(int ncid, int varid, const long *op) +{ + return PIOc_put_vars_long(ncid, varid, NULL, NULL, NULL, op); } From 4d335b3732817c9175002eb2a9dadcbf46c93ade Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 23 May 2016 18:49:27 -0400 Subject: [PATCH 77/83] added file for varm functions --- src/clib/pio_varm.c | 1013 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1013 insertions(+) create mode 100644 src/clib/pio_varm.c diff --git a/src/clib/pio_varm.c b/src/clib/pio_varm.c new file mode 100644 index 000000000000..63c90aac5183 --- /dev/null +++ b/src/clib/pio_varm.c @@ -0,0 +1,1013 @@ +#include +#include +#include + +/// +/// PIO interface to nc_put_varm +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_uchar +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned char *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_UCHAR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_uchar(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_short +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const short *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_SHORT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_short(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} +/// +/// PIO interface to nc_put_varm_text +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const char *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_TEXT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_text(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_ushort +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned short *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_USHORT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_ushort(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_ulonglong +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned long long *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_ULONGLONG; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_ulonglong(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} +/// +/// PIO interface to nc_put_varm_int +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const int *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_INT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_int(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_float +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const float *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_FLOAT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_float(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} +/// +/// PIO interface to nc_put_varm_long +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const long *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_LONG; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_long(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_uint +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const unsigned int *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_UINT; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_uint(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_double +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const double *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_DOUBLE; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_double(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} +/// +/// PIO interface to nc_put_varm_schar +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const signed char *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_SCHAR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_schar(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} + +/// +/// PIO interface to nc_put_varm_longlong +/// +/// This routine is called collectively by all tasks in the communicator ios.union_comm. +/// +/// Refer to the netcdf documentation. +/// +int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], const long long *op) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + var_desc_t *vdesc; + PIO_Offset usage; + int *request; + + ierr = PIO_NOERR; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_PUT_VARM_LONGLONG; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); + ierr = nc_put_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + if(ios->io_rank==0){ + ierr = nc_put_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, op);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: + vdesc = file->varlist + varid; + + if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ + vdesc->request = realloc(vdesc->request, + sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); + } + request = vdesc->request+vdesc->nreqs; + + if(ios->io_rank==0){ + ierr = ncmpi_bput_varm_longlong(file->fh, varid, start, count, stride, imap, op, request);; + }else{ + *request = PIO_REQ_NULL; + } + vdesc->nreqs++; + flush_output_buffer(file, false, 0); + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + return ierr; +} From 7119c0bb62b3a318a1c3511cf9c6baa50de337dc Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 23 May 2016 18:52:04 -0400 Subject: [PATCH 78/83] return error for async use with varm --- src/clib/pio_varm.c | 117 ++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 69 deletions(-) diff --git a/src/clib/pio_varm.c b/src/clib/pio_varm.c index 63c90aac5183..d13b2ac41c18 100644 --- a/src/clib/pio_varm.c +++ b/src/clib/pio_varm.c @@ -28,12 +28,9 @@ int PIOc_put_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offs ios = file->iosystem; msg = PIO_MSG_PUT_VARM; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; if(ios->ioproc){ switch(file->iotype){ @@ -106,12 +103,9 @@ int PIOc_put_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PI ios = file->iosystem; msg = PIO_MSG_PUT_VARM_UCHAR; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; if(ios->ioproc){ switch(file->iotype){ @@ -184,12 +178,9 @@ int PIOc_put_varm_short (int ncid, int varid, const PIO_Offset start[], const PI ios = file->iosystem; msg = PIO_MSG_PUT_VARM_SHORT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; if(ios->ioproc){ switch(file->iotype){ @@ -261,11 +252,10 @@ int PIOc_put_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO ios = file->iosystem; msg = PIO_MSG_PUT_VARM_TEXT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -339,11 +329,10 @@ int PIOc_put_varm_ushort (int ncid, int varid, const PIO_Offset start[], const P ios = file->iosystem; msg = PIO_MSG_PUT_VARM_USHORT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -417,11 +406,10 @@ int PIOc_put_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], cons ios = file->iosystem; msg = PIO_MSG_PUT_VARM_ULONGLONG; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -494,11 +482,10 @@ int PIOc_put_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_ ios = file->iosystem; msg = PIO_MSG_PUT_VARM_INT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -572,11 +559,10 @@ int PIOc_put_varm_float (int ncid, int varid, const PIO_Offset start[], const PI ios = file->iosystem; msg = PIO_MSG_PUT_VARM_FLOAT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -649,11 +635,10 @@ int PIOc_put_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO ios = file->iosystem; msg = PIO_MSG_PUT_VARM_LONG; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -727,11 +712,10 @@ int PIOc_put_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO ios = file->iosystem; msg = PIO_MSG_PUT_VARM_UINT; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -805,11 +789,10 @@ int PIOc_put_varm_double (int ncid, int varid, const PIO_Offset start[], const P ios = file->iosystem; msg = PIO_MSG_PUT_VARM_DOUBLE; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -882,11 +865,10 @@ int PIOc_put_varm_schar (int ncid, int varid, const PIO_Offset start[], const PI ios = file->iosystem; msg = PIO_MSG_PUT_VARM_SCHAR; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; + if(ios->ioproc){ @@ -960,12 +942,9 @@ int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const ios = file->iosystem; msg = PIO_MSG_PUT_VARM_LONGLONG; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - + /* Sorry, but varm functions are not supported by the async interface. */ + if(ios->async_interface) + return PIO_EINVAL; if(ios->ioproc){ switch(file->iotype){ From 2fe1f56eb847adeaf75b58f8965d1c33de05116a Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 24 May 2016 09:15:56 -0400 Subject: [PATCH 79/83] cleaned up put_var1 functions --- src/clib/pio_nc_async.c | 1718 +++++++++++++++++------------------ src/clib/pio_put_nc_async.c | 1376 ++++++++-------------------- 2 files changed, 1218 insertions(+), 1876 deletions(-) diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index a8db152c91ff..93b59ae2721e 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -36,7 +36,7 @@ * PIOc_Set_File_Error_Handling */ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, - int *unlimdimidp) + int *unlimdimidp) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -47,93 +47,93 @@ int PIOc_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ; /** Message for async notification. */ - char ndims_present = ndimsp ? true : false; - char nvars_present = nvarsp ? true : false; - char ngatts_present = ngattsp ? true : false; - char unlimdimid_present = unlimdimidp ? true : false; - - if (ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ; /** Message for async notification. */ + char ndims_present = ndimsp ? true : false; + char nvars_present = nvarsp ? true : false; + char ngatts_present = ngattsp ? true : false; + char unlimdimid_present = unlimdimidp ? true : false; + + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&nvars_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ngatts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&unlimdimid_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype == PIO_IOTYPE_NETCDF && file->do_io) - { - /* Should not be necessary to do this - nc_inq should - * handle null pointers. This has been reported as a bug - * to netCDF developers. */ - int tmp_ndims, tmp_nvars, tmp_ngatts, tmp_unlimdimid; - ierr = nc_inq(ncid, &tmp_ndims, &tmp_nvars, &tmp_ngatts, &tmp_unlimdimid); - if (ndimsp) - *ndimsp = tmp_ndims; - if (nvarsp) - *nvarsp = tmp_nvars; - if (ngattsp) - *ngattsp = tmp_ngatts; - if (unlimdimidp) - *unlimdimidp = tmp_unlimdimid; - } else if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); + if (file->iotype == PIO_IOTYPE_NETCDF && file->do_io) + { + /* Should not be necessary to do this - nc_inq should + * handle null pointers. This has been reported as a bug + * to netCDF developers. */ + int tmp_ndims, tmp_nvars, tmp_ngatts, tmp_unlimdimid; + ierr = nc_inq(ncid, &tmp_ndims, &tmp_nvars, &tmp_ngatts, &tmp_unlimdimid); + if (ndimsp) + *ndimsp = tmp_ndims; + if (nvarsp) + *nvarsp = tmp_nvars; + if (ngattsp) + *ngattsp = tmp_ngatts; + if (unlimdimidp) + *unlimdimidp = tmp_unlimdimid; + } else if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp); #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) { - if (ndimsp) - if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - - if (nvarsp) - if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - - if (ngattsp) - if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - - if (unlimdimidp) - if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (ndimsp) + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + + if (nvarsp) + if ((mpierr = MPI_Bcast(nvarsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + + if (ngattsp) + if ((mpierr = MPI_Bcast(ngattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + + if (unlimdimidp) + if ((mpierr = MPI_Bcast(unlimdimidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -178,7 +178,7 @@ int PIOc_inq_unlimdim(int ncid, int *unlimdimidp) /** Internal function to provide inq_type function for pnetcdf. */ int pioc_pnetcdf_inq_type(int ncid, nc_type xtype, char *name, - PIO_Offset *sizep) + PIO_Offset *sizep) { int typelen; char typename[NC_MAX_NAME + 1]; @@ -188,29 +188,29 @@ int pioc_pnetcdf_inq_type(int ncid, nc_type xtype, char *name, case NC_UBYTE: case NC_BYTE: case NC_CHAR: - typelen = 1; - break; + typelen = 1; + break; case NC_SHORT: case NC_USHORT: - typelen = 2; - break; + typelen = 2; + break; case NC_UINT: case NC_INT: case NC_FLOAT: - typelen = 4; - break; + typelen = 4; + break; case NC_UINT64: case NC_INT64: case NC_DOUBLE: - typelen = 8; - break; + typelen = 8; + break; } /* If pointers were supplied, copy results. */ if (sizep) - *sizep = typelen; + *sizep = typelen; if (name) - strcpy(name, "some type"); + strcpy(name, "some type"); return PIO_NOERR; } @@ -231,72 +231,72 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_TYPE; /** Message for async notification. */ - char name_present = name ? true : false; - char size_present = sizep ? true : false; - - if (ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_TYPE; /** Message for async notification. */ + char name_present = name ? true : false; + char size_present = sizep ? true : false; + + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = pioc_pnetcdf_inq_type(ncid, xtype, name, sizep); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = pioc_pnetcdf_inq_type(ncid, xtype, name, sizep); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_type(ncid, xtype, name, (size_t *)sizep); #endif /* _NETCDF */ - LOG((2, "PIOc_inq_type netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq_type netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) { - if (name) - { - int slen; - if (ios->iomaster) - slen = strlen(name); - if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - } - if (sizep) - if ((mpierr = MPI_Bcast(sizep , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (name) + { + int slen; + if (ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (sizep) + if ((mpierr = MPI_Bcast(sizep , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -317,57 +317,57 @@ int PIOc_inq_format (int ncid, int *formatp) /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_FORMAT; - char format_present = formatp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_FORMAT; + char format_present = formatp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&format_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&format_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_format(file->fh, formatp); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_format(file->fh, formatp); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_format(file->fh, formatp); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_format(file->fh, formatp); #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) { - if (formatp) - if ((mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (formatp) + if ((mpierr = MPI_Bcast(formatp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -398,74 +398,74 @@ int PIOc_inq_dim(int ncid, int dimid, char *name, PIO_Offset *lenp) /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_DIM; - char name_present = name ? true : false; - char len_present = lenp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); - if (!mpierr) - mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_DIM; + char name_present = name ? true : false; + char len_present = lenp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast name_present = %d", name_present)); + if (!mpierr) + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq netcdf Bcast len_present = %d", len_present)); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_dim(file->fh, dimid, name, lenp);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_dim(file->fh, dimid, name, (size_t *)lenp);; #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) { - if (name) - { - int slen; - if (ios->iomaster) - slen = strlen(name); - if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - } - - if (lenp) - if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (name) + { + int slen; + if (ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + } + + if (lenp) + if ((mpierr = MPI_Bcast(lenp , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -512,66 +512,66 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) /* Name must be provided. */ if (!name) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_inq_dimid name = %s", name)); /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If using async, and not an IO task, then send parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_DIMID; - char id_present = idp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen = strlen(name); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_DIMID; + char id_present = idp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* IO tasks call the netCDF functions. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_dimid(file->fh, name, idp);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_dimid(file->fh, name, idp);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_dimid(file->fh, name, idp);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_dimid(file->fh, name, idp);; #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) - if (idp) - if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (idp) + if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -593,7 +593,7 @@ int PIOc_inq_dimid(int ncid, const char *name, int *idp) * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, - int *dimidsp, int *nattsp) + int *dimidsp, int *nattsp) { iosystem_desc_t *ios; file_desc_t *file; @@ -605,108 +605,108 @@ int PIOc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, /* Get the file info, based on the ncid. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_VAR; - char name_present = name ? true : false; - char xtype_present = xtypep ? true : false; - char ndims_present = ndimsp ? true : false; - char dimids_present = dimidsp ? true : false; - char natts_present = nattsp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " - "dimids_present = %d, natts_present = %d nattsp = %d", - name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - } - + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_VAR; + char name_present = name ? true : false; + char xtype_present = xtypep ? true : false; + char ndims_present = ndimsp ? true : false; + char dimids_present = dimidsp ? true : false; + char natts_present = nattsp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimids_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&natts_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_inq_var name_present = %d xtype_present = %d ndims_present = %d " + "dimids_present = %d, natts_present = %d nattsp = %d", + name_present, xtype_present, ndims_present, dimids_present, natts_present, nattsp)); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + } + /* Call the netCDF layer. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - { - ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); - if (!ierr) - ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; - } + if (file->iotype == PIO_IOTYPE_PNETCDF) + { + ierr = ncmpi_inq_varndims(file->fh, varid, &ndims); + if (!ierr) + ierr = ncmpi_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp);; + } #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - { - ierr = nc_inq_varndims(file->fh, varid, &ndims); - if (!ierr) - ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); - } + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + { + ierr = nc_inq_varndims(file->fh, varid, &ndims); + if (!ierr) + ierr = nc_inq_var(file->fh, varid, name, xtypep, ndimsp, dimidsp, nattsp); + } #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + return check_mpi(file, mpierr, __FILE__, __LINE__); check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast the results for non-null pointers. */ if (!ierr) { - if (name) - { - int slen; - if(ios->iomaster) - slen = strlen(name); - if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - } - if (xtypep) - if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - - if (ndimsp) - { - if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - file->varlist[varid].ndims = (*ndimsp); - } - if (dimidsp) - { - if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); - } - if (nattsp) - if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (name) + { + int slen; + if(ios->iomaster) + slen = strlen(name); + if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (xtypep) + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + + if (ndimsp) + { + if ((mpierr = MPI_Bcast(ndimsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + file->varlist[varid].ndims = (*ndimsp); + } + if (dimidsp) + { + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(dimidsp, ndims, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + } + if (nattsp) + if ((mpierr = MPI_Bcast(nattsp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -781,65 +781,65 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) /* Caller must provide name. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; /* Get file info based on ncid. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; LOG((1, "PIOc_inq_varid ncid = %d name = %s", ncid, name)); if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_VARID; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen; - namelen = strlen(name); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_VARID; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen; + namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_varid(file->fh, name, varidp);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_varid(file->fh, name, varidp);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_varid(file->fh, name, varidp); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_varid(file->fh, name, varidp); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (varidp) - if ((mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(varidp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -861,7 +861,7 @@ int PIOc_inq_varid (int ncid, const char *name, int *varidp) * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, - PIO_Offset *lenp) + PIO_Offset *lenp) { int msg = PIO_MSG_INQ_ATT; iosystem_desc_t *ios; @@ -871,79 +871,79 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, /* Caller must provide a name. */ if (!name) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_inq_att ncid = %d varid = %d xtpyep = %d lenp = %d", - ncid, varid, xtypep, lenp)); + ncid, varid, xtypep, lenp)); /* Find file based on ncid. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - char xtype_present = xtypep ? true : false; - char len_present = lenp ? true : false; - int namelen = strlen(name); - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + char xtype_present = xtypep ? true : false; + char len_present = lenp ? true : false; + int namelen = strlen(name); + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_att(file->fh, varid, name, xtypep, lenp); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_att(file->fh, varid, name, xtypep, (size_t *)lenp); #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) { - if(xtypep) - if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if(lenp) - if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if(xtypep) + if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if(lenp) + if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -990,73 +990,73 @@ int PIOc_inq_attname(int ncid, int varid, int attnum, char *name) int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ LOG((1, "PIOc_inq_attname ncid = %d varid = %d attnum = %d", ncid, varid, - attnum)); + attnum)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_ATTNAME; - char name_present = name ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_ATTNAME; + char name_present = name ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&attnum, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&name_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_attname(file->fh, varid, attnum, name);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_attname(file->fh, varid, attnum, name);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_attname(file->fh, varid, attnum, name);; #endif /* _NETCDF */ - LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) - if (name) - { - int namelen = strlen(name); - if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->ioroot, - ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - } + if (name) + { + int namelen = strlen(name); + if ((mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->ioroot, + ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } return ierr; } @@ -1085,73 +1085,73 @@ int PIOc_inq_attid(int ncid, int varid, const char *name, int *idp) /* User must provide name shorter than NC_MAX_NAME +1. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_inq_attid ncid = %d varid = %d name = %s", ncid, varid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_ATTID; - int namelen = strlen(name); - char id_present = idp ? true : false; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_ATTID; + int namelen = strlen(name); + char id_present = idp ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&id_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_attid(file->fh, varid, name, idp);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_attid(file->fh, varid, name, idp);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_attid(file->fh, varid, name, idp);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_attid(file->fh, varid, name, idp);; #endif /* _NETCDF */ - LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq_attname netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) { - if (idp) - if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (idp) + if ((mpierr = MPI_Bcast(idp, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } return ierr; @@ -1179,42 +1179,42 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) /* User must provide name of correct length. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_rename_dim ncid = %d dimid = %d name = %s", ncid, dimid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_RENAME_DIM; /** Message for async notification. */ - int namelen = strlen(name); + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_DIM; /** Message for async notification. */ + int namelen = strlen(name); - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_rename_dim Bcast file->fh = %d dimid = %d namelen = %d name = %s", - file->fh, dimid, namelen, name)); - } + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&dimid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_rename_dim Bcast file->fh = %d dimid = %d namelen = %d name = %s", + file->fh, dimid, namelen, name)); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -1222,21 +1222,21 @@ int PIOc_rename_dim(int ncid, int dimid, const char *name) if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_rename_dim(file->fh, dimid, name); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_dim(file->fh, dimid, name); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_rename_dim(file->fh, dimid, name);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_dim(file->fh, dimid, name);; #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1266,42 +1266,42 @@ int PIOc_rename_var(int ncid, int varid, const char *name) /* User must provide name of correct length. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_rename_var ncid = %d varid = %d name = %s", ncid, varid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_RENAME_VAR; /** Message for async notification. */ - int namelen = strlen(name); + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_VAR; /** Message for async notification. */ + int namelen = strlen(name); - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - LOG((2, "PIOc_rename_var Bcast file->fh = %d varid = %d namelen = %d name = %s", - file->fh, varid, namelen, name)); - } + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_rename_var Bcast file->fh = %d varid = %d namelen = %d name = %s", + file->fh, varid, namelen, name)); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -1309,21 +1309,21 @@ int PIOc_rename_var(int ncid, int varid, const char *name) if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_rename_var(file->fh, varid, name); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_var(file->fh, varid, name); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_rename_var(file->fh, varid, name);; + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_var(file->fh, varid, name);; #endif /* _NETCDF */ - LOG((2, "PIOc_inq netcdf call returned %d", ierr)); + LOG((2, "PIOc_inq netcdf call returned %d", ierr)); } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1346,7 +1346,7 @@ int PIOc_rename_var(int ncid, int varid, const char *name) * PIOc_Set_File_Error_Handling */ int PIOc_rename_att (int ncid, int varid, const char *name, - const char *newname) + const char *newname) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -1355,67 +1355,67 @@ int PIOc_rename_att (int ncid, int varid, const char *name, /* User must provide names of correct length. */ if (!name || strlen(name) > NC_MAX_NAME || - !newname || strlen(newname) > NC_MAX_NAME) - return PIO_EINVAL; + !newname || strlen(newname) > NC_MAX_NAME) + return PIO_EINVAL; LOG((1, "PIOc_rename_att ncid = %d varid = %d name = %s newname = %s", - ncid, varid, name, newname)); + ncid, varid, name, newname)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_RENAME_ATT; /** Message for async notification. */ - int namelen = strlen(name); - int newnamelen = strlen(newname); - - if (ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_RENAME_ATT; /** Message for async notification. */ + int namelen = strlen(name); + int newnamelen = strlen(newname); + + if (ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&newnamelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)newname, newnamelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_rename_att(file->fh, varid, name, newname); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_rename_att(file->fh, varid, name, newname); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_rename_att(file->fh, varid, name, newname); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_rename_att(file->fh, varid, name, newname); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1446,60 +1446,60 @@ int PIOc_del_att(int ncid, int varid, const char *name) /* User must provide name of correct length. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_del_att ncid = %d varid = %d name = %s", ncid, varid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_DEL_ATT; - int namelen = strlen(name); /** Length of name string. */ + if (!ios->ioproc) + { + int msg = PIO_MSG_DEL_ATT; + int namelen = strlen(name); /** Length of name string. */ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - } + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((char *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_del_att(file->fh, varid, name); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_del_att(file->fh, varid, name); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_del_att(file->fh, varid, name); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_del_att(file->fh, varid, name); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1528,31 +1528,31 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI functions. */ LOG((1, "PIOc_set_fill ncid = %d fillmode = %d old_modep = %d", ncid, fillmode, - old_modep)); + old_modep)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_SET_FILL; + if (!ios->ioproc) + { + int msg = PIO_MSG_SET_FILL; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - } + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } @@ -1560,20 +1560,20 @@ int PIOc_set_fill (int ncid, int fillmode, int *old_modep) if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_set_fill(file->fh, fillmode, old_modep); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_set_fill(file->fh, fillmode, old_modep); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_set_fill(file->fh, fillmode, old_modep); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_set_fill(file->fh, fillmode, old_modep); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1597,53 +1597,53 @@ int pioc_change_def(int ncid, int is_enddef) /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = is_enddef ? PIO_MSG_ENDDEF : PIO_MSG_REDEF; + if (!ios->ioproc) + { + int msg = is_enddef ? PIO_MSG_ENDDEF : PIO_MSG_REDEF; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - } + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - if (is_enddef) - ierr = ncmpi_enddef(file->fh); - else - ierr = ncmpi_redef(file->fh); + if (file->iotype == PIO_IOTYPE_PNETCDF) + if (is_enddef) + ierr = ncmpi_enddef(file->fh); + else + ierr = ncmpi_redef(file->fh); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - if (is_enddef) - ierr = nc_enddef(file->fh); - else - ierr = nc_redef(file->fh); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + if (is_enddef) + ierr = nc_enddef(file->fh); + else + ierr = nc_redef(file->fh); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -1709,70 +1709,70 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) /* User must provide name. */ if (!name || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_def_dim ncid = %d name = %s len = %d", ncid, name, len)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_DEF_DIM; - int namelen = strlen(name); + if (!ios->ioproc) + { + int msg = PIO_MSG_DEF_DIM; + int namelen = strlen(name); - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); - } + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_INT, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_def_dim(file->fh, name, len, idp);; + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_def_dim(file->fh, name, len, idp);; #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_def_dim(file->fh, name, (size_t)len, idp); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_def_dim(file->fh, name, (size_t)len, idp); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr2, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr2, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) - if (idp) - if ((mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (idp) + if ((mpierr = MPI_Bcast(idp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -1794,7 +1794,7 @@ int PIOc_def_dim (int ncid, const char *name, PIO_Offset len, int *idp) * PIOc_Set_File_Error_Handling */ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, - const int *dimidsp, int *varidp) + const int *dimidsp, int *varidp) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -1804,67 +1804,67 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, /* User must provide name and storage for varid. */ if (!name || !varidp || strlen(name) > NC_MAX_NAME) { - check_netcdf(file, PIO_EINVAL, __FILE__, __LINE__); - return PIO_EINVAL; + check_netcdf(file, PIO_EINVAL, __FILE__, __LINE__); + return PIO_EINVAL; } /* Get the file information. */ if (!(file = pio_get_file_from_id(ncid))) { - check_netcdf(file, PIO_EBADID, __FILE__, __LINE__); - return PIO_EBADID; + check_netcdf(file, PIO_EBADID, __FILE__, __LINE__); + return PIO_EBADID; } ios = file->iosystem; /* If using async, and not an IO task, then send parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_DEF_VAR; - int namelen = strlen(name); - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&(ncid), 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_DEF_VAR; + int namelen = strlen(name); + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&(ncid), 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)dimidsp, ndims, MPI_INT, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_def_var(ncid, name, xtype, ndims, dimidsp, varidp); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_def_var(ncid, name, xtype, ndims, dimidsp, varidp); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_def_var(ncid, name, xtype, ndims, dimidsp, varidp); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_def_var(ncid, name, xtype, ndims, dimidsp, varidp); #ifdef _NETCDF4 - /* For netCDF-4 serial files, turn on compression for this variable. */ - if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C) - ierr = nc_def_var_deflate(ncid, *varidp, 0, 1, 1); + /* For netCDF-4 serial files, turn on compression for this variable. */ + if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C) + ierr = nc_def_var_deflate(ncid, *varidp, 0, 1, 1); - /* For netCDF-4 parallel files, set parallel access to collective. */ - if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4P) - ierr = nc_var_par_access(ncid, *varidp, NC_COLLECTIVE); + /* For netCDF-4 parallel files, set parallel access to collective. */ + if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4P) + ierr = nc_var_par_access(ncid, *varidp, NC_COLLECTIVE); #endif /* _NETCDF4 */ #endif /* _NETCDF */ } @@ -1872,16 +1872,16 @@ int PIOc_def_var (int ncid, const char *name, nc_type xtype, int ndims, /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results. */ if (!ierr) - if (varidp) - if ((mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (varidp) + if ((mpierr = MPI_Bcast(varidp , 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -1911,55 +1911,55 @@ int PIOc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep) /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_INQ_VAR_FILL; + if (!ios->ioproc) + { + int msg = PIO_MSG_INQ_VAR_FILL; - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - if (!mpierr) - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } + if (!mpierr) + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); + } - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_valuep); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_inq_var_fill(file->fh, varid, no_fill, fill_valuep); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_valuep); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_inq_var_fill(file->fh, varid, no_fill, fill_valuep); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); /* Broadcast results to all tasks. Ignore NULL parameters. */ if (!ierr) - if (fill_valuep) - if ((mpierr = MPI_Bcast(fill_valuep, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (fill_valuep) + if ((mpierr = MPI_Bcast(fill_valuep, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); return ierr; } @@ -1990,98 +1990,98 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) /* User must provide a name and destination pointer. */ if (!name || !ip || strlen(name) > NC_MAX_NAME) - return PIO_EINVAL; + return PIO_EINVAL; LOG((1, "PIOc_get_att ncid %d varid %d name %s", ncid, varid, name)); /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* Run these on all tasks if async is not in use, but only on * non-IO tasks if async is in use. */ if (!ios->async_interface || !ios->ioproc) { - /* Get the type and length of the attribute. */ - if ((ierr = PIOc_inq_att(file->fh, varid, name, &atttype, &attlen))) - { - check_netcdf(file, ierr, __FILE__, __LINE__); - return ierr; - } + /* Get the type and length of the attribute. */ + if ((ierr = PIOc_inq_att(file->fh, varid, name, &atttype, &attlen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } - /* Get the length (in bytes) of the type. */ - if ((ierr = PIOc_inq_type(file->fh, atttype, NULL, &typelen))) - { - check_netcdf(file, ierr, __FILE__, __LINE__); - return ierr; - } + /* Get the length (in bytes) of the type. */ + if ((ierr = PIOc_inq_type(file->fh, atttype, NULL, &typelen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } } /* If async is in use, and this is not an IO task, bcast the * parameters and the attribute and type information we fetched. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_GET_ATT; - - /* Send the message to IO master. */ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - - /* Send the function parameters. */ - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen = strlen(name); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - - /* Broadcast values currently only known on computation tasks to IO tasks. */ - LOG((2, "PIOc_get_att bcast from comproot = %d attlen = %d typelen = %d", ios->comproot, attlen, typelen)); - if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); - LOG((2, "PIOc_get_att bcast complete attlen = %d typelen = %d", attlen, typelen)); - } - + if (!ios->ioproc) + { + int msg = PIO_MSG_GET_ATT; + + /* Send the message to IO master. */ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + + /* Send the function parameters. */ + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&file->iotype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&atttype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + + /* Broadcast values currently only known on computation tasks to IO tasks. */ + LOG((2, "PIOc_get_att bcast from comproot = %d attlen = %d typelen = %d", ios->comproot, attlen, typelen)); + if ((mpierr = MPI_Bcast(&attlen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + LOG((2, "PIOc_get_att bcast complete attlen = %d typelen = %d", attlen, typelen)); + } + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_get_att(file->fh, varid, name, ip); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_get_att(file->fh, varid, name, ip); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_get_att(file->fh, varid, name, ip); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_get_att(file->fh, varid, name, ip); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -2089,11 +2089,11 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) if (!ierr) { if ((mpierr = MPI_Bcast(ip, (int)attlen * typelen, MPI_BYTE, ios->ioroot, - ios->my_comm))) - { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; - } + ios->my_comm))) + { + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; + } } return ierr; } @@ -2113,7 +2113,7 @@ int PIOc_get_att(int ncid, int varid, const char *name, void *ip) * @return PIO_NOERR for success, error code otherwise. See PIOc_Set_File_Error_Handling */ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const void *op) + PIO_Offset len, const void *op) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -2125,83 +2125,83 @@ int PIOc_put_att(int ncid, int varid, const char *name, nc_type xtype, /* Find the info about this file. */ if (!(file = pio_get_file_from_id(ncid))) - return PIO_EBADID; + return PIO_EBADID; ios = file->iosystem; /* Run these on all tasks if async is not in use, but only on * non-IO tasks if async is in use. */ if (!ios->async_interface || !ios->ioproc) { - /* Get the length (in bytes) of the type. */ - if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen))) - { - check_netcdf(file, ierr, __FILE__, __LINE__); - return ierr; - } - LOG((2, "PIOc_put_att typelen = %d", ncid, typelen)); + /* Get the length (in bytes) of the type. */ + if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen))) + { + check_netcdf(file, ierr, __FILE__, __LINE__); + return ierr; + } + LOG((2, "PIOc_put_att typelen = %d", ncid, typelen)); } /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async_interface) { - if (!ios->ioproc) - { - int msg = PIO_MSG_PUT_ATT; - - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); - - if (!mpierr) - mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); - int namelen = strlen(name); - if (!mpierr) - mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); - if (!mpierr) - mpierr = MPI_Bcast((void *)op, len * typelen, MPI_BYTE, ios->compmaster, - ios->intercomm); - LOG((2, "PIOc_put_att finished bcast ncid = %d varid = %d namelen = %d name = %s " - "len = %d typelen = %d", file->fh, varid, namelen, name, len, typelen)); - } - - /* Handle MPI errors. */ - if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - check_mpi(file, mpierr2, __FILE__, __LINE__); - check_mpi(file, mpierr, __FILE__, __LINE__); - - /* Broadcast values currently only known on computation tasks to IO tasks. */ - LOG((2, "PIOc_put_att bcast from comproot = %d typelen = %d", ios->comproot, typelen)); - if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) - check_mpi(file, mpierr, __FILE__, __LINE__); + if (!ios->ioproc) + { + int msg = PIO_MSG_PUT_ATT; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + if (!mpierr) + mpierr = MPI_Bcast(&file->fh, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + int namelen = strlen(name); + if (!mpierr) + mpierr = MPI_Bcast(&namelen, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)name, namelen + 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&len, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast((void *)op, len * typelen, MPI_BYTE, ios->compmaster, + ios->intercomm); + LOG((2, "PIOc_put_att finished bcast ncid = %d varid = %d namelen = %d name = %s " + "len = %d typelen = %d", file->fh, varid, namelen, name, len, typelen)); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + + /* Broadcast values currently only known on computation tasks to IO tasks. */ + LOG((2, "PIOc_put_att bcast from comproot = %d typelen = %d", ios->comproot, typelen)); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); } /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { #ifdef _PNETCDF - if (file->iotype == PIO_IOTYPE_PNETCDF) - ierr = ncmpi_put_att(file->fh, varid, name, xtype, len, op); + if (file->iotype == PIO_IOTYPE_PNETCDF) + ierr = ncmpi_put_att(file->fh, varid, name, xtype, len, op); #endif /* _PNETCDF */ #ifdef _NETCDF - if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) - ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + ierr = nc_put_att(file->fh, varid, name, xtype, (size_t)len, op); #endif /* _NETCDF */ } /* Broadcast and check the return code. */ if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) { - check_mpi(file, mpierr, __FILE__, __LINE__); - return PIO_EIO; + check_mpi(file, mpierr, __FILE__, __LINE__); + return PIO_EIO; } check_netcdf(file, ierr, __FILE__, __LINE__); @@ -2330,7 +2330,7 @@ int PIOc_get_att_float (int ncid, int varid, const char *name, float *ip) * The PIO-C interface for the NetCDF function nc_put_att_schar. */ int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const signed char *op) + PIO_Offset len, const signed char *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2340,7 +2340,7 @@ int PIOc_put_att_schar(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_long. */ int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const long *op) + PIO_Offset len, const long *op) { return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } @@ -2350,7 +2350,7 @@ int PIOc_put_att_long(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_int. */ int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const int *op) + PIO_Offset len, const int *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2360,7 +2360,7 @@ int PIOc_put_att_int(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_uchar. */ int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned char *op) + PIO_Offset len, const unsigned char *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2370,7 +2370,7 @@ int PIOc_put_att_uchar(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_longlong. */ int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const long long *op) + PIO_Offset len, const long long *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2380,7 +2380,7 @@ int PIOc_put_att_longlong(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_uint. */ int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned int *op) + PIO_Offset len, const unsigned int *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2390,7 +2390,7 @@ int PIOc_put_att_uint(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_ubyte. */ int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned char *op) + PIO_Offset len, const unsigned char *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2400,7 +2400,7 @@ int PIOc_put_att_ubyte(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_float. */ int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const float *op) + PIO_Offset len, const float *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2410,7 +2410,7 @@ int PIOc_put_att_float(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_ulonglong. */ int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned long long *op) + PIO_Offset len, const unsigned long long *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2420,7 +2420,7 @@ int PIOc_put_att_ulonglong(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_ushort. */ int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const unsigned short *op) + PIO_Offset len, const unsigned short *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2430,7 +2430,7 @@ int PIOc_put_att_ushort(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_text. */ int PIOc_put_att_text(int ncid, int varid, const char *name, - PIO_Offset len, const char *op) + PIO_Offset len, const char *op) { return PIOc_put_att(ncid, varid, name, NC_CHAR, len, op); } @@ -2440,7 +2440,7 @@ int PIOc_put_att_text(int ncid, int varid, const char *name, * The PIO-C interface for the NetCDF function nc_put_att_short. */ int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const short *op) + PIO_Offset len, const short *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } @@ -2450,7 +2450,7 @@ int PIOc_put_att_short(int ncid, int varid, const char *name, nc_type xtype, * The PIO-C interface for the NetCDF function nc_put_att_double. */ int PIOc_put_att_double(int ncid, int varid, const char *name, nc_type xtype, - PIO_Offset len, const double *op) + PIO_Offset len, const double *op) { return PIOc_put_att(ncid, varid, name, xtype, len, op); } diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index 3a10a6dd2d5f..4d80cf889892 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -287,90 +287,6 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off return ierr; } -/** - * PIO interface to nc_put_vars - * - * This routine is called collectively by all tasks in the - * communicator ios.union_comm. - - * Refer to the - * netcdf documentation. */ -int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const void *buf, PIO_Offset bufcount, - MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VARS; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_vars(file->fh, varid, (size_t *)start, (size_t *)count, - (ptrdiff_t *)stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, - bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - /** Interface to netCDF data write function. */ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, @@ -406,966 +322,292 @@ int PIOc_put_var_ushort(int ncid, int varid, const unsigned short *op) return PIOc_put_vars_tc(ncid, varid, NULL, NULL, NULL, NC_USHORT, op); } -/// -/// PIO interface to nc_put_var1_longlong -/// -/// This routine is called collectively by all tasks in the communicator ios.union_comm. -/// -/// Refer to the netcdf documentation. -/// -int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) { + int ndims; int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_longlong(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; + return PIOc_put_vars_text(ncid, varid, index, count, NULL, op); +} - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], + const unsigned char *op) +{ + int ndims; + int ierr; - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_longlong(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - return ierr; + return PIOc_put_vars_uchar(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned char *op) +int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const signed char *op) { - return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); -} + int ndims; + int ierr; + + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; + + return PIOc_put_vars_schar(ncid, varid, index, count, NULL, op); +} /** Interface to netCDF data write function. */ -int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset index[], const long *ip) +int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], + const unsigned short *op) { + int ndims; int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - ierr = PIO_NOERR; + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_LONG; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } + return PIOc_put_vars_short(ncid, varid, index, count, NULL, op); +} +/** Interface to netCDF data write function. */ +int PIOc_put_var1_uint(int ncid, int varid, const PIO_Offset index[], const unsigned int *op) +{ + int ndims; + int ierr; - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_long(file->fh, varid, (size_t *) index, ip);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_long(file->fh, varid, index, ip, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_put_vars_uint(ncid, varid, index, count, NULL, op); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +/** Interface to netCDF data write function. */ +int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const short *op) +{ + int ndims; + int ierr; - return ierr; + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; + + return PIOc_put_vars_short(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const long *op) +int PIOc_put_var1_int(int ncid, int varid, const PIO_Offset index[], const int *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); + int ndims; + int ierr; + + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; + + return PIOc_put_vars_int(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_short(int ncid, int varid, const short *op) +int PIOc_put_var1_float(int ncid, int varid, const PIO_Offset index[], const float *op) { - return PIOc_put_vars_short(ncid, varid, NULL, NULL, NULL, op); + int ndims; + int ierr; + + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; + + return PIOc_put_vars_float(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const int *op) +int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset index[], const long *op) { - return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); + int ndims; + int ierr; + + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; + + return PIOc_put_vars_long(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], - const unsigned short *op) +int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const double *op) { + int ndims; int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - ierr = PIO_NOERR; + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_USHORT; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_ushort(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ushort(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const char *op) -{ - return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) -{ - return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_double(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_int(int ncid, int varid, const int *op) +int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) { - return PIOc_put_vars_int(ncid, varid, NULL, NULL, NULL, op); -} + int ndims; + int ierr; -/** Interface to netCDF data write function. */ -int PIOc_put_var_longlong(int ncid, int varid, const long long *op) -{ - return PIOc_put_vars_longlong(ncid, varid, NULL, NULL, NULL, op); -} + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; -/** Interface to netCDF data write function. */ -int PIOc_put_var_schar(int ncid, int varid, const signed char *op) -{ - return PIOc_put_vars_schar(ncid, varid, NULL, NULL, NULL, op); -} + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; -/** Interface to netCDF data write function. */ -int PIOc_put_var_uint(int ncid, int varid, const unsigned int *op) -{ - return PIOc_put_vars_uint(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_ulonglong(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, - MPI_Datatype buftype) +int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) { + int ndims; int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - if(ios->io_rank==0){ - ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - return ierr; + return PIOc_put_vars_longlong(ncid, varid, index, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_ushort(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned short *op) +int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned char *op) { - return PIOc_put_vars_ushort(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); } -/** Interface to netCDF data write function. */ -int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const PIO_Offset *stride, const short *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_SHORT, op); -} /** Interface to netCDF data write function. */ -int PIOc_put_vara_uint(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned int *op) +int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long *op) { - return PIOc_put_vars_uint(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const signed char *op) +int PIOc_put_var_short(int ncid, int varid, const short *op) { - return PIOc_put_vars_schar(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_short(ncid, varid, NULL, NULL, NULL, op); } - /** Interface to netCDF data write function. */ -int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], - const unsigned char *op) +int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const int *op) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UCHAR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_uchar(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uchar(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; + return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_schar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const signed char *op) +int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const char *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_BYTE, op); + return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); } -/** Interface to netCDF data write function. */ -int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, - PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_float(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const float *op) -{ - return PIOc_put_vars_float(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_float (int ncid, int varid, const PIO_Offset index[], - const float *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_FLOAT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_float(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_float(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_TEXT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_text(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_text(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_text(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const char *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_CHAR, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_double(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const double *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_DOUBLE, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const long long *op) -{ - return PIOc_put_vars_longlong(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_double (int ncid, int varid, const double *op) -{ - return PIOc_put_vars_double(ncid, varid, NULL, NULL, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_float(int ncid, int varid, const float *op) -{ - return PIOc_put_vars_float(ncid, varid, NULL, NULL, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_ULONGLONG; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_ulonglong(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_ulonglong(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_uint (int ncid, int varid, const PIO_Offset index[], const unsigned int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_UINT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_uint(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_uint(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - return ierr; -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_int (int ncid, int varid, const PIO_Offset index[], const int *op) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - var_desc_t *vdesc; - PIO_Offset usage; - int *request; - - ierr = PIO_NOERR; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_INT; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - if(ios->io_rank==0){ - ierr = nc_put_var1_int(file->fh, varid, (size_t *) index, op);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: - vdesc = file->varlist + varid; - - if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, - sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); - } - request = vdesc->request+vdesc->nreqs; - - if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_int(file->fh, varid, index, op, request);; - }else{ - *request = PIO_REQ_NULL; - } - vdesc->nreqs++; - flush_output_buffer(file, false, 0); - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +/** Interface to netCDF data write function. */ +int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) +{ + return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); +} - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var_int(int ncid, int varid, const int *op) +{ + return PIOc_put_vars_int(ncid, varid, NULL, NULL, NULL, op); } -int PIOc_put_vars_float(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const float *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_longlong(int ncid, int varid, const long long *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, op); + return PIOc_put_vars_longlong(ncid, varid, NULL, NULL, NULL, op); } -int PIOc_put_vara_short(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const short *op) +/** Interface to netCDF data write function. */ +int PIOc_put_var_schar(int ncid, int varid, const signed char *op) { - return PIOc_put_vars_short(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_schar(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const signed char *op) +int PIOc_put_var_uint(int ncid, int varid, const unsigned int *op) +{ + return PIOc_put_vars_uint(ncid, varid, NULL, NULL, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, + MPI_Datatype buftype) { int ierr; int msg; @@ -1382,7 +624,7 @@ int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const sig if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_SCHAR; + msg = PIO_MSG_PUT_VAR; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1397,13 +639,13 @@ int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const sig #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var(file->fh, varid, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_schar(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var(file->fh, varid, buf);; } break; #endif @@ -1418,7 +660,7 @@ int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const sig request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_schar(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var(file->fh, varid, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -1436,6 +678,94 @@ int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const sig return ierr; } +/** Interface to netCDF data write function. */ +int PIOc_put_vara_ushort(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned short *op) +{ + return PIOc_put_vars_ushort(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, const short *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_SHORT, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_uint(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned int *op) +{ + return PIOc_put_vars_uint(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const signed char *op) +{ + return PIOc_put_vars_schar(ncid, varid, start, count, NULL, op); +} + + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_schar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const signed char *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_BYTE, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_float(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const float *op) +{ + return PIOc_put_vars_float(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_text(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const char *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_CHAR, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_double(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const double *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_DOUBLE, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const long long *op) +{ + return PIOc_put_vars_longlong(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_double (int ncid, int varid, const double *op) +{ + return PIOc_put_vars_double(ncid, varid, NULL, NULL, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_float(int ncid, int varid, const float *op) +{ + return PIOc_put_vars_float(ncid, varid, NULL, NULL, NULL, op); +} + +int PIOc_put_vars_float(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const float *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, op); +} + +int PIOc_put_vara_short(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const short *op) +{ + return PIOc_put_vars_short(ncid, varid, start, count, NULL, op); +} + /** Interface to netCDF data write function. */ int PIOc_put_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const unsigned long long *op) @@ -1445,8 +775,64 @@ int PIOc_put_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, const /** Interface to netCDF data write function. */ -int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const void *buf, - PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_put_vara_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const long *op) +{ + return PIOc_put_vars_long(ncid, varid, start, count, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_text(int ncid, int varid, const char *op) +{ + return PIOc_put_vars_text(ncid, varid, NULL, NULL, NULL, op); +} + +/** PIO interface to nc_put_vars_int */ +int PIOc_put_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const int *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long long *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT64, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vara_double(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const double *op) +{ + return PIOc_put_vars_double(ncid, varid, start, count, NULL, op); +} + + +/** Interface to netCDF data write function. */ +int PIOc_put_var_uchar(int ncid, int varid, const unsigned char *op) +{ + return PIOc_put_vars_uchar(ncid, varid, NULL, NULL, NULL, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_var_long(int ncid, int varid, const long *op) +{ + return PIOc_put_vars_long(ncid, varid, NULL, NULL, NULL, op); +} + +/** + * PIO interface to nc_put_vars + * + * This routine is called collectively by all tasks in the + * communicator ios.union_comm. + + * Refer to the + * netcdf documentation. */ +int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const void *buf, PIO_Offset bufcount, + MPI_Datatype buftype) { int ierr; int msg; @@ -1463,7 +849,7 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VARA; + msg = PIO_MSG_PUT_VARS; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1478,13 +864,14 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_put_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_put_vars(file->fh, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf);; } break; #endif @@ -1499,7 +886,8 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; + ierr = ncmpi_bput_vars(file->fh, varid, start, count, stride, buf, + bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -1518,14 +906,8 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset } /** Interface to netCDF data write function. */ -int PIOc_put_vara_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const long *op) -{ - return PIOc_put_vars_long(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const double *op) +int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, + PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -1542,7 +924,7 @@ int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const do if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_DOUBLE; + msg = PIO_MSG_PUT_VAR1; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1557,13 +939,13 @@ int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const do #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_double(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_var1(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -1578,7 +960,7 @@ int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const do request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_double(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_var1(file->fh, varid, index, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -1597,20 +979,8 @@ int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const do } /** Interface to netCDF data write function. */ -int PIOc_put_var_text(int ncid, int varid, const char *op) -{ - return PIOc_put_vars_text(ncid, varid, NULL, NULL, NULL, op); -} - -/** PIO interface to nc_put_vars_int */ -int PIOc_put_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const int *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const short *op) +int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const void *buf, + PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -1627,7 +997,7 @@ int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const sho if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_PUT_VAR1_SHORT; + msg = PIO_MSG_PUT_VARA; if(ios->async_interface && ! ios->ioproc){ if(ios->compmaster) @@ -1642,13 +1012,13 @@ int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const sho #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE); - ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: if(ios->io_rank==0){ - ierr = nc_put_var1_short(file->fh, varid, (size_t *) index, op);; + ierr = nc_put_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; } break; #endif @@ -1663,7 +1033,7 @@ int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const sho request = vdesc->request+vdesc->nreqs; if(ios->io_rank==0){ - ierr = ncmpi_bput_var1_short(file->fh, varid, index, op, request);; + ierr = ncmpi_bput_vara(file->fh, varid, start, count, buf, bufcount, buftype, request);; }else{ *request = PIO_REQ_NULL; } @@ -1681,31 +1051,3 @@ int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const sho return ierr; } -/** Interface to netCDF data write function. */ -int PIOc_put_vars_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const long long *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT64, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_double(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const double *op) -{ - return PIOc_put_vars_double(ncid, varid, start, count, NULL, op); -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_var_uchar(int ncid, int varid, const unsigned char *op) -{ - return PIOc_put_vars_uchar(ncid, varid, NULL, NULL, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_long(int ncid, int varid, const long *op) -{ - return PIOc_put_vars_long(ncid, varid, NULL, NULL, NULL, op); -} - - From 98eed4dd7836f6b6449b7700250a796345b3404d Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 24 May 2016 09:38:50 -0400 Subject: [PATCH 80/83] futher cleanup of var1 functions --- src/clib/pio_put_nc_async.c | 572 ++++++++++++++---------------------- 1 file changed, 225 insertions(+), 347 deletions(-) diff --git a/src/clib/pio_put_nc_async.c b/src/clib/pio_put_nc_async.c index 4d80cf889892..ba653397e0bd 100644 --- a/src/clib/pio_put_nc_async.c +++ b/src/clib/pio_put_nc_async.c @@ -23,7 +23,7 @@ * @param *stride an array of strides (must have same number of * entries as variable has dimensions). If NULL, strides of 1 will be * used. - * + * * @param xtype the netCDF type of the data being passed in buf. Data * will be automatically covnerted from this type to the type of the * variable being written to. @@ -33,7 +33,7 @@ * @return PIO_NOERR on success, error code otherwise. */ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, nc_type xtype, const void *buf) + const PIO_Offset *stride, nc_type xtype, const void *buf) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -79,11 +79,11 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off if (!count) { int dimid[ndims]; - + /* Get the dimids for this var. */ if ((ierr = PIOc_inq_vardimid(ncid, varid, dimid))) return check_netcdf(file, ierr, __FILE__, __LINE__); - + /* Get the length of each dimension. */ for (int vd = 0; vd < ndims; vd++) if ((ierr = PIOc_inq_dimlen(ncid, dimid[vd], &dimlen[vd]))) @@ -116,7 +116,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off char count_present = count ? true : false; char stride_present = stride ? true : false; - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); /* Send the function parameters and associated informaiton @@ -134,11 +134,11 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off if (!mpierr) mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && count_present) - mpierr = MPI_Bcast((PIO_Offset *)count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((PIO_Offset *)count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); if (!mpierr && stride_present) - mpierr = MPI_Bcast((PIO_Offset *)stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + mpierr = MPI_Bcast((PIO_Offset *)stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); if (!mpierr) mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); if (!mpierr) @@ -151,7 +151,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off for (int e = 0; e < num_elem; e++) LOG((2, "PIOc_put_vars_tc element %d = %d", e, ((int *)buf)[e])); - + /* Send the data. */ if (!mpierr) mpierr = MPI_Bcast((void *)buf, num_elem * typelen, MPI_BYTE, ios->compmaster, @@ -160,7 +160,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off /* Handle MPI errors. */ if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr2, __FILE__, __LINE__); + return check_mpi(file, mpierr2, __FILE__, __LINE__); check_mpi(file, mpierr, __FILE__, __LINE__); /* /\* Broadcast values currently only known on computation tasks to IO tasks. *\/ */ @@ -169,7 +169,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off /* if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) */ /* check_mpi(file, mpierr, __FILE__, __LINE__); */ } - + /* If this is an IO task, then call the netCDF function. */ if (ios->ioproc) { @@ -178,7 +178,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off { vdesc = file->varlist + varid; if (vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0) - vdesc->request = realloc(vdesc->request, + vdesc->request = realloc(vdesc->request, sizeof(int) * (vdesc->nreqs + PIO_REQUEST_ALLOC_CHUNK)); request = vdesc->request+vdesc->nreqs; @@ -208,14 +208,14 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off break; default: LOG((0, "Unknown type for pnetcdf file! xtype = %d", xtype)); - + } else *request = PIO_REQ_NULL; - + vdesc->nreqs++; flush_output_buffer(file, false, 0); - } + } #endif /* _PNETCDF */ #ifdef _NETCDF if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) @@ -245,7 +245,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off ierr = nc_put_vars_double(ncid, varid, (size_t *)start, (size_t *)count, (ptrdiff_t *)stride, buf); break; -#ifdef _NETCDF4 +#ifdef _NETCDF4 case NC_UBYTE: ierr = nc_put_vars_uchar(ncid, varid, (size_t *)start, (size_t *)count, (ptrdiff_t *)stride, buf); @@ -273,7 +273,7 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off default: ierr = nc_put_vars(ncid, varid, (size_t *)start, (size_t *)count, (ptrdiff_t *)stride, buf); -#endif /* _NETCDF4 */ +#endif /* _NETCDF4 */ } #endif /* _NETCDF */ } @@ -287,117 +287,94 @@ int PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off return ierr; } +/** Interface to netCDF data write function. */ +int PIOc_put_vars_text(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const char *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_CHAR, op); +} + /** Interface to netCDF data write function. */ int PIOc_put_vars_uchar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, - const unsigned char *op) + const unsigned char *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UBYTE, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UBYTE, op); +} + +/** Interface to netCDF data write function. */ +int PIOc_put_vars_schar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const signed char *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_BYTE, op); } /** Interface to netCDF data write function. */ int PIOc_put_vars_ushort(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const unsigned short *op) + const PIO_Offset *stride, const unsigned short *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_USHORT, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_USHORT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vars_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const unsigned long long *op) +int PIOc_put_vars_short(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, const short *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT64, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_SHORT, op); } /** Interface to netCDF data write function. */ int PIOc_put_vars_uint(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const unsigned int *op) + const PIO_Offset *stride, const unsigned int *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT, op); } -/** Interface to netCDF data write function. */ -int PIOc_put_var_ushort(int ncid, int varid, const unsigned short *op) +/** PIO interface to nc_put_vars_int */ +int PIOc_put_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const int *op) { - return PIOc_put_vars_tc(ncid, varid, NULL, NULL, NULL, NC_USHORT, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_text (int ncid, int varid, const PIO_Offset index[], const char *op) +int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long *op) { - int ndims; - int ierr; - - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; - - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; - - return PIOc_put_vars_text(ncid, varid, index, count, NULL, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_uchar (int ncid, int varid, const PIO_Offset index[], - const unsigned char *op) +int PIOc_put_vars_float(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const float *op) { - int ndims; - int ierr; - - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; - - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; - - return PIOc_put_vars_uchar(ncid, varid, index, count, NULL, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset index[], const signed char *op) +int PIOc_put_vars_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const long long *op) { - int ndims; - int ierr; - - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; - - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; - - return PIOc_put_vars_schar(ncid, varid, index, count, NULL, op); + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT64, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_ushort (int ncid, int varid, const PIO_Offset index[], - const unsigned short *op) +int PIOc_put_vars_double(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const double *op) { - int ndims; - int ierr; - - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; - - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_DOUBLE, op); +} - return PIOc_put_vars_short(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_vars_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, const unsigned long long *op) +{ + return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_UINT64, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_uint(int ncid, int varid, const PIO_Offset index[], const unsigned int *op) +int PIOc_put_var1_tc(int ncid, int varid, const PIO_Offset *index, nc_type xtype, + const void *op) { int ndims; int ierr; @@ -411,203 +388,248 @@ int PIOc_put_var1_uint(int ncid, int varid, const PIO_Offset index[], const unsi for (int c = 0; c < ndims; c++) count[c] = 1; - return PIOc_put_vars_uint(ncid, varid, index, count, NULL, op); + return PIOc_put_vars_tc(ncid, varid, index, count, NULL, xtype, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset index[], const short *op) +int PIOc_put_var1_text(int ncid, int varid, const PIO_Offset *index, const char *op) { - int ndims; - int ierr; - - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; - - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; - - return PIOc_put_vars_short(ncid, varid, index, count, NULL, op); + return PIOc_put_var1_tc(ncid, varid, index, NC_CHAR, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_int(int ncid, int varid, const PIO_Offset index[], const int *op) +int PIOc_put_var1_uchar(int ncid, int varid, const PIO_Offset *index, + const unsigned char *op) { - int ndims; - int ierr; + return PIOc_put_var1_tc(ncid, varid, index, NC_UBYTE, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_schar(int ncid, int varid, const PIO_Offset *index, + const signed char *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_BYTE, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_ushort(int ncid, int varid, const PIO_Offset *index, + const unsigned short *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_USHORT, op); +} - return PIOc_put_vars_int(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_var1_short(int ncid, int varid, const PIO_Offset *index, + const short *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_SHORT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_float(int ncid, int varid, const PIO_Offset index[], const float *op) +int PIOc_put_var1_uint(int ncid, int varid, const PIO_Offset *index, + const unsigned int *op) { - int ndims; - int ierr; + return PIOc_put_var1_tc(ncid, varid, index, NC_UINT, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_int(int ncid, int varid, const PIO_Offset *index, const int *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_INT, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_float(int ncid, int varid, const PIO_Offset *index, const float *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_FLOAT, op); +} - return PIOc_put_vars_float(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset *index, const long *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_LONG, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_long(int ncid, int varid, const PIO_Offset index[], const long *op) +int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset *index, + const double *op) { - int ndims; - int ierr; + return PIOc_put_var1_tc(ncid, varid, index, NC_DOUBLE, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_ulonglong(int ncid, int varid, const PIO_Offset *index, + const unsigned long long *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_UINT64, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_var1_longlong(int ncid, int varid, const PIO_Offset *index, + const long long *op) +{ + return PIOc_put_var1_tc(ncid, varid, index, NC_INT64, op); +} - return PIOc_put_vars_long(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_vara_text(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const char *op) +{ + return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_double(int ncid, int varid, const PIO_Offset index[], const double *op) +int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned char *op) { - int ndims; - int ierr; + return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_schar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const signed char *op) +{ + return PIOc_put_vars_schar(ncid, varid, start, count, NULL, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_ushort(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned short *op) +{ + return PIOc_put_vars_ushort(ncid, varid, start, count, NULL, op); +} - return PIOc_put_vars_double(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_vara_short(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const short *op) +{ + return PIOc_put_vars_short(ncid, varid, start, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], const unsigned long long *op) +int PIOc_put_vara_uint(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned int *op) { - int ndims; - int ierr; + return PIOc_put_vars_uint(ncid, varid, start, count, NULL, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const int *op) +{ + return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_long(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const long *op) +{ + return PIOc_put_vars_long(ncid, varid, start, count, NULL, op); +} - return PIOc_put_vars_ulonglong(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_vara_float(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const float *op) +{ + return PIOc_put_vars_float(ncid, varid, start, count, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var1_longlong (int ncid, int varid, const PIO_Offset index[], const long long *op) +int PIOc_put_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const unsigned long long *op) { - int ndims; - int ierr; + return PIOc_put_vars_ulonglong(ncid, varid, start, count, NULL, op); +} - /* Find the number of dimensions. */ - if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) - return ierr; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_longlong(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const long long *op) +{ + return PIOc_put_vars_longlong(ncid, varid, start, count, NULL, op); +} - /* Set up count array. */ - PIO_Offset count[ndims]; - for (int c = 0; c < ndims; c++) - count[c] = 1; +/** Interface to netCDF data write function. */ +int PIOc_put_vara_double(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const double *op) +{ + return PIOc_put_vars_double(ncid, varid, start, count, NULL, op); +} - return PIOc_put_vars_longlong(ncid, varid, index, count, NULL, op); +/** Interface to netCDF data write function. */ +int PIOc_put_var_text(int ncid, int varid, const char *op) +{ + return PIOc_put_vars_text(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_uchar(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned char *op) +int PIOc_put_var_uchar(int ncid, int varid, const unsigned char *op) { - return PIOc_put_vars_uchar(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_uchar(ncid, varid, NULL, NULL, NULL, op); } +/** Interface to netCDF data write function. */ +int PIOc_put_var_schar(int ncid, int varid, const signed char *op) +{ + return PIOc_put_vars_schar(ncid, varid, NULL, NULL, NULL, op); +} /** Interface to netCDF data write function. */ -int PIOc_put_vars_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const long *op) +int PIOc_put_var_ushort(int ncid, int varid, const unsigned short *op) { - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); + return PIOc_put_vars_tc(ncid, varid, NULL, NULL, NULL, NC_USHORT, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_short(int ncid, int varid, const short *op) +int PIOc_put_var_short(int ncid, int varid, const short *op) { return PIOc_put_vars_short(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const int *op) +int PIOc_put_var_uint(int ncid, int varid, const unsigned int *op) { - return PIOc_put_vars_int(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_uint(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_vara_text (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const char *op) +int PIOc_put_var_int(int ncid, int varid, const int *op) { - return PIOc_put_vars_text(ncid, varid, start, count, NULL, op); + return PIOc_put_vars_int(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_ulonglong (int ncid, int varid, const unsigned long long *op) +int PIOc_put_var_long(int ncid, int varid, const long *op) { - return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_long(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_int(int ncid, int varid, const int *op) +int PIOc_put_var_float(int ncid, int varid, const float *op) { - return PIOc_put_vars_int(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_float(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_longlong(int ncid, int varid, const long long *op) +int PIOc_put_var_ulonglong(int ncid, int varid, const unsigned long long *op) { - return PIOc_put_vars_longlong(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_ulonglong(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_schar(int ncid, int varid, const signed char *op) +int PIOc_put_var_longlong(int ncid, int varid, const long long *op) { - return PIOc_put_vars_schar(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_longlong(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ -int PIOc_put_var_uint(int ncid, int varid, const unsigned int *op) +int PIOc_put_var_double(int ncid, int varid, const double *op) { - return PIOc_put_vars_uint(ncid, varid, NULL, NULL, NULL, op); + return PIOc_put_vars_double(ncid, varid, NULL, NULL, NULL, op); } /** Interface to netCDF data write function. */ int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, - MPI_Datatype buftype) + MPI_Datatype buftype) { int ierr; int msg; @@ -627,7 +649,7 @@ int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, msg = PIO_MSG_PUT_VAR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -654,7 +676,7 @@ int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, vdesc = file->varlist + varid; if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, + vdesc->request = realloc(vdesc->request, sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); } request = vdesc->request+vdesc->nreqs; @@ -678,149 +700,6 @@ int PIOc_put_var(int ncid, int varid, const void *buf, PIO_Offset bufcount, return ierr; } -/** Interface to netCDF data write function. */ -int PIOc_put_vara_ushort(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned short *op) -{ - return PIOc_put_vars_ushort(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_short (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const PIO_Offset *stride, const short *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_SHORT, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_uint(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const unsigned int *op) -{ - return PIOc_put_vars_uint(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_schar (int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const signed char *op) -{ - return PIOc_put_vars_schar(ncid, varid, start, count, NULL, op); -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_schar(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const signed char *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_BYTE, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_float(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const float *op) -{ - return PIOc_put_vars_float(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_text(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const char *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_CHAR, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_double(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const double *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_DOUBLE, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const long long *op) -{ - return PIOc_put_vars_longlong(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_double (int ncid, int varid, const double *op) -{ - return PIOc_put_vars_double(ncid, varid, NULL, NULL, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_float(int ncid, int varid, const float *op) -{ - return PIOc_put_vars_float(ncid, varid, NULL, NULL, NULL, op); -} - -int PIOc_put_vars_float(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const float *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, op); -} - -int PIOc_put_vara_short(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const short *op) -{ - return PIOc_put_vars_short(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const unsigned long long *op) -{ - return PIOc_put_vars_ulonglong(ncid, varid, start, count, NULL, op); -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_long(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const long *op) -{ - return PIOc_put_vars_long(ncid, varid, start, count, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_text(int ncid, int varid, const char *op) -{ - return PIOc_put_vars_text(ncid, varid, NULL, NULL, NULL, op); -} - -/** PIO interface to nc_put_vars_int */ -int PIOc_put_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const int *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vars_longlong(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, const long long *op) -{ - return PIOc_put_vars_tc(ncid, varid, start, count, stride, NC_INT64, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_vara_double(int ncid, int varid, const PIO_Offset *start, - const PIO_Offset *count, const double *op) -{ - return PIOc_put_vars_double(ncid, varid, start, count, NULL, op); -} - - -/** Interface to netCDF data write function. */ -int PIOc_put_var_uchar(int ncid, int varid, const unsigned char *op) -{ - return PIOc_put_vars_uchar(ncid, varid, NULL, NULL, NULL, op); -} - -/** Interface to netCDF data write function. */ -int PIOc_put_var_long(int ncid, int varid, const long *op) -{ - return PIOc_put_vars_long(ncid, varid, NULL, NULL, NULL, op); -} - /** * PIO interface to nc_put_vars * @@ -832,7 +711,7 @@ int PIOc_put_var_long(int ncid, int varid, const long *op) * netcdf documentation. */ int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, const void *buf, PIO_Offset bufcount, - MPI_Datatype buftype) + MPI_Datatype buftype) { int ierr; int msg; @@ -852,7 +731,7 @@ int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset msg = PIO_MSG_PUT_VARS; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -880,7 +759,7 @@ int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset vdesc = file->varlist + varid; if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, + vdesc->request = realloc(vdesc->request, sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); } request = vdesc->request+vdesc->nreqs; @@ -906,8 +785,8 @@ int PIOc_put_vars(int ncid, int varid, const PIO_Offset *start, const PIO_Offset } /** Interface to netCDF data write function. */ -int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *buf, - PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_put_var1(int ncid, int varid, const PIO_Offset *index, const void *buf, + PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -927,7 +806,7 @@ int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *bu msg = PIO_MSG_PUT_VAR1; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -954,7 +833,7 @@ int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *bu vdesc = file->varlist + varid; if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, + vdesc->request = realloc(vdesc->request, sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); } request = vdesc->request+vdesc->nreqs; @@ -980,7 +859,7 @@ int PIOc_put_var1 (int ncid, int varid, const PIO_Offset index[], const void *bu /** Interface to netCDF data write function. */ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const void *buf, - PIO_Offset bufcount, MPI_Datatype buftype) + PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -1000,7 +879,7 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset msg = PIO_MSG_PUT_VARA; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, ios->compmaster, ios->intercomm); } @@ -1027,7 +906,7 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset vdesc = file->varlist + varid; if(vdesc->nreqs%PIO_REQUEST_ALLOC_CHUNK == 0 ){ - vdesc->request = realloc(vdesc->request, + vdesc->request = realloc(vdesc->request, sizeof(int)*(vdesc->nreqs+PIO_REQUEST_ALLOC_CHUNK)); } request = vdesc->request+vdesc->nreqs; @@ -1050,4 +929,3 @@ int PIOc_put_vara(int ncid, int varid, const PIO_Offset *start, const PIO_Offset return ierr; } - From de1c4e7ea5d066aecff9ac082cb387ddf0899f4e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 26 May 2016 15:14:43 -0400 Subject: [PATCH 81/83] got get_vars working --- src/clib/pio_get_nc_async.c | 7508 ++++++++++++++++------------------- src/clib/pio_msg.c | 203 +- src/clib/pio_nc_async.c | 5 +- src/clib/pio_varm.c | 998 +++++ tests/unit/test_intercomm.c | 15 +- 5 files changed, 4547 insertions(+), 4182 deletions(-) diff --git a/src/clib/pio_get_nc_async.c b/src/clib/pio_get_nc_async.c index 0da690aaf216..f3cbc0f5a9ec 100644 --- a/src/clib/pio_get_nc_async.c +++ b/src/clib/pio_get_nc_async.c @@ -1,4988 +1,4198 @@ +#include #include #include -int PIOc_get_var1_schar (int ncid, int varid, const PIO_Offset index[], signed char *buf) +int PIOc_get_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, nc_type xtype, void *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SCHAR; - ibuftype = MPI_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif + iosystem_desc_t *ios; /** Pointer to io system information. */ + file_desc_t *file; /** Pointer to file information. */ + int ierr = PIO_NOERR; /** Return code from function calls. */ + int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */ + int ndims; /** The number of dimensions in the variable. */ + int *dimids; /** The IDs of the dimensions for this variable. */ + PIO_Offset typelen; /** Size (in bytes) of the data type of data in buf. */ + size_t num_elem = 1; /** Number of data elements in the buffer. */ + int bcast = false; + + LOG((1, "PIOc_get_vars_tc ncid = %d varid = %d start = %d count = %d " + "stride = %d xtype = %d", ncid, varid, start, count, stride, xtype)); + + /* User must provide a place to put some data. */ + if (!buf) + return PIO_EINVAL; + + /* Find the info about this file. */ + if (!(file = pio_get_file_from_id(ncid))) + return PIO_EBADID; + ios = file->iosystem; + + /* Run these on all tasks if async is not in use, but only on + * non-IO tasks if async is in use. */ + if (!ios->async_interface || !ios->ioproc) + { + /* Get the length of the data type. */ + if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &typelen))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Get the number of dims for this var. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + PIO_Offset dimlen[ndims]; + + /* If no count array was passed, we need to know the dimlens + * so we can calculate how many data elements are in the + * buf. */ + if (!count) + { + int dimid[ndims]; + + /* Get the dimids for this var. */ + if ((ierr = PIOc_inq_vardimid(ncid, varid, dimid))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Get the length of each dimension. */ + for (int vd = 0; vd < ndims; vd++) + if ((ierr = PIOc_inq_dimlen(ncid, dimid[vd], &dimlen[vd]))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + } + + /* Figure out the real start, count, and stride arrays. (The + * user may have passed in NULLs.) */ + PIO_Offset rstart[ndims], rcount[ndims], rstride[ndims]; + for (int vd = 0; vd < ndims; vd++) + { + rstart[vd] = start ? start[vd] : 0; + rcount[vd] = count ? count[vd] : dimlen[vd]; + rstride[vd] = stride ? stride[vd] : 1; + } + + /* How many elements in buf? */ + for (int vd = 0; vd < ndims; vd++) + num_elem *= (rcount[vd] - rstart[vd])/rstride[vd]; + LOG((2, "PIOc_put_vars_tc num_elem = %d", num_elem)); + } + + /* If async is in use, and this is not an IO task, bcast the parameters. */ + if (ios->async_interface) + { + if (!ios->ioproc) + { + int msg = PIO_MSG_GET_VARS; + char start_present = start ? true : false; + char count_present = count ? true : false; + char stride_present = stride ? true : false; + + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1, MPI_INT, ios->ioroot, 1, ios->union_comm); + + /* Send the function parameters and associated informaiton + * to the msg handler. */ + if (!mpierr) + mpierr = MPI_Bcast(&ncid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&varid, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&ndims, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && start_present) + mpierr = MPI_Bcast((PIO_Offset *)start, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && count_present) + mpierr = MPI_Bcast((PIO_Offset *)count, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, ios->compmaster, ios->intercomm); + if (!mpierr && stride_present) + mpierr = MPI_Bcast((PIO_Offset *)stride, ndims, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&xtype, 1, MPI_INT, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + if (!mpierr) + mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->compmaster, ios->intercomm); + LOG((2, "PIOc_get_vars_tc ncid = %d varid = %d ndims = %d start_present = %d " + "count_present = %d stride_present = %d xtype = %d num_elem = %d", ncid, varid, + ndims, start_present, count_present, stride_present, xtype, num_elem)); + } + + /* Handle MPI errors. */ + if ((mpierr2 = MPI_Bcast(&mpierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr2, __FILE__, __LINE__); + check_mpi(file, mpierr, __FILE__, __LINE__); + + /* Broadcast values currently only known on computation tasks to IO tasks. */ + if ((mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, ios->comproot, ios->my_comm))) + check_mpi(file, mpierr, __FILE__, __LINE__); + } + + /* If this is an IO task, then call the netCDF function. */ + if (ios->ioproc) + { #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + if (file->iotype == PIO_IOTYPE_PNETCDF) + { #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_schar(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_schar_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + LOG((1, "PNET_READ_AND_BCAST")); + ncmpi_begin_indep_data(file->fh); + if (ios->iomaster) + { + switch(xtype) + { + case NC_BYTE: + ierr = ncmpi_get_vars_schar(ncid, varid, start, count, stride, buf); + break; + case NC_CHAR: + ierr = ncmpi_get_vars_text(ncid, varid, start, count, stride, buf); + break; + case NC_SHORT: + ierr = ncmpi_get_vars_short(ncid, varid, start, count, stride, buf); + break; + case NC_INT: + ierr = ncmpi_get_vars_int(ncid, varid, start, count, stride, buf); + break; + case NC_FLOAT: + ierr = ncmpi_get_vars_float(ncid, varid, start, count, stride, buf); + break; + case NC_DOUBLE: + ierr = ncmpi_get_vars_double(ncid, varid, start, count, stride, buf); + break; + case NC_INT64: + ierr = ncmpi_get_vars_longlong(ncid, varid, start, count, stride, buf); + break; + default: + LOG((0, "Unknown type for pnetcdf file! xtype = %d", xtype)); + } + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else /* PNET_READ_AND_BCAST */ + LOG((1, "not PNET_READ_AND_BCAST")); + switch(xtype) + { + case NC_BYTE: + ierr = ncmpi_get_vars_schar_all(ncid, varid, start, count, stride, buf); + break; + case NC_CHAR: + ierr = ncmpi_get_vars_text_all(ncid, varid, start, count, stride, buf); + break; + case NC_SHORT: + ierr = ncmpi_get_vars_short_all(ncid, varid, start, count, stride, buf); + break; + case NC_INT: + ierr = ncmpi_get_vars_int_all(ncid, varid, start, count, stride, buf); + for (int i = 0; i < 4; i++) + LOG((2, "((int *)buf)[%d] = %d", i, ((int *)buf)[0])); + break; + case NC_FLOAT: + ierr = ncmpi_get_vars_float_all(ncid, varid, start, count, stride, buf); + break; + case NC_DOUBLE: + ierr = ncmpi_get_vars_double_all(ncid, varid, start, count, stride, buf); + break; + case NC_INT64: + ierr = ncmpi_get_vars_longlong_all(ncid, varid, start, count, stride, buf); + break; + default: + LOG((0, "Unknown type for pnetcdf file! xtype = %d", xtype)); + } +#endif /* PNET_READ_AND_BCAST */ + } +#endif /* _PNETCDF */ +#ifdef _NETCDF + if (file->iotype != PIO_IOTYPE_PNETCDF && file->do_io) + switch(xtype) + { + case NC_BYTE: + ierr = nc_get_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_CHAR: + ierr = nc_get_vars_schar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_SHORT: + ierr = nc_get_vars_short(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT: + ierr = nc_get_vars_int(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_FLOAT: + ierr = nc_get_vars_float(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_DOUBLE: + ierr = nc_get_vars_double(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; +#ifdef _NETCDF4 + case NC_UBYTE: + ierr = nc_get_vars_uchar(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_USHORT: + ierr = nc_get_vars_ushort(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT: + ierr = nc_get_vars_uint(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_INT64: + ierr = nc_get_vars_longlong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + case NC_UINT64: + ierr = nc_get_vars_ulonglong(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); + break; + /* case NC_STRING: */ + /* ierr = nc_get_vars_string(ncid, varid, (size_t *)start, (size_t *)count, */ + /* (ptrdiff_t *)stride, (void *)buf); */ + /* break; */ + default: + ierr = nc_get_vars(ncid, varid, (size_t *)start, (size_t *)count, + (ptrdiff_t *)stride, buf); +#endif /* _NETCDF4 */ + } +#endif /* _NETCDF */ } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + /* Broadcast and check the return code. */ + if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); + if (ierr) + return check_netcdf(file, ierr, __FILE__, __LINE__); + + /* Send the data. */ + LOG((2, "PIOc_get_vars_tc bcasting data num_elem = %d typelen = %d", num_elem, + typelen)); + if (!mpierr) + mpierr = MPI_Bcast((void *)buf, num_elem * typelen, MPI_BYTE, ios->ioroot, + ios->my_comm); + return ierr; +} - return ierr; +int PIOc_get_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_INT, buf); } -int PIOc_get_vars_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], unsigned long long *buf) +int PIOc_get_var1_schar (int ncid, int varid, const PIO_Offset *index, signed char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_SCHAR; + ibuftype = MPI_CHAR; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_ulonglong(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_schar(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_ulonglong_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_schar_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned char *buf) +int PIOc_get_vars_ulonglong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_uchar(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_varm_uchar_all(file->fh, varid, start, count, stride, imap, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], signed char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_schar(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_ulonglong(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_schar_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_vars_ulonglong_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], short *buf) +int PIOc_get_vars_short (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_SHORT; + ibuftype = MPI_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_short(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_short(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_short_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_short_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_double (int ncid, int varid, double *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_DOUBLE; + ibuftype = MPI_DOUBLE; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_double(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_double(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_double(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_double(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_double(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_double(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_double_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_double_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], double *buf) +int PIOc_get_vara_double (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, double *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_DOUBLE; + ibuftype = MPI_DOUBLE; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_double(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_double(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_double_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_double_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_int (int ncid, int varid, int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_INT; + ibuftype = MPI_INT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_int(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_int(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_int(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_int(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_int(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_int(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_int_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_int_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_ushort (int ncid, int varid, unsigned short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_ushort(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_ushort(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_ushort(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_ushort_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = PIO_NOERR; - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vara_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_ushort(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_ushort(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_text(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_ushort(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_text_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var_ushort_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], int *buf) +int PIOc_get_vara_text (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_TEXT; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_int(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_text(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_int_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_text_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset index[], float *buf) +int PIOc_get_vara_int (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_FLOAT; - ibuftype = MPI_FLOAT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_INT; + ibuftype = MPI_INT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_float(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_int(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_float_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_vara_int_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset index[], short *buf) +int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset *index, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SHORT; - ibuftype = MPI_SHORT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_FLOAT; + ibuftype = MPI_FLOAT; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_short(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_float(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_short_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_float_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], int *buf) +int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_SHORT; + ibuftype = MPI_SHORT; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_int(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_short(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_int_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_short_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_text (int ncid, int varid, char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_text(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_text(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_text(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_text_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_TEXT; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = PIO_NOERR; - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], double *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_text(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_text(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_double(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_text(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_double_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_var_text_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], signed char *buf) +int PIOc_get_vars_schar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, signed char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_SCHAR; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_schar(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_schar(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_schar_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_schar_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], unsigned short *buf) +int PIOc_get_vara_ushort (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_ushort(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_ushort(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_ushort_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_ushort_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_ushort (int ncid, int varid, const PIO_Offset index[], unsigned short *buf) +int PIOc_get_var1_ushort (int ncid, int varid, const PIO_Offset *index, unsigned short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ushort(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_ushort(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_ushort_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_ushort_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_float (int ncid, int varid, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_FLOAT; + ibuftype = MPI_FLOAT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_float(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_float(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_float(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_float(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_float(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_float(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_float_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_float_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], unsigned char *buf) +int PIOc_get_vars_uchar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_UCHAR; + ibuftype = MPI_UNSIGNED_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_uchar(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_uchar(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_uchar_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_uchar_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR; + ibufcnt = bufcount; + ibuftype = buftype; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; + ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset index[], long long *buf) +int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONGLONG; - ibuftype = MPI_LONG_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_LONGLONG; + ibuftype = MPI_LONG_LONG; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_longlong(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_longlong(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_longlong_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_longlong_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], unsigned short *buf) +int PIOc_get_vars_ushort (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_ushort(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_ushort(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_ushort_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_ushort_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_long (int ncid, int varid, long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_LONG; + ibuftype = MPI_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_long(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_long(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_long(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_long(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_long(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_long(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_long_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_long_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset index[], double *buf) +int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset *index, double *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_DOUBLE; - ibuftype = MPI_DOUBLE; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_DOUBLE; + ibuftype = MPI_DOUBLE; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_double(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_double(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_double_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_double_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], unsigned int *buf) +int PIOc_get_vara_uint (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_UINT; + ibuftype = MPI_UNSIGNED; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_uint(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_uint(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_uint_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_uint_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], long long *buf) +int PIOc_get_vars_longlong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_LONGLONG; + ibuftype = MPI_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_longlong(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_longlong(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_longlong_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_longlong_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_longlong (int ncid, int varid, long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_LONGLONG; + ibuftype = MPI_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_longlong(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_longlong(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_longlong(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_longlong(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_longlong(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_longlong(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_longlong_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_longlong_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], short *buf) +int PIOc_get_vara_short (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_SHORT; + ibuftype = MPI_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_short(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_short(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_short_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_short_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], long *buf) +int PIOc_get_vara_long (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_LONG; + ibuftype = MPI_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_long(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_long(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_long_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_long_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_int (int ncid, int varid, const PIO_Offset index[], int *buf) +int PIOc_get_var1_int (int ncid, int varid, const PIO_Offset *index, int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_INT; - ibuftype = MPI_INT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_INT; + ibuftype = MPI_INT; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_int(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_int(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_int_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_int_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset index[], unsigned long long *buf) +int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset *index, unsigned long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ulonglong(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_ulonglong(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_ulonglong_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_ulonglong_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_uchar (int ncid, int varid, unsigned char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_UCHAR; + ibuftype = MPI_UNSIGNED_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_uchar(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_uchar(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_uchar(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_uchar(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_uchar(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_uchar(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_uchar_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_uchar_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], unsigned char *buf) +int PIOc_get_vara_uchar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_UCHAR; + ibuftype = MPI_UNSIGNED_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_uchar(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_uchar(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_uchar_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_uchar_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], float *buf) +int PIOc_get_vars_float (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_FLOAT; + ibuftype = MPI_FLOAT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_float(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_float(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_float_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_float_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], long *buf) +int PIOc_get_vars_long (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_LONG; + ibuftype = MPI_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_long(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_long(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_long_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vars_long_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1 (int ncid, int varid, const PIO_Offset index[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_var1 (int ncid, int varid, const PIO_Offset *index, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1; + ibufcnt = bufcount; + ibuftype = buftype; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; + ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_uint(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_uint(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_uint(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_uint_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_UINT; + ibuftype = MPI_UNSIGNED; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; } - } + ierr = PIO_NOERR; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vara (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_uint(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_uint(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_uint(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; + ierr = ncmpi_get_var_uint_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], signed char *buf) +int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA; + ibufcnt = bufcount; + ibuftype = buftype; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_schar(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_schar_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset index[], unsigned int *buf) +int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, signed char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_UINT; - ibuftype = MPI_UNSIGNED; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_uint(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_uint_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_SCHAR; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], unsigned int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_uint(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_schar(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_uint_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_vara_schar_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], float *buf) +int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_UINT; + ibuftype = MPI_UNSIGNED; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_float(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_uint(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_float_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_uint_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], char *buf) +int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned int *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_text(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_varm_text_all(file->fh, varid, start, count, stride, imap, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_UINT; + ibuftype = MPI_UNSIGNED; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset index[], char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_TEXT; - ibuftype = MPI_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_text(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_uint(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var1_text_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_vars_uint_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], int *buf) +int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_int(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_varm_int_all(file->fh, varid, start, count, stride, imap, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_FLOAT; + ibuftype = MPI_FLOAT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_uint(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_float(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_uint_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_vara_float_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_TEXT; + ibuftype = MPI_CHAR; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_text(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_all(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype);; + ierr = ncmpi_get_var1_text_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], double *buf) +int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, double *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_double(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_double_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_DOUBLE; + ibuftype = MPI_DOUBLE; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_longlong(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_double(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_longlong_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vars_double_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) +int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_ulonglong(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_ulonglong(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_ulonglong(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_ulonglong_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_LONGLONG; + ibuftype = MPI_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], unsigned long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_ulonglong(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_longlong(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vara_ulonglong_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_longlong_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var_short (int ncid, int varid, short *buf) +int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_short(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_short(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_short(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_short_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; } - } + ierr = PIO_NOERR; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], float *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_ulonglong(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_ulonglong(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_float(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_ulonglong(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_float_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_var_ulonglong_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset index[], long *buf) +int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned long long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONG; - ibuftype = MPI_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_long(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_long_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARA_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_long(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vara_ulonglong(file->fh, varid, start, count, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_long_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_vara_ulonglong_all(file->fh, varid, start, count, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned short *buf) +int PIOc_get_var_short (int ncid, int varid, short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_ushort(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_varm_ushort_all(file->fh, varid, start, count, stride, imap, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_SHORT; + ibuftype = MPI_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; } - } + ierr = PIO_NOERR; - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_varm_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_short(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_short(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_longlong(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_short(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_longlong_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_var_short_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], char *buf) +int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_LONG; + ibuftype = MPI_LONG; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_text(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_long(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_text_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_long_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset index[], unsigned char *buf) +int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_uchar(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_uchar_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS_TEXT; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } - return ierr; -} -int PIOc_get_vars (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars(file->fh, varid, start, count, stride, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars_text(file->fh, varid, start, count, stride, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_vars_all(file->fh, varid, start, count, stride, buf, bufcount, buftype);; + ierr = ncmpi_get_vars_text_all(file->fh, varid, start, count, stride, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], short *buf) +int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR1_UCHAR; + ibuftype = MPI_UNSIGNED_CHAR; + ibufcnt = 1; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_short(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var1_uchar(file->fh, varid, index, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_short_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_var1_uchar_all(file->fh, varid, index, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } -int PIOc_get_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned long long *buf) +int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARM_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARS; + ibufcnt = bufcount; + ibuftype = buftype; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_vars(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_varm_ulonglong(file->fh, varid, start, count, stride, imap, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_vars(file->fh, varid, start, count, stride, buf, bufcount, buftype);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_varm_ulonglong_all(file->fh, varid, start, count, stride, imap, buf);; + ierr = ncmpi_get_vars_all(file->fh, varid, start, count, stride, buf, bufcount, buftype);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } int PIOc_get_var_schar (int ncid, int varid, signed char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VAR_SCHAR; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + int dimid[ndims]; + PIO_Offset dimsize; + ibufcnt = 1; + PIOc_inq_vardimid(file->fh, varid, dimid); + for(int i=0;ifh, dimid[i], &dimsize); + ibufcnt *= dimsize; + } + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ #ifdef _NETCDF #ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_schar(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_schar(file->fh, varid, buf);; - } - break; + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_var_schar(file->fh, varid, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_var_schar(file->fh, varid, buf);; + } + break; #endif #ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: + case PIO_IOTYPE_PNETCDF: #ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_schar(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_var_schar(file->fh, varid, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; #else - ierr = ncmpi_get_var_schar_all(file->fh, varid, buf);; + ierr = ncmpi_get_var_schar_all(file->fh, varid, buf);; #endif - break; + break; #endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } } - } - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } - return ierr; + return ierr; } diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 9c509398ca2a..be5c2676f7bf 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -40,8 +40,8 @@ int inq_type_handler(iosystem_desc_t *ios) return PIO_EIO; if ((mpierr = MPI_Bcast(&size_present, 1, MPI_CHAR, 0, ios->intercomm))) return PIO_EIO; - LOG((2, "inq_type_handler got parameters ncid = %d datatype = %d", ncid, xtype)); + /* Handle null pointer issues. */ if (name_present) namep = name; if (size_present) @@ -51,8 +51,6 @@ int inq_type_handler(iosystem_desc_t *ios) if ((ret = PIOc_inq_type(ncid, xtype, namep, sizep))) return ret; - if (sizep) - LOG((2, "inq_type_handler size = %d", *sizep)); LOG((1, "inq_type_handler succeeded!")); return PIO_NOERR; } @@ -676,63 +674,208 @@ int put_vars_handler(iosystem_desc_t *ios) switch(xtype) { case NC_BYTE: - ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_schar(ncid, varid, startp, countp, stridep, buf); break; case NC_CHAR: - ierr = PIOc_put_vars_schar(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_schar(ncid, varid, startp, countp, stridep, buf); break; case NC_SHORT: - ierr = PIOc_put_vars_short(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_short(ncid, varid, startp, countp, stridep, buf); break; case NC_INT: - ierr = PIOc_put_vars_int(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_int(ncid, varid, startp, countp, + stridep, buf); break; case NC_FLOAT: - ierr = PIOc_put_vars_float(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_float(ncid, varid, startp, countp, + stridep, buf); break; case NC_DOUBLE: - ierr = PIOc_put_vars_double(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_double(ncid, varid, startp, countp, + stridep, buf); break; #ifdef _NETCDF4 case NC_UBYTE: - ierr = PIOc_put_vars_uchar(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_uchar(ncid, varid, startp, countp, + stridep, buf); break; case NC_USHORT: - ierr = PIOc_put_vars_ushort(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_ushort(ncid, varid, startp, countp, + stridep, buf); break; case NC_UINT: - ierr = PIOc_put_vars_uint(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_uint(ncid, varid, startp, countp, + stridep, buf); break; case NC_INT64: - ierr = PIOc_put_vars_longlong(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_longlong(ncid, varid, startp, countp, + stridep, buf); break; case NC_UINT64: - ierr = PIOc_put_vars_ulonglong(ncid, varid, (size_t *)startp, (size_t *)countp, - (ptrdiff_t *)stridep, buf); + ierr = PIOc_put_vars_ulonglong(ncid, varid, startp, countp, + stridep, buf); break; /* case NC_STRING: */ - /* ierr = PIOc_put_vars_string(ncid, varid, (size_t *)startp, (size_t *)countp, */ - /* (ptrdiff_t *)stridep, (void *)buf); */ + /* ierr = PIOc_put_vars_string(ncid, varid, startp, countp, */ + /* stridep, (void *)buf); */ /* break; */ /* default:*/ - /* ierr = PIOc_put_vars(ncid, varid, (size_t *)startp, (size_t *)countp, */ - /* (ptrdiff_t *)stridep, buf); */ + /* ierr = PIOc_put_vars(ncid, varid, startp, countp, */ + /* stridep, buf); */ #endif /* _NETCDF4 */ } return PIO_NOERR; } +/** Handle var get operations. This code only runs on IO tasks. + * + * @param ios pointer to the iosystem_desc_t. + * @return PIO_NOERR for success, error code otherwise. +*/ +int get_vars_handler(iosystem_desc_t *ios) +{ + int ncid; + int varid; + int mpierr; + int ierr; + char *name; + int namelen; + PIO_Offset typelen; /** Length (in bytes) of this type. */ + nc_type xtype; /** Type of the data being written. */ + char start_present, count_present, stride_present; + PIO_Offset *startp = NULL, *countp = NULL, *stridep = NULL; + int ndims; /** Number of dimensions. */ + void *buf; /** Buffer for data storage. */ + size_t num_elem; /** Number of data elements in the buffer. */ + + LOG((1, "get_vars_handler")); + + /* Get the parameters for this function that the the comp master + * task is broadcasting. */ + if ((mpierr = MPI_Bcast(&ncid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&varid, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&ndims, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + + /* Now we know how big to make these arrays. */ + PIO_Offset start[ndims], count[ndims], stride[ndims]; + + if ((mpierr = MPI_Bcast(&start_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && start_present) + { + if ((mpierr = MPI_Bcast(start, ndims, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + LOG((1, "put_vars_handler getting start[0] = %d ndims = %d", start[0], ndims)); + } + if ((mpierr = MPI_Bcast(&count_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && count_present) + if ((mpierr = MPI_Bcast(count, ndims, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&stride_present, 1, MPI_CHAR, 0, ios->intercomm))) + return PIO_EIO; + if (!mpierr && stride_present) + if ((mpierr = MPI_Bcast(stride, ndims, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&xtype, 1, MPI_INT, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&num_elem, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + if ((mpierr = MPI_Bcast(&typelen, 1, MPI_OFFSET, 0, ios->intercomm))) + return PIO_EIO; + LOG((1, "get_vars_handler ncid = %d varid = %d ndims = %d start_present = %d " + "count_present = %d stride_present = %d xtype = %d num_elem = %d typelen = %d", + ncid, varid, ndims, start_present, count_present, stride_present, xtype, + num_elem, typelen)); + + for (int d = 0; d < ndims; d++) + { + if (start_present) + LOG((2, "start[%d] = %d\n", d, start[d])); + if (count_present) + LOG((2, "count[%d] = %d\n", d, count[d])); + if (stride_present) + LOG((2, "stride[%d] = %d\n", d, stride[d])); + } + + /* Allocate room for our data. */ + if (!(buf = malloc(num_elem * typelen))) + return PIO_ENOMEM; + + /* Set the non-NULL pointers. */ + if (start_present) + startp = start; + if (count_present) + countp = count; + if (stride_present) + stridep = stride; + + /* Call the function to read the data. */ + switch(xtype) + { + case NC_BYTE: + ierr = PIOc_get_vars_schar(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_CHAR: + ierr = PIOc_get_vars_schar(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_SHORT: + ierr = PIOc_get_vars_short(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_INT: + ierr = PIOc_get_vars_int(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_FLOAT: + ierr = PIOc_get_vars_float(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_DOUBLE: + ierr = PIOc_get_vars_double(ncid, varid, startp, countp, + stridep, buf); + break; +#ifdef _NETCDF4 + case NC_UBYTE: + ierr = PIOc_get_vars_uchar(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_USHORT: + ierr = PIOc_get_vars_ushort(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_UINT: + ierr = PIOc_get_vars_uint(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_INT64: + ierr = PIOc_get_vars_longlong(ncid, varid, startp, countp, + stridep, buf); + break; + case NC_UINT64: + ierr = PIOc_get_vars_ulonglong(ncid, varid, startp, countp, + stridep, buf); + break; + /* case NC_STRING: */ + /* ierr = PIOc_get_vars_string(ncid, varid, startp, countp, */ + /* stridep, (void *)buf); */ + /* break; */ + /* default:*/ + /* ierr = PIOc_get_vars(ncid, varid, startp, countp, */ + /* stridep, buf); */ +#endif /* _NETCDF4 */ + } + + LOG((1, "get_vars_handler succeeded!")); + return PIO_NOERR; +} + /** Do an inq_var on a netCDF variable. This function is only run on * IO tasks. * @@ -1493,7 +1636,7 @@ int pio_msg_handler(int io_rank, int component_count, iosystem_desc_t *iosys) inq_attid_handler(my_iosys); break; case PIO_MSG_GET_VARS: - var_handler(my_iosys, msg); + get_vars_handler(my_iosys); break; case PIO_MSG_PUT_VARS: put_vars_handler(my_iosys); diff --git a/src/clib/pio_nc_async.c b/src/clib/pio_nc_async.c index 93b59ae2721e..b05a2637ffda 100644 --- a/src/clib/pio_nc_async.c +++ b/src/clib/pio_nc_async.c @@ -291,8 +291,9 @@ int PIOc_inq_type(int ncid, nc_type xtype, char *name, PIO_Offset *sizep) slen = strlen(name); if ((mpierr = MPI_Bcast(&slen, 1, MPI_INT, ios->ioroot, ios->my_comm))) return check_mpi(file, mpierr, __FILE__, __LINE__); - if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) - return check_mpi(file, mpierr, __FILE__, __LINE__); + if (!mpierr) + if ((mpierr = MPI_Bcast((void *)name, slen + 1, MPI_CHAR, ios->ioroot, ios->my_comm))) + return check_mpi(file, mpierr, __FILE__, __LINE__); } if (sizep) if ((mpierr = MPI_Bcast(sizep , 1, MPI_OFFSET, ios->ioroot, ios->my_comm))) diff --git a/src/clib/pio_varm.c b/src/clib/pio_varm.c index d13b2ac41c18..3110a4333f39 100644 --- a/src/clib/pio_varm.c +++ b/src/clib/pio_varm.c @@ -990,3 +990,1001 @@ int PIOc_put_varm_longlong (int ncid, int varid, const PIO_Offset start[], const return ierr; } + +int PIOc_get_varm_uchar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned char *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_UCHAR; + ibuftype = MPI_UNSIGNED_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_uchar(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_uchar_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_schar (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], signed char *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_SCHAR; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_schar(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_schar_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_double (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], double *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_DOUBLE; + ibuftype = MPI_DOUBLE; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_double(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_double_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_text (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], char *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_TEXT; + ibuftype = MPI_CHAR; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_text(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_text_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_int (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], int *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_INT; + ibuftype = MPI_INT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_int(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_int(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_int_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_uint (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned int *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_UINT; + ibuftype = MPI_UNSIGNED; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_uint(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_uint_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM; + ibufcnt = bufcount; + ibuftype = buftype; + ierr = PIO_NOERR; + + if(ios->async_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_all(file->fh, varid, start, count, stride, imap, buf, bufcount, buftype);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_float (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], float *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_FLOAT; + ibuftype = MPI_FLOAT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_float(file->fh, varid,(size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_float(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_float_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_long (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], long *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_LONG; + ibuftype = MPI_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_long(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_long_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_ushort (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned short *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_ushort(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_ushort_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_longlong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], long long *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_LONGLONG; + ibuftype = MPI_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_longlong(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_longlong_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_short (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], short *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_SHORT; + ibuftype = MPI_SHORT; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_short(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_short_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + +int PIOc_get_varm_ulonglong (int ncid, int varid, const PIO_Offset start[], const PIO_Offset count[], const PIO_Offset stride[], const PIO_Offset imap[], unsigned long long *buf) +{ + int ierr; + int msg; + int mpierr; + iosystem_desc_t *ios; + file_desc_t *file; + MPI_Datatype ibuftype; + int ndims; + int ibufcnt; + bool bcast = false; + + file = pio_get_file_from_id(ncid); + if(file == NULL) + return PIO_EBADID; + ios = file->iosystem; + msg = PIO_MSG_GET_VARM_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; + ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + ibufcnt = 1; + for(int i=0;iasync_interface && ! ios->ioproc){ + if(ios->compmaster) + mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); + mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); + } + + + if(ios->ioproc){ + switch(file->iotype){ +#ifdef _NETCDF +#ifdef _NETCDF4 + case PIO_IOTYPE_NETCDF4P: + ierr = nc_get_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + break; + case PIO_IOTYPE_NETCDF4C: +#endif + case PIO_IOTYPE_NETCDF: + bcast = true; + if(ios->iomaster){ + ierr = nc_get_varm_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, (ptrdiff_t *) imap, buf);; + } + break; +#endif +#ifdef _PNETCDF + case PIO_IOTYPE_PNETCDF: +#ifdef PNET_READ_AND_BCAST + ncmpi_begin_indep_data(file->fh); + if(ios->iomaster){ + ierr = ncmpi_get_varm_ulonglong(file->fh, varid, start, count, stride, imap, buf);; + }; + ncmpi_end_indep_data(file->fh); + bcast=true; +#else + ierr = ncmpi_get_varm_ulonglong_all(file->fh, varid, start, count, stride, imap, buf);; +#endif + break; +#endif + default: + ierr = iotype_error(file->iotype,__FILE__,__LINE__); + } + } + + ierr = check_netcdf(file, ierr, __FILE__,__LINE__); + + if(ios->async_interface || bcast || + (ios->num_iotasks < ios->num_comptasks)){ + MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); + } + + return ierr; +} + diff --git a/tests/unit/test_intercomm.c b/tests/unit/test_intercomm.c index 6cb671b6ec31..fd999ce91dbc 100644 --- a/tests/unit/test_intercomm.c +++ b/tests/unit/test_intercomm.c @@ -99,6 +99,19 @@ check_file(int iosysid, int format, char *filename, int my_rank, int verbose) NC_NOWRITE))) ERR(ret); + /* Try to read the data. */ + PIO_Offset start[NDIM] = {0}, count[NDIM] = {DIM_LEN}; + int data_in[DIM_LEN]; + if ((ret = PIOc_get_vars_tc(ncid, 0, start, count, NULL, NC_INT, data_in))) + ERR(ret); + for (int i = 0; i < DIM_LEN; i++) + { + if (verbose) + printf("%d test_intercomm read data_in[%d] = %d\n", my_rank, i, data_in[i]); + if (data_in[i] != i) + ERR(ERR_AWFUL); + } + /* Find the number of dimensions, variables, and global attributes.*/ if ((ret = PIOc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid))) ERR(ret); @@ -372,7 +385,7 @@ main(int argc, char **argv) if (comp_task) { for (int fmt = 0; fmt < NUM_NETCDF_FLAVORS; fmt++) -/* for (int fmt = 0; fmt < 1; fmt++) */ +/* for (int fmt = 1; fmt < 2; fmt++) */ { int ncid, varid, dimid; PIO_Offset start[NDIM], count[NDIM] = {0}; From e7eced0e159fbfa744a80bdd89ecab5f989d895e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 26 May 2016 16:07:31 -0400 Subject: [PATCH 82/83] got get_var/vara working --- src/clib/pio_get_nc_async.c | 3168 ++++------------------------------- 1 file changed, 316 insertions(+), 2852 deletions(-) diff --git a/src/clib/pio_get_nc_async.c b/src/clib/pio_get_nc_async.c index f3cbc0f5a9ec..da55a082e2eb 100644 --- a/src/clib/pio_get_nc_async.c +++ b/src/clib/pio_get_nc_async.c @@ -3,7 +3,7 @@ #include int PIOc_get_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, nc_type xtype, void *buf) + const PIO_Offset *stride, nc_type xtype, void *buf) { iosystem_desc_t *ios; /** Pointer to io system information. */ file_desc_t *file; /** Pointer to file information. */ @@ -272,2630 +272,219 @@ int PIOc_get_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off /* Send the data. */ LOG((2, "PIOc_get_vars_tc bcasting data num_elem = %d typelen = %d", num_elem, - typelen)); + typelen)); if (!mpierr) mpierr = MPI_Bcast((void *)buf, num_elem * typelen, MPI_BYTE, ios->ioroot, ios->my_comm); return ierr; } -int PIOc_get_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, - const PIO_Offset *stride, int *buf) +int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, char *buf) { - return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_INT, buf); + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_CHAR, buf); } -int PIOc_get_var1_schar (int ncid, int varid, const PIO_Offset *index, signed char *buf) +int PIOc_get_vars_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, unsigned char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SCHAR; - ibuftype = MPI_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_schar(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_schar_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_UBYTE, buf); } -int PIOc_get_vars_ulonglong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned long long *buf) +int PIOc_get_vars_schar (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, signed char *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_BYTE, buf); +} +int PIOc_get_vars_ushort(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, unsigned short *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_USHORT, buf); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_ulonglong(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_ulonglong_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } +int PIOc_get_vars_short(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, short *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_SHORT, buf); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +int PIOc_get_vars_uint(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, unsigned int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_UINT, buf); +} - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } +int PIOc_get_vars_int(int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, + const PIO_Offset *stride, int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_INT, buf); +} - return ierr; +int PIOc_get_vars_long(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_LONG, buf); } -int PIOc_get_vars_short (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, short *buf) +int PIOc_get_vars_float(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_FLOAT, buf); +} - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } +int PIOc_get_vars_ulonglong(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, + unsigned long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_UINT64, buf); +} +int PIOc_get_vars_longlong (int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, const PIO_Offset *stride, long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, stride, NC_UINT64, buf); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_short(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_short(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_short_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } +int PIOc_get_vara_text(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_CHAR, buf); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +int PIOc_get_vara_uchar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, unsigned char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_UBYTE, buf); +} - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } +int PIOc_get_vara_schar(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, signed char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_BYTE, buf); +} - return ierr; +int PIOc_get_vara_ushort(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, unsigned short *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_USHORT, buf); } -int PIOc_get_var_double (int ncid, int varid, double *buf) +int PIOc_get_vara_short(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_SHORT, buf); +} - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; +int PIOc_get_vara_long(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_LONG, buf); +} - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } +int PIOc_get_vara_uint(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, unsigned int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_UINT, buf); +} +int PIOc_get_vara_int(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_INT, buf); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_double(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_double(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_double(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_double_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_double (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, double *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_double(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_double(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_double_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_int (int ncid, int varid, int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_int(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_int(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_int(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_int_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_ushort (int ncid, int varid, unsigned short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_ushort(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_ushort(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_ushort(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_ushort_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_text (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_text(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_text(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_text_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_int (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_INT; - ibuftype = MPI_INT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_int(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_int(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_int_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset *index, float *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_FLOAT; - ibuftype = MPI_FLOAT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_float(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_float_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SHORT; - ibuftype = MPI_SHORT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_short(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_short_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_text (int ncid, int varid, char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_text(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_text(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_text(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_text_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_schar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, signed char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_schar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_schar(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_schar_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_ushort (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_ushort(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_ushort(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_ushort_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_ushort (int ncid, int varid, const PIO_Offset *index, unsigned short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ushort(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_ushort_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_float (int ncid, int varid, float *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_float(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_float(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_float(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_float_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_uchar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_uchar(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_uchar(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_uchar_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONGLONG; - ibuftype = MPI_LONG_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_longlong(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_longlong_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_ushort (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_ushort(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_ushort(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_ushort_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_long (int ncid, int varid, long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_long(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_long(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_long(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_long_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset *index, double *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_DOUBLE; - ibuftype = MPI_DOUBLE; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_double(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_double_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_uint (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_uint(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_uint(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_uint_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_longlong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_longlong(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_longlong(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_longlong_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_longlong (int ncid, int varid, long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_longlong(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_longlong(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_longlong(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_longlong_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_short (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_short(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_short(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_short_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_long (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_long(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_long(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_long_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_int (int ncid, int varid, const PIO_Offset *index, int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_INT; - ibuftype = MPI_INT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_int(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_int_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset *index, unsigned long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ulonglong(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_ulonglong_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_uchar (int ncid, int varid, unsigned char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_uchar(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_uchar(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_uchar(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_uchar_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vara_uchar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara_uchar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara_uchar(file->fh, varid, start, count, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_uchar_all(file->fh, varid, start, count, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_float (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, float *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_float(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_float(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_float_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_vars_long (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARS_LONG; - ibuftype = MPI_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vars_long(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vars_long(file->fh, varid, start, count, stride, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vars_long_all(file->fh, varid, start, count, stride, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1 (int ncid, int varid, const PIO_Offset *index, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_vara_float(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, float *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_FLOAT, buf); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +int PIOc_get_vara_double(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, double *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_DOUBLE, buf); +} - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } +int PIOc_get_vara_ulonglong(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, unsigned long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_UINT64, buf); +} - return ierr; +int PIOc_get_vara_longlong(int ncid, int varid, const PIO_Offset *start, + const PIO_Offset *count, long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, start, count, NULL, NC_INT64, buf); +} + +int PIOc_get_var_text(int ncid, int varid, char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_CHAR, buf); +} + +int PIOc_get_var_uchar(int ncid, int varid, unsigned char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_UBYTE, buf); +} + +int PIOc_get_var_schar(int ncid, int varid, signed char *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_BYTE, buf); +} + +int PIOc_get_var_ushort(int ncid, int varid, unsigned short *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_USHORT, buf); +} + +int PIOc_get_var_short(int ncid, int varid, short *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_SHORT, buf); +} + +int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_UINT, buf); +} + +int PIOc_get_var_int(int ncid, int varid, int *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_INT, buf); } -int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) +int PIOc_get_var_long (int ncid, int varid, long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_LONG, buf); +} + +int PIOc_get_var_float(int ncid, int varid, float *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_FLOAT, buf); +} + +int PIOc_get_var_double(int ncid, int varid, double *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_DOUBLE, buf); +} + +int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_UINT64, buf); +} + +int PIOc_get_var_longlong (int ncid, int varid, long long *buf) +{ + return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_INT64, buf); +} + +int PIOc_get_var1_schar (int ncid, int varid, const PIO_Offset *index, signed char *buf) { int ierr; int msg; @@ -2911,21 +500,13 @@ int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; + msg = PIO_MSG_GET_VAR1_SCHAR; + ibuftype = MPI_CHAR; ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -2936,14 +517,14 @@ int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_uint(file->fh, varid, buf);; + ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var_uint(file->fh, varid, buf);; + ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -2952,12 +533,12 @@ int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var_uint(file->fh, varid, buf);; + ierr = ncmpi_get_var1_schar(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var_uint_all(file->fh, varid, buf);; + ierr = ncmpi_get_var1_schar_all(file->fh, varid, index, buf);; #endif break; #endif @@ -2968,7 +549,7 @@ int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -2976,7 +557,7 @@ int PIOc_get_var_uint (int ncid, int varid, unsigned int *buf) return ierr; } -int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset *index, float *buf) { int ierr; int msg; @@ -2992,13 +573,13 @@ int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offse if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARA; - ibufcnt = bufcount; - ibuftype = buftype; + msg = PIO_MSG_GET_VAR1_FLOAT; + ibuftype = MPI_FLOAT; + ibufcnt = 1; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3009,14 +590,14 @@ int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offse #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3025,12 +606,12 @@ int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offse #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; + ierr = ncmpi_get_var1_float(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; + ierr = ncmpi_get_var1_float_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3041,7 +622,7 @@ int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offse ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3049,7 +630,7 @@ int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offse return ierr; } -int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, signed char *buf) +int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *buf) { int ierr; int msg; @@ -3065,17 +646,13 @@ int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARA_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + msg = PIO_MSG_GET_VAR1_SHORT; + ibuftype = MPI_SHORT; ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3086,14 +663,14 @@ int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vara_schar(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3102,12 +679,12 @@ int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vara_schar(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_short(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vara_schar_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_short_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3118,7 +695,7 @@ int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3126,7 +703,8 @@ int PIOc_get_vara_schar (int ncid, int varid, const PIO_Offset *start, const PIO return ierr; } -int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned int *buf) + +int PIOc_get_var1_ushort (int ncid, int varid, const PIO_Offset *index, unsigned short *buf) { int ierr; int msg; @@ -3142,13 +720,13 @@ int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned i if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_UINT; - ibuftype = MPI_UNSIGNED; + msg = PIO_MSG_GET_VAR1_USHORT; + ibuftype = MPI_UNSIGNED_SHORT; ibufcnt = 1; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3159,14 +737,14 @@ int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned i #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3175,12 +753,12 @@ int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned i #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var1_uint(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_ushort(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var1_uint_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_ushort_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3191,7 +769,7 @@ int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned i ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3199,7 +777,8 @@ int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned i return ierr; } -int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, unsigned int *buf) + +int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -3215,17 +794,13 @@ int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_ if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARS_UINT; - ibuftype = MPI_UNSIGNED; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3236,14 +811,14 @@ int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var(file->fh, varid, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vars_uint(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var(file->fh, varid, buf);; } break; #endif @@ -3252,12 +827,12 @@ int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_ #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vars_uint(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vars_uint_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; #endif break; #endif @@ -3268,7 +843,7 @@ int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_ ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3276,7 +851,7 @@ int PIOc_get_vars_uint (int ncid, int varid, const PIO_Offset *start, const PIO_ return ierr; } -int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, float *buf) +int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long long *buf) { int ierr; int msg; @@ -3292,17 +867,13 @@ int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARA_FLOAT; - ibuftype = MPI_FLOAT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + msg = PIO_MSG_GET_VAR1_LONGLONG; + ibuftype = MPI_LONG_LONG; ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3313,14 +884,14 @@ int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vara_float(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3329,12 +900,12 @@ int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vara_float(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_longlong(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vara_float_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_longlong_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3345,7 +916,7 @@ int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3353,7 +924,7 @@ int PIOc_get_vara_float (int ncid, int varid, const PIO_Offset *start, const PIO return ierr; } -int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) +int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset *index, double *buf) { int ierr; int msg; @@ -3369,13 +940,13 @@ int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_TEXT; - ibuftype = MPI_CHAR; + msg = PIO_MSG_GET_VAR1_DOUBLE; + ibuftype = MPI_DOUBLE; ibufcnt = 1; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3386,14 +957,14 @@ int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3402,12 +973,12 @@ int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var1_text(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_double(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var1_text_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_double_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3418,7 +989,7 @@ int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3426,7 +997,8 @@ int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) return ierr; } -int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, double *buf) + +int PIOc_get_var1_int (int ncid, int varid, const PIO_Offset *index, int *buf) { int ierr; int msg; @@ -3442,17 +1014,13 @@ int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PI if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARS_DOUBLE; - ibuftype = MPI_DOUBLE; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + msg = PIO_MSG_GET_VAR1_INT; + ibuftype = MPI_INT; ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3463,14 +1031,14 @@ int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PI #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vars_double(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3479,12 +1047,12 @@ int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PI #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vars_double(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_int(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vars_double_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_int_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3495,7 +1063,7 @@ int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PI ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3503,7 +1071,7 @@ int PIOc_get_vars_double (int ncid, int varid, const PIO_Offset *start, const PI return ierr; } -int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, long long *buf) +int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset *index, unsigned long long *buf) { int ierr; int msg; @@ -3519,17 +1087,13 @@ int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARA_LONGLONG; - ibuftype = MPI_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + msg = PIO_MSG_GET_VAR1_ULONGLONG; + ibuftype = MPI_UNSIGNED_LONG_LONG; ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3540,14 +1104,14 @@ int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vara_longlong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3556,12 +1120,12 @@ int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vara_longlong(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_ulonglong(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vara_longlong_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_var1_ulonglong_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3572,7 +1136,7 @@ int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3580,7 +1144,8 @@ int PIOc_get_vara_longlong (int ncid, int varid, const PIO_Offset *start, const return ierr; } -int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) + +int PIOc_get_var1 (int ncid, int varid, const PIO_Offset *index, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -3596,21 +1161,13 @@ int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } + msg = PIO_MSG_GET_VAR1; + ibufcnt = bufcount; + ibuftype = buftype; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3621,14 +1178,14 @@ int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_ulonglong(file->fh, varid, buf);; + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var_ulonglong(file->fh, varid, buf);; + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3637,12 +1194,12 @@ int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var_ulonglong(file->fh, varid, buf);; + ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var_ulonglong_all(file->fh, varid, buf);; + ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; #endif break; #endif @@ -3653,7 +1210,7 @@ int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3661,7 +1218,8 @@ int PIOc_get_var_ulonglong (int ncid, int varid, unsigned long long *buf) return ierr; } -int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, unsigned long long *buf) + +int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -3677,17 +1235,13 @@ int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARA_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3698,14 +1252,14 @@ int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vara_ulonglong(file->fh, varid, (size_t *) start, (size_t *) count, buf);; + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; } break; #endif @@ -3714,12 +1268,12 @@ int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vara_ulonglong(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vara_ulonglong_all(file->fh, varid, start, count, buf);; + ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; #endif break; #endif @@ -3730,7 +1284,7 @@ int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3738,7 +1292,8 @@ int PIOc_get_vara_ulonglong (int ncid, int varid, const PIO_Offset *start, const return ierr; } -int PIOc_get_var_short (int ncid, int varid, short *buf) + +int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned int *buf) { int ierr; int msg; @@ -3754,21 +1309,13 @@ int PIOc_get_var_short (int ncid, int varid, short *buf) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR_SHORT; - ibuftype = MPI_SHORT; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; + msg = PIO_MSG_GET_VAR1_UINT; + ibuftype = MPI_UNSIGNED; ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3779,14 +1326,14 @@ int PIOc_get_var_short (int ncid, int varid, short *buf) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_short(file->fh, varid, buf);; + ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var_short(file->fh, varid, buf);; + ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3795,12 +1342,12 @@ int PIOc_get_var_short (int ncid, int varid, short *buf) #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var_short(file->fh, varid, buf);; + ierr = ncmpi_get_var1_uint(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var_short_all(file->fh, varid, buf);; + ierr = ncmpi_get_var1_uint_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3811,7 +1358,7 @@ int PIOc_get_var_short (int ncid, int varid, short *buf) ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3819,7 +1366,7 @@ int PIOc_get_var_short (int ncid, int varid, short *buf) return ierr; } -int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) +int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) { int ierr; int msg; @@ -3835,13 +1382,13 @@ int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONG; - ibuftype = MPI_LONG; + msg = PIO_MSG_GET_VAR1_TEXT; + ibuftype = MPI_CHAR; ibufcnt = 1; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3852,14 +1399,14 @@ int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3868,12 +1415,12 @@ int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var1_long(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_text(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var1_long_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var1_text_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3884,7 +1431,7 @@ int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3892,7 +1439,9 @@ int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) return ierr; } -int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, char *buf) + + +int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) { int ierr; int msg; @@ -3908,17 +1457,13 @@ int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_ if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VARS_TEXT; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); + msg = PIO_MSG_GET_VAR1_LONG; + ibuftype = MPI_LONG; ibufcnt = 1; - for(int i=0;iasync_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -3929,14 +1474,14 @@ int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_ #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_vars_text(file->fh, varid, (size_t *) start, (size_t *) count, (ptrdiff_t *) stride, buf);; + ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -3945,12 +1490,12 @@ int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_ #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_vars_text(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_long(file->fh, varid, index, buf);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_vars_text_all(file->fh, varid, start, count, stride, buf);; + ierr = ncmpi_get_var1_long_all(file->fh, varid, index, buf);; #endif break; #endif @@ -3961,7 +1506,7 @@ int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_ ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -3969,7 +1514,7 @@ int PIOc_get_vars_text (int ncid, int varid, const PIO_Offset *start, const PIO_ return ierr; } -int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned char *buf) +int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned char *buf) { int ierr; int msg; @@ -3991,7 +1536,7 @@ int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -4034,7 +1579,7 @@ int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } @@ -4042,7 +1587,7 @@ int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned return ierr; } -int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -4064,7 +1609,7 @@ int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offse ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) + if(ios->compmaster) mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); } @@ -4107,88 +1652,7 @@ int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offse ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var_schar (int ncid, int varid, signed char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR_SCHAR; - ibuftype = MPI_CHAR; - ierr = PIOc_inq_varndims(file->fh, varid, &ndims); - int dimid[ndims]; - PIO_Offset dimsize; - ibufcnt = 1; - PIOc_inq_vardimid(file->fh, varid, dimid); - for(int i=0;ifh, dimid[i], &dimsize); - ibufcnt *= dimsize; - } - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var_schar(file->fh, varid, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var_schar(file->fh, varid, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var_schar(file->fh, varid, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var_schar_all(file->fh, varid, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || + if(ios->async_interface || bcast || (ios->num_iotasks < ios->num_comptasks)){ MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); } From 696d403b85ef340408903fa2aeb0a129d90c03d0 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 26 May 2016 16:51:29 -0400 Subject: [PATCH 83/83] got get_var1 working --- src/clib/pio_get_nc_async.c | 959 ++++-------------------------------- 1 file changed, 83 insertions(+), 876 deletions(-) diff --git a/src/clib/pio_get_nc_async.c b/src/clib/pio_get_nc_async.c index da55a082e2eb..610f0a6cfd33 100644 --- a/src/clib/pio_get_nc_async.c +++ b/src/clib/pio_get_nc_async.c @@ -484,153 +484,88 @@ int PIOc_get_var_longlong (int ncid, int varid, long long *buf) return PIOc_get_vars_tc(ncid, varid, NULL, NULL, NULL, NC_INT64, buf); } -int PIOc_get_var1_schar (int ncid, int varid, const PIO_Offset *index, signed char *buf) +int PIOc_get_var1_tc(int ncid, int varid, const PIO_Offset *index, nc_type xtype, + void *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SCHAR; - ibuftype = MPI_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; + int ierr; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } + /* Find the number of dimensions. */ + if ((ierr = PIOc_inq_varndims(ncid, varid, &ndims))) + return ierr; + /* Set up count array. */ + PIO_Offset count[ndims]; + for (int c = 0; c < ndims; c++) + count[c] = 1; - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_schar(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_schar(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_schar_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } + return PIOc_get_vars_tc(ncid, varid, index, count, NULL, xtype, buf); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +int PIOc_get_var1_text(int ncid, int varid, const PIO_Offset *index, char *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_CHAR, buf); +} - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } +int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned char *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_UBYTE, buf); +} - return ierr; +int PIOc_get_var1_schar(int ncid, int varid, const PIO_Offset *index, signed char *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_BYTE, buf); } -int PIOc_get_var1_float (int ncid, int varid, const PIO_Offset *index, float *buf) +int PIOc_get_var1_ushort(int ncid, int varid, const PIO_Offset *index, unsigned short *buf) { - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; + return PIOc_get_var1_tc(ncid, varid, index, NC_USHORT, buf); +} - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_FLOAT; - ibuftype = MPI_FLOAT; - ibufcnt = 1; - ierr = PIO_NOERR; +int PIOc_get_var1_short(int ncid, int varid, const PIO_Offset *index, short *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_SHORT, buf); +} - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } +int PIOc_get_var1_uint(int ncid, int varid, const PIO_Offset *index, unsigned int *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_UINT, buf); +} +int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_LONG, buf); +} - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_float(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_float(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_float_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } +int PIOc_get_var1_int(int ncid, int varid, const PIO_Offset *index, int *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_INT, buf); +} - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); +int PIOc_get_var1_float(int ncid, int varid, const PIO_Offset *index, float *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_FLOAT, buf); +} - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } +int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset *index, double *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_DOUBLE, buf); +} - return ierr; +int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset *index, + unsigned long long *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_INT64, buf); } + -int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *buf) +int PIOc_get_var1_longlong(int ncid, int varid, const PIO_Offset *index, + long long *buf) +{ + return PIOc_get_var1_tc(ncid, varid, index, NC_INT64, buf); +} + +int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -646,9 +581,9 @@ int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *bu if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_SHORT; - ibuftype = MPI_SHORT; - ibufcnt = 1; + msg = PIO_MSG_GET_VAR; + ibufcnt = bufcount; + ibuftype = buftype; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ @@ -663,14 +598,14 @@ int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *bu #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var(file->fh, varid, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var1_short(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_var(file->fh, varid, buf);; } break; #endif @@ -679,12 +614,12 @@ int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *bu #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var1_short(file->fh, varid, index, buf);; + ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var1_short_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; #endif break; #endif @@ -704,81 +639,11 @@ int PIOc_get_var1_short (int ncid, int varid, const PIO_Offset *index, short *bu } -int PIOc_get_var1_ushort (int ncid, int varid, const PIO_Offset *index, unsigned short *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_USHORT; - ibuftype = MPI_UNSIGNED_SHORT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ushort(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ushort(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_ushort_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - return ierr; -} -int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) +int PIOc_get_var1 (int ncid, int varid, const PIO_Offset *index, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -794,7 +659,7 @@ int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datat if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR; + msg = PIO_MSG_GET_VAR1; ibufcnt = bufcount; ibuftype = buftype; ierr = PIO_NOERR; @@ -811,14 +676,14 @@ int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datat #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var(file->fh, varid, buf);; + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var(file->fh, varid, buf);; + ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; } break; #endif @@ -827,12 +692,12 @@ int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datat #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var(file->fh, varid, buf, bufcount, buftype);; + ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var_all(file->fh, varid, buf, bufcount, buftype);; + ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; #endif break; #endif @@ -851,7 +716,7 @@ int PIOc_get_var (int ncid, int varid, void *buf, PIO_Offset bufcount, MPI_Datat return ierr; } -int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long long *buf) +int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) { int ierr; int msg; @@ -867,9 +732,9 @@ int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long l if(file == NULL) return PIO_EBADID; ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONGLONG; - ibuftype = MPI_LONG_LONG; - ibufcnt = 1; + msg = PIO_MSG_GET_VARA; + ibufcnt = bufcount; + ibuftype = buftype; ierr = PIO_NOERR; if(ios->async_interface && ! ios->ioproc){ @@ -884,14 +749,14 @@ int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long l #ifdef _NETCDF #ifdef _NETCDF4 case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; break; case PIO_IOTYPE_NETCDF4C: #endif case PIO_IOTYPE_NETCDF: bcast = true; if(ios->iomaster){ - ierr = nc_get_var1_longlong(file->fh, varid, (size_t *) index, buf);; + ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; } break; #endif @@ -900,12 +765,12 @@ int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long l #ifdef PNET_READ_AND_BCAST ncmpi_begin_indep_data(file->fh); if(ios->iomaster){ - ierr = ncmpi_get_var1_longlong(file->fh, varid, index, buf);; + ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; }; ncmpi_end_indep_data(file->fh); bcast=true; #else - ierr = ncmpi_get_var1_longlong_all(file->fh, varid, index, buf);; + ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; #endif break; #endif @@ -924,668 +789,10 @@ int PIOc_get_var1_longlong (int ncid, int varid, const PIO_Offset *index, long l return ierr; } -int PIOc_get_var1_double (int ncid, int varid, const PIO_Offset *index, double *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_DOUBLE; - ibuftype = MPI_DOUBLE; - ibufcnt = 1; - ierr = PIO_NOERR; - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_double(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_double(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_double_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - - -int PIOc_get_var1_int (int ncid, int varid, const PIO_Offset *index, int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_INT; - ibuftype = MPI_INT; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_int(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_int(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_int_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_ulonglong (int ncid, int varid, const PIO_Offset *index, unsigned long long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_ULONGLONG; - ibuftype = MPI_UNSIGNED_LONG_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_ulonglong(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_ulonglong(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_ulonglong_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - - -int PIOc_get_var1 (int ncid, int varid, const PIO_Offset *index, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1(file->fh, varid, index, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_all(file->fh, varid, index, buf, bufcount, buftype);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - - -int PIOc_get_vara (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VARA; - ibufcnt = bufcount; - ibuftype = buftype; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_vara(file->fh, varid, (size_t *) start, (size_t *) count, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_vara(file->fh, varid, start, count, buf, bufcount, buftype);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_vara_all(file->fh, varid, start, count, buf, bufcount, buftype);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - - -int PIOc_get_var1_uint (int ncid, int varid, const PIO_Offset *index, unsigned int *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_UINT; - ibuftype = MPI_UNSIGNED; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_uint(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_uint(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_uint_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_text (int ncid, int varid, const PIO_Offset *index, char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_TEXT; - ibuftype = MPI_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_text(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_text(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_text_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - - - -int PIOc_get_var1_long (int ncid, int varid, const PIO_Offset *index, long *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_LONG; - ibuftype = MPI_LONG; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_long(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_long(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_long_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} - -int PIOc_get_var1_uchar (int ncid, int varid, const PIO_Offset *index, unsigned char *buf) -{ - int ierr; - int msg; - int mpierr; - iosystem_desc_t *ios; - file_desc_t *file; - MPI_Datatype ibuftype; - int ndims; - int ibufcnt; - bool bcast = false; - - file = pio_get_file_from_id(ncid); - if(file == NULL) - return PIO_EBADID; - ios = file->iosystem; - msg = PIO_MSG_GET_VAR1_UCHAR; - ibuftype = MPI_UNSIGNED_CHAR; - ibufcnt = 1; - ierr = PIO_NOERR; - - if(ios->async_interface && ! ios->ioproc){ - if(ios->compmaster) - mpierr = MPI_Send(&msg, 1,MPI_INT, ios->ioroot, 1, ios->union_comm); - mpierr = MPI_Bcast(&(file->fh),1, MPI_INT, 0, ios->intercomm); - } - - - if(ios->ioproc){ - switch(file->iotype){ -#ifdef _NETCDF -#ifdef _NETCDF4 - case PIO_IOTYPE_NETCDF4P: - ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; - break; - case PIO_IOTYPE_NETCDF4C: -#endif - case PIO_IOTYPE_NETCDF: - bcast = true; - if(ios->iomaster){ - ierr = nc_get_var1_uchar(file->fh, varid, (size_t *) index, buf);; - } - break; -#endif -#ifdef _PNETCDF - case PIO_IOTYPE_PNETCDF: -#ifdef PNET_READ_AND_BCAST - ncmpi_begin_indep_data(file->fh); - if(ios->iomaster){ - ierr = ncmpi_get_var1_uchar(file->fh, varid, index, buf);; - }; - ncmpi_end_indep_data(file->fh); - bcast=true; -#else - ierr = ncmpi_get_var1_uchar_all(file->fh, varid, index, buf);; -#endif - break; -#endif - default: - ierr = iotype_error(file->iotype,__FILE__,__LINE__); - } - } - - ierr = check_netcdf(file, ierr, __FILE__,__LINE__); - - if(ios->async_interface || bcast || - (ios->num_iotasks < ios->num_comptasks)){ - MPI_Bcast(buf, ibufcnt, ibuftype, ios->ioroot, ios->my_comm); - } - - return ierr; -} int PIOc_get_vars (int ncid, int varid, const PIO_Offset *start, const PIO_Offset *count, const PIO_Offset *stride, void *buf, PIO_Offset bufcount, MPI_Datatype buftype) {