Skip to content

Commit

Permalink
now assume frame=0 for darray read if frame was not set
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jan 10, 2018
1 parent cc6a5fd commit fda1302
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
27 changes: 25 additions & 2 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,16 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
the mpitype. */
region = iodesc->firstregion;

/* ??? */
/* There are different numbers of dims in the decomposition
* and the file. */
if (fndims > ndims)
{
ndims++;

/* If the user did not call setframe, use a default frame
* of 0. This is required for backward compatibility. */
if (vdesc->record < 0)
vdesc->record = 0;
}

/* For each regions, read the data. */
Expand All @@ -833,7 +839,8 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
else
bufptr=(void *)((char *)iobuf + iodesc->mpitype_size * region->loffset);

LOG((2, "%d %d %d", iodesc->llen - region->loffset, iodesc->llen, region->loffset));
LOG((2, "iodesc->llen - region->loffset %d, iodesc->llen %d, region->loffset %d vdesc->record %d",
iodesc->llen - region->loffset, iodesc->llen, region->loffset, vdesc->record));

/* Get the start/count arrays. */
if (vdesc->record >= 0 && fndims > 1)
Expand Down Expand Up @@ -862,6 +869,11 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
}
}

#ifdef LOGGING
for (int i = 1; i < ndims; i++)
LOG((3, "start[%d] %d count[%d] %d", i, start[i], i, count[i]));
#endif /* LOGGING */

/* Do the read. */
switch (file->iotype)
{
Expand Down Expand Up @@ -1023,6 +1035,11 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid,
if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);

/* If setframe was not called, use a default value of 0. This is
* required for backward compatibility. */
if (fndims == ndims + 1 && vdesc->record < 0)
vdesc->record = 0;

/* Confirm that we are being called with the correct ndims. */
pioassert((fndims == ndims && vdesc->record < 0) ||
(fndims == ndims + 1 && vdesc->record >= 0),
Expand All @@ -1043,6 +1060,12 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid,
the mpitype. */
region = iodesc->firstregion;

/* If setframe was not set before this call, assume a value of
* 0. This is required for backward compatibility. */
if (fndims > ndims)
if (vdesc->record < 0)
vdesc->record = 0;

/* Put together start/count arrays for all regions. */
for (int regioncnt = 0; regioncnt < iodesc->maxregions; regioncnt++)
{
Expand Down
1 change: 0 additions & 1 deletion src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ int PIOc_setframe(int ncid, int varid, int frame)

/* Set the record dimension value for this variable. This will be
* used by the write_darray functions. */
/* file->varlist[varid].record = frame; */
vdesc->record = frame;

return PIO_NOERR;
Expand Down
8 changes: 3 additions & 5 deletions tests/cunit/test_darray_1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,9 @@ int test_darray_fill_unlim(int iosysid, int ioid, int pio_type, int num_flavors,
if (!(test_data_in = malloc(type_size * arraylen)))
ERR(PIO_ENOMEM);

/* Set the record number for the unlimited dimension. */
if ((ret = PIOc_setframe(ncid, varid, 0)))
ERR(ret);

/* Read the data. */
/* Read the data. We don't have to set the record number for
* the unlimited dimension. If we don't set it, PIO will
* assume a value of 0. */
if ((ret = PIOc_read_darray(ncid, varid, ioid, arraylen, test_data_in)))
ERR(ret);

Expand Down

0 comments on commit fda1302

Please sign in to comment.