MPI 集体通信中的指针分配

Allocation of pointers in MPI collective communications

我想知道当发送缓冲区分配在 root 中但未分配在其他 ranks 时,MPI 集体通信(如 Bcast、Scatter、Gather 等)的行为如何。

例如:

rowptr = (int*)malloc(sizeof(int) * (row_count + 1));
MPI_Scatterv(all_rows, rowCounts, rowDispls, MPI_INT, 
                    rowptr, row_count, MPI_INT, MASTER, MPI_COMM_WORLD);

其中all_rows只分配在MASTER (rank == 0)进程中。 MPI 在这种情况下的行为是什么。

或者在下面的情况下;

    MPI_Scatter(eCounts, 1, MPI_INT, &elm_count, 1, MASTER, MPI_COMM_WORLD);

其中eCountsint[]elm_countint,但是eCount只分配在MASTER

我是否也应该分配发送缓冲区,即使它们未在其他队列中使用?

来自 MPI 3.1 标准(第 5.6 章第 160 页)

The send buffer is ignored for all non-root processes.

[...]

All arguments to the function are significant on process root, while on other processes, only arguments recvbuf, recvcount, recvtype, root, and comm are significant.

MPI_Gather() 相同,但将 recv* 替换为 send*

All 参数在 MPI_Bcast() 的情况下很重要(缓冲区是根等级上的发送缓冲区,其他等级上的接收缓冲区)。