有什么方法可以不使用 MPI_Wait 来编写非阻塞 MPI 代码吗?
Is there any way to write non blocking MPI code without using MPI_Wait?
我的这段代码运行良好。我的问题是,是否可以在没有 MPI_Wait
的情况下使用非阻塞代码?我在想,是否通过这种方式,我的代码无意中表现为阻塞模式。另外,为了确认这是一个非阻塞代码,我应该测量执行时间吗?如果它更快,我可以断定这是非阻塞的。但是,这里,由于MPI_Wait
和数据计算之间没有涉及任何工作;我认为这是行不通的。那么,我怎样才能确保这表现为非阻塞模式?
#include <iostream>
#include <mpi.h>
using namespace std;
int main() {
MPI_Init(NULL, NULL);
MPI_Request request;
MPI_Status status;
int rank, size, data;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank > 0) {
MPI_Irecv(&data, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &request);
MPI_Wait(&request, &status);
cout << "Rank " << rank << " has received message with data " << data << " from rank " << rank - 1 << endl;
}
cout << "Hello from rank " << rank << " out of " << size << " " << endl;
data = rank;
MPI_Isend(&data, 1, MPI_INT, (rank + 1) % size, 0, MPI_COMM_WORLD, &request);
if (rank == 0) {
MPI_Irecv(&data, 1, MPI_INT, size - 1, 0, MPI_COMM_WORLD, &request);
MPI_Wait(&request, &status);
cout << "Rank " << rank << " has received message with data " << data << " from rank " << size - 1 << endl;
}
MPI_Finalize();
return 0;
}
My question is that is it possible to have a non-blocking code without
MPI_Wait
是的,没有 MPI_Wait
也可以有一个非阻塞代码;然而,问题是在非阻塞通信例程中使用的数据可能会进入不一致的状态。换句话说,无法确定该数据是否可以安全使用(或不能)。
在当前上下文中,非阻塞简单地说意味着不阻塞等待数据被复制to/from缓冲区和received/send .调用非阻塞例程后,可以立即恢复计算。
I am thinking that whether by this way, my code behaves as a blocking
mode inadvertently. Also, to confirm that this is a non-blocking code,
shall I measure execution time? and if it is faster, I can conclude
that this is non-blcoking.
可以随时测试,但也可以相信规范(and/or 实现)给定例程是否是非阻塞的。
However, here, since no work is involved between MPI_Wait and
calculating of data; I think this does not work.
确实,使用此类例程的要点之一是将计算与通信重叠,只要该计算不适用于通信中使用的数据即可。
我的这段代码运行良好。我的问题是,是否可以在没有 MPI_Wait
的情况下使用非阻塞代码?我在想,是否通过这种方式,我的代码无意中表现为阻塞模式。另外,为了确认这是一个非阻塞代码,我应该测量执行时间吗?如果它更快,我可以断定这是非阻塞的。但是,这里,由于MPI_Wait
和数据计算之间没有涉及任何工作;我认为这是行不通的。那么,我怎样才能确保这表现为非阻塞模式?
#include <iostream>
#include <mpi.h>
using namespace std;
int main() {
MPI_Init(NULL, NULL);
MPI_Request request;
MPI_Status status;
int rank, size, data;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank > 0) {
MPI_Irecv(&data, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &request);
MPI_Wait(&request, &status);
cout << "Rank " << rank << " has received message with data " << data << " from rank " << rank - 1 << endl;
}
cout << "Hello from rank " << rank << " out of " << size << " " << endl;
data = rank;
MPI_Isend(&data, 1, MPI_INT, (rank + 1) % size, 0, MPI_COMM_WORLD, &request);
if (rank == 0) {
MPI_Irecv(&data, 1, MPI_INT, size - 1, 0, MPI_COMM_WORLD, &request);
MPI_Wait(&request, &status);
cout << "Rank " << rank << " has received message with data " << data << " from rank " << size - 1 << endl;
}
MPI_Finalize();
return 0;
}
My question is that is it possible to have a non-blocking code without MPI_Wait
是的,没有 MPI_Wait
也可以有一个非阻塞代码;然而,问题是在非阻塞通信例程中使用的数据可能会进入不一致的状态。换句话说,无法确定该数据是否可以安全使用(或不能)。
在当前上下文中,非阻塞简单地说意味着不阻塞等待数据被复制to/from缓冲区和received/send .调用非阻塞例程后,可以立即恢复计算。
I am thinking that whether by this way, my code behaves as a blocking mode inadvertently. Also, to confirm that this is a non-blocking code, shall I measure execution time? and if it is faster, I can conclude that this is non-blcoking.
可以随时测试,但也可以相信规范(and/or 实现)给定例程是否是非阻塞的。
However, here, since no work is involved between MPI_Wait and calculating of data; I think this does not work.
确实,使用此类例程的要点之一是将计算与通信重叠,只要该计算不适用于通信中使用的数据即可。