1

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

Kan
  • 169
  • 2
  • 6
  • 1
    Haven't used MPI in a while, but my first guess is that some buffer is full and the `Send` waits until a matching `Receive` consumes. – Baum mit Augen May 11 '18 at 11:28
  • 3
    You must post a matching `MPI_Recieve`! No matter whether it "runs" for `n<=500` - it's always wrong. Please consult introductory material for MPI. – Zulan May 11 '18 at 11:31
  • maybe related: https://stackoverflow.com/questions/13558861/maximum-amount-of-data-that-can-be-sent-using-mpisend?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – 463035818_is_not_an_ai May 11 '18 at 11:32
  • @user463035818, no - not really related. – Zulan May 11 '18 at 11:42

1 Answers1

4

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.

Gilles Gouaillardet
  • 8,193
  • 11
  • 24
  • 30