简体   繁体   English

mpiexec 和 python mpi4py 为所有进程提供等级 0 和大小 1

[英]mpiexec and python mpi4py gives rank 0 and size 1 for all processes

I'm on macOS 10.14.我在 macOS 10.14 上。 Attempting the following in test.py :test.py中尝试以下操作:

from mpi4py import MPI

comm = MPI.COMM_WORLD
i = comm.Get_rank()
p = comm.Get_size()

print('proc {}/{}'.format(i, p))

results in结果是

proc 0/1
proc 0/1
proc 0/1
proc 0/1

The typical cause of this problem, as far as I can tell, is having two different MPI implementations installed.据我所知,这个问题的典型原因是安装了两个不同的 MPI 实现。 This can happen if the library used in building mpi4py is different than the one providing the mpiexec that I use to run the program.如果用于构建mpi4py的库与提供用于运行程序的mpiexec的库不同,就会发生这种情况。

I thought I did this carefully, though.不过,我认为我这样做是小心翼翼的。 I built mpi4py from source as per the instructions provided in the docs , via我按照文档中提供的说明从源代码构建mpi4py ,通过

$ python setup.py build --mpi=openmpi

where openmpi is defined in mpi.cfg as其中openmpimpi.cfg中定义为

[openmpi]
mpi_dir              = /usr/local/Cellar/open-mpi/4.0.2
mpicc                = %(mpi_dir)s/bin/mpicc
mpicxx               = %(mpi_dir)s/bin/mpicxx
include_dirs         = %(mpi_dir)s/include
#libraries            = mpi
library_dirs         = %(mpi_dir)s/lib
runtime_library_dirs = %(library_dirs)s

I verify that the install went as intended in python:我验证安装在 python 中按预期进行:

$ python
>>> import mpi4py
>>> mpi4py.get_config()
{'mpicc': '/usr/local/Cellar/open-mpi/4.0.2/bin/mpicc', 'mpicxx': '/usr/local/Cellar/open-mpi/4.0.2/bin/mpicxx', 'library_dirs': '/usr/local/Cellar/open-mpi/4.0.2/lib', 'runtime_library_dirs': '/usr/local/Cellar/open-mpi/4.0.2/lib'}

which matches the mpiexec in use:与正在使用的mpiexec匹配:

$ which mpiexec
/usr/local/Cellar/open-mpi/4.0.2/bin/mpiexec

and the situation is identical for mpirun . mpirun的情况是相同的。 What am I missing?我错过了什么? Is there some "piece" of the package which is for some reason silently expecting mpich , even though this all seems to add up?是否有一些 package 的“部分”出于某种原因默默地期待mpich ,即使这一切似乎都加起来了?

I was never able to resolve this particular issue, but instead tried uninstalling my original installation of mpi4py , and then instead installing mpi4py via conda in a fresh miniconda environment, which comes with it's own binaries eg mpiexec , mpicc ... This is way cleaner than trying to muck around with the dependencies yourself.我永远无法解决这个特定问题,而是尝试卸载我原来安装的mpi4py ,然后在miniconda环境中通过conda安装mpi4py ,它附带它自己的二进制文件,例如mpiexecmpicc ......这更干净而不是试图自己解决依赖关系。 It now just works, though I need to point to the new mpiexec manually (since my original openmpi installation via homebrew needs to be kept as it remains a dependency for other things).它现在可以正常工作,尽管我需要手动指向新的mpiexec (因为我通过homebrew安装的原始openmpi需要保留,因为它仍然是其他东西的依赖项)。 I must do我必须这样做

/Users/me/miniconda3/bin/mpiexec -n 4 python ./test.py

I didn't try this in the first place because my conda installation was having issues unrelated to the present issue.我一开始没有尝试这个,因为我的 conda 安装出现了与当前问题无关的问题。 If that's also your roadblock, just reinstall miniconda or whatever Anaconda distro you prefer.如果这也是您的障碍,只需重新安装miniconda或您喜欢的任何 Anaconda 发行版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM