Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 26, 2019
2 parents 71d46ce + 0725be7 commit 729d7fa
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 57 deletions.
7 changes: 5 additions & 2 deletions src/clib/pio_getput_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,10 @@ int PIOc_get_var_tc(int ncid, int varid, nc_type xtype, void *buf)
if (!(startp = malloc(ndims * sizeof(PIO_Offset))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
if (!(countp = malloc(ndims * sizeof(PIO_Offset))))
{
free(startp);
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
}

/* Find the dimension lengths. */
for (int d = 0; d < ndims; d++)
Expand All @@ -886,9 +889,9 @@ int PIOc_get_var_tc(int ncid, int varid, nc_type xtype, void *buf)
}

ierr = PIOc_get_vars_tc(ncid, varid, startp, countp, NULL, xtype, buf);
if(startp != NULL)
if (startp)
free(startp);
if(countp != NULL)
if (countp)
free(countp);
return ierr;

Expand Down
2 changes: 1 addition & 1 deletion src/clib/pio_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,7 @@ int write_darray_multi_handler(iosystem_desc_t *ios)

/* Get decomposition information. */
if (!(iodesc = pio_get_iodesc_from_id(ioid)))
return pio_err(ios, file, PIO_EBADID, __FILE__, __LINE__);
return pio_err(ios, NULL, PIO_EBADID, __FILE__, __LINE__);

if ((mpierr = MPI_Bcast(&arraylen, 1, MPI_OFFSET, 0, ios->intercomm)))
return check_mpi2(ios, NULL, mpierr, __FILE__, __LINE__);
Expand Down
3 changes: 3 additions & 0 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ int PIOc_InitDecomp(int iosysid, int pio_type, int ndims, const int *gdimlen, in
if (!(tmpsort = malloc(sizeof(struct sort_map) * maplen)))
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);
if (!(iodesc->remap = malloc(sizeof(int) * maplen)))
{
free(tmpsort);
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);
}
for (int m=0; m < maplen; m++)
{
tmpsort[m].remap = m;
Expand Down
4 changes: 2 additions & 2 deletions src/clib/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void determineiotasks(const MPI_Comm comm, int *numiotasks,int *base, int *strid

Kernel_GetPersonality(&pers, sizeof(pers));

int numIONodes,numPsets,numNodesInPset,rankInPset;
int numiotasks_per_node,remainder,numIONodes_per_pset;
int numIONodes, numPsets, numNodesInPset, rankInPset;
int numiotasks_per_node, remainder = 0, numIONodes_per_pset;
int lstride;

/* Number of computational nodes in processor set */
Expand Down
16 changes: 13 additions & 3 deletions tests/cunit/pio_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,34 @@
#endif /* _NETCDF4 */

/** Handle MPI errors. This should only be used with MPI library
* function calls. */
* function calls. Finalize and return. */
#define MPIERR(e) do { \
MPI_Error_string(e, err_buffer, &resultlen); \
fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
MPI_Finalize(); \
return ERR_AWFUL; \
} while (0)

/** Handle MPI errors. This should only be used with MPI library
* function calls. Finalize and goto exit. */
#define MPIBAIL(e) do { \
MPI_Error_string(e, err_buffer, &resultlen); \
fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
MPI_Finalize(); \
ret = NC_EIO; \
goto exit; \
} while (0)

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

/** Handle non-MPI errors by finalizing the MPI library and goto
* exit. */
* exit. Finalize and goto exit. */
#define BAIL(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
MPI_Finalize(); \
Expand Down
76 changes: 40 additions & 36 deletions tests/cunit/test_darray_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,15 @@ int run_darray_async_test(int iosysid, int my_rank, MPI_Comm test_comm, MPI_Comm
PIO_Offset elements_per_pe = LAT_LEN;
PIO_Offset compdof[LAT_LEN] = {my_rank * 2 - 2, my_rank * 2 - 1};
char decomp_filename[PIO_MAX_NAME + 1];
void *my_data_multi;
int ret;

sprintf(decomp_filename, "decomp_rdat_%s_.nc", TEST_NAME);

/* Create the PIO decomposition for this test. */
if ((ret = PIOc_init_decomp(iosysid, piotype, NDIM2, &dim_len[1], elements_per_pe,
compdof, &ioid, PIO_REARR_BOX, NULL, NULL)))
ERR(ret);
BAIL(ret);

/* Write the decomp file (on appropriate tasks). */
if ((ret = PIOc_write_nc_decomp(iosysid, decomp_filename, 0, ioid, NULL, NULL, 0)))
Expand All @@ -255,7 +256,7 @@ int run_darray_async_test(int iosysid, int my_rank, MPI_Comm test_comm, MPI_Comm

/* Free the decomposition. */
if ((ret = PIOc_freedecomp(iosysid, ioid2)))
ERR(ret);
BAIL(ret);

/* Test each available iotype. */
for (int fmt = 0; fmt < num_flavors; fmt++)
Expand All @@ -266,7 +267,6 @@ int run_darray_async_test(int iosysid, int my_rank, MPI_Comm test_comm, MPI_Comm
int varid[NVAR];
char data_filename[PIO_MAX_NAME + 1];
void *my_data;
void *my_data_multi;
void *my_data_norec;
signed char my_data_byte[LAT_LEN] = {my_rank * 10, my_rank * 10 + 1};
char my_data_char[LAT_LEN] = {my_rank * 10, my_rank * 10 + 1};
Expand Down Expand Up @@ -353,127 +353,131 @@ int run_darray_async_test(int iosysid, int my_rank, MPI_Comm test_comm, MPI_Comm
break;
#endif /* _NETCDF4 */
default:
ERR(ERR_WRONG);
BAIL(ERR_WRONG);
}

/* Create sample output file. */
sprintf(data_filename, "data_%s_iotype_%d_piotype_%d.nc", TEST_NAME, flavor[fmt],
piotype);
if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], data_filename,
NC_CLOBBER)))
ERR(ret);
BAIL(ret);

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

