MPI-reduce 操作中的求和顺序

Order of summation in MPI-reduce operations

我们知道浮点数的求和顺序不同会导致不同的结果。

考虑使用 MPI_SUM 操作调用的 MPI 函数 MPI_reduce。

#include <mpi.h>
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
               MPI_Datatype datatype, MPI_Op op, int root,
               MPI_Comm comm)

MPI标准或MPI实现是否保证每次我们运行具有相同输入和输出数据的函数,结果都是相同的?

这就是我在 documentation

中找到的

The ‘‘canonical’’ evaluation order of a reduction is determined by the ranks of the processes in the group. However, the implementation can take advantage of associativity, or associativity and commutativity, in order to change the order of evaluation.

但这并没有给出任何关于可重复性的见解。

actual standard 提供了一些进一步的见解:

Advice to implementors. It is strongly recommended that MPI_REDUCE be implemented so that the same result be obtained whenever the function is applied on the same arguments, appearing in the same order. Note that this may prevent optimizations that take advantage of the physical location of ranks. (End of advice to implementors.)

因此,虽然不能保证,但我希望实施遵循此建议并产生可重现的结果。

如果您每次 运行 时在节点和核心之间具有相同数量的列且物理位置相同,那么您可能每次都期望相同的结果(尽管如上所示,标准不保证这一点)。

实际上,在共享使用的 HPC 系统上,您通常不会获得完全相同的位置,因此归约顺序通常不同,并且由于归约操作的不同顺序,您会看到细微的差异。

我还应该说:即使您始终如一地复制物理布局,由于共享基础设施(互连或磁盘,即使是非排他性使用的节点)上的不同条件,操作顺序仍可能会有所不同。如果其他用户以不同的方式加载系统,它可以更改到达每个级别的数据的顺序,从而更改操作的顺序(取决于并行缩减算法)。