[英]mpiexec and python mpi4py gives rank 0 and size 1
I have a problem with running a python Hello World mpi4py code on a virtual machine.我在虚拟机上运行 python Hello World mpi4py 代码时遇到问题。
The hello.py code is: hello.py 代码是:
#!/usr/bin/python
#hello.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
print "hello world from process ", rank,"of", size
I've tried to run it using mpiexec and mpirun, but it is not running well.我尝试使用 mpiexec 和 mpirun 运行它,但它运行得不好。 The output:
输出:
$ mpirun -c 4 python hello.py
hello world from process 0 of 1
hello world from process 0 of 1
hello world from process 0 of 1
hello world from process 0 of 1
And from mpiexec:并来自 mpiexec:
$ mpiexec -n 4 python hello.py
hello world from process 0 of 1
hello world from process 0 of 1
hello world from process 0 of 1
hello world from process 0 of 1
They seem not getting rank and size of comm.他们似乎没有得到通讯的等级和大小。 What can cause this?
什么会导致这种情况? How to solve it?
如何解决?
mpiexec --version
mpiexec (OpenRTE) 1.6.5
mpirun --version
mpirun (Open MPI) 1.6.5
The system is Ubuntu 14.04 on the Virtal Machine.该系统是虚拟机上的 Ubuntu 14.04。
Any ideas why?任何想法为什么? Thanks!
谢谢!
I had the same issue when running the python module emcee
.运行 python 模块
emcee
时我遇到了同样的问题。 It would give me an error:它会给我一个错误:
"ValueError: Tried to create an MPI pool, but there was only one MPI process available.
Need at least two."
The solution I found for my particular cluster was to use a different MPI.我为我的特定集群找到的解决方案是使用不同的 MPI。 My code worked with
intel-mpi
and mpich2
but not openmpi
.我的代码适用于
intel-mpi
和mpich2
但不适用于openmpi
。 For this system, all I had to do was switch the MPI.对于这个系统,我所要做的就是切换 MPI。 In my
PBS
script I used module load mpich2
instead of module load openmpi
.在我的
PBS
脚本中,我使用了module load mpich2
而不是module load openmpi
。 In this case mpiexec
and mpirun
worked correctly.在这种情况下,
mpiexec
和mpirun
工作正常。
As suggested above and in this question for C, this has to do with having mpirun
coming from a different MPI than mpi4py
was linked against.正如上面和 C 的这个问题所建议的那样,这与
mpirun
来自与mpi4py
关联的不同 MPI 有关。
In my case, and I suspect the same is true for many other Python users, this came from having originally installed mpi4py
through conda
, which pulled a non-system version of MPI into my conda
-- ie which mpirun
gave a path in my conda
environment.就我而言,我怀疑许多其他 Python 用户也是如此,这是因为最初通过
conda
安装了mpi4py
,它将 MPI 的非系统版本拉入我的conda
—— 即which mpirun
在我的conda
中提供了一个路径环境。
To solve the problem, I ran conda remove mpi4py
and then pip install mpi4py
, which seemed to rebuild mpi4py
against the MPI in the conda
environment and solved the issue.为了解决这个问题,我运行
conda remove mpi4py
然后pip install mpi4py
,这似乎在conda
环境中针对 MPI 重建mpi4py
并解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.