Kan
Kan

Reputation: 169

Limitation of data exchange using MPI c++

I am writing a MPI C++ code for data exchange, below is the sample code:

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
    int size, rank;
    int dest, tag, i;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    printf("SIZE = %d RANK = %d\n",size,rank);

    if ( rank == 0 )
    {
        double data[500];
        for (i = 0; i < 500; i++) 
        {
            data[i] = i;
        }
        dest = 1;
        tag = 1;
        MPI_Send(data,500,MPI_DOUBLE,dest,tag, MPI_COMM_WORLD );
    }

    MPI_Finalize();   
    return(0);
}

Looks like 500 is the maximum that I can send. If the number of data increases to 600, the code seems to stop at "MPI_SEND" without further progress. I am suspecting is there any limitation for the data be transferred using MPI_SEND. Can you someone enlighten me?

Thanks in advance,

Kan

Upvotes: 1

Views: 109

Answers (1)

Gilles Gouaillardet
Gilles Gouaillardet

Reputation: 8395

Long story short, your program is incorrect and you are lucky it did not hang with a small count.

Per the MPI standard, you cannot assume MPI_Send() will return unless a matching MPI_Recv() has been posted.

From a pragmatic point of view, "short" messages are generally sent in eager mode, and MPI_Send() likely returns immediately. On the other hand, "long" messages usually involve a rendez-vous protocol, and hence hang until a matching receive have been posted.

"small" and "long" depend on several factor, including the interconnect you are using. And once again, you cannot assume MPI_Send() will always return immediately if you send messages that are small enough.

Upvotes: 4

Related Questions