From 958d9b91af035675682bcb8b2814d12562cbee30 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 22 Jul 2020 07:01:33 -0600 Subject: [PATCH] added test_simple.c --- tests/cunit/CMakeLists.txt | 7 ++ tests/cunit/Makefile.am | 2 +- tests/cunit/run_tests.sh | 2 +- tests/cunit/test_simple.c | 155 +++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 tests/cunit/test_simple.c diff --git a/tests/cunit/CMakeLists.txt b/tests/cunit/CMakeLists.txt index c314c24425f..4502ecd7398 100644 --- a/tests/cunit/CMakeLists.txt +++ b/tests/cunit/CMakeLists.txt @@ -111,6 +111,8 @@ if (NOT PIO_USE_MPISERIAL) target_link_libraries (test_async_manyproc pioc) add_executable (test_async_1d EXCLUDE_FROM_ALL test_async_1d.c) target_link_libraries (test_async_1d pioc) + add_executable (test_simple EXCLUDE_FROM_ALL test_simple.c) + target_link_libraries (test_simple pioc) endif () endif () add_executable (test_spmd EXCLUDE_FROM_ALL test_spmd.c test_common.c) @@ -143,6 +145,7 @@ if(PIO_USE_MALLOC) add_dependencies (tests test_async_multi2) add_dependencies (tests test_async_manyproc) add_dependencies (tests test_async_1d) + add_dependencies (tests test_simple) endif () # Test Timeout in seconds. @@ -310,4 +313,8 @@ else () EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_decomps NUMPROCS ${AT_LEAST_FOUR_TASKS} TIMEOUT ${DEFAULT_TEST_TIMEOUT}) + add_mpi_test(test_simple + EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/test_simple + NUMPROCS ${AT_LEAST_FOUR_TASKS} + TIMEOUT ${DEFAULT_TEST_TIMEOUT}) endif () diff --git a/tests/cunit/Makefile.am b/tests/cunit/Makefile.am index a21f08563c7..c1ca26cf407 100644 --- a/tests/cunit/Makefile.am +++ b/tests/cunit/Makefile.am @@ -19,7 +19,7 @@ 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_darray_fill test_decomp_frame test_perf2 test_async_perf \ -test_darray_vard test_async_1d +test_darray_vard test_async_1d test_simple if RUN_TESTS # Tests will run from a bash script. diff --git a/tests/cunit/run_tests.sh b/tests/cunit/run_tests.sh index 89ebd0fcf0a..9e41ae1f319 100755 --- a/tests/cunit/run_tests.sh +++ b/tests/cunit/run_tests.sh @@ -17,7 +17,7 @@ PIO_TESTS='test_intercomm2 test_async_mpi test_spmd test_rearr test_async_simple '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_fill test_darray_vard test_async_1d' +'test_darray_fill test_darray_vard test_async_1d test_simple' success1=true success2=true diff --git a/tests/cunit/test_simple.c b/tests/cunit/test_simple.c new file mode 100644 index 00000000000..92425f0521a --- /dev/null +++ b/tests/cunit/test_simple.c @@ -0,0 +1,155 @@ +/* + * Tests for PIOc_Intercomm. This tests basic asynch I/O capability. + * + * This very simple test runs on 4 ranks. + * + * @author Ed Hartnett + */ +#include +#include +#include + +/* The number of tasks this test should run on. */ +#define TARGET_NTASKS 4 + +/* The number of IO tasks. */ +#define NUM_IO_TASKS 1 + +/* The number of computational tasks. */ +#define NUM_COMP_TASKS 3 + +/* The name of this test. */ +#define TEST_NAME "test_async_1d" + +/* The name of the output of the test. */ +#define FILE_NAME "test_async_1d.nc" + +/* Number of different combonations of IO and computation processor + * numbers we will try in this test. */ +#define NUM_COMBOS 3 + +/* Number of computational components to create. */ +#define COMPONENT_COUNT 1 + +#define NDIM1 1 +#define NDIM2 2 +#define DIM_NAME_0 "unlim" +#define DIM_NAME_1 "dim_1" +#define DIM_LEN_1 3 +#define VAR_NAME "async_var" +#define MAPLEN 1 + +/* Run async tests. */ +int main(int argc, char **argv) +{ +#ifdef USE_NETCDF4 + int my_rank; /* Zero-based rank of processor. */ + int ntasks; /* Number of processors involved in current execution. */ + int iosysid; /* The ID for the parallel I/O system. */ + int num_procs_per_comp[COMPONENT_COUNT] = {3}; + /* int num_flavors; /\* Number of PIO netCDF flavors in this build. *\/ */ + /* int flavor[NUM_FLAVORS]; /\* iotypes for the supported netCDF IO flavors. *\/ */ + int ret; /* Return code. */ + + /* Initialize MPI. */ + if ((ret = MPI_Init(&argc, &argv))) + MPIERR(ret); + + /* Learn my rank and the total number of processors. */ + if ((ret = MPI_Comm_rank(MPI_COMM_WORLD, &my_rank))) + MPIERR(ret); + if ((ret = MPI_Comm_size(MPI_COMM_WORLD, &ntasks))) + MPIERR(ret); + + /* Make sure we have 4 tasks. */ + if (ntasks != TARGET_NTASKS) ERR(ERR_WRONG); + + /* PIOc_set_log_level(4); */ + + /* Change error handling so we can test inval parameters. */ + if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL))) + return ret; + + /* Set up IO system. Task 0 will do IO, tasks 1-3 will be a single + * computational unit. Task 0 will stay in this function until the + * computational component calls PIOc_finalize(). */ + if ((ret = PIOc_init_async(MPI_COMM_WORLD, NUM_IO_TASKS, NULL, COMPONENT_COUNT, + num_procs_per_comp, NULL, NULL, NULL, + PIO_REARR_BOX, &iosysid))) + ERR(ret); + + /* Only computational processors run this code. */ + if (my_rank) + { + int ncid; + int iotype = PIO_IOTYPE_NETCDF4C; + int dimid[NDIM2]; + int gdimlen[NDIM1] = {DIM_LEN_1}; + PIO_Offset compmap[MAPLEN]; + int varid; + int data; + int data_in; + int ioid; + + /* Create a file. */ + if ((ret = PIOc_createfile(iosysid, &ncid, &iotype, FILE_NAME, 0))) + ERR(ret); + if ((ret = PIOc_def_dim(ncid, DIM_NAME_0, PIO_UNLIMITED, &dimid[0]))) + ERR(ret); + if ((ret = PIOc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid[1]))) + ERR(ret); + if ((ret = PIOc_def_var(ncid, VAR_NAME, PIO_INT, NDIM2, dimid, &varid))) + ERR(ret); + if ((ret = PIOc_def_var_fill(ncid, varid, PIO_NOFILL, NULL))) + ERR(ret); + if ((ret = PIOc_enddef(ncid))) + ERR(ret); + + /* Set up a decomposition. Each of the 3 computational procs + * will write one value, to get the 3-values of each + * record. */ + compmap[0] = my_rank - 1; + if ((ret = PIOc_init_decomp(iosysid, PIO_INT, NDIM1, gdimlen, MAPLEN, + compmap, &ioid, PIO_REARR_BOX, NULL, NULL))) + ERR(ret); + + /* Write a record of data. */ + data = my_rank; + if ((ret = PIOc_setframe(ncid, 0, 0))) + ERR(ret); + if ((ret = PIOc_write_darray(ncid, 0, ioid, MAPLEN, &data, NULL))) + ERR(ret); + + /* Close the file. */ + if ((ret = PIOc_closefile(ncid))) + ERR(ret); + + /* Reopen the file and check. */ + if ((ret = PIOc_openfile(iosysid, &ncid, &iotype, FILE_NAME, 0))) + ERR(ret); + + /* Read the data. */ + if ((ret = PIOc_setframe(ncid, 0, 0))) + ERR(ret); + if ((ret = PIOc_read_darray(ncid, 0, ioid, MAPLEN, &data_in))) + ERR(ret); + if (data_in != data) ERR(ERR_WRONG); + + /* Close the file. */ + if ((ret = PIOc_closefile(ncid))) + ERR(ret); + + /* Free the decomposition. */ + if ((ret = PIOc_freedecomp(iosysid, ioid))) + ERR(ret); + + /* Shut down the IO system. */ + if ((ret = PIOc_finalize(iosysid))) + ERR(ret); + } + + printf("%d %s SUCCESS!!\n", my_rank, TEST_NAME); +#endif /* USE_NETCDF4 */ + + return 0; +}