python-2.7openmpimpi4py

mpi4py - MPI_ERR_TRUNCATE: message truncated


I converted the ring_c.c code from OPENMPI examples in python to experiment with mpi4py. Here is my code.

from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

next_proc = (rank + 1) % size
prev_proc = (rank + size - 1) % size

tag = 2
message = 10

if 0 == rank:
    comm.send(message, dest=next_proc, tag=tag)

while(1):
    message = comm.recv(message, source=prev_proc, tag=tag)  
    comm.Recv_init

    if 0 == rank:
        message = message - 1
        print "Process %d decremented value: %d\n" %(rank, message)

    comm.send(message, dest=next_proc, tag=tag)

    if 0 == message:
        print "Process %d exiting\n" %(rank)
        break;

if 0 == rank:
    message = comm.recv(message, source=prev_proc, tag=tag)

When I run it via mpiexec for any number of processes, for example

mpiexec -n 10 python ring_py.py

It gives the following output and error:

Process 0 decremented value: 9

Process 0 decremented value: 8

Process 0 decremented value: 7

Process 0 decremented value: 6

Process 0 decremented value: 5

Process 0 decremented value: 4

Traceback (most recent call last):
  File "ring_py.py", line 20, in <module>
    message = comm.recv(message, source=prev_proc, tag=tag)  
  File "MPI/Comm.pyx", line 1192, in mpi4py.MPI.Comm.recv (src/mpi4py.MPI.c:106889)
  File "MPI/msgpickle.pxi", line 287, in mpi4py.MPI.PyMPI_recv (src/mpi4py.MPI.c:42965)
mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated

A couple of observations

A few details about my system.

Can someone please help me understand what is going on with my code.

Thank you, Jayant


Solution

  • I tried your code and I got an error at:

    message = comm.recv(message, source=prev_proc, tag=tag) 
    

    Stating:

    TypeError: expected a writeable buffer object

    Following the tutorial of mpi4py or MPI4Py causes error on send/recv , I successfully tried:

    message = comm.recv( source=prev_proc, tag=tag)