Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non blocking way of receiving a pickled item in mpi4py

Tags:

python

mpi

Is there any non-blocking way for process of receiving a pickled item from another process. Irecv only works for numpy arrays. I want a function which works for a dictionary.

like image 837
Pranav Raj Avatar asked Mar 18 '23 22:03

Pranav Raj


1 Answers

It looks like irecv() isn't really implemented, according to the tutorial, so you'll have to take another approach: rather than posting a receive and using Test or Wait for the request to be ready, you can use Probe to test to see if there's a message waiting to be received and use a (blocking) receive to get it when there is:

#!/usr/bin/env python
from mpi4py import MPI
import time

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

if rank == 0:
   data = {'a': 7, 'b': 3.14}
   time.sleep(3)
   comm.send(data, dest=1, tag=11)
elif rank == 1:
   while not comm.Iprobe(source=0, tag=11):
        print 'rank 1 Doing some work...'
        time.sleep(1)
   rdata = comm.recv(source=0, tag=11)
   print 'rank 1: got ', rdata

Running gives:

$ mpirun -np 2 ./foo.py 
rank 1 Doing some work...
rank 1 Doing some work...
rank 1 Doing some work...
rank 1 Doing some work...
rank 1: got  {'a': 7, 'b': 3.1400000000000001}
like image 200
Jonathan Dursi Avatar answered Mar 31 '23 21:03

Jonathan Dursi