Skip to content

Commit

Permalink
starting to add new test_async_1d
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Sep 4, 2019
1 parent 3686e8b commit 2c57b59
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 28 deletions.
3 changes: 2 additions & 1 deletion tests/cunit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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_darray_vard test_async_1d

if RUN_TESTS
# Tests will run from a bash script.
Expand Down Expand Up @@ -64,6 +64,7 @@ test_decomp_frame_SOURCES = test_decomp_frame.c test_common.c pio_tests.h
test_perf2_SOURCES = test_perf2.c test_common.c pio_tests.h
test_async_perf_SOURCES = test_async_perf.c test_common.c pio_tests.h
test_darray_vard_SOURCES = test_darray_vard.c test_common.c pio_tests.h
test_async_1d_SOURCES = test_async_1d.c test_common.c pio_tests.h

# Distribute the test script.
EXTRA_DIST = run_tests.sh CMakeLists.txt test_darray_frame.c
Expand Down
112 changes: 112 additions & 0 deletions tests/cunit/test_async_1d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Tests for PIOc_Intercomm. This tests basic asynch I/O capability.
*
* This very simple test runs on 4 ranks.
*
* @author Ed Hartnett
*/
#include <config.h>
#include <pio.h>
#include <pio_tests.h>

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

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

/* 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

/* Run async tests. */
int main(int argc, char **argv)
{
int my_rank; /* Zero-based rank of processor. */
int ntasks; /* Number of processors involved in current execution. */
int iosysid[COMPONENT_COUNT]; /* The ID for the parallel I/O system. */
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. */
MPI_Comm test_comm;

/* Num procs for computation. */
int num_procs2[NUM_COMBOS][COMPONENT_COUNT] = {{1}, {2}, {3}};

/* Number of processors that will do IO. */
int num_io_procs[NUM_COMBOS] = {3, 2, 1};

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

/* Test code runs on TARGET_NTASKS tasks. The left over tasks do
* nothing. */
if (my_rank < TARGET_NTASKS)
{
/* Figure out iotypes. */
if ((ret = get_iotypes(&num_flavors, flavor)))
ERR(ret);

for (int combo = 0; combo < NUM_COMBOS; combo++)
{
/* Is the current process a computation task? */
int comp_task = my_rank < num_io_procs[combo] ? 0 : 1;

/* Initialize the IO system. */
if ((ret = PIOc_init_async(test_comm, num_io_procs[combo], NULL, COMPONENT_COUNT,
num_procs2[combo], NULL, NULL, NULL, PIO_REARR_BOX, iosysid)))
ERR(ERR_INIT);

/* All the netCDF calls are only executed on the computation
* tasks. The IO tasks have not returned from PIOc_Init_Intercomm,
* and when the do, they should go straight to finalize. */
if (comp_task)
{
for (int flv = 0; flv < num_flavors; flv++)
{
char filename[PIO_MAX_NAME + 1]; /* Test filename. */
int my_comp_idx = 0; /* Index in iosysid array. */

for (int sample = 0; sample < NUM_SAMPLES; sample++)
{
char iotype_name[PIO_MAX_NAME + 1];

/* Create a filename. */
if ((ret = get_iotype_name(flavor[flv], iotype_name)))
return ret;
sprintf(filename, "%s_%s_%d_%d.nc", TEST_NAME, iotype_name, sample, my_comp_idx);

/* Create sample file. */
if ((ret = create_nc_sample(sample, iosysid[my_comp_idx], flavor[flv], filename, my_rank, NULL)))
ERR(ret);

/* Check the file for correctness. */
if ((ret = check_nc_sample(sample, iosysid[my_comp_idx], flavor[flv], filename, my_rank, NULL)))
ERR(ret);
}
} /* next netcdf flavor */

/* Finalize the IO system. Only call this from the computation tasks. */
for (int c = 0; c < COMPONENT_COUNT; c++)
if ((ret = PIOc_free_iosystem(iosysid[c])))
ERR(ret);
} /* endif comp_task */

/* Wait for everyone to catch up. */
MPI_Barrier(test_comm);
} /* next combo */
}/* my_rank < TARGET_NTASKS */

/* Finalize test. */
if ((ret = pio_test_finalize(&test_comm)))
return ERR_AWFUL;

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

return 0;
}
60 changes: 33 additions & 27 deletions tests/ncint/tst_pio_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define DIM_NAME_UNLIMITED "dim_unlimited"
#define DIM_NAME_X "dim_x"
#define DIM_NAME_Y "dim_y"
#define DIM_LEN_X 4
#define DIM_LEN_X 3
#define DIM_LEN_Y 4
#define NDIM2 2
#define NDIM3 3
Expand Down Expand Up @@ -57,7 +57,9 @@ main(int argc, char **argv)
if (!my_rank)
nc_set_log_level(3);

