Skip to content

Commit

Permalink
Merge pull request ESMCI#1386 from NCAR/ejh_perf
Browse files Browse the repository at this point in the history
Some changes to performance program
  • Loading branch information
edhartnett authored Apr 2, 2019
2 parents 2882bb9 + 8ba35c2 commit 496d343
Showing 1 changed file with 24 additions and 81 deletions.
105 changes: 24 additions & 81 deletions tests/cunit/test_perf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include <sys/time.h>

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

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

/* The name of this test. */
#define TEST_NAME "test_perf2"
Expand All @@ -35,7 +35,7 @@
/* The length of our sample data along each dimension. */
#define X_DIM_LEN 512
#define Y_DIM_LEN 512
#define Z_DIM_LEN 64
#define Z_DIM_LEN 512

/* This is the length of the map for each task. */
#define EXPECTED_MAPLEN (X_DIM_LEN * Y_DIM_LEN * Z_DIM_LEN / TARGET_NTASKS)
Expand Down Expand Up @@ -122,36 +122,15 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
char filename[PIO_MAX_NAME + 1]; /* Name for the output files. */
int dimids[NDIM]; /* The dimension IDs. */
int ncid; /* The ncid of the netCDF file. */
int ncid2; /* The ncid of the re-opened netCDF file. */
int varid; /* The ID of the netCDF varable. */
int ret; /* Return code. */
PIO_Offset arraylen = EXPECTED_MAPLEN;
int int_fillvalue = NC_FILL_INT;
void *fillvalue = NULL;
int *test_data;
int *test_data2;
int *test_data_in;
int ret; /* Return code. */

if (!(test_data = malloc(sizeof(int) * arraylen)))
ERR(PIO_ENOMEM);
if (!(test_data2 = malloc(sizeof(int) * arraylen)))
{
free(test_data);
ERR(PIO_ENOMEM);
}
if (!(test_data_in = malloc(sizeof(int) * arraylen)))
{
free(test_data);
free(test_data2);
ERR(PIO_ENOMEM);
}

/* Initialize some data. */
for (int f = 0; f < arraylen; f++)
{
test_data[f] = my_rank * 10 + f;
test_data2[f] = 2 * (my_rank * 10 + f);
}

/* Are we providing a fill value? */
if (provide_fill)
Expand All @@ -166,11 +145,8 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
long long delta;

/* Create the filename. */
/* sprintf(filename, "data_%s_iotype_%d.nc", TEST_NAME, flavor[fmt]); */
sprintf(filename, "data__iotype_.nc");

/* Start the clock. */
gettimeofday(&starttime, NULL);
sprintf(filename, "data_%s_iotype_%d_rearr_%d.nc", TEST_NAME, flavor[fmt],
rearranger);

/* Create the netCDF output file. */
if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], filename, PIO_CLOBBER)))
Expand All @@ -193,74 +169,41 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
if ((ret = PIOc_enddef(ncid)))
ERR(ret);

/* Set the value of the record dimension. */
if ((ret = PIOc_setframe(ncid, varid, 0)))
ERR(ret);
/* Start the clock. */
gettimeofday(&starttime, NULL);

/* Write the data. */
if ((ret = PIOc_write_darray(ncid, varid, ioid, arraylen, test_data, fillvalue)))
ERR(ret);
for (int t = 0; t < NUM_TIMESTEPS; t++)
{
/* Initialize some data. */
for (int f = 0; f < arraylen; f++)
test_data[f] = (my_rank * 10 + f) + t * 1000;

/* Set the value of the record dimension to the second record. */
if ((ret = PIOc_setframe(ncid, varid, 1)))
ERR(ret);
/* Set the value of the record dimension. */
if ((ret = PIOc_setframe(ncid, varid, t)))
ERR(ret);

/* Write the data for the second record. */
if ((ret = PIOc_write_darray(ncid, varid, ioid, arraylen, test_data2, fillvalue)))
ERR(ret);
/* Write the data. */
if ((ret = PIOc_write_darray(ncid, varid, ioid, arraylen, test_data, fillvalue)))
ERR(ret);

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

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

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

/* 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%lld\n", rearranger, provide_fill, fmt, delta);

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

/* Set the value of the record dimension. */
if ((ret = PIOc_setframe(ncid2, varid, 0)))
ERR(ret);

/* Read the data. */
if ((ret = PIOc_read_darray(ncid2, varid, ioid, arraylen, test_data_in)))
ERR(ret);

/* Check the results. */
for (int f = 0; f < arraylen; f++)
if (test_data_in[f] != test_data[f])
return ERR_WRONG;

/* Set the value of the record dimension to the second record. */
if ((ret = PIOc_setframe(ncid2, varid, 1)))
ERR(ret);

/* Read the data. */
if ((ret = PIOc_read_darray(ncid2, varid, ioid, arraylen, test_data_in)))
ERR(ret);

/* Check the results. */
for (int f = 0; f < arraylen; f++)
if (test_data_in[f] != test_data2[f])
return ERR_WRONG;

/* Close the netCDF file. */
if ((ret = PIOc_closefile(ncid2)))
ERR(ret);
}

free(test_data);
free(test_data2);
free(test_data_in);

return PIO_NOERR;
}
Expand Down

0 comments on commit 496d343

Please sign in to comment.