Skip to content

Commit

Permalink
remove restrictions to data conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 13, 2019
1 parent 6e3be58 commit bffeeb9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 52 deletions.
7 changes: 1 addition & 6 deletions cmake/mpiexec.nwscla
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@

NP=$1
shift
if [[ "$LMOD_FAMILY_MPI" == "openmpi" ]]
then
mpirun -np $NP $@
else
mpiexec_mpt -n $NP $@
fi
mpirun -np $NP $@
61 changes: 31 additions & 30 deletions src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars,
var_desc_t *vdesc;
if ((ierr = get_var_desc(varids[v], &file->varlist, &vdesc)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);
if (vdesc->pio_type != iodesc->piotype)
return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__);
// if (vdesc->pio_type != iodesc->piotype)
// return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__);
}

/* Get a pointer to the variable info for the first variable. */
Expand Down Expand Up @@ -247,7 +247,7 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars,

/* If fill values are desired, and we're using the BOX
* rearranger, insert fill values. */
if (iodesc->needsfill && iodesc->rearranger == PIO_REARR_BOX)
if (iodesc->needsfill && iodesc->rearranger == PIO_REARR_BOX && fillvalue)
{
LOG((3, "inerting fill values iodesc->maxiobuflen = %d", iodesc->maxiobuflen));
for (int nv = 0; nv < nvars; nv++)
Expand Down Expand Up @@ -339,10 +339,11 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars,
/* copying the fill value into the data buffer for the box
* rearranger. This will be overwritten with data where
* provided. */
for (int nv = 0; nv < nvars; nv++)
for (int i = 0; i < iodesc->holegridsize; i++)
memcpy(&((char *)vdesc0->fillbuf)[iodesc->mpitype_size * (i + nv * iodesc->holegridsize)],
&((char *)fillvalue)[iodesc->mpitype_size * nv], iodesc->mpitype_size);
if(fillvalue)
for (int nv = 0; nv < nvars; nv++)
for (int i = 0; i < iodesc->holegridsize; i++)
memcpy(&((char *)vdesc0->fillbuf)[iodesc->mpitype_size * (i + nv * iodesc->holegridsize)],
&((char *)fillvalue)[iodesc->mpitype_size * nv], iodesc->mpitype_size);

/* Write the darray based on the iotype. */
switch (file->iotype)
Expand Down Expand Up @@ -647,10 +648,10 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *

/* If the type of the var doesn't match the type of the
* decomposition, return an error. */
if (iodesc->piotype != vdesc->pio_type)
return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__);
pioassert(iodesc->mpitype_size == vdesc->mpi_type_size, "wrong mpi info",
__FILE__, __LINE__);
// if (iodesc->piotype != vdesc->pio_type)
// return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__);
// pioassert(iodesc->mpitype_size == vdesc->mpi_type_size, "wrong mpi info",
// __FILE__, __LINE__);

