unpickling error from fortran

Issue #68 resolved
Former user created an issue

Hi, I try to send a message from fortran to python:

===================================== ! FORTRAN program hello_world use mpi implicit none integer ierr, rank, recv_status(mpi_status_size)

call MPI_INIT (ierr) call MPI_COMM_RANK (MPI_COMM_WORLD , rank , ierr) if (rank .eq. 0) then call MPI_SEND(9, 1 , MPI_INT, 1 , 22 , MPI_COMM_WORLD , ierr) endif call MPI_FINALIZE ( ierr ) stop end ======================================

#!/usr/bin/python3 from mpi4py import MPI

comm = MPI.COMM_WORLD rank = comm.Get_rank() if rank == 1: data = comm.recv(source=0, tag=22) print(data)

====================================== Python is fine sending/receiving from itself. Fortran is also fine. So I try to combine the two based on http://stackoverflow.com/questions/41699585/is-it-possible-to-send-data-from-a-fortran-program-to-python-using-mpi:

             mpiexec -n 1 ./mpi.f90.bin : -n 1 python3 ./p.py

Traceback (most recent call last): File "./p.py", line 10, in <module> data = comm.recv(source=0, tag=22) File "MPI/Comm.pyx", line 1192, in mpi4py.MPI.Comm.recv (src/mpi4py.MPI.c:106889) File "MPI/msgpickle.pxi", line 292, in mpi4py.MPI.PyMPI_recv (src/mpi4py.MPI.c:43053) File "MPI/msgpickle.pxi", line 143, in mpi4py.MPI.Pickle.load (src/mpi4py.MPI.c:41248) _pickle.UnpicklingError: invalid load key, ' '.


Primary job terminated normally, but 1 process returned a non-zero exit code.. Per user-direction, the job has been aborted.

This is my setup: In [13]: MPI.Get_version() Out[13]: (3, 0)

In [14]: MPI.get_vendor() Out[14]: ('Open MPI', (1, 10, 2))

In [15]: MPI.Get_library_version() Out[15]: 'Open MPI v1.10.2, package: Open MPI buildd@lgw01-57 Distribution, ident: 1.10.2, repo rev: v1.10.1-145-g799148f, Jan 21, 2016\x00'

Ubuntu 16.04.1 LTS

Any idea?

Comments (4)

  1. mimooh

    The formatting went out all wrong, sorry. Once again:

    program hello_world
    use mpi
    implicit none
    integer ierr, rank, recv_status(mpi_status_size)
    
    call MPI_INIT (ierr)
    call MPI_COMM_RANK (MPI_COMM_WORLD , rank , ierr)
    
    if (rank .eq. 0) then
        write (*,*)"fortran 0 rank:", rank
        call MPI_SEND(9, 1 , MPI_INT, 1 , 22 , MPI_COMM_WORLD , ierr)
    endif
    
    call MPI_FINALIZE ( ierr )
    
    stop
    end
    
    from mpi4py import MPI
    
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    
    if rank == 1:
        data = comm.recv(source=0, tag=22)
        print(data)
    
    Traceback (most recent call last):
      File "./p.py", line 10, in <module>
        data = comm.recv(source=0, tag=22)
      File "MPI/Comm.pyx", line 1192, in mpi4py.MPI.Comm.recv (src/mpi4py.MPI.c:106889)
      File "MPI/msgpickle.pxi", line 292, in mpi4py.MPI.PyMPI_recv (src/mpi4py.MPI.c:43053)
      File "MPI/msgpickle.pxi", line 143, in mpi4py.MPI.Pickle.load (src/mpi4py.MPI.c:41248)
    _pickle.UnpicklingError: invalid load key, '    '.
    -------------------------------------------------------
    Primary job  terminated normally, but 1 process returned
    a non-zero exit code.. Per user-direction, the job has been aborted.
    
  2. Lisandro Dalcin

    The all-lowercase method comm.recv() cannot be used here, it is a Python-only thing to communicate between Python processes using pickling/unpickling.

    In your example, the Python code should create a NumPy array with one 32 bit integer, and use comm.Recv(), Your Fortran code should store "9" in a variable, just to make explicit the type.

  3. Log in to comment