How does MPI_IN_PLACE work with MPI_Scatter?

后端 未结 1 640
面向向阳花
面向向阳花 2020-12-18 05:17

What exactly does MPI_IN_PLACE do when given as an argument to MPI_Scatter and how should it be used? I can\'t make sense of man MPI_Scatter<

相关标签:
1条回答
  • 2020-12-18 06:09

    The sendbuf of MPI_scatter is only relevant on the root according to mpich,

    sendbuf -- address of send buffer (choice, significant only at root)

    From this discussion,

    For scatter/scatterv, MPI_IN_PLACE should be passed as the recvbuf. For gather and most other collectives, MPI_IN_PLACE should passed as the sendbuf.

    You therefore need to use MPI_IN_PLACE in the recv buffer location on the root process, e.g.

    if (rank == iroot)
         MPI_Scatter(buf, sendcount, MPI_Datatype, MPI_IN_PLACE, sendcount,  
                     MPI_Datatype, iroot, MPI_COMM_WORLD);
    else
         MPI_Scatter(dummy, sendcount, MPI_Datatype, buf, sendcount, MPI_Datatype,  
                     iroot, MPI_COMM_WORLD);
    

    You could then use buf in the send on root and the same buf in the recv position on each other process. The dummy buffer on the receiving processors could probably also be replaced by MPI_IN_PLACE.

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