【问题标题】:Parallel HDF5 C++ program that creates a group for each MPI process rank为每个 MPI 进程等级创建一个组的并行 HDF5 C++ 程序
【发布时间】: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 docssimple 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 运行的组一起运行,我需要进行哪些更改?

【问题讨论】:

    标签: c++ hdf5


    【解决方案1】:

    在 HDF5 中,所有“元数据”必须由所有等级以集体模式创建。也就是说:每个处理器都会打开文件,创建所有组,创建所有数据集。然后,您可以单独写入指定的数据集。请注意,在可扩展数据集的情况下,调整大小也必须集体完成。

    在实践中:您必须在程序中循环以创建组、属性和数据集。

    原因是每个等级都必须知道HDF5文件的整个布局。

    在某些情况下,另一种方法是为每个等级写入一个 hdf5 文件。对于完全独立的组,这是有道理的。

    页面Collective Calling Requirements in Parallel HDF5 Applications 列出了必须在“集体”模式下调用的例程。所有 API(C、C++、Fortran 等)的要求都是相同的。

    【讨论】:

    • 上例中不是集体模式调用了“file.createGroup”吗?我在示例中没有类似 if (rank == 3) { file.createGroup(groupPath) }; 的内容。还是我必须设置一些标志以确保并行操作以集体模式运行?
    • 在您的代码中,每个等级都写入自己的组。在集体模式下,必须在每个处理器上调用/执行操作。这就是我提到循环的原因:所有处理器都必须创建RANK_GROUP0RANK_GROUP1 等。
    • 谢谢,明白了!关于代码的另一个问题:如何使用 C++ 接口获得与 H5Pset_fapl_mpio 相同的结果,您可能知道 C++ API 中的哪个类负责此操作?
    • 我对 c++ API 不熟悉。根据 1.the documentation for file creation property lists H5::FileCreatPropList - 相当于 set_fapl 和 2.mailing list message by a member of the HDF group C++ API 不支持并行 HDF5 接口。但是,您可以使用 C++ 中的普通 C API,无论如何您已经开始这样做了。
    • 您可能对h5xx 感兴趣,这是一个仅依赖于 HDF5 的 C API 的 C++ 包装器。
    猜你喜欢
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 2015-01-28
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多