diff --git a/tests/ncint/tst_var_compress.c b/tests/ncint/tst_var_compress.c index 2db2761d1de..f7fd811e4cd 100644 --- a/tests/ncint/tst_var_compress.c +++ b/tests/ncint/tst_var_compress.c @@ -21,11 +21,75 @@ #define NDIM3 3 #define TEST_VAL_42 42 -extern NC_Dispatch NCINT_dispatcher; +int +run_var_compress_test(int my_rank, int ntasks, int iosysid) +{ + int ncid, ioid; + int dimid[NDIM3], varid; + int dimlen[NDIM3] = {NC_UNLIMITED, DIM_LEN_X, DIM_LEN_Y}; + size_t elements_per_pe; + size_t *compdof; /* The decomposition mapping. */ + int *my_data; + int *data_in; + int i; + + /* Turn on logging for PIO library. */ + /* PIOc_set_log_level(3); */ + + /* Create a file with a 3D record var. */ + if (nc_create(FILE_NAME, NC_PIO, &ncid)) PERR; + if (nc_def_dim(ncid, DIM_NAME_UNLIMITED, dimlen[0], &dimid[0])) PERR; + if (nc_def_dim(ncid, DIM_NAME_X, dimlen[1], &dimid[1])) PERR; + if (nc_def_dim(ncid, DIM_NAME_Y, dimlen[2], &dimid[2])) PERR; + if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM3, dimid, &varid)) PERR; + + /* Calculate a decomposition for distributed arrays. */ + elements_per_pe = DIM_LEN_X * DIM_LEN_Y / ntasks; + if (!(compdof = malloc(elements_per_pe * sizeof(size_t)))) + PERR; + for (i = 0; i < elements_per_pe; i++) + compdof[i] = my_rank * elements_per_pe + i; + + /* Create the PIO decomposition for this test. */ + if (nc_def_decomp(iosysid, PIO_INT, NDIM2, &dimlen[1], elements_per_pe, + compdof, &ioid, 1, NULL, NULL)) PERR; + free(compdof); + + /* Create some data on this processor. */ + if (!(my_data = malloc(elements_per_pe * sizeof(int)))) PERR; + for (i = 0; i < elements_per_pe; i++) + my_data[i] = my_rank * 10 + i; + + /* Write some data with distributed arrays. */ + if (nc_put_vard_int(ncid, varid, ioid, 0, my_data)) PERR; + if (nc_close(ncid)) PERR; + + /* Open the file. */ + if (nc_open(FILE_NAME, NC_PIO, &ncid)) PERR; + + /* Read distributed arrays. */ + if (!(data_in = malloc(elements_per_pe * sizeof(int)))) PERR; + if (nc_get_vard_int(ncid, varid, ioid, 0, data_in)) PERR; + + /* Check results. */ + for (i = 0; i < elements_per_pe; i++) + if (data_in[i] != my_data[i]) PERR; + + /* Close file. */ + if (nc_close(ncid)) PERR; + + /* Free resources. */ + free(data_in); + free(my_data); + if (nc_free_decomp(ioid)) PERR; + + return 0; +} int main(int argc, char **argv) { + int iosysid; int my_rank; int ntasks; @@ -38,89 +102,16 @@ main(int argc, char **argv) if (!my_rank) printf("\n*** Testing netCDF integration layer.\n"); - if (!my_rank) - printf("*** testing getting/setting of default iosystemid..."); - { - int iosysid; - - if (nc_set_iosystem(TEST_VAL_42)) PERR; - if (nc_get_iosystem(&iosysid)) PERR; - if (iosysid != TEST_VAL_42) PERR; - } - PSUMMARIZE_ERR; if (!my_rank) - printf("*** testing simple use of netCDF integration layer format..."); - { - int ncid, ioid; - int dimid[NDIM3], varid; - int dimlen[NDIM3] = {NC_UNLIMITED, DIM_LEN_X, DIM_LEN_Y}; - int iosysid; - NC_Dispatch *disp_in; - size_t elements_per_pe; - size_t *compdof; /* The decomposition mapping. */ - int *my_data; - int *data_in; - int i; - - /* Turn on logging for PIO library. */ - /* PIOc_set_log_level(3); */ - - /* Initialize the intracomm. */ - if (nc_def_iosystem(MPI_COMM_WORLD, 1, 1, 0, 0, &iosysid)) PERR; - - /* Create a file with a 3D record var. */ - if (nc_create(FILE_NAME, NC_PIO, &ncid)) PERR; - if (nc_def_dim(ncid, DIM_NAME_UNLIMITED, dimlen[0], &dimid[0])) PERR; - if (nc_def_dim(ncid, DIM_NAME_X, dimlen[1], &dimid[1])) PERR; - if (nc_def_dim(ncid, DIM_NAME_Y, dimlen[2], &dimid[2])) PERR; - if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM3, dimid, &varid)) PERR; - - /* Calculate a decomposition for distributed arrays. */ - elements_per_pe = DIM_LEN_X * DIM_LEN_Y / ntasks; - if (!(compdof = malloc(elements_per_pe * sizeof(size_t)))) - PERR; - for (i = 0; i < elements_per_pe; i++) - compdof[i] = my_rank * elements_per_pe + i; - - /* Create the PIO decomposition for this test. */ - if (nc_def_decomp(iosysid, PIO_INT, NDIM2, &dimlen[1], elements_per_pe, - compdof, &ioid, 1, NULL, NULL)) PERR; - free(compdof); - - /* Create some data on this processor. */ - if (!(my_data = malloc(elements_per_pe * sizeof(int)))) PERR; - for (i = 0; i < elements_per_pe; i++) - my_data[i] = my_rank * 10 + i; - - /* Write some data with distributed arrays. */ - if (nc_put_vard_int(ncid, varid, ioid, 0, my_data)) PERR; - if (nc_close(ncid)) PERR; - - /* Check that our user-defined format has been added. */ - if (nc_inq_user_format(NC_PIO, &disp_in, NULL)) PERR; - if (disp_in != &NCINT_dispatcher) PERR; - - /* Open the file. */ - if (nc_open(FILE_NAME, NC_PIO, &ncid)) PERR; - - /* Read distributed arrays. */ - if (!(data_in = malloc(elements_per_pe * sizeof(int)))) PERR; - if (nc_get_vard_int(ncid, varid, ioid, 0, data_in)) PERR; - - /* Check results. */ - for (i = 0; i < elements_per_pe; i++) - if (data_in[i] != my_data[i]) PERR; - - /* Close file. */ - if (nc_close(ncid)) PERR; - - /* Free resources. */ - free(data_in); - free(my_data); - if (nc_free_decomp(ioid)) PERR; - if (nc_free_iosystem(iosysid)) PERR; - } + printf("*** testing var compression with netCDF integration layer..."); + + /* Initialize the intracomm. */ + if (nc_def_iosystem(MPI_COMM_WORLD, 1, 1, 0, 0, &iosysid)) PERR; + + if (run_var_compress_test(my_rank, ntasks, iosysid)) PERR; + + if (nc_free_iosystem(iosysid)) PERR; PSUMMARIZE_ERR; /* Finalize MPI. */