Skip to content

Commit

Permalink
fix issue in sorting and add test to catch it
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Jan 5, 2019
1 parent bb6137e commit e062f76
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
56 changes: 28 additions & 28 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define USE_VARD_WRITE 1
#endif


/* 10MB default limit. */
extern PIO_Offset pio_buffer_size_limit;

Expand Down Expand Up @@ -72,6 +71,7 @@ int compute_buffer_init(iosystem_desc_t *ios)

return PIO_NOERR;
}

#if USE_VARD
int get_gdim0(file_desc_t *file,io_desc_t *iodesc, int varid, int fndims, MPI_Offset *gdim0)
{
Expand Down Expand Up @@ -262,8 +262,6 @@ int get_vard_mpidatatype(io_desc_t *iodesc, MPI_Offset gdim0, PIO_Offset unlimdi

#endif



/**
* Fill start/count arrays for write_darray_multi_par(). This is an
* internal funciton.
Expand Down Expand Up @@ -456,6 +454,7 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
for (int i = 0; i < fndims; i++)
dsize *= count[i];
LOG((3, "dsize = %d", dsize));

/* For pnetcdf's ncmpi_iput_varn() function, we need
* to provide arrays of arrays for start/count. */
if (dsize > 0)
Expand Down Expand Up @@ -962,6 +961,7 @@ int recv_and_write_data(file_desc_t *file, const int *varids, const int *frame,
}

/* Call the netCDF functions to write the data. */

if ((ierr = nc_put_vara(file->fh, varids[nv], start, count, bufptr)))
return check_netcdf2(ios, NULL, ierr, __FILE__, __LINE__);

Expand Down Expand Up @@ -1217,7 +1217,6 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
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 @@ -1864,6 +1863,7 @@ int flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk)

/* Check input. */
pioassert(wmb, "invalid input", __FILE__, __LINE__);

/* Get the file info (to get error handler). */
if ((ret = pio_get_file(ncid, &file)))
return pio_err(NULL, NULL, ret, __FILE__, __LINE__);
Expand Down Expand Up @@ -1918,7 +1918,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((signed char *)sortedarray)[m] = ((signed char *)array)[iodesc->remap[m]+maplen*v];
((signed char *)sortedarray)[m+maplen*v] = ((signed char *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1927,7 +1927,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((char *)sortedarray)[m] = ((char *)array)[iodesc->remap[m]+maplen*v];
((char *)sortedarray)[m+maplen*v] = ((char *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1936,7 +1936,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((short *)sortedarray)[m] = ((short *)array)[iodesc->remap[m]+maplen*v];
((short *)sortedarray)[m+maplen*v] = ((short *)array)[iodesc->remap[m]+maplen*v];
}
}

Expand All @@ -1946,7 +1946,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((int *)sortedarray)[m] = ((int *)array)[iodesc->remap[m]+maplen*v];
((int *)sortedarray)[m+maplen*v] = ((int *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1955,7 +1955,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((float *)sortedarray)[m] = ((float *)array)[iodesc->remap[m]+maplen*v];
((float *)sortedarray)[m+maplen*v] = ((float *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1964,7 +1964,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((double *)sortedarray)[m] = ((double *)array)[iodesc->remap[m]+maplen*v];
((double *)sortedarray)[m+maplen*v] = ((double *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1973,7 +1973,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned char *)sortedarray)[m] = ((unsigned char *)array)[iodesc->remap[m]+maplen*v];
((unsigned char *)sortedarray)[m+maplen*v] = ((unsigned char *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1982,7 +1982,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned short *)sortedarray)[m] = ((unsigned short *)array)[iodesc->remap[m]+maplen*v];
((unsigned short *)sortedarray)[m+maplen*v] = ((unsigned short *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -1991,7 +1991,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned int *)sortedarray)[m] = ((unsigned int *)array)[iodesc->remap[m]+maplen*v];
((unsigned int *)sortedarray)[m+maplen*v] = ((unsigned int *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -2000,7 +2000,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((long long *)sortedarray)[m] = ((long long *)array)[iodesc->remap[m]+maplen*v];
((long long *)sortedarray)[m+maplen*v] = ((long long *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -2009,7 +2009,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned long long *)sortedarray)[m] = ((unsigned long long *)array)[iodesc->remap[m]+maplen*v];
((unsigned long long *)sortedarray)[m+maplen*v] = ((unsigned long long *)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -2018,7 +2018,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((char **)sortedarray)[m] = ((char **)array)[iodesc->remap[m]+maplen*v];
((char **)sortedarray)[m+maplen*v] = ((char **)array)[iodesc->remap[m]+maplen*v];
}
}
break;
Expand All @@ -2035,7 +2035,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((signed char *)sortedarray)[iodesc->remap[m]] = ((signed char *)array)[m+maplen*v];
((signed char *)sortedarray)[iodesc->remap[m]+maplen*v] = ((signed char *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2044,7 +2044,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((char *)sortedarray)[iodesc->remap[m]] = ((char *)array)[m+maplen*v];
((char *)sortedarray)[iodesc->remap[m]+maplen*v] = ((char *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2053,7 +2053,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((short *)sortedarray)[iodesc->remap[m]] = ((short *)array)[m+maplen*v];
((short *)sortedarray)[iodesc->remap[m]+maplen*v] = ((short *)array)[m+maplen*v];
}
}

Expand All @@ -2063,7 +2063,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((int *)sortedarray)[iodesc->remap[m]] = ((int *)array)[m+maplen*v];
((int *)sortedarray)[iodesc->remap[m]+maplen*v] = ((int *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2072,7 +2072,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((float *)sortedarray)[iodesc->remap[m]] = ((float *)array)[m+maplen*v];
((float *)sortedarray)[iodesc->remap[m]+maplen*v] = ((float *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2081,7 +2081,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((double *)sortedarray)[iodesc->remap[m]] = ((double *)array)[m+maplen*v];
((double *)sortedarray)[iodesc->remap[m]+maplen*v] = ((double *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2090,7 +2090,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned char *)sortedarray)[iodesc->remap[m]] = ((unsigned char *)array)[m+maplen*v];
((unsigned char *)sortedarray)[iodesc->remap[m]+maplen*v] = ((unsigned char *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2099,7 +2099,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned short *)sortedarray)[iodesc->remap[m]] = ((unsigned short *)array)[m+maplen*v];
((unsigned short *)sortedarray)[iodesc->remap[m]+maplen*v] = ((unsigned short *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2108,7 +2108,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned int *)sortedarray)[iodesc->remap[m]] = ((unsigned int *)array)[m+maplen*v];
((unsigned int *)sortedarray)[iodesc->remap[m]+maplen*v] = ((unsigned int *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2117,7 +2117,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((long long *)sortedarray)[iodesc->remap[m]] = ((long long *)array)[m+maplen*v];
((long long *)sortedarray)[iodesc->remap[m]+maplen*v] = ((long long *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2126,7 +2126,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((unsigned long long *)sortedarray)[iodesc->remap[m]] = ((unsigned long long *)array)[m+maplen*v];
((unsigned long long *)sortedarray)[iodesc->remap[m]+maplen*v] = ((unsigned long long *)array)[m+maplen*v];
}
}
break;
Expand All @@ -2135,7 +2135,7 @@ int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int
{
for (int m=0; m < maplen; m++)
{
((char **)sortedarray)[iodesc->remap[m]] = ((char **)array)[m+maplen*v];
((char **)sortedarray)[iodesc->remap[m]+maplen*v] = ((char **)array)[m+maplen*v];
}
}
break;
Expand Down
30 changes: 25 additions & 5 deletions tests/general/pio_decomp_tests_1d.F90.in
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ PIO_TF_AUTO_TEST_SUB_BEGIN nc_wr_rd_1d_bc
PIO_TF_CHECK_VAL((rbuf, exp_val), "Got wrong val")

call PIO_closefile(pio_file)

wbuf = wbuf - 200
call PIO_deletefile(pio_tf_iosystem_, filename);
end do

Expand Down Expand Up @@ -318,7 +318,7 @@ PIO_TF_TEMPLATE<PIO_TF_PREDEF_TYPENAME PIO_TF_DATA_TYPE, PIO_TF_PREDEF_TYPENAME
PIO_TF_AUTO_TEST_SUB_BEGIN nc_wr_1d_bc_random
use mpi, only : MPI_INT, MPI_SCATTER
implicit none
type(var_desc_t) :: pio_var
type(var_desc_t) :: pio_var1, pio_var2
type(file_desc_t) :: pio_file
character(len=PIO_TF_MAX_STR_LEN) :: filename
type(io_desc_t) :: wr_iodesc
Expand Down Expand Up @@ -375,25 +375,45 @@ PIO_TF_AUTO_TEST_SUB_BEGIN nc_wr_1d_bc_random
ierr = PIO_def_dim(pio_file, 'PIO_TF_test_dim', dims(1), pio_dim)
PIO_TF_CHECK_ERR(ierr, "Failed to define a dim : " // trim(filename))

ierr = PIO_def_var(pio_file, 'PIO_TF_test_var', PIO_TF_DATA_TYPE, (/pio_dim/), pio_var)
ierr = PIO_def_var(pio_file, 'PIO_TF_test_var1', PIO_TF_DATA_TYPE, (/pio_dim/), pio_var1)
PIO_TF_CHECK_ERR(ierr, "Failed to define a var : " // trim(filename))

ierr = PIO_def_var(pio_file, 'PIO_TF_test_var2', PIO_TF_DATA_TYPE, (/pio_dim/), pio_var2)
PIO_TF_CHECK_ERR(ierr, "Failed to define a var : " // trim(filename))

ierr = PIO_enddef(pio_file)
PIO_TF_CHECK_ERR(ierr, "Failed to end redef mode : " // trim(filename))

! Write the variable out
call PIO_write_darray(pio_file, pio_var, wr_iodesc, wbuf, ierr)
call PIO_write_darray(pio_file, pio_var1, wr_iodesc, wbuf, ierr)
PIO_TF_CHECK_ERR(ierr, "Failed to write darray : " // trim(filename))

wbuf = wbuf + 200

call PIO_write_darray(pio_file, pio_var2, wr_iodesc, wbuf, ierr)
PIO_TF_CHECK_ERR(ierr, "Failed to write darray : " // trim(filename))

call PIO_syncfile(pio_file)

call PIO_read_darray(pio_file, pio_var, wr_iodesc, rbuf, ierr)

call PIO_read_darray(pio_file, pio_var1, wr_iodesc, rbuf, ierr)
PIO_TF_CHECK_ERR(ierr, "Failed to read darray : " // trim(filename))

wbuf = wbuf - 200

PIO_TF_CHECK_VAL((rbuf, wbuf), "Got wrong val")

wbuf = wbuf + 200

call PIO_read_darray(pio_file, pio_var2, wr_iodesc, rbuf, ierr)
PIO_TF_CHECK_ERR(ierr, "Failed to read darray : " // trim(filename))

PIO_TF_CHECK_VAL((rbuf, wbuf), "Got wrong val")

call PIO_closefile(pio_file)

wbuf = wbuf + 200

call PIO_deletefile(pio_tf_iosystem_, filename);
end do

Expand Down

0 comments on commit e062f76

Please sign in to comment.