问题描述
我在虚拟机上运行python Hello World mpi4py代码时遇到问题.
I have a problem with running a python Hello World mpi4py code on a virtual machine.
hello.py代码为:
The hello.py code is:
#!/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
我尝试使用mpiexec和mpirun运行它,但是运行不正常.输出:
I've tried to run it using mpiexec and mpirun, but it is not running well.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
并且来自mpiexec:
And from 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
系统是Virtal机器上的Ubuntu 14.04.
The system is Ubuntu 14.04 on the Virtal Machine.
任何想法为何?谢谢!
推荐答案
如上所述和,这与mpirun
来自与mpi4py
链接所不同的MPI有关.
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.
就我而言,我怀疑许多其他Python用户也是如此,这是由于最初通过conda
安装了mpi4py
,从而将非系统版本的MPI拉入了我的conda
中-即which mpirun
在我的conda
环境中给出了一条路径.
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
-- i.e. which mpirun
gave a path in my conda
environment.
要解决此问题,我先运行conda remove mpi4py
然后运行pip install mpi4py
,它似乎在conda
环境中针对MPI重建mpi4py
并解决了该问题.
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.
这篇关于mpiexec和python mpi4py给出等级0和大小1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!