hdf5/testpar/t_ph5basic.c

184 lines
7.0 KiB
C
Raw Permalink Normal View History

2022-05-14 03:31:31 +08:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
2024-04-24 15:00:37 +08:00
* distribution tree, or in https://www.hdfgroup.org/licenses. *
2022-05-14 03:31:31 +08:00
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Test parallel HDF5 basic components
*/
#include "testphdf5.h"
/*-------------------------------------------------------------------------
* Function: test_fapl_mpio_dup
*
* Purpose: Test if fapl_mpio property list keeps a duplicate of the
2024-04-24 15:00:37 +08:00
* communicator and INFO objects given when set; and returns
* duplicates of its components when H5Pget_fapl_mpio is called.
2022-05-14 03:31:31 +08:00
*
2024-04-24 15:00:37 +08:00
* Return: Success: None
* Failure: Abort
2022-05-14 03:31:31 +08:00
*
* Programmer: Albert Cheng
* January 9, 2003
*
*-------------------------------------------------------------------------
*/
void
test_fapl_mpio_dup(void)
{
2024-04-24 15:00:37 +08:00
int mpi_size, mpi_rank;
2022-05-14 03:31:31 +08:00
MPI_Comm comm, comm_tmp;
2024-04-24 15:00:37 +08:00
int mpi_size_old, mpi_rank_old;
int mpi_size_tmp, mpi_rank_tmp;
MPI_Info info = MPI_INFO_NULL;
2022-05-14 03:31:31 +08:00
MPI_Info info_tmp = MPI_INFO_NULL;
2024-04-24 15:00:37 +08:00
int mrc; /* MPI return value */
hid_t acc_pl; /* File access properties */
herr_t ret; /* HDF5 return value */
int nkeys, nkeys_tmp;
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("Verify fapl_mpio duplicates communicator and INFO objects\n");
2022-05-14 03:31:31 +08:00
/* set up MPI parameters */
2024-04-24 15:00:37 +08:00
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("rank/size of MPI_COMM_WORLD are %d/%d\n", mpi_rank, mpi_size);
2022-05-14 03:31:31 +08:00
/* Create a new communicator that has the same processes as MPI_COMM_WORLD.
2024-04-24 15:00:37 +08:00
* Use MPI_Comm_split because it is simpler than MPI_Comm_create
2022-05-14 03:31:31 +08:00
*/
mrc = MPI_Comm_split(MPI_COMM_WORLD, 0, 0, &comm);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Comm_split");
MPI_Comm_size(comm, &mpi_size_old);
MPI_Comm_rank(comm, &mpi_rank_old);
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("rank/size of comm are %d/%d\n", mpi_rank_old, mpi_size_old);
2022-05-14 03:31:31 +08:00
/* create a new INFO object with some trivial information. */
mrc = MPI_Info_create(&info);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Info_create");
2022-05-14 03:31:31 +08:00
mrc = MPI_Info_set(info, "hdf_info_name", "XYZ");
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Info_set");
if (MPI_INFO_NULL != info) {
mrc = MPI_Info_get_nkeys(info, &nkeys);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_get_nkeys");
2022-05-14 03:31:31 +08:00
}
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
h5_dump_info_object(info);
2022-05-14 03:31:31 +08:00
2024-04-24 15:00:37 +08:00
acc_pl = H5Pcreate(H5P_FILE_ACCESS);
2022-05-14 03:31:31 +08:00
VRFY((acc_pl >= 0), "H5P_FILE_ACCESS");
ret = H5Pset_fapl_mpio(acc_pl, comm, info);
VRFY((ret >= 0), "");
/* Case 1:
* Free the created communicator and INFO object.
* Check if the access property list is still valid and can return
* valid communicator and INFO object.
*/
mrc = MPI_Comm_free(&comm);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Comm_free");
if (MPI_INFO_NULL != info) {
mrc = MPI_Info_free(&info);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_free");
2022-05-14 03:31:31 +08:00
}
ret = H5Pget_fapl_mpio(acc_pl, &comm_tmp, &info_tmp);
VRFY((ret >= 0), "H5Pget_fapl_mpio");
2024-04-24 15:00:37 +08:00
MPI_Comm_size(comm_tmp, &mpi_size_tmp);
MPI_Comm_rank(comm_tmp, &mpi_rank_tmp);
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("After H5Pget_fapl_mpio: rank/size of comm are %d/%d\n", mpi_rank_tmp, mpi_size_tmp);
VRFY((mpi_size_tmp == mpi_size), "MPI_Comm_size");
VRFY((mpi_rank_tmp == mpi_rank), "MPI_Comm_rank");
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_get_nkeys(info_tmp, &nkeys_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_get_nkeys");
VRFY((nkeys_tmp == nkeys), "new and old nkeys equal");
2022-05-14 03:31:31 +08:00
}
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
h5_dump_info_object(info_tmp);
2022-05-14 03:31:31 +08:00
/* Case 2:
* Free the retrieved communicator and INFO object.
* Check if the access property list is still valid and can return
* valid communicator and INFO object.
* Also verify the NULL argument option.
*/
mrc = MPI_Comm_free(&comm_tmp);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Comm_free");
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_free(&info_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_free");
2022-05-14 03:31:31 +08:00
}
/* check NULL argument options. */
ret = H5Pget_fapl_mpio(acc_pl, &comm_tmp, NULL);
VRFY((ret >= 0), "H5Pget_fapl_mpio Comm only");
mrc = MPI_Comm_free(&comm_tmp);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Comm_free");
2022-05-14 03:31:31 +08:00
ret = H5Pget_fapl_mpio(acc_pl, NULL, &info_tmp);
VRFY((ret >= 0), "H5Pget_fapl_mpio Info only");
2024-04-24 15:00:37 +08:00
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_free(&info_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_free");
2022-05-14 03:31:31 +08:00
}
ret = H5Pget_fapl_mpio(acc_pl, NULL, NULL);
VRFY((ret >= 0), "H5Pget_fapl_mpio neither");
/* now get both and check validity too. */
2024-04-24 15:00:37 +08:00
/* Do not free the returned objects which are used in the next case. */
2022-05-14 03:31:31 +08:00
ret = H5Pget_fapl_mpio(acc_pl, &comm_tmp, &info_tmp);
VRFY((ret >= 0), "H5Pget_fapl_mpio");
2024-04-24 15:00:37 +08:00
MPI_Comm_size(comm_tmp, &mpi_size_tmp);
MPI_Comm_rank(comm_tmp, &mpi_rank_tmp);
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("After second H5Pget_fapl_mpio: rank/size of comm are %d/%d\n", mpi_rank_tmp, mpi_size_tmp);
VRFY((mpi_size_tmp == mpi_size), "MPI_Comm_size");
VRFY((mpi_rank_tmp == mpi_rank), "MPI_Comm_rank");
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_get_nkeys(info_tmp, &nkeys_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_get_nkeys");
VRFY((nkeys_tmp == nkeys), "new and old nkeys equal");
2022-05-14 03:31:31 +08:00
}
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
h5_dump_info_object(info_tmp);
2022-05-14 03:31:31 +08:00
/* Case 3:
* Close the property list and verify the retrieved communicator and INFO
* object are still valid.
*/
H5Pclose(acc_pl);
2024-04-24 15:00:37 +08:00
MPI_Comm_size(comm_tmp, &mpi_size_tmp);
MPI_Comm_rank(comm_tmp, &mpi_rank_tmp);
2022-05-14 03:31:31 +08:00
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
HDprintf("After Property list closed: rank/size of comm are %d/%d\n", mpi_rank_tmp, mpi_size_tmp);
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_get_nkeys(info_tmp, &nkeys_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_get_nkeys");
2022-05-14 03:31:31 +08:00
}
if (VERBOSE_MED)
2024-04-24 15:00:37 +08:00
h5_dump_info_object(info_tmp);
2022-05-14 03:31:31 +08:00
/* clean up */
mrc = MPI_Comm_free(&comm_tmp);
2024-04-24 15:00:37 +08:00
VRFY((mrc == MPI_SUCCESS), "MPI_Comm_free");
if (MPI_INFO_NULL != info_tmp) {
mrc = MPI_Info_free(&info_tmp);
VRFY((mrc == MPI_SUCCESS), "MPI_Info_free");
2022-05-14 03:31:31 +08:00
}
2024-04-24 15:00:37 +08:00
} /* end test_fapl_mpio_dup() */