From 1b1892231599a4a51de6e7cf3ce806fd211ffcf0 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 4 May 2018 05:49:17 -0600 Subject: [PATCH] test development --- tests/cunit/test_darray_fill.c | 188 ++++++++++++++++++++------------- 1 file changed, 115 insertions(+), 73 deletions(-) diff --git a/tests/cunit/test_darray_fill.c b/tests/cunit/test_darray_fill.c index 14e324f9551..baf93a0e424 100644 --- a/tests/cunit/test_darray_fill.c +++ b/tests/cunit/test_darray_fill.c @@ -39,7 +39,7 @@ int dim_len[NDIM1] = {28}; /* Run test for each of the rearrangers. */ -#define NUM_REARRANGERS_TO_TEST 1 +#define NUM_REARRANGERS_TO_TEST 2 /* Run tests for darray functions. */ int main(int argc, char **argv) @@ -62,8 +62,7 @@ int main(int argc, char **argv) /* 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 rearranger[NUM_REARRANGERS_TO_TEST] = {PIO_REARR_BOX, 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. */ @@ -74,7 +73,37 @@ int main(int argc, char **argv) int data[MAPLEN]; int data_in[MAPLEN]; int expected[MAPLEN]; - int fill_value_int = -2; + + /* Custom fill value for each type. */ + signed char byte_fill = NC_FILL_BYTE; + char char_fill = NC_FILL_CHAR; + short short_fill = NC_FILL_SHORT; + int int_fill = -2; + float float_fill = NC_FILL_FLOAT; + double double_fill = NC_FILL_DOUBLE; +#ifdef _NETCDF4 + unsigned char ubyte_fill = NC_FILL_UBYTE; + unsigned short ushort_fill = NC_FILL_USHORT; + unsigned int uint_fill = NC_FILL_UINT; + long long int64_fill = NC_FILL_INT64; + unsigned long long uint64_fill = NC_FILL_UINT64; +#endif /* _NETCDF4 */ + + /* Default fill value for each type. */ + signed char byte_default_fill = NC_FILL_BYTE; + char char_default_fill = NC_FILL_CHAR; + short short_default_fill = NC_FILL_SHORT; + int int_default_fill = NC_FILL_INT; + float float_default_fill = NC_FILL_FLOAT; + double double_default_fill = NC_FILL_DOUBLE; +#ifdef _NETCDF4 + unsigned char ubyte_default_fill = NC_FILL_UBYTE; + unsigned short ushort_default_fill = NC_FILL_USHORT; + unsigned int uint_default_fill = NC_FILL_UINT; + long long int64_default_fill = NC_FILL_INT64; + unsigned long long uint64_default_fill = NC_FILL_UINT64; +#endif /* _NETCDF4 */ + int ret; /* Return code. */ /* Set up the compmaps. Don't forget these are 1-based @@ -84,87 +113,100 @@ int main(int argc, char **argv) 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++) + for (int fv = 0; fv < NUM_TEST_CASES_FILLVALUE; fv++) { - /* 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; - char filename[NC_MAX_NAME + 1]; - - /* Use PIO to create the example file in each of the four - * available ways. */ - for (int fmt = 0; fmt < num_flavors; fmt++) +#define NUM_TYPES 1 + int test_type[NUM_TYPES] = {PIO_INT}; + for (int t = 0; t < NUM_TYPES; t++) { - /* Put together filename. */ - sprintf(filename, "%s_%d.nc", TEST_NAME, flavor[fmt]); + + /* Determine what result we should expect. */ + for (int i = 0; i < MAPLEN; i++) + expected[i] = i % 2 ? my_rank * MAPLEN + i + 1 : int_fill; - /* Create file. */ - if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], 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++) + for (int r = 0; r < NUM_REARRANGERS_TO_TEST; r++) { - if (data_in[j] != expected[j]) - return ERR_AWFUL; - printf("data_in[%d] = %d\n", j, data_in[j]); - } + /* 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, test_type[t], NDIM1, dim_len, maplen, wcompmap, + &wioid, &rearranger[r], NULL, NULL))) + return ret; + if ((ret = PIOc_InitDecomp(iosysid, test_type[t], NDIM1, dim_len, maplen, rcompmap, + &rioid, &rearranger[r], NULL, NULL))) + return ret; + + int ncid, dimid, varid; + char filename[NC_MAX_NAME + 1]; + + /* Use PIO to create the example file in each of the four + * available ways. */ + for (int fmt = 0; fmt < num_flavors; fmt++) + { + /* Put together filename. */ + sprintf(filename, "%s_%d_%d.nc", TEST_NAME, flavor[fmt], rearranger[r]); - /* Close file. */ - if ((ret = PIOc_closefile(ncid))) - return ret; - } /* next iotype */ + /* Create file. */ + if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], 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, test_type[t], NDIM1, &dimid, &varid))) + return ret; + if ((ret = PIOc_put_att_int(ncid, varid, FILL_VALUE_NAME, test_type[t], + 1, &int_fill))) + return ret; + if ((ret = PIOc_enddef(ncid))) + return ret; + + /* Write some data. */ + if ((ret = PIOc_write_darray(ncid, varid, wioid, MAPLEN, data, &int_fill))) + 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]); + } - /* 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 */ + /* Close file. */ + if ((ret = PIOc_closefile(ncid))) + return ret; + } /* next iotype */ + + /* 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 */ + } /* next type */ + } /* next fill value test case */ } /* endif my_rank < TARGET_NTASKS */ /* Finalize the MPI library. */