All to All 广播是指每个进程将自己的数据发送给所有其他进程。这个过程可以用 MPI 实现。
示例代码如下(假设每个进程的数据类型为 int,数据长度为 count):
int* send_buf = new int[count]; int* recv_buf = new int[count * size];
// 初始化 send_buf
MPI_Allgather(send_buf, count, MPI_INT, recv_buf, count, MPI_INT, MPI_COMM_WORLD);
// 现在 recv_buf 中包含了所有进程的数据