From 72cf15acf40dfdbef9fffd1a024eec510e3b495a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 20 Feb 2019 09:58:39 -0700 Subject: [PATCH] add new error type, change a test --- src/clib/pio.h | 2 ++ src/clib/pio_darray.c | 9 ++++++++- src/clib/pio_darray_int.c | 4 +++- src/clib/pio_internal.h | 3 +++ src/clib/pioc_support.c | 3 +++ tests/cunit/test_darray.c | 4 +++- tests/cunit/test_darray_multivar3.c | 13 ++++++++----- 7 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/clib/pio.h b/src/clib/pio.h index 8c2a8f96cb3..bcc305079d8 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -760,6 +760,8 @@ enum PIO_ERROR_HANDLERS /** Define error codes for PIO. */ #define PIO_FIRST_ERROR_CODE (-500) #define PIO_EBADIOTYPE (-500) +/** variable dimensions do not match in a multivar call */ +#define PIO_EVARDIMMISMATCH (-501) /** ??? */ #define PIO_REQ_NULL (NC_REQ_NULL-1) diff --git a/src/clib/pio_darray.c b/src/clib/pio_darray.c index fd6092fe01d..3dc1eb47006 100644 --- a/src/clib/pio_darray.c +++ b/src/clib/pio_darray.c @@ -110,7 +110,7 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars, io_desc_t *iodesc; /* Pointer to IO description information. */ int rlen; /* Total data buffer size. */ var_desc_t *vdesc0; /* First entry in array of var_desc structure for each var. */ - int fndims; /* Number of dims in the var in the file. */ + int fndims, fndims2; /* Number of dims in the var in the file. */ int mpierr = MPI_SUCCESS, mpierr2; /* Return code from MPI function calls. */ int ierr; /* Return code. */ void *tmparray; @@ -162,6 +162,13 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars, if ((ierr = PIOc_inq_varndims(file->pio_ncid, varids[0], &fndims))) return check_netcdf(file, ierr, __FILE__, __LINE__); LOG((3, "called PIOc_inq_varndims varids[0] = %d fndims = %d", varids[0], fndims)); + for (int v=1; v < nvars; v++){ + if ((ierr = PIOc_inq_varndims(file->pio_ncid, varids[v], &fndims2))) + return check_netcdf(file, ierr, __FILE__, __LINE__); + if(fndims != fndims2) + return pio_err(ios, file, PIO_EVARDIMMISMATCH, __FILE__, __LINE__); + } + } /* If async is in use, and this is not an IO task, bcast the parameters. */ diff --git a/src/clib/pio_darray_int.c b/src/clib/pio_darray_int.c index 173845cf7c4..aa931d342e8 100644 --- a/src/clib/pio_darray_int.c +++ b/src/clib/pio_darray_int.c @@ -638,7 +638,9 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int * /* Write, in non-blocking fashion, a list of subarrays. */ LOG((3, "about to call ncmpi_iput_varn() varids[%d] = %d rrcnt = %d, llen = %d", nv, varids[nv], rrcnt, llen)); - ierr = ncmpi_iput_varn(file->fh, varids[nv], rrcnt, startlist, countlist, + for (int i=0; i< rrcnt; i++) + LOG((3, "i %d start %ld count %ld start %ld count %ld\n",i,startlist[i][0], countlist[i][0],startlist[i][1], countlist[i][1])); + ierr = ncmpi_iput_varn(file->fh, varids[nv], rrcnt, startlist, countlist, bufptr, llen, iodesc->mpitype, &vdesc->request[vdesc->nreqs]); /* keeps wait calls in sync */ diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index d18cc3b212a..b43549f657e 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -362,6 +362,9 @@ extern "C" { int **proc_list, int **my_proc_list); int pio_sorted_copy(const void *array, void *tmparray, io_desc_t *iodesc, int nvars, int direction); + + int PIOc_inq_att_eh(int ncid, int varid, const char *name, int eh, + nc_type *xtypep, PIO_Offset *lenp); #if defined(__cplusplus) } #endif diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index 0bc8dfbc21e..88234e9a7d4 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -76,6 +76,9 @@ int PIOc_strerror(int pioerr, char *errmsg) case PIO_EBADIOTYPE: strcpy(errmsg, "Bad IO type"); break; + case PIO_EVARDIMMISMATCH: + strcpy(errmsg, "Variable dim mismatch in multivar call"); + break; default: strcpy(errmsg, "Unknown Error: Unrecognized error code"); } diff --git a/tests/cunit/test_darray.c b/tests/cunit/test_darray.c index 5ed1f578763..f36793f9b70 100644 --- a/tests/cunit/test_darray.c +++ b/tests/cunit/test_darray.c @@ -79,7 +79,7 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank int varid2; /* The ID of a netCDF varable of different type. */ int wrong_varid = TEST_VAL_42; /* A wrong ID. */ int ret; /* Return code. */ - int mpi_type; + MPI_Datatype mpi_type; int type_size; /* size of a variable of type pio_type */ int other_type; /* another variable of the same size but different type */ PIO_Offset arraylen = 4; @@ -231,9 +231,11 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if (PIOc_write_darray_multi(ncid, &varid_big, ioid, 1, arraylen, test_data, &frame, fillvalue, flushtodisk) != PIO_ENOTVAR) ERR(ERR_WRONG); +// pio_setloglevel(3); if (PIOc_write_darray_multi(ncid, &wrong_varid, ioid, 1, arraylen, test_data, &frame, fillvalue, flushtodisk) != PIO_ENOTVAR) ERR(ERR_WRONG); +// pio_setloglevel(0); /* This should work - library type conversion */ if (other_type && (ret = PIOc_write_darray_multi(ncid, &varid2, ioid, 1, arraylen, test_data, &frame, diff --git a/tests/cunit/test_darray_multivar3.c b/tests/cunit/test_darray_multivar3.c index fd3f0b6d019..35c932f6afd 100644 --- a/tests/cunit/test_darray_multivar3.c +++ b/tests/cunit/test_darray_multivar3.c @@ -106,7 +106,7 @@ int test_multivar_darray(int iosysid, int ioid, int num_flavors, int *flavor, if ((ret = PIOc_def_dim(ncid, dim_name[d], (PIO_Offset)dim_len[d], &dimids[d]))) ERR(ret); - /* Var 0 does not have a record dim, varid 1 is a record var. */ + /* Var 0 does not have a record dim, varid 1 and 2 are record vars. */ if ((ret = PIOc_def_var(ncid, var_name[0], PIO_INT, NDIM - 1, &dimids[1], &varid[0]))) ERR(ret); if ((ret = PIOc_def_var(ncid, var_name[1], PIO_INT, NDIM, dimids, &varid[1]))) @@ -148,14 +148,17 @@ int test_multivar_darray(int iosysid, int ioid, int num_flavors, int *flavor, fvp_int))) ERR(ret); - /* This should work since an int and a - * float are the same size. */ + /* This should not work since we cannot mix record and not record vars */ int frame[NUM_VAR] = {0, 0, 0}; + if (PIOc_write_darray_multi(ncid, varid, ioid, NUM_VAR, arraylen * NUM_VAR, test_data_float, - frame, NULL, 0) != PIO_EINVAL) + frame, NULL, 0) != PIO_EVARDIMMISMATCH) + ERR(ERR_WRONG); + /* This should work since int and float are the same size and both are record vars */ + if ((ret = PIOc_write_darray_multi(ncid, varid+1, ioid, NUM_VAR-1, arraylen * (NUM_VAR-1), test_data_float, + frame, NULL, 0))) ERR(ret); - /* Close the netCDF file. */ if ((ret = PIOc_closefile(ncid))) ERR(ret);