MPI_Send(100):无效等级的值为 1,但必须为非负且小于 1

MPI_Send(100): Invalid rank has value 1 but must be nonnegative and less than 1

我正在 python 自学 MPI。我刚从MPI4py的基础文档入手。我从这段代码开始:

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)

当我运行这个程序时,我得到以下错误:

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

我没有找到解决此问题的有效方法。我正在使用 Mac OS X El Capitan.

提前致谢!

该程序抱怨 1 不是 MPI_Send() 的有效排名:这意味着您的程序正在 运行 单进程上运行。

您是否运行使用 python main.py 来安装它?尝试使用 mpirun -np 2 python main.py,其中 2 是进程数。后者是 运行 mpi 程序的常用方法。