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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With