问题
I am learning MPI in python by myself. I just started from the basic documentation of MPI4py
. I started with this code:
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
if rank == 0:
data = {'a': 7, 'b': 3.14}
comm.send(data, dest=1, tag=11)
elif rank == 1:
data = comm.recv(source=0, tag=11)
When I ran this program, I got following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MPI/Comm.pyx", line 1175, in mpi4py.MPI.Comm.send (src/mpi4py.MPI.c:106424)
File "MPI/msgpickle.pxi", line 211, in mpi4py.MPI.PyMPI_send (src/mpi4py.MPI.c:42120)
mpi4py.MPI.Exception: Invalid rank, error stack:
MPI_Send(174): MPI_Send(buf=0x10e137554, count=25, MPI_BYTE, dest=1, tag=11, MPI_COMM_WORLD) failed
MPI_Send(100): Invalid rank has value 1 but must be nonnegative and less than 1
I didn't find any working solution for this problem. I am using Mac OS X El Capitan
.
Thanks in Advance!
回答1:
The program complains that 1
is not a valid rank for MPI_Send()
: it means that your program is running on a single process.
Are you running it by using python main.py
? Try to use mpirun -np 2 python main.py
, where 2
is the number of processes. The latter is the usual way to run mpi programs.
来源:https://stackoverflow.com/questions/35669614/mpi-send100-invalid-rank-has-value-1-but-must-be-nonnegative-and-less-than-1