/* Initialize the intracomm. */
/* Initialize the intracomm. The IO task will not return from
* this call until the PIOc_finalize() is called by the
* compute tasks. */
if (nc_def_async(MPI_COMM_WORLD, num_io_procs, NULL, COMPONENT_COUNT,
num_procs2, NULL, NULL, NULL, PIO_REARR_BOX, &iosysid))
PERR;
Expand All @@ -73,11 +75,15 @@ main(int argc, char **argv)
if (nc_enddef(ncid)) PERR;

/* Calculate a decomposition for distributed arrays. */
elements_per_pe = DIM_LEN_X * DIM_LEN_Y / ntasks;
elements_per_pe = DIM_LEN_X * DIM_LEN_Y / (ntasks - num_io_procs);
printf("my_rank %d elements_per_pe %ld\n", my_rank, elements_per_pe);
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;
{
compdof[i] = (my_rank - num_io_procs) * elements_per_pe + i;
printf("my_rank %d compdof[%d]=%ld\n", my_rank, i, compdof[i]);
}

/* Create the PIO decomposition for this test. */
if (nc_def_decomp(iosysid, PIO_INT, NDIM2, &dimlen[1], elements_per_pe,
Expand All @@ -96,6 +102,8 @@ main(int argc, char **argv)
/* Reopen the file using normal PIO calls. */
{
int ndims, nvars, ngatts, unlimdimid;
int ioid2;
PIO_Offset *compdof2; /* The decomposition mapping. */
nc_type xtype_in;
char var_name_in[NC_MAX_NAME + 1];
char dim_name_in[NC_MAX_NAME + 1];
Expand All @@ -106,37 +114,35 @@ main(int argc, char **argv)

/* Open the file. */
if (PIOc_openfile(iosysid, &ncid, &iotype, FILE_NAME, 0)) PERR;
if (PIOc_closefile(ncid)) PERR;

/* Check the file. */
/* if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) PERR; */
/* if (ndims != 3 || nvars != 1 || ngatts != 0 || */
/* unlimdimid != 0) PERR; */
/* if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims, */
/* dimids_in, &natts_in)) PERR; */
/* if (strcmp(var_name_in, VAR_NAME) || xtype_in != NC_INT || ndims != NDIM3 */
/* || dimids_in[0] != 0 || dimids_in[1] != 1 || dimids_in[2] != 2 || */
/* natts_in != 0) PERR; */
/* if (nc_inq_dim(ncid, 0, dim_name_in, &dim_len_in)) PERR; */
/* if (strcmp(dim_name_in, DIM_NAME_UNLIMITED) || dim_len_in != 1) PERR; */
/* if (nc_inq_dim(ncid, 1, dim_name_in, &dim_len_in)) PERR; */
/* if (strcmp(dim_name_in, DIM_NAME_X) || dim_len_in != DIM_LEN_X) PERR; */
/* if (nc_inq_dim(ncid, 2, dim_name_in, &dim_len_in)) PERR; */
/* if (strcmp(dim_name_in, DIM_NAME_Y) || dim_len_in != DIM_LEN_Y) 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; */
/* Set up decomposition. */
if (!(compdof2 = malloc(elements_per_pe * sizeof(size_t))))
PERR;
for (i = 0; i < elements_per_pe; i++)
{
compdof2[i] = (my_rank - num_io_procs) * elements_per_pe + i;
printf("my_rank %d compdof2[%d]=%lld\n", my_rank, i, compdof2[i]);
}

if (PIOc_init_decomp(iosysid, PIO_INT, NDIM2, &dimlen[1], elements_per_pe, compdof2,
&ioid2, 1, NULL, NULL)) PERR;
free(compdof2);

/* Read distributed arrays. */
if (!(data_in = malloc(elements_per_pe * sizeof(int)))) PERR;
if (PIOc_setframe(ncid, 0, 0)) PERR;
/* if (PIOc_read_darray(ncid, 0, ioid, elements_per_pe, 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; */
if (PIOc_closefile(ncid)) PERR;

/* /\* Free resources. *\/ */
/* free(data_in); */
/* Free resources. */
free(data_in);
if (PIOc_freedecomp(iosysid, ioid2)) PERR;
}

/* Reopen the file using netCDF integration. */
Expand Down

0 comments on commit 2c57b59

Please sign in to comment.