Skip to content

Commit

Permalink
now run examples from autotools build as well
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed May 7, 2018
1 parent efd9b10 commit 3e80380
Show file tree
Hide file tree
Showing 13 changed files with 748 additions and 286 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Ed Hartnett

SUBDIRS = src tests
SUBDIRS = src tests examples

# Look in the m4 directory for autotools stuff.
ACLOCAL_AMFLAGS= -I m4
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ AC_OUTPUT(Makefile
src/Makefile
src/clib/Makefile
tests/Makefile
tests/cunit/Makefile)
tests/cunit/Makefile
examples/Makefile
examples/c/Makefile)
6 changes: 6 additions & 0 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is part of PIO. It creates the examples Makefile.

# Ed Hartnett

SUBDIRS = c

20 changes: 20 additions & 0 deletions examples/c/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## This is the automake file for building the C examples for the PIO
## library.

# Ed Hartnett 5/7/18

# Link to our assembled library.
AM_LDFLAGS = ${top_builddir}/src/clib/libpio.la
AM_CPPFLAGS = -I$(top_srcdir)/src/clib

# Build the tests for make check.
check_PROGRAMS = example1 examplePio darray_no_async

# Tests will run from a bash script.
TESTS = run_tests.sh

# Distribute the test script.
EXTRA_DIST = run_tests.sh

# Clean up files produced during testing.
CLEANFILES = *.nc *.log
233 changes: 119 additions & 114 deletions examples/c/darray_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* This example can be run in parallel for 4 processors.
*/

#include "config.h"
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -187,114 +188,118 @@ int resultlen;

/* Write, then read, a simple example with darrays.
The sample file created by this program is a small netCDF file. It
has the following contents (as shown by ncdump):
<pre>
netcdf darray_no_async_iotype_1 {
dimensions:
unlimted = UNLIMITED ; // (2 currently)
x = 4 ;
y = 4 ;
variables:
int foo(unlimted, x, y) ;
data:
foo =
42, 42, 42, 42,
43, 43, 43, 43,
44, 44, 44, 44,
45, 45, 45, 45,
142, 142, 142, 142,
143, 143, 143, 143,
144, 144, 144, 144,
145, 145, 145, 145 ;
}
</pre>
The sample file created by this program is a small netCDF file. It
has the following contents (as shown by ncdump):
<pre>
netcdf darray_no_async_iotype_1 {
dimensions:
unlimted = UNLIMITED ; // (2 currently)
x = 4 ;
y = 4 ;
variables:
int foo(unlimted, x, y) ;
data:
foo =
42, 42, 42, 42,
43, 43, 43, 43,
44, 44, 44, 44,
45, 45, 45, 45,
142, 142, 142, 142,
143, 143, 143, 143,
144, 144, 144, 144,
145, 145, 145, 145 ;
}
</pre>
*/
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; /* The ID for the parallel I/O system. */
/* int ncid; /\* The ncid of the netCDF file. *\/ */
/* int dimid[NDIM3]; /\* The dimension ID. *\/ */
/* int varid; /\* The ID of the netCDF varable. *\/ */
/* char filename[NC_MAX_NAME + 1]; /\* Test filename. *\/ */
/* int num_flavors = 0; /\* Number of iotypes available in this build. *\/ */
/* int format[NUM_NETCDF_FLAVORS]; /\* Different output flavors. *\/ */
int ret; /* Return value. */
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; /* The ID for the parallel I/O system. */
/* int ncid; /\* The ncid of the netCDF file. *\/ */
/* int dimid[NDIM3]; /\* The dimension ID. *\/ */
/* int varid; /\* The ID of the netCDF varable. *\/ */
/* char filename[NC_MAX_NAME + 1]; /\* Test filename. *\/ */
/* int num_flavors = 0; /\* Number of iotypes available in this build. *\/ */
/* int format[NUM_NETCDF_FLAVORS]; /\* Different output flavors. *\/ */
int ret; /* Return value. */

#ifdef TIMING
/* Initialize the GPTL timing library. */
if ((ret = GPTLinitialize ()))
return ret;
/* Initialize the GPTL timing library. */
if ((ret = GPTLinitialize ()))
return ret;
#endif

/* Initialize MPI. */
if ((ret = MPI_Init(&argc, &argv)))
MPIERR(ret);
if ((ret = MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN)))
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);

/* Check that a valid number of processors was specified. */
printf("%d: ParallelIO Library darray_async example running on %d processors.\n",
my_rank, ntasks);
if (ntasks != TARGET_NTASKS)
{
fprintf(stderr, "Number of processors must be %d!\n", TARGET_NTASKS);
return ERR_BAD;
}

/* Turn on logging. */
if ((ret = PIOc_set_log_level(LOG_LEVEL)))
return ret;

/* Num procs for computation. */
int num_procs2[COMPONENT_COUNT] = {4};
/* Initialize MPI. */
if ((ret = MPI_Init(&argc, &argv)))
MPIERR(ret);
if ((ret = MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN)))
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);

/* Check that a valid number of processors was specified. */
printf("%d: ParallelIO Library darray_async example running on %d processors.\n",
my_rank, ntasks);
if (ntasks != TARGET_NTASKS)
{
fprintf(stderr, "Number of processors must be %d!\n", TARGET_NTASKS);
return ERR_BAD;
}

/* Turn on logging. */
if ((ret = PIOc_set_log_level(LOG_LEVEL)))
return ret;