/* Create the data for the darray_multi call by making two
* copies of the data. */
if (!(my_data_multi = malloc(2 * type_size * elements_per_pe)))
ERR(PIO_ENOMEM);
BAIL(PIO_ENOMEM);
memcpy(my_data_multi, my_data, type_size * elements_per_pe);
memcpy((char *)my_data_multi + type_size * elements_per_pe, my_data, type_size * elements_per_pe);

/* Define dimensions. */
for (int d = 0; d < NDIM3; d++)
if ((ret = PIOc_def_dim(ncid, dim_name[d], dim_len[d], &dimid[d])))
ERR(ret);
BAIL(ret);

/* Define variables. */
if ((ret = PIOc_def_var(ncid, REC_VAR_NAME, piotype, NDIM3, dimid, &varid[0])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_def_var(ncid, REC_VAR_NAME2, piotype, NDIM3, dimid, &varid[1])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_def_var(ncid, NOREC_VAR_NAME, piotype, NDIM2, &dimid[1],
&varid[2])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_def_var(ncid, NOREC_VAR_NAME2, piotype, NDIM2, &dimid[1],
&varid[3])))
ERR(ret);
BAIL(ret);

/* End define mode. */
if ((ret = PIOc_enddef(ncid)))
ERR(ret);
BAIL(ret);

/* Set the record number for the record vars. */
if ((ret = PIOc_setframe(ncid, varid[0], 0)))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_setframe(ncid, varid[1], 0)))
ERR(ret);
BAIL(ret);

/* Write some data to the record vars. */
if ((ret = PIOc_write_darray(ncid, varid[0], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_write_darray(ncid, varid[1], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);

/* Write some data to the non-record vars. */
if ((ret = PIOc_write_darray(ncid, varid[2], ioid, elements_per_pe, my_data_norec, NULL)))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_write_darray(ncid, varid[3], ioid, elements_per_pe, my_data_norec, NULL)))
ERR(ret);
BAIL(ret);

/* Sync the file. */
if ((ret = PIOc_sync(ncid)))
ERR(ret);
BAIL(ret);

/* Increment the record number for the record vars. */
if ((ret = PIOc_advanceframe(ncid, varid[0])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_advanceframe(ncid, varid[1])))
ERR(ret);
BAIL(ret);

/* Write another record. */
if ((ret = PIOc_write_darray(ncid, varid[0], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_write_darray(ncid, varid[1], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);

/* Sync the file. */
if ((ret = PIOc_sync(ncid)))
ERR(ret);
BAIL(ret);

/* Increment the record number for the record var. */
if ((ret = PIOc_advanceframe(ncid, varid[0])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_advanceframe(ncid, varid[1])))
ERR(ret);
BAIL(ret);

/* Write a third record. */
if ((ret = PIOc_write_darray(ncid, varid[0], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_write_darray(ncid, varid[1], ioid, elements_per_pe, my_data, NULL)))
ERR(ret);
BAIL(ret);

/* Increment the record number for the record var. */
if ((ret = PIOc_advanceframe(ncid, varid[0])))
ERR(ret);
BAIL(ret);
if ((ret = PIOc_advanceframe(ncid, varid[1])))
ERR(ret);
BAIL(ret);

/* Write a forth record, using darray_multi(). */
int frame[2] = {3, 3};
if ((ret = PIOc_write_darray_multi(ncid, varid, ioid, 2, elements_per_pe, my_data_multi, frame, NULL, 0)))
ERR(ret);
BAIL(ret);

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

/* Free resources. */
free(my_data_multi);
my_data_multi = NULL;

/* Check the file for correctness. */
if ((ret = check_darray_file(iosysid, data_filename, PIO_IOTYPE_NETCDF, my_rank, piotype)))
ERR(ret);
BAIL(ret);

} /* next iotype */

/* Free the decomposition. */
if ((ret = PIOc_freedecomp(iosysid, ioid)))
ERR(ret);
BAIL(ret);

return 0;
exit:
if (my_data_multi)
free(my_data_multi);
return ret;
}

/* Run Tests for pio_spmd.c functions. */
Expand Down
Loading

0 comments on commit 729d7fa

Please sign in to comment.