Question

I have this MPI program which hangs without completing. Any idea where it is going wrong? May be I am missing something but I cannot think of a possible issue with the code. Changing the order of send and receive doesn't work either. (But I am guessing any order would do due to nonblocking nature of the calls.)

#include <mpi.h>

int main(int argc, char** argv) {

    int p = 2;
    int myrank;

    double in_buf[1];
    double out_buf[1];

    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Status stat;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(comm, &myrank);
    MPI_Comm_size(comm, &p);

    MPI_Request requests[2];
    MPI_Status statuses[2];

    if (myrank == 0) {
        MPI_Isend(out_buf,1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &requests[0]);
        MPI_Irecv(in_buf, 1, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &requests[1]);
    } else {
        MPI_Irecv(in_buf, 1, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &requests[0]);
        MPI_Isend(out_buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &requests[1]);
    }

    MPI_Waitall(2, requests, statuses);

    printf("Done...\n");

}
Was it helpful?

Solution

Right of the bat it looks like your tags are mismatched. You post isend from rank 0 with tag=0 but post irecv from rank 1 with tag=1.

I assume you launch two processes as well, right? the int p = 2 doesn't do anything useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top