Skip to content

Commit

Permalink
add new error type, change a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 20, 2019
1 parent 55887b8 commit 72cf15a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
4 changes: 3 additions & 1 deletion src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 3 additions & 1 deletion tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions tests/cunit/test_darray_multivar3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 72cf15a

Please sign in to comment.