Using irecv and isend

904 views
Skip to first unread message

Ao Liu

unread,
Oct 30, 2013, 4:58:44 PM10/30/13
to mpi...@googlegroups.com
Hi, How may I do the following?

I want rank 0 to wait for rank 1 to finish calculation of b, and receive b;
while this waiting, it should proceed and do something else.

I wrote the following, but it didn't work, a was only a memory address.

if commrank == 0:
a = comm.irecv()
print 'ahei'
        print a
else:
time.sleep(1)
b = 1
request = comm.isend(b,dest=0)
print 'aha'

Thanks,
Ao

Lisandro Dalcin

unread,
Oct 30, 2013, 5:10:59 PM10/30/13
to mpi4py
I recommend you to read some MPI tutorial about non-blocking communication

[dalcinl@macarena mpi4py-dev]$ cat ~/tmp/mpi_wait.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
import time

assert comm.size == 2
if comm.rank == 0:
request = comm.irecv(source=1)
while not request.Get_status():
print("waiting")
time.sleep(0.1)
msg = request.wait()
print(msg)
else:
time.sleep(1)
comm.send('Hello, World!', dest=0)

[dalcinl@macarena mpi4py-dev]$ mpiexec -n 2 python ~/tmp/mpi_wait.py
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
Hello, World!



--
Lisandro Dalcin
---------------
CIMEC (UNL/CONICET)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1016)
Tel/Fax: +54-342-4511169

Ao Liu

unread,
Oct 30, 2013, 5:14:00 PM10/30/13
to mpi4py
That is very nice of you.

I hope this can be implemented in the documentations of MPI4PY. I googled a lot but found nothing, then I had to bother the group.

Best,
Ao


--
You received this message because you are subscribed to the Google Groups "mpi4py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpi4py+un...@googlegroups.com.
To post to this group, send email to mpi...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpi4py.
To view this discussion on the web visit https://groups.google.com/d/msgid/mpi4py/CAEcYPwCtEFhMq5QB0qch1b6C73SJdy9%3DH6bz15_bGXAXOC9Y1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
I am Ao.Liu, always hungry and still waiting for what I've always been believing.

To know me more, please visit my little tiny personal website: www.frankliuao.com

Ao Liu

unread,
Oct 30, 2013, 5:18:23 PM10/30/13
to mpi4py
I got this error when doing what you said.

Traceback (most recent call last):
  File "try.py", line 30, in <module>
    a = comm.irecv(source=1)
  File "Comm.pyx", line 850, in mpi4py.MPI.Comm.irecv (src/mpi4py.MPI.c:67545)
TypeError: irecv() got an unexpected keyword argument 'source'

Ao Liu

unread,
Oct 30, 2013, 5:27:24 PM10/30/13
to mpi4py
succeeded by 
comm.irecv(dest=1)

Lisandro Dalcin

unread,
Oct 30, 2013, 5:28:45 PM10/30/13
to mpi4py
On 31 October 2013 00:27, Ao Liu <frank...@gmail.com> wrote:
> succeeded by
> comm.irecv(dest=1)
>

Yes, that's a but in the API, I've fixed it in mpi4py-dev. To be safe
for a future upgrade, use comm.irecv(None, 1)
> https://groups.google.com/d/msgid/mpi4py/CA%2Buij29z_gQq0g5wamXYvKov4dym_Gpfno%2BS-dTbMp_Of3D9rg%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--

Lisandro Dalcin

unread,
Oct 30, 2013, 5:32:08 PM10/30/13
to mpi4py
On 31 October 2013 00:14, Ao Liu <frank...@gmail.com> wrote:
> I hope this can be implemented in the documentations of MPI4PY. I googled a
> lot but found nothing, then I had to bother the group.

This is the hope of many uses. And my hope is that users contribute
back to the project with documentation and examples, e.g.
http://jeremybejarano.zzl.org/MPIwithPython/index.html

Ao Liu

unread,
Oct 30, 2013, 5:36:33 PM10/30/13
to mpi4py
How could users edit the page? If you could open it like Wiki did, and keep your approval authority, it would be nice that everyone can write their own cases, and wait for your approval.

Best,
Ao


--
You received this message because you are subscribed to the Google Groups "mpi4py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpi4py+un...@googlegroups.com.
To post to this group, send email to mpi...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpi4py.

Lisandro Dalcin

unread,
Oct 31, 2013, 5:28:55 AM10/31/13
to mpi4py
On 31 October 2013 00:36, Ao Liu <frank...@gmail.com> wrote:
> How could users edit the page? If you could open it like Wiki did, and keep
> your approval authority, it would be nice that everyone can write their own
> cases, and wait for your approval.
>

Do you mean the bitbucket Wiki
https://bitbucket.org/mpi4py/mpi4py/wiki/Home? Bitbucket handle wikis
with repositories, you can clone, edit, commit, push ask for a pull
request.

Lisandro Dalcin

unread,
Oct 31, 2013, 5:31:59 AM10/31/13
to mpi4py
On 31 October 2013 12:28, Lisandro Dalcin <dal...@gmail.com> wrote:
> On 31 October 2013 00:36, Ao Liu <frank...@gmail.com> wrote:
>> How could users edit the page? If you could open it like Wiki did, and keep
>> your approval authority, it would be nice that everyone can write their own
>> cases, and wait for your approval.
>>
>
> Do you mean the bitbucket Wiki
> https://bitbucket.org/mpi4py/mpi4py/wiki/Home? Bitbucket handle wikis
> with repositories, you can clone, edit, commit, push ask for a pull
> request.
>

Moreover, mpi4py's wiki at Bitbucket DO IS public, however I guess you
need to register in Bitbucket to actually be able to make editions.
Reply all
Reply to author
Forward
0 new messages