MPI_IN_PLACE 如何与 MPI_Scatter 一起使用?

How does MPI_IN_PLACE work with MPI_Scatter?

当作为 MPI_Scatter 的参数时,MPI_IN_PLACE 究竟做了什么?应该如何使用它?我无法理解 man MPI_Scatter:

When the communicator is an intracommunicator, you can perform a gather operation in-place (the output buffer is used as the input buffer). Use the variable MPI_IN_PLACE as the value of the root process recvbuf. In this case, recvcount and recvtype are ignored, and the root process sends no data to itself. Because the in-place option converts the receive buffer into a send-and-receive buffer, a Fortran binding that includes INTENT must mark these as INOUT, not OUT.

我想要做的是使用包含根数据的相同缓冲区作为每个其他进程的接收缓冲区(如 MPI_Bcast)。 MPI_ScatterMPI_IN_PLACE 会让我这样做吗?

根据mpich

,MPI_scatter的sendbuf仅与根相关

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

来自 this 讨论,

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.

因此您需要在根进程的接收缓冲区位置使用 MPI_IN_PLACE,例如

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);

然后您可以在 root 上的发送中使用 buf,在每个其他进程的 recv 位置中使用相同的 buf。接收处理器上的 dummy 缓冲区可能也可以替换为 MPI_IN_PLACE