MPI recv from an unknown source

前端 未结 2 2013
后悔当初
后悔当初 2021-02-05 04:33

I am implementing in MPI a program in which the main process (with rank=0) should be able to receive requests from the other processes who ask for values of variables that are o

相关标签:
2条回答
  • 2021-02-05 04:48

    This assumes you are using C. There are similar concepts in C++ and Fortran. You would just specify MPI_ANY_SOURCE as the source in the MPI_recv(). The status struct contains the actual source of the message.

    int buf[32];
    MPI_Status status;
    // receive message from any source
    MPI_recv(buf, 32, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
    int replybuf[];
    // send reply back to sender of the message received above
    MPI_send(buf, 32, MPI_INT, status.MPI_SOURCE, tag, MPI_COMM_WORLD);
    
    0 讨论(0)
  • 2021-02-05 05:05

    MPI_ANY_SOURCE is the obvious answer.

    However, if all the ranks will be sending a request to rank 0, then MPI_Irecv combined with MPI_Testall might also work as a pattern. This will allow the MPI_Send calls to be executed in any order, and the information can be received and processed in the order that the MPI_Irecv calls are matched.

    0 讨论(0)
提交回复
热议问题