/* If we don't know the fill value for this var, get it. */
if (!vdesc->fillvalue)
Expand Down Expand Up @@ -689,13 +690,13 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
wmb->frame = NULL;
wmb->fillvalue = NULL;
}
LOG((2, "wmb->num_arrays = %d arraylen = %d vdesc->mpi_type_size = %d\n",
wmb->num_arrays, arraylen, vdesc->mpi_type_size));
LOG((2, "wmb->num_arrays = %d arraylen = %d iodesc->mpitype_size = %d\n",
wmb->num_arrays, arraylen, iodesc->mpitype_size));
#if PIO_USE_MALLOC
/* Try realloc first and call flush if realloc fails. */
if (arraylen > 0)
{
size_t data_size = (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size;
size_t data_size = (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size;

if ((realloc_data = realloc(wmb->data, data_size)))
{
Expand All @@ -716,12 +717,12 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
/* maxfree is the available memory. If that is < 10% greater than
* the size of the current request needsflush is true. */
if (needsflush == 0)
needsflush = (maxfree <= 1.1 * (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size);
needsflush = (maxfree <= 1.1 * (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size);
#endif
/* the limit of data_size < INT_MAX is due to a bug in ROMIO which limits
the size of contiguous data to INT_MAX, a fix has been proposed in
https://github.com/pmodels/mpich/pull/2888 */
io_data_size = (1 + wmb->num_arrays) * iodesc->maxiobuflen * vdesc->mpi_type_size;
io_data_size = (1 + wmb->num_arrays) * iodesc->maxiobuflen * iodesc->mpitype_size;
if(io_data_size > INT_MAX)
needsflush = 2;

Expand All @@ -740,8 +741,8 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
/* Collect a debug report about buffer. */
cn_buffer_report(ios, true);
LOG((2, "maxfree = %ld wmb->num_arrays = %d (1 + wmb->num_arrays) *"
" arraylen * vdesc->mpi_type_size = %ld totfree = %ld\n", maxfree, wmb->num_arrays,
(1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size, totfree));
" arraylen * iodesc->mpitype_size = %ld totfree = %ld\n", maxfree, wmb->num_arrays,
(1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size, totfree));
#endif /* PIO_ENABLE_LOGGING */
#endif /* !PIO_USE_MALLOC */

Expand All @@ -756,17 +757,17 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
/* Try realloc again if there is a flush. */
if (arraylen > 0 && needsflush > 0)
{
if (!(wmb->data = realloc(wmb->data, (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size)))
if (!(wmb->data = realloc(wmb->data, (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size)))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
LOG((2, "after a flush, realloc got %ld bytes for data", (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size));
LOG((2, "after a flush, realloc got %ld bytes for data", (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size));
}
#else
/* Get memory for data. */
if (arraylen > 0)
{
if (!(wmb->data = bgetr(wmb->data, (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size)))
if (!(wmb->data = bgetr(wmb->data, (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size)))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
LOG((2, "got %ld bytes for data", (1 + wmb->num_arrays) * arraylen * vdesc->mpi_type_size));
LOG((2, "got %ld bytes for data", (1 + wmb->num_arrays) * arraylen * iodesc->mpitype_size));
}
#endif

Expand All @@ -788,11 +789,11 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
if (iodesc->needsfill)
{
/* Get memory to hold fill value. */
if (!(wmb->fillvalue = bgetr(wmb->fillvalue, vdesc->mpi_type_size * (1 + wmb->num_arrays))))
if (!(wmb->fillvalue = bgetr(wmb->fillvalue, iodesc->mpitype_size * (1 + wmb->num_arrays))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);

memcpy((char *)wmb->fillvalue + vdesc->mpi_type_size * wmb->num_arrays,
vdesc->fillvalue, vdesc->mpi_type_size);
memcpy((char *)wmb->fillvalue + iodesc->mpitype_size * wmb->num_arrays,
vdesc->fillvalue, iodesc->mpitype_size);
}

/* Tell the buffer about the data it is getting. */
Expand All @@ -802,11 +803,11 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
wmb->vid[wmb->num_arrays]));

/* Copy the user-provided data to the buffer. */
bufptr = (void *)((char *)wmb->data + arraylen * vdesc->mpi_type_size * wmb->num_arrays);
bufptr = (void *)((char *)wmb->data + arraylen * iodesc->mpitype_size * wmb->num_arrays);
if (arraylen > 0)
{
memcpy(bufptr, array, arraylen * vdesc->mpi_type_size);
LOG((3, "copied %ld bytes of user data", arraylen * vdesc->mpi_type_size));
memcpy(bufptr, array, arraylen * iodesc->mpitype_size);
LOG((3, "copied %ld bytes of user data", arraylen * iodesc->mpitype_size));
}

/* Add the unlimited dimension value of this variable to the frame
Expand All @@ -815,9 +816,9 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
wmb->frame[wmb->num_arrays] = vdesc->record;
wmb->num_arrays++;

LOG((2, "wmb->num_arrays = %d iodesc->maxbytes / vdesc->mpi_type_size = %d "
LOG((2, "wmb->num_arrays = %d iodesc->maxbytes / iodesc->mpitype_size = %d "
"iodesc->ndof = %d iodesc->llen = %d", wmb->num_arrays,
iodesc->maxbytes / vdesc->mpi_type_size, iodesc->ndof, iodesc->llen));
iodesc->maxbytes / iodesc->mpitype_size, iodesc->ndof, iodesc->llen));

return PIO_NOERR;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
ERR(ERR_WRONG);
if (PIOc_write_darray(ncid, TEST_VAL_42, ioid, arraylen, test_data, fillvalue) != PIO_ENOTVAR)
ERR(ERR_WRONG);
if (PIOc_write_darray(ncid, varid2, ioid, arraylen, test_data, fillvalue) != PIO_EINVAL)
ERR(ERR_WRONG);
// if (PIOc_write_darray(ncid, varid2, ioid, arraylen, test_data, fillvalue) != PIO_EINVAL)
// ERR(ERR_WRONG);

/* Write the data. */
if ((ret = PIOc_write_darray(ncid, varid, ioid, arraylen, test_data, fillvalue)))
Expand Down
6 changes: 3 additions & 3 deletions tests/cunit/test_darray_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
wrong_varid[0] = varid[0];
wrong_varid[1] = varid[1];
wrong_varid[0] = other_varid;
if (PIOc_write_darray_multi(ncid, wrong_varid, ioid, NVAR, arraylen, test_data, frame,
fillvalue, flushtodisk) != PIO_EINVAL)
ERR(ERR_WRONG);
// if (PIOc_write_darray_multi(ncid, wrong_varid, ioid, NVAR, arraylen, test_data, frame,
// fillvalue, flushtodisk) != PIO_EINVAL)
// ERR(ERR_WRONG);

/* Write the data with the _multi function. */
if ((ret = PIOc_write_darray_multi(ncid, varid, ioid, NVAR, arraylen, test_data, frame,
Expand Down
22 changes: 11 additions & 11 deletions tests/cunit/test_darray_multivar3.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ int test_multivar_darray(int iosysid, int ioid, int num_flavors, int *flavor,
ERR(ret);

/* Set the custom fill values. */
if ((ret = PIOc_def_var_fill(ncid, varid[0], 0, &custom_fillvalue_int)))
if ((ret = PIOc_def_var_fill(ncid, varid[0], 0, &custom_fillvalue_int)))
ERR(ret);
if ((ret = PIOc_def_var_fill(ncid, varid[1], 0, &custom_fillvalue_int)))
if ((ret = PIOc_def_var_fill(ncid, varid[1], 0, &custom_fillvalue_int)))
ERR(ret);
if ((ret = PIOc_def_var_fill(ncid, varid[2], 0, &custom_fillvalue_float)))
if ((ret = PIOc_def_var_fill(ncid, varid[2], 0, &custom_fillvalue_float)))
ERR(ret);

/* End define mode. */
Expand Down Expand Up @@ -149,18 +149,18 @@ int test_multivar_darray(int iosysid, int ioid, int num_flavors, int *flavor,
ERR(ret);

/* This should not work, since the type of the var is
* PIO_FLOAT, and the type if the decomposition is
* PIO_FLOAT, and the type of the decomposition is
* PIO_INT. */
if (PIOc_write_darray(ncid, varid[2], ioid, arraylen, test_data_float,
fvp_float) != PIO_EINVAL)
ERR(ERR_WRONG);
// if (PIOc_write_darray(ncid, varid[2], ioid, arraylen, test_data_float,
// fvp_float) != PIO_EINVAL)
// ERR(ERR_WRONG);

/* This should also fail, because it mixes an int and a
* float. */
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)
ERR(ERR_WRONG);
// 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)
// ERR(ERR_WRONG);


/* Close the netCDF file. */
Expand Down

0 comments on commit bffeeb9

Please sign in to comment.