Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] MPI_Irecv, MPI_Wait and MPI_Iprobe
From: Lukas Razik (linux_at_[hidden])
Date: 2011-11-20 10:17:09


Mudassar Majeed <mudassarm30_at_[hidden]> wrote
>What if two processes Pi and Pj send message to each other at the same time ? Will both block in your suggested code ?

The suggested code can't block if there are no bugs...
If it will block when you add send operations will depend on which/when send operations you use.

If you send with Isend then the processes won't block but be careful:
Don't use the send buffer again as long as you don't know if the belonging message has been sent out by Isend.
You can check if Isend() could really send out your message by
- the blocking operation MPI_Wait() or
- by the non-blocking MPI_Test():

http://mpi.deino.net/mpi_functions/MPI_Test.html

Only when one of these calls returns that the request which belongs to your Isend(buffer,...,request) has been finished you can use the buffer again!

>if not then I can go for that.  BTW, I have tried that before.

Regards and good luck!
Lukas

>________________________________
> From: Lukas Razik <linux_at_[hidden]>
>To: Mudassar Majeed <mudassarm30_at_[hidden]>; "users_at_[hidden]" <users_at_[hidden]>
>Sent: Sunday, November 20, 2011 3:22 PM
>Subject: Re: [OMPI users] MPI_Irecv, MPI_Wait and MPI_Iprobe
>
>Hello Mudassar!
>
>
>
>>Dear people,
>>                       I have a scenario as shown below, please tell me if it is possible or not
>>
>>
>>------------------------------------------------------------------
>>while(!IsDone)
>>{
>>
>>// some code here
>>
>>MPI_Irecv( .......... );
>>
>>// some code here
>>
>>MPI_Iprobe( ........., &is_there_a_message);
>>
>>if(is_there_a_message)
>>    MPI_Wait( ....... );
>>
>>// move forward ... some other code here....
>>
>>}
>>--------------------------------------------------------------------
>>
>>My scenario is an
>asynchronous communication where some other process may or may not send a
>message to this
>> process, will MPI_Iprobe find out
whether it is necessary to call MPI_Wait()  or not ?
>
>
>Sorry, but this conveys no sense to me...
>1.You don't need to call MPI_Irecv() before MPI_Iprobe() to get the information if there's a new message... :)
>
>2. If MPI_Iprobe() returns that there's a message then you don't need to call MPI_Wait() anymore.
>Just receive it by MPI_Recv()... :)
>
>
>
>> because if we do not do this the process may start waiting for a message that may not come and will block.
>
>
>Wouldn't this fit?
>---
>while(!isDone) {
>    // some code here
>
>
>    MPI_Iprobe(...,there_is_a_message,...); // never blocks
>
>    if( there_is_a_message ) {
>        // doesn't block because there's a message:
>
>        MPI_Recv(message,...);
>        // here you can use your message:
>  
     process(message);
>
>    }
>
>    else
>        process(other_work); // we have no new message so we do another work
>
>}
>---
>
>
>Here the process will receive the message if there's one.
>
>It won't block if there's no message.
>
>If I haven't understood your problem in the right way - please write more systematically
>- how receiver should react if there's a message (e.g. receive it or what else?)
>
>- how receiver should react if there's no message (e.g. block or continue with another work?)
>
>
>Best regards,
>Lukas
>
>
>
>
>
>