首页 > 解决方案 > 大型数组的 MPI.Gather 调用挂起

问题描述

我使用 mpi4py 来并行化我的 Python 应用程序。MPI.Gather我注意到,每当我过多地增加进程数量或涉及的数组大小时,我都会遇到死锁。

例子:

from mpi4py import MPI

import numpy as np

COMM = MPI.COMM_WORLD
RANK = COMM.Get_rank()
SIZE = COMM.Get_size()


def test():
    arr = RANK * np.ones((100, 400, 15), dtype='int64')

    recvbuf = None
    if RANK == 0:
        recvbuf = np.empty((SIZE,) + arr.shape, dtype=arr.dtype)

    print("%s gathering" % RANK)
    COMM.Gather([arr, arr.size, MPI.LONG], recvbuf, root=0)
    print("%s done" % RANK)

    if RANK == 0:
        for i in range(SIZE):
            assert np.all(recvbuf[i] == i)


if __name__ == '__main__':
    test()

执行这个给出:

$ mpirun -n 4 python bug.py 
1 gathering
2 gathering
3 gathering
0 gathering
1 done
2 done

而进程 0 和 3 无限期挂起。但是,如果我将数组维度更改为(10, 400, 15),或使用 运行脚本-n 2,一切都会按预期工作。

我错过了什么吗?这是 OpenMPI 或 mpi4py 中的错误吗?

平台:

标签: pythonopenmpimpi4py

解决方案


我刚刚注意到通过 Homebrew 使用 MPICH 一切正常。因此,如果有人在 OSX 上遇到类似情况,解决方法是

$ brew unlink open-mpi
$ brew install mpich
$ pip uninstall mpi4py
$ pip install mpi4py --no-cache-dir

然后,我不得不编辑/etc/hosts并添加该行

127.0.0.1     <mycomputername>

为了让 MPICH 正常工作。

更新

至此,这个问题应该已经解决了。报告了该错误并将 OpenMPI 更新到 4.0.1 为我修复了它。


推荐阅读