Skip to content

Commit

Permalink
Create test for H5Pget_dxpl_mpio (#3825)
Browse files Browse the repository at this point in the history
* Create test and add to testphdf5
  • Loading branch information
glennsong09 authored Nov 6, 2023
1 parent 6a3c859 commit 3c07147
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
136 changes: 136 additions & 0 deletions testpar/t_ph5basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,139 @@ test_fapl_mpio_dup(void)
VRFY((mrc == MPI_SUCCESS), "MPI_Info_free");
}
} /* end test_fapl_mpio_dup() */

/*-------------------------------------------------------------------------
* Function: test_get_dxpl_mpio
*
* Purpose: Test that H5Pget_dxpl_mpio will properly return the data
* transfer mode of collective and independent I/O access
* after setting it and writing some data.
*
* Return: Success: None
* Failure: Abort
*-------------------------------------------------------------------------
*/
void
test_get_dxpl_mpio(void)
{
hid_t fid = H5I_INVALID_HID;
hid_t sid = H5I_INVALID_HID;
hid_t did = H5I_INVALID_HID;
hid_t fapl = H5I_INVALID_HID;
hid_t dxpl = H5I_INVALID_HID;
H5FD_mpio_xfer_t xfer_mode;
hsize_t dims[2] = {100, 100};
hsize_t i, j;
int *data = NULL;
int mpi_rank, mpi_size;
const char *filename;
herr_t ret;

if (VERBOSE_MED)
printf("Verify get_dxpl_mpio correctly gets the data transfer mode"
"set in the data transfer property list after a write\n");

/* Set up MPI for VRFY macro */
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);

/* Initialize data array */
data = malloc(100 * 100 * sizeof(*data));
VRFY((data != NULL), "Data buffer initialized properly");

/* Create parallel fapl */
fapl = create_faccess_plist(MPI_COMM_WORLD, MPI_INFO_NULL, FACC_MPIO);
VRFY((fapl >= 0), "Fapl creation succeeded");

/* Create a file */
filename = (const char *)GetTestParameters();
fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
VRFY((fid >= 0), "H5Fcreate succeeded");

/* Create a dataset */
sid = H5Screate_simple(2, dims, NULL);
VRFY((sid >= 0), "H5Screate succeeded");
did = H5Dcreate2(fid, "dset", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((did >= 0), "H5Dcreate2 succeeded");

/* Use collective I/O access */
dxpl = H5Pcreate(H5P_DATASET_XFER);
VRFY((dxpl >= 0), "H5Pcreate succeeded");
ret = H5Pset_dxpl_mpio(dxpl, H5FD_MPIO_COLLECTIVE);
VRFY((ret >= 0), "H5Pset_dxpl_mpio set to collective succeeded");

/* Write some data */
for (i = 0; i < dims[0]; i++)
for (j = 0; j < dims[1]; j++)
data[(i * 100) + j] = (int)(i + (i * j) + j);

ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, dxpl, data);
VRFY((ret >= 0), "H5Dwrite succeeded");

/* Check to make sure the property is still correct */
ret = H5Pget_dxpl_mpio(dxpl, &xfer_mode);
VRFY((ret >= 0), "H5Pget_dxpl_mpio succeeded");
VRFY((xfer_mode == H5FD_MPIO_COLLECTIVE), "Xfer_mode retrieved"
" successfully");

/* Read the data */
ret = H5Dread(did, H5T_NATIVE_INT, sid, sid, dxpl, data);
VRFY((ret >= 0), "H5Dread succeeded");

/* Check to make sure the property is still correct */
ret = H5Pget_dxpl_mpio(dxpl, &xfer_mode);
VRFY((ret >= 0), "H5Pget_dxpl_mpio succeeded");
VRFY((xfer_mode == H5FD_MPIO_COLLECTIVE), "Xfer_mode retrieved"
" successfully");

/* Check it does nothing on receiving NULL */
ret = H5Pget_dxpl_mpio(dxpl, NULL);
VRFY((ret >= 0), "H5Pget_dxpl_mpio succeeded on NULL input");

/* Use independent I/O access */
ret = H5Pset_dxpl_mpio(dxpl, H5FD_MPIO_INDEPENDENT);
VRFY((ret >= 0), "H5Pset_dxpl_mpio set to independent succeeded");

/* Write some data */
for (i = 0; i < dims[0]; i++)
for (j = 0; j < dims[1]; j++)
data[(i * 100) + j] = (int)(i + (j * j) + i);

ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, dxpl, data);
VRFY((ret >= 0), "H5Dwrite succeeded");

/* Check to make sure the property is still correct */
ret = H5Pget_dxpl_mpio(dxpl, &xfer_mode);
VRFY((ret >= 0), "H5Pget_dxpl_mpio succeeded");
VRFY((xfer_mode == H5FD_MPIO_INDEPENDENT), "Xfer_mode retrieved"
" successfully");

/* Read the data */
ret = H5Dread(did, H5T_NATIVE_INT, sid, sid, dxpl, data);
VRFY((ret >= 0), "H5Dread succeeded");

/* Check to make sure the property is still correct */
ret = H5Pget_dxpl_mpio(dxpl, &xfer_mode);
VRFY((ret >= 0), "H5Pget_dxpl_mpio succeeded");
VRFY((xfer_mode == H5FD_MPIO_INDEPENDENT), "Xfer_mode retrieved"
" successfully");

/* Close everything */
free(data);

ret = H5Pclose(fapl);
VRFY((ret >= 0), "H5Pclose succeeded");

ret = H5Pclose(dxpl);
VRFY((ret >= 0), "H5Pclose succeeded");

ret = H5Dclose(did);
VRFY((ret >= 0), "H5Dclose succeeded");

ret = H5Sclose(sid);
VRFY((ret >= 0), "H5Sclose succeeded");

ret = H5Fclose(fid);
VRFY((ret >= 0), "H5Fclose succeeded");

} /* end test_get_dxpl_mpio() */
1 change: 1 addition & 0 deletions testpar/testphdf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ main(int argc, char **argv)

/* Tests are generally arranged from least to most complexity... */
AddTest("mpiodup", test_fapl_mpio_dup, NULL, "fapl_mpio duplicate", NULL);
AddTest("getdxplmpio", test_get_dxpl_mpio, NULL, "dxpl_mpio get", PARATESTFILE);

AddTest("split", test_split_comm_access, NULL, "dataset using split communicators", PARATESTFILE);
AddTest("h5oflusherror", test_oflush, NULL, "H5Oflush failure", PARATESTFILE);
Expand Down
1 change: 1 addition & 0 deletions testpar/testphdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void collective_group_write_independent_group_read(void);
void collective_group_write(void);
void independent_group_read(void);
void test_fapl_mpio_dup(void);
void test_get_dxpl_mpio(void);
void test_split_comm_access(void);
void test_page_buffer_access(void);
void dataset_atomicity(void);
Expand Down

0 comments on commit 3c07147

Please sign in to comment.