Hello everyone,
I have asked this question on Stack Overflow and got some guidance, but I am still not sure about what I should do.
I am trying to use the C++ API to the PHDF5 to write a simple parallel program where each MPI process should create a group in a HDF5 file. This is what I have got so far, with a modification with respect to the Stack Overflow Post:
#include <iostream>
#include <mpi.h>
#include <sstream>
#include <iostream>
#include <memory>
using std::cout;
using std::endl;
#include <string>
#include "H5Cpp.h"
using namespace H5;
using namespace std;
int main(void)
{
MPI_Init(NULL, NULL);
// Get the number of processes
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
// Get the rank of the process
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
auto acc_tpl1 = H5Pcreate(H5P_FILE_ACCESS);
/* set Parallel access with communicator */
H5Pset_fapl_mpio(acc_tpl1, MPI_COMM_WORLD, MPI_INFO_NULL);
// Creating the file with H5File stores only a single group with 4 MPI processes.
auto testFile = H5File("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl1);
for (unsigned int i = 0; i < size; ++i)
{
std::stringstream ss;
ss << "/RANK_GROUP" << rank;
string rankGroup {ss.str()};
// Create the rank group with testFile.
if (! testFile.exists(rankGroup))
{
cout << rankGroup << endl;
testFile.createGroup(rankGroup);
}
}
// Release the file-access template
H5Pclose(acc_tpl1);
// Release the testFile
testFile.close();
MPI_Finalize();
return 0;
}
I have compiled the program using:
h5c++ test-mpi-group-creation.cpp -o test-mpi-group-creation
The version of h5c++
is wrapped around g++ (GCC) 8.2.0. I am using the community/hdf5-openmpi 1.10.3-1 HDF5 library with openmpi support on Arch Linux, extra/openmpi 3.1.2-1 .
The output of the program execution is:
mpirun -np 4 ./test-mpi-group-creation 2>&1 | tee log
/RANK_GROUP0
/RANK_GROUP3
/RANK_GROUP2
/RANK_GROUP1
Which is great, as it seems that H5File
is executing the branch and reporting the proper number of groups being created. However, when I examine the test.h5
file, I see that only process with rank 1 has created a group:
h5ls -lr test.h5
/ Group
/RANK_GROUP1 Group
I still have a few questions:
-
I am using a mix of C++ and C API. C API I have used to set up the MPI driver for the file, based on online documenation. How can I do the same using the C++ API?
-
Why aren’t the groups written in
test.h5
file as expected?