为什么MPI_Isend挂在这里



我正在尝试从左到右发送缓冲区(0->1,1->2 2->3等)。我很确定进程正在从正确的合作伙伴发送和接收,但代码挂起或输出 seg 错误。

#include "mpi.h"
#include <iostream>
int main(int argc, char *argv[])
{
int comm_rank, num_procs, recieve1, send1;
int buffer[10];
MPI_Request request, request2;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);

send1 = (comm_rank + 1) % num_procs;
recieve1 = comm_rank - 1;
if (recieve1 < 0)
    recieve1 = num_procs - 1;
//std::cout << "Comm Rank = " << comm_rank << "trecieve1 = " << recieve1 << "tsend1 = " << send1 << std::endl;     
if (comm_rank == 0)
    send1 = 1;
if (comm_rank == num_procs-1)
    recieve1 = num_procs-2;
if (comm_rank != 0) 
{
    MPI_Irecv(buffer, 10, MPI_INT, recieve1, 123, MPI_COMM_WORLD, &request);
    std::cout << comm_rank << " <- " << recieve1 << std::endl;
}
if (comm_rank != num_procs-1)
{
    MPI_Isend(buffer, 10, MPI_INT, send1, 123, MPI_COMM_WORLD, &request2);
    std::cout << comm_rank << " -> " << send1 << std::endl;
}
MPI_Wait(&request, &status);
MPI_Wait(&request2, &status);

MPI_Finalize();
return 0;
}

您无条件地在requestrequest2上执行MPI_Wait,而您有条件地执行MPI_Isend/MPI_Irecv。您只能等待实际启动的请求。

相关内容

  • 没有找到相关文章

最新更新