首页 > 解决方案 > mpi4py MPI.init() 无限期挂起

问题描述

我正在尝试使用 mpi4py 中的 MPI 模块在 python (3.7.0) 中初始化 MPI,但是当我尝试以下操作时它会无限期挂起:

mpirun -n 4 python -c "from mpi4py import MPI"

这有效:

python -c "from mpi4py import MPI"

但这不是:

mpirun -n 1 python -c "from mpi4py import MPI"

我也试过

import mpi4py
mpi4py.rc.initialize = False
from mpi4py import MPI
MPI.Init()

但是当使用 mpirun 执行时,它会挂在 MPI.Init() 步骤。

我的 mpirun 版本是 1.10.7,mpi4py 版本是 3.0.1,我使用的是 macOS Mojave (10.14.3)。

编辑(响应@jcgiret):

我还尝试了以下方法:

mpirun -n 4 python -c "print('Before'); from mpi4py import MPI; print('After')"

只为得到

Before
Before
Before
Before

作为输出

标签: macospython

解决方案


我设法通过安装 Miniconda 并使用包的 conda-forge 版本(3.0.1)来解决这个问题:

conda install -c conda-forge mpi4py

注意:它仍然不适用于 anaconda 版本(2.0.0)


推荐阅读