cpp_noname
cpp_noname

Reputation: 2071

Non-overtaking Property of MPI messages in the presence of MPI_ANY_SOURCE and MPI_ANY_TAG

Suppose I have one server that processes several kinds of requests identified by different kinds of MPI tags.

while(!stop)
{
    MPI_Iprobe(MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&ready,&status);
    if(ready)
    {
        src = status.MPI_SOURCE;
        switch(status.MPI_TAG)
        {
            case MPI_REQ_A:
                MPI_Irecv(...);
                //do something else useful while waiting
                MPI_Wait(...);
                break;

            case MPI_REQ_B:
                MPI_Irecv(...);
                //do something else useful while waiting
                MPI_Wait(...);
                break;
        }
    }

    //do something else before calling MPI_Iprobe() again
}

And there are N clients that send requests to the server. If each client sends messages as in the following code:

for( int i=0; i<k ; i++ )
{
    MPI_Send(....,MPI_REQ_A,..);
    MPI_Send(....,MPI_REQ_B,..);
}

If MPI_Probe() or MPI_Iprobe() is used with MPI_ANY_SOURCE and MPI_ANY_TAG on the receiving side as in the code above,

Question 1) Is it still guaranteed that the message of type A sent in iteration i is received before the message of the same type sent in iteration i+1 by the same client?

Question 2) Is it still guaranteed that the message of type A sent in iteration i is received before the message of type B sent in the same iteration i by the same client?

Upvotes: 2

Views: 661

Answers (1)

suszterpatt
suszterpatt

Reputation: 8273

According to this:

If a sender sends two messages in succession to the same destination, and both match the same receive, then this operation cannot receive the second message if the first one is still pending.

Now, if you unroll that loop in the client, it basically does this:

 MPI_Send(....,MPI_REQ_A,..); // i
 MPI_Send(....,MPI_REQ_B,..); // i
 MPI_Send(....,MPI_REQ_A,..); // i + 1
 MPI_Send(....,MPI_REQ_B,..); // i + 1
 MPI_Send(....,MPI_REQ_A,..); // i + 2
 MPI_Send(....,MPI_REQ_B,..); // i + 2
 ...

Since the server's receives match all of those calls, the messages are guaranteed to be received in that exact order for that client. So the answer to both your questions is Yes: on any one client, messages are delivered in the order they are posted.


On a side note, there is no requirement as to the order in which messages from different clients are received. For instance, the following scenario is perfectly legal:

  1. The server posts its first receive
  2. All clients post their first send and block
  3. The server matches its receive to client X's first message, and posts its second receive
  4. Client X's first send completes, and it posts its second send
  5. Meanwhile, the server matches its second receive to client Y's first send and posts its third receive
  6. Client Y's first send completes, and it posts its second send
  7. At this point, the server is free to match its third receive to client X's second send instead of any of the other clients' first send

And so forth, the server can alternate between accepting sends from client X and Y only, leaving the others starved.

Upvotes: 3

Related Questions