如何重叠非阻塞通信

How to overlap nonblocking communication

我知道Nonblocking communication是不阻塞代码,比如MPI_Isend会立即发送数据。但是当我们有一些全对全通信并且我们需要读取这些数据时,我们需要先使用MPI_Wait来获取数据。

对于所有人之间的交流,我首先想到的是:(这是一个真实的代码)

1- initialise the MPI, getting the rank and size... 
2- creating the data or read the first data from file
3- in a for loop, we need to send the data from all ranks to the other, by MPI_Isend or Evan MPI_Bcast
4- finalise the MPI

为了写for循环,发送和接收都需要使用MPI_Wait。 我的问题是我们如何在非阻塞中使用重叠。

我想在每个迭代循环中使用两次MPI_Isend和MPI_Irecv来重叠一些从第一个接收数据开始的计算,同时进行另一个发送和接收,但是这种方法需要4个等待, 有没有重叠非阻塞通信的算法?

I know that None-blocking communication is not blocking the code, such as MPI_Isend will send the data immediately.

这不准确,数据没有立即发送。让我更详细地解释一下:

MPI_Irecv and MPI_Isend are nonblocking communication routines, therefore one needs to use the MPI_Wait (or use MPI_Test测试请求是否完成)确保消息完成,send/receive缓冲区中的数据可以再次安全 操纵。

这里的非阻塞是指不等待数据的读取和发送;相反,数据 立即可供读取和发送。 但是,这并不意味着数据会立即发送。如果是,就不需要调用 MPI_Wait.

But when we have some all-to-all communication and we need to read this data we need to use MPI_Wait to get the data first.

您需要在 1 对 1、1 对 n 等呼叫通信类型中呼叫 MPI_Wait(或 MPI_Test),而不仅仅是在 all-to-all 中。调用 MPI_Wait 并不是先获取数据,而是在 MPI_Isend 期间必须读取和发送缓冲区的内容(例如,整数数组);同时,可以将一些计算与正在进行的过程重叠,但是该计算不能更改(或读取)send/recv 缓冲区的内容。然后调用 MPI_Wait 以确保从那时起数据 send/recv 可以安全地 read/modified 没有任何问题。

I want to use two times MPI_Isend and MPI_Irecv in each iteration loop to overlap some the computation from the first receiving data and meanwhile do another send and receive, but this approach needs 4 waiting, Is there any algorithm for overlapping the nonblocking communications?

只要有可能就在构建通信例程中使用它们可能比人们能够优化的更优化。您所描述的完全符合 MPI 例程 MPI_Ialltoall:

Sends data from all to all processes in a nonblocking way