【问题标题】:h5py open file blocks with MPIh5py 使用 MPI 打开文件块
【发布时间】:2017-10-05 00:43:22
【问题描述】:

我正在尝试通过执行使用 h5py 和 mpi 打开一个 hdf5 文件

print("Opening...")
f = h5py.File(file_path, "r", driver='mpio', comm=MPI.COMM_WORLD)
print("Done")

由于某种原因,该行在我的项目中执行时会阻塞。 我试图创建一个可重现的小示例,但没有成功,因为这条线在这些示例中应该可以正常工作。

所以我的代码库中有一些我无法追踪的东西,导致上述行阻塞。

问题:什么会导致h5py.File 被屏蔽?

注意:CPU 达到 100%,所以 mpi 似乎在等待什么...


注意2:从我的代码库中添加了一些根本没有帮助的代码:

在 if 有效之前打开文件,在 if 中只是阻塞...

from mpi4py import MPI
import h5py
from DataProviderH5PYPool import init_pool, new_worker
import Settings


rank = MPI.COMM_WORLD.Get_rank()
task = [
    "main",
    "h5py_worker"
]

task = task[rank] if rank < len(task)-1 else task[-1]
print("Starting new process:  {} with rank {}".format(task,rank))

def init():
    # works
    print(h5py.File(Settings.h5py.training[0], "r", driver='mpio', comm=MPI.COMM_WORLD)["0"][0])
    if task == "main":
        # blocks
        # print(h5py.File(Settings.h5py.training[0], "r", driver='mpio', comm=MPI.COMM_WORLD)["0"][0])

        init_pool(n=MPI.COMM_WORLD.Get_size()-1)
        return True
    elif task == "h5py_worker":
        # works too but results in 
        # RuntimeError: Can't decrement id ref count (Can't close file, there are objects still open
        # print(h5py.File(Settings.h5py.training[0], "r", driver='mpio', comm=MPI.COMM_WORLD)["0"][0])

        new_worker()
        return False
    else:
        raise RuntimeError("Unsupported task '{}'".format(task))

代码通过

执行
mpiexec -n 2 python Test.py
or
mpiexec.mpich -n 2 python Test.py

两者都安装并尝试了,但得到了相同的结果...

【问题讨论】:

    标签: python python-2.7 python-3.x mpi h5py


    【解决方案1】:

    我的猜测是公开调用是集体的,因此需要由通信器中的所有进程调用,并且由于您指定 COMM_WORLD,这意味着每个人。如果你只调用一个子集,那么它会阻塞。

    我不是 100% 清楚您想要做什么 - 您只想在主要任务中打开文件吗?这意味着只有主要任务才能真正写入文件,因此工作人员需要使用 MPI 发送他们想要写入的任何数据。

    如果是这样,您可以只在 main 上调用 open,但使用通信器 COMM_SELF,这意味着它不会等待所有其他排名也调用 open。

    问候,

    大卫

    【讨论】:

    • 感谢您的建议。我通过在主进程中打开文件然后使用 COMM_SELF 让它工作
    猜你喜欢
    • 2014-12-24
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2011-12-02
    • 1970-01-01
    • 2017-12-25
    相关资源
    最近更新 更多