python - 大型数组的 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 中的错误吗?
平台:
- OSX 莫哈韦
- OpenMPI 4.0.0(通过 Homebrew)
- mpi4py 3.0.1
- 蟒蛇 3.7
解决方案
我刚刚注意到通过 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 为我修复了它。
推荐阅读
- pentaho - Pentaho 报告缓慢
- wordpress - 在 Wordpress 中自动重定向/重写 1000 个旧帖子 url
- facebook - Facebook 新权限 - 无法将视频发布到用户时间轴
- python - 如何在 txt 文件中搜索一个单词,然后打印包含该单词的行(Python)?
- python - 如何使用 Mysql Python 连接器检索二进制数据?
- excel - 使用 VLOOKUP 时需要创建重复行
- android - Xamarin Forms - Android - 更改每个内容页面的向上/后退箭头颜色
- asp.net - 在 Azure 上运行的 ASP.NET 应用程序未删除 Redis 客户端
- c# - 从 MVC 操作返回 html 内容时引用链接的 css 和 js 资源
- kubernetes - 如何确保 kubernetes cronjob 在失败时不会重新启动