Skip to content

Commit

Permalink
added some timing to test_perf2.c
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 20, 2019
1 parent 544f6c7 commit fe1019e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
8 changes: 8 additions & 0 deletions tests/cunit/pio_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
return e; \
} while (0)

/** Handle non-MPI errors by finalizing the MPI library and goto
* exit. */
#define BAIL(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
MPI_Finalize(); \
goto exit; \
} while (0)

/** Global err buffer for MPI. When there is an MPI error, this buffer
* is used to store the error message that is associated with the MPI
* error. */
Expand Down
79 changes: 41 additions & 38 deletions tests/cunit/test_darray_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
int ncid;
int varid[NVAR] = {0, 1, 2, 3};
void *data_in;
void *data_in_norec;
void *data_in = NULL;
void *data_in_norec = NULL;
PIO_Offset type_size;
int ret;

/* Reopen the file. */
if ((ret = PIOc_openfile(iosysid, &ncid, &iotype, data_filename, NC_NOWRITE)))
ERR(ret);
BAIL(ret);

/* Get the size of the type. */
if ((ret = PIOc_inq_type(ncid, piotype, NULL, &type_size)))
ERR(ret);
BAIL(ret);

/* Allocate memory to read data. */
if (!(data_in = malloc(LAT_LEN * LON_LEN * type_size * NREC)))
ERR(PIO_ENOMEM);
BAIL(PIO_ENOMEM);
if (!(data_in_norec = malloc(LAT_LEN * LON_LEN * type_size)))
ERR(PIO_ENOMEM);
BAIL(PIO_ENOMEM);

/* We have two sets of variables, those with unlimted, and those
* without unlimited dimension. */
Expand All @@ -90,12 +90,12 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
/* Read the record data. The values we expect are: 10, 11, 20, 21, 30,
* 31, in each of three records. */
if ((ret = PIOc_get_var(ncid, rec_varid, data_in)))
ERR(ret);
BAIL(ret);

/* Read the non-record data. The values we expect are: 10, 11, 20, 21, 30,
* 31. */
if ((ret = PIOc_get_var(ncid, norec_varid, data_in_norec)))
ERR(ret);
BAIL(ret);

/* Check the results. */
for (int r = 0; r < LAT_LEN * LON_LEN * NREC; r++)
Expand All @@ -105,52 +105,52 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
case PIO_BYTE:
if (((signed char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_CHAR:
if (((char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_SHORT:
if (((short *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT:
if (((int *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_FLOAT:
if (((float *)data_in)[r] != (tmp_r/2 + 1) * 10.0 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_DOUBLE:
if (((double *)data_in)[r] != (tmp_r/2 + 1) * 10.0 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
#ifdef _NETCDF4
case PIO_UBYTE:
if (((unsigned char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_USHORT:
if (((unsigned short *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT:
if (((unsigned int *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT64:
if (((long long *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT64:
if (((unsigned long long *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
#endif /* _NETCDF4 */
default:
ERR(ERR_WRONG);
BAIL(ERR_WRONG);
}
}

Expand All @@ -161,65 +161,68 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
case PIO_BYTE:
if (((signed char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_CHAR:
if (((char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_SHORT:
if (((short *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT:
if (((int *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_FLOAT:
if (((float *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_DOUBLE:
if (((double *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
#ifdef _NETCDF4
case PIO_UBYTE:
if (((unsigned char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_USHORT:
if (((unsigned short *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT:
if (((unsigned int *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT64:
if (((long long *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT64:
if (((unsigned long long *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
#endif /* _NETCDF4 */
default:
ERR(ERR_WRONG);
BAIL(ERR_WRONG);
}
}
} /* next var set */

/* Free resources. */
free(data_in);
free(data_in_norec);

/* Close the file. */
if ((ret = PIOc_closefile(ncid)))
ERR(ret);
BAIL(ret);

return 0;
exit:
/* Free resources. */
if (data_in)
free(data_in);
if (data_in_norec)
free(data_in_norec);

return ret;
}

/* Run a simple test using darrays with async. */
Expand Down
18 changes: 18 additions & 0 deletions tests/cunit/test_perf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <pio.h>
#include <pio_internal.h>
#include <pio_tests.h>
#include <sys/time.h>

/* The number of tasks this test should run on. */
#define TARGET_NTASKS 4
Expand Down Expand Up @@ -124,6 +125,9 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
int varid; /* The ID of the netCDF varable. */
int ret; /* Return code. */
PIO_Offset arraylen = EXPECTED_MAPLEN;
struct timeval starttime, endtime;
long long startt, endt;
long long delta;
int int_fillvalue = NC_FILL_INT;
void *fillvalue = NULL;
int *test_data;
Expand Down Expand Up @@ -163,6 +167,9 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
/* sprintf(filename, "data_%s_iotype_%d.nc", TEST_NAME, flavor[fmt]); */
sprintf(filename, "data__iotype_.nc");

/* Start the clock. */
gettimeofday(&starttime, NULL);

/* Create the netCDF output file. */
if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], filename, PIO_CLOBBER)))
ERR(ret);
Expand Down Expand Up @@ -204,6 +211,17 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
if ((ret = PIOc_closefile(ncid)))
ERR(ret);

/* Stop the clock. */
gettimeofday(&endtime, NULL);

/* Compute the time delta */
startt = (1000000 * starttime.tv_sec) + starttime.tv_usec;
endt = (1000000 * endtime.tv_sec) + endtime.tv_usec;
delta = (endt - startt)/NUM_TIMESTEPS;
/* if (!my_rank) */
/* printf("%d\t%d\t%d\t%d\t%lld\n", rearranger, fmt, pio_type, test_multi, */
/* delta); */

/* Reopen the file. */
if ((ret = PIOc_openfile(iosysid, &ncid2, &flavor[fmt], filename, PIO_NOWRITE)))
ERR(ret);
Expand Down

0 comments on commit fe1019e

Please sign in to comment.