Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed May 2, 2018
1 parent 3fc7ce8 commit b23f6f1
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 13 deletions.
11 changes: 10 additions & 1 deletion src/clib/pio_rearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
}

/* Handle fill values if needed. */
LOG((4, "ios->ioproc %d iodesc->needsfill %d", ios->ioproc, iodesc->needsfill));
if (ios->ioproc && iodesc->needsfill)
{
/* we need the list of offsets which are not in the union of iomap */
Expand All @@ -1844,6 +1845,7 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
thisgridsize[0] = totalgridsize / ios->num_iotasks;
thisgridmax[0] = thisgridsize[0];
int xtra = totalgridsize - thisgridsize[0] * ios->num_iotasks;
LOG((4, "xtra %d", xtra));

for (nio = 0; nio < ios->num_iotasks; nio++)
{
Expand All @@ -1855,7 +1857,9 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
if (nio >= ios->num_iotasks - xtra)
thisgridsize[nio]++;
thisgridmin[nio] = thisgridmax[nio - 1] + 1;
thisgridmax[nio]= thisgridmin[nio] + thisgridsize[nio] - 1;
thisgridmax[nio] = thisgridmin[nio] + thisgridsize[nio] - 1;
LOG((4, "nio %d thisgridsize[nio] %d thisgridmin[nio] %d thisgridmax[nio] %d",
nio, thisgridsize[nio], thisgridmin[nio], thisgridmax[nio]));
}
for (int i = 0; i < iodesc->llen; i++)
{
Expand All @@ -1866,6 +1870,7 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
imin = i;
}
}
LOG((4, "cnt %d", cnt));

/* Gather cnt from all tasks in the IO communicator into array gcnt. */
if ((mpierr = MPI_Gather(&cnt, 1, MPI_INT, gcnt, 1, MPI_INT, nio, ios->io_comm)))
Expand Down Expand Up @@ -1893,6 +1898,7 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma

/* Allocate and initialize a grid to fill in missing values. ??? */
PIO_Offset grid[thisgridsize[ios->io_rank]];
LOG((4, "thisgridsize[ios->io_rank] %d", thisgridsize[ios->io_rank]));
for (i = 0; i < thisgridsize[ios->io_rank]; i++)
grid[i] = 0;

