I'm on macOS 10.14. Attempting the following in 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. 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.
I thought I did this carefully, though. I built mpi4py from source as per the instructions provided in the docs, via
$ python setup.py build --mpi=openmpi
where openmpi is defined in mpi.cfg as
[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
>>> 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:
$ which mpiexec
/usr/local/Cellar/open-mpi/4.0.2/bin/mpiexec
and the situation is identical for 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?