Arya Anantula
Arya Anantula

Reputation: 11

MPI comm.size is always 1

My MPI comm.size is always 1. I ran the following python script (test_mpi.py) to check if MPI was working properly.

mpirun -np 4 python test_mpi.py

from mpi4py import MPI
import mpi4py

comm = MPI.COMM_WORLD

print(f"Hello from {comm.rank} of {comm.size}")

My output is:

Hello from 0 of 1 Hello from 0 of 1 Hello from 0 of 1 Hello from 0 of 1

I also tested a similar script with a C script and got the same results, so I am pretty sure the problem has to do with MPI and not mpi4py.

Does anyone have any idea how to resolve this?

Btw I am also running inside a pyenv so I'm not sure if that affects anything. I installed everything inside the environment and it doesn't work.

I am expecting the output to be:

Hello from 0 of 4 Hello from 1 of 4 Hello from 2 of 4 Hello from 3 of 4

when I run test_mpi.py

Upvotes: 1

Views: 252

Answers (1)

Gilles Gouaillardet
Gilles Gouaillardet

Reputation: 8380

That typically occurs when mpirun and libmpi.so (either linked to your C program, or used under the hood by mpi4py) do not match.

You can

python -c "from mpi4py import MPI; print(MPI.Get_library_version())"

in order to figure out which MPI library is used by mpi4py, and then

mpirun -V

in order to figure out which MPI implentation provides mpirun.

If they do not match, either re-install mpi4py or use the matching mpirun

Upvotes: 1

Related Questions