Expand All @@ -1902,6 +1908,7 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
int j = myusegrid[i] - thisgridmin[ios->io_rank];
pioassert(j < thisgridsize[ios->io_rank], "out of bounds array index",
__FILE__, __LINE__);
LOG((4, "i %d myusegrid[i] %d j %d", i, myusegrid[i], j));
if (j >= 0)
{
grid[j] = 1;
Expand All @@ -1912,6 +1919,8 @@ int subset_rearrange_create(iosystem_desc_t *ios, int maplen, PIO_Offset *compma
free(myusegrid);

iodesc->holegridsize = thisgridsize[ios->io_rank] - cnt;
LOG((3, "iodesc->holegridsize %d thisgridsize[%d] %d cnt %d", iodesc->holegridsize, ios->io_rank,
thisgridsize[ios->io_rank], cnt));
if (iodesc->holegridsize > 0)
{
/* Allocate space for the fillgrid. */
Expand Down
3 changes: 3 additions & 0 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,10 @@ int PIOc_InitDecomp(int iosysid, int pio_type, int ndims, const int *gdimlen, in
if (!(iodesc->map = malloc(sizeof(PIO_Offset) * maplen)))
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);
for (int m = 0; m < maplen; m++)
{
iodesc->map[m] = compmap[m];
LOG((4, "compmap[%d] = %d", m, compmap[m]));
}

/* Remember the dim sizes. */
if (!(iodesc->dimlen = malloc(sizeof(int) * ndims)))
Expand Down
21 changes: 11 additions & 10 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,17 @@ void pio_log(int severity, const char *fmt, ...)
ptr += strlen(rank_str);
rem_len -= strlen(rank_str);

/* Show the severity. */
snprintf(rank_str, MAX_RANK_STR, ":%d ", severity);
strncpy(ptr, rank_str, (rem_len > 0) ? rem_len : 0);
ptr += strlen(rank_str);
rem_len -= strlen(rank_str);
/* /\* Show the severity. *\/ */
/* snprintf(rank_str, MAX_RANK_STR, ":%d ", severity); */
/* strncpy(ptr, rank_str, (rem_len > 0) ? rem_len : 0); */
/* ptr += strlen(rank_str); */
/* rem_len -= strlen(rank_str); */

/* Print out the variable list of args with vprintf. */
va_start(argp, fmt);
vsnprintf(ptr, ((rem_len > 0) ? rem_len : 0), fmt, argp);
va_end(argp);


/* Put on a final linefeed. */
ptr = msg + strlen(msg);
rem_len = MAX_LOG_MSG - strlen(msg);
Expand Down Expand Up @@ -420,10 +419,12 @@ int check_netcdf2(iosystem_desc_t *ios, file_desc_t *file, int status,

if (file && file->iosystem->ioproc &&
(file->iotype == PIO_IOTYPE_PNETCDF || file->iotype == PIO_IOTYPE_NETCDF4P))
if (file->iosystem->io_rank == 0)
MPI_Reduce(MPI_IN_PLACE, &status, 1, MPI_INT, MPI_MIN, 0, file->iosystem->io_comm);
else
MPI_Reduce(&status, &rbuf, 1, MPI_INT, MPI_MIN, 0, file->iosystem->io_comm);
{
if (file->iosystem->io_rank == 0)
MPI_Reduce(MPI_IN_PLACE, &status, 1, MPI_INT, MPI_MIN, 0, file->iosystem->io_comm);
else
MPI_Reduce(&status, &rbuf, 1, MPI_INT, MPI_MIN, 0, file->iosystem->io_comm);
}

LOG((1, "check_netcdf2 status = %d fname = %s line = %d", status, fname, line));

Expand Down
7 changes: 7 additions & 0 deletions tests/cunit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ if (NOT PIO_USE_MPISERIAL)
target_link_libraries (test_decomps pioc)
add_executable (test_rearr EXCLUDE_FROM_ALL test_rearr.c test_common.c)
target_link_libraries (test_rearr pioc)
add_executable (test_darray_fill EXCLUDE_FROM_ALL test_darray_fill.c test_common.c)
target_link_libraries (test_darray_fill pioc)
if (PIO_USE_MALLOC)
add_executable (test_darray_async_simple EXCLUDE_FROM_ALL test_darray_async_simple.c test_common.c)
target_link_libraries (test_darray_async_simple pioc)
Expand Down Expand Up @@ -123,6 +125,7 @@ add_dependencies (tests test_darray_1d)
add_dependencies (tests test_darray_3d)
add_dependencies (tests test_decomp_uneven)
add_dependencies (tests test_decomps)
add_dependencies (tests test_darray_fill)
if(PIO_USE_MALLOC)
add_dependencies (tests test_darray_async_simple)
add_dependencies (tests test_darray_async)
Expand Down Expand Up @@ -252,6 +255,10 @@ else ()
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_darray_3d
NUMPROCS ${AT_LEAST_FOUR_TASKS}
TIMEOUT ${DEFAULT_TEST_TIMEOUT})
add_mpi_test(test_darray_fill
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_darray_fill
NUMPROCS ${AT_LEAST_FOUR_TASKS}
TIMEOUT ${DEFAULT_TEST_TIMEOUT})
if(PIO_USE_MALLOC)
add_mpi_test(test_darray_2sync
EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_darray_2sync
Expand Down
4 changes: 3 additions & 1 deletion tests/cunit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ test_darray_multi test_darray_multivar test_darray_multivar2 \
test_darray_multivar3 test_darray_1d test_darray_3d \
test_decomp_uneven test_decomps test_rearr test_darray_async_simple \
test_darray_async test_darray_async_many test_darray_2sync \
test_async_multicomp test_async_multi2 test_async_manyproc
test_async_multicomp test_async_multi2 test_async_manyproc \
test_darray_fill

# Tests will run from a bash script.
TESTS = run_tests.sh
Expand Down Expand Up @@ -56,6 +57,7 @@ test_async_3proc_SOURCES = test_async_3proc.c test_common.c pio_tests.h
test_async_multicomp_SOURCES = test_async_multicomp.c test_common.c pio_tests.h
test_async_multi2_SOURCES = test_async_multi2.c test_common.c pio_tests.h
test_async_manyproc_SOURCES = test_async_manyproc.c test_common.c pio_tests.h
test_darray_fill_SOURCES = test_darray_fill.c test_common.c pio_tests.h

# Distribute the test script.
EXTRA_DIST = run_tests.sh
Expand Down
3 changes: 2 additions & 1 deletion tests/cunit/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ PIO_TESTS='test_intercomm2 test_async_mpi test_spmd test_rearr test_async_simple
'test_pioc_unlim test_pioc_putget test_pioc_fill test_darray test_darray_multi '\
'test_darray_multivar test_darray_multivar2 test_darray_multivar3 test_darray_1d '\
'test_darray_3d test_decomp_uneven test_decomps test_darray_async_simple '\
'test_darray_async test_darray_async_many test_darray_2sync test_async_multicomp '
'test_darray_async test_darray_async_many test_darray_2sync test_async_multicomp '\
'test_darray_fill'

success1=true
success2=true
Expand Down
172 changes: 172 additions & 0 deletions tests/cunit/test_darray_fill.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* Tests for PIO distributed arrays.
*
* @author Ed Hartnett
* @date 4/21/18
*/
#include <config.h>
#include <pio.h>
#include <pio_internal.h>
#include <pio_tests.h>

/* The number of tasks this test should run on. */
#define TARGET_NTASKS 4

/* The minimum number of tasks this test should run on. */
#define MIN_NTASKS 4

/* The name of this test. */
#define TEST_NAME "test_darray_fill"

/* Number of processors that will do IO. */
#define NUM_IO_PROCS 4

/* Number of computational components to create. */
#define COMPONENT_COUNT 1

#define VAR_NAME "PIO_TF_test_var"
#define DIM_NAME "PIO_TF_test_dim"
#define FILL_VALUE_NAME "_FillValue"

/* Test with and without specifying a fill value to
* PIOc_write_darray(). */
#define NUM_TEST_CASES_FILLVALUE 2

#define NDIM1 1
#define MAPLEN 7

/* Length of the dimensions in the sample data. */
int dim_len[NDIM1] = {28};

/* Run test for each of the rearrangers. */
#define NUM_REARRANGERS_TO_TEST 1

/* Run tests for darray functions. */
int main(int argc, char **argv)
{
int my_rank;
int ntasks;
int num_flavors; /* Number of PIO netCDF flavors in this build. */
int flavor[NUM_FLAVORS]; /* iotypes for the supported netCDF IO flavors. */
MPI_Comm test_comm; /* A communicator for this test. */
int ret; /* Return code. */

/* Initialize test. */
if ((ret = pio_test_init2(argc, argv, &my_rank, &ntasks, MIN_NTASKS,
MIN_NTASKS, 4, &test_comm)))
ERR(ERR_INIT);

if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL)))
return ret;

/* Only do something on max_ntasks tasks. */
if (my_rank < TARGET_NTASKS)
{
/* int rearranger[NUM_REARRANGERS_TO_TEST] = {PIO_REARR_BOX, PIO_REARR_SUBSET}; */
int rearranger[NUM_REARRANGERS_TO_TEST] = {PIO_REARR_SUBSET};
int iosysid; /* The ID for the parallel I/O system. */
int ioproc_stride = 1; /* Stride in the mpi rank between io tasks. */
int ioproc_start = 0; /* Zero based rank of first processor to be used for I/O. */
int wioid, rioid;
int maplen = MAPLEN;
MPI_Offset wcompmap[MAPLEN];
MPI_Offset rcompmap[MAPLEN];
int data[MAPLEN];
int data_in[MAPLEN];
int expected[MAPLEN];
int fill_value_int = -2;
int ret; /* Return code. */

/* Set up the compmaps. Don't forget these are 1-based
* numbers, like in Fortran! */
for (int i = 0; i < MAPLEN; i++)
{
wcompmap[i] = i % 2 ? my_rank * MAPLEN + i + 1 : 0; /* Even values missing. */
rcompmap[i] = my_rank * MAPLEN + i + 1;
data[i] = wcompmap[i];
expected[i] = i % 2 ? my_rank * MAPLEN + i + 1 : fill_value_int;
}

/* Figure out iotypes. */
if ((ret = get_iotypes(&num_flavors, flavor)))
ERR(ret);

for (int r = 0; r < NUM_REARRANGERS_TO_TEST; r++)
{
/* Initialize the PIO IO system. This specifies how
* many and which processors are involved in I/O. */
if ((ret = PIOc_Init_Intracomm(test_comm, NUM_IO_PROCS, ioproc_stride, ioproc_start,
rearranger[r], &iosysid)))
return ret;

/* /\* Initialize decompositions. *\/ */
if ((ret = PIOc_InitDecomp(iosysid, PIO_INT, NDIM1, dim_len, maplen, wcompmap,
&wioid, &rearranger[r], NULL, NULL)))
return ret;
if ((ret = PIOc_InitDecomp(iosysid, PIO_INT, NDIM1, dim_len, maplen, rcompmap,
&rioid, &rearranger[r], NULL, NULL)))
return ret;

int ncid, dimid, varid;
int iotype = PIO_IOTYPE_NETCDF4C;
char filename[NC_MAX_NAME + 1];

/* Put together filename. */
sprintf(filename, "%s_%d.nc", TEST_NAME, iotype);

/* Create file. */
if ((ret = PIOc_createfile(iosysid, &ncid, &iotype, filename, NC_CLOBBER)))
return ret;

/* Define metadata. */
if ((ret = PIOc_def_dim(ncid, DIM_NAME, dim_len[0], &dimid)))
return ret;
if ((ret = PIOc_def_var(ncid, VAR_NAME, PIO_INT, NDIM1, &dimid, &varid)))
return ret;
if ((ret = PIOc_put_att_int(ncid, varid, FILL_VALUE_NAME, PIO_INT, 1, &fill_value_int)))
return ret;
if ((ret = PIOc_enddef(ncid)))
return ret;

/* Write some data. */
if ((ret = PIOc_write_darray(ncid, varid, wioid, MAPLEN, data, &fill_value_int)))
return ret;
if ((ret = PIOc_sync(ncid)))
return ret;

/* Read the data. */
if ((ret = PIOc_read_darray(ncid, varid, rioid, MAPLEN, data_in)))
return ret;

/* Check results. */
for (int j = 0; j < MAPLEN; j++)
{
if (data_in[j] != expected[j])
return ERR_AWFUL;
printf("data_in[%d] = %d\n", j, data_in[j]);
}

/* Close file. */
if ((ret = PIOc_closefile(ncid)))
return ret;

/* Free decompositions. */
if ((ret = PIOc_freedecomp(iosysid, wioid)))
return ret;
if ((ret = PIOc_freedecomp(iosysid, rioid)))
return ret;

/* Finalize PIO system. */
if ((ret = PIOc_finalize(iosysid)))
return ret;

} /* next rearranger */
} /* endif my_rank < TARGET_NTASKS */

/* Finalize the MPI library. */
if ((ret = pio_test_finalize(&test_comm)))
return ret;

printf("%d %s SUCCESS!!\n", my_rank, TEST_NAME);
return 0;
}

0 comments on commit b23f6f1

Please sign in to comment.