为什么MPI_Isend挂在这里?

时间:2017-01-18 13:48:38

标签: c++ parallel-processing segmentation-fault mpi hang

我正在尝试从左到右发送缓冲区(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;
}

1 个答案:

答案 0 :(得分:0)

您无条件地在MPI_Waitrequest上执行request2,而您有条件地执行MPI_Isend / MPI_Irecv。您只能等待实际发起的请求。