/* Change error handling so we can test inval parameters. */
if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL)))
return ret;

/* Num procs for computation. */
int num_procs2[COMPONENT_COUNT] = {4};

/* Is the current process a computation task? */
int comp_task = my_rank < NUM_IO_TASKS ? 0 : 1;
/* Is the current process a computation task? */
int comp_task = my_rank < NUM_IO_TASKS ? 0 : 1;

/* Initialize the IO system. */
if ((ret = PIOc_init_async(MPI_COMM_WORLD, NUM_IO_TASKS, NULL, COMPONENT_COUNT,
num_procs2, NULL, NULL, NULL, PIO_REARR_BOX, &iosysid)))
ERR(ret);
/* Initialize the IO system. */
if ((ret = PIOc_init_async(MPI_COMM_WORLD, NUM_IO_TASKS, NULL, COMPONENT_COUNT,
num_procs2, NULL, NULL, NULL, PIO_REARR_BOX, &iosysid)))
ERR(ret);


/* The rest of the code executes on computation tasks only. As
* PIO functions are called on the computation tasks, the
* async system will call them on the IO task. When the
* computation tasks call PIO_finalize(), the IO task will get
* a message to shut itself down. */
if (comp_task)
{
/* PIO_Offset elements_per_pe; /\* Array elements per processing unit. *\/ */
/* int ioid; /\* The I/O description ID. *\/ */
/* The rest of the code executes on computation tasks only. As
* PIO functions are called on the computation tasks, the
* async system will call them on the IO task. When the
* computation tasks call PIO_finalize(), the IO task will get
* a message to shut itself down. */
if (comp_task)
{
/* PIO_Offset elements_per_pe; /\* Array elements per processing unit. *\/ */
/* int ioid; /\* The I/O description ID. *\/ */

/* /\* How many elements on each computation task? *\/ */
/* elements_per_pe = DIM_LEN_X * DIM_LEN_Y / NUM_COMP_TASKS; */

/* /\* Allocate and initialize array of decomposition mapping. *\/ */
/* PIO_Offset compdof[elements_per_pe]; */
/* for (int i = 0; i < elements_per_pe; i++) */
/* compdof[i] = my_rank * elements_per_pe + i; */

/* /\* Create the PIO decomposition for this example. Since */
/* this is a variable with an unlimited dimension, we want */
/* to create a 2-D composition which represents one */
/* record. *\/ */
/* printf("rank: %d Creating decomposition...\n", my_rank); */
/* if ((ret = PIOc_init_decomp(iosysid, PIO_INT, NDIM3 - 1, &dim_len[1], elements_per_pe, */
/* compdof, &ioid, 0, NULL, NULL))) */
/* ERR(ret); */
/* /\* How many elements on each computation task? *\/ */
/* elements_per_pe = DIM_LEN_X * DIM_LEN_Y / NUM_COMP_TASKS; */

/* /\* Allocate and initialize array of decomposition mapping. *\/ */
/* PIO_Offset compdof[elements_per_pe]; */
/* for (int i = 0; i < elements_per_pe; i++) */
/* compdof[i] = my_rank * elements_per_pe + i; */

/* /\* Create the PIO decomposition for this example. Since */
/* this is a variable with an unlimited dimension, we want */
/* to create a 2-D composition which represents one */
/* record. *\/ */
/* printf("rank: %d Creating decomposition...\n", my_rank); */
/* if ((ret = PIOc_init_decomp(iosysid, PIO_INT, NDIM3 - 1, &dim_len[1], elements_per_pe, */
/* compdof, &ioid, 0, NULL, NULL))) */
/* ERR(ret); */

/* /\* The number of favors may change with the build parameters. *\/ */
/* #ifdef _PNETCDF */
Expand Down Expand Up @@ -362,26 +367,26 @@ netcdf darray_no_async_iotype_1 {
/* /\* ERR(ret); *\/ */
/* } */

/* Free the PIO decomposition. */
/* printf("rank: %d Freeing PIO decomposition...\n", my_rank); */
/* if ((ret = PIOc_freedecomp(iosysid, ioid))) */
/* ERR(ret); */
/* Free the PIO decomposition. */
/* printf("rank: %d Freeing PIO decomposition...\n", my_rank); */
/* if ((ret = PIOc_freedecomp(iosysid, ioid))) */
/* ERR(ret); */

/* Finalize the IO system. Only call this from the computation tasks. */
printf("%d %s Freeing PIO resources\n", my_rank, TEST_NAME);
if ((ret = PIOc_finalize(iosysid)))
ERR(ret);
} /* endif comp_task */
/* Finalize the IO system. Only call this from the computation tasks. */
printf("%d %s Freeing PIO resources\n", my_rank, TEST_NAME);
if ((ret = PIOc_finalize(iosysid)))
ERR(ret);
} /* endif comp_task */

/* Finalize the MPI library. */
MPI_Finalize();
/* Finalize the MPI library. */
MPI_Finalize();

#ifdef TIMING
/* Finalize the GPTL timing library. */
if ((ret = GPTLfinalize ()))
return ret;
/* Finalize the GPTL timing library. */
if ((ret = GPTLfinalize ()))
return ret;
#endif

printf("rank: %d SUCCESS!\n", my_rank);
return 0;
}
printf("rank: %d SUCCESS!\n", my_rank);
return 0;
}
Loading

0 comments on commit 3e80380

Please sign in to comment.