我正在尝试找到一个最小的示例,该示例使用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的组一起运行,我需要更改什么?
答案 0 :(得分:2)
在HDF5中,所有级别的所有“元数据”必须以集体模式创建。即:每个处理器将打开文件,创建所有组,创建所有数据集。然后,您可以分别写入指定的数据集。请注意,在可扩展数据集的情况下,必须同时调整大小。
实际上:您必须在程序中循环创建组,属性和数据集。
原因是每个级别都必须了解HDF5文件的整个布局。
在某些情况下,一种替代方法是每个等级写入一个hdf5文件。对于完全独立的群体,这是有道理的。
页面Collective Calling Requirements in Parallel HDF5 Applications列出了必须以“集合”模式调用的例程。所有API(C,C ++,Fortran等)的要求都相同。