【发布时间】:2018-09-21 07:27:03
【问题描述】:
我正在尝试找到一个最小示例,用于使用 HDF5 的 C++ 接口中的 MPIO 驱动程序并行打开和关闭 HDF5 文件,该驱动程序为每个 MPI 进程等级创建一个 HDF5 组并保存文件。 The parallel programming example given in the repo 不是我所说的最小的,但我尝试使用该示例的一部分,together with the C++ API docs 和 simple C++ parallel HDF5 example set。
这是我到目前为止想出的:
编辑:我在 MPI 等级上添加了一个循环,以尝试在集体模式下创建 HDF5 组,结果是一样的。
#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;
}
我不知道from the C++ API how to set the MPIO driver。
另外,并不是每个等级都写分组:
?> h5c++ test-mpi-group-creation.cpp -o test-mpi-group-creation
?> mpirun -np 4 ./test-mpi-group-creation
/RANK_GROUP0
/RANK_GROUP1
/RANK_GROUP2
/RANK_GROUP3
?> h5ls -lr test.h5
/ Group
/RANK_GROUP1 Group
为了让这个最小的并行示例与使用 C++ API 到 hdf5 运行的组一起运行,我需要进行哪些更改?
【问题讨论】: