MPI。大块数组的调用被挂起

问题描述 投票:1回答:1

我使用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中的错误吗?

平台:

  • OSX Mojave
  • OpenMPI 4.0.0(通过Homebrew)
  • mpi4py 3.0.1
  • Python 3.7
python openmpi mpi4py
1个回答
1
投票

我只是注意到通过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正常工作。

更新

目前,此问题应已解决。 The bug was reported并将OpenMPI更新为4.0.1对其进行了修复。

© www.soinside.com 2019 - 2024. All rights reserved.