简体   繁体   English

MPI Isend 和 Irecv 问题

[英]MPI Isend and Irecv problems

I'm having trouble with my MPI_Isend and MPI_Irecv blocks of code.我的 MPI_Isend 和 MPI_Irecv 代码块有问题。 I need to send a number Cin to the next process up the line, then the current process can go about it's business.我需要将一个数字 Cin 发送到下一个流程,然后当前流程可以继续其业务。

The receiving process needs to receive before it can go further in it's calculations, but when I don't have MPI_Wait it nevers gets the data, and when I do it just hangs forever.接收过程需要先接收,然后才能进一步进行计算,但是当我没有 MPI_Wait 时,它永远不会获取数据,而当我这样做时,它就会永远挂起。 What am I doing wrong?我究竟做错了什么?

Note: I only set Cin to 3 in order to see when the message doesn't go through.注意:我只将 Cin 设置为 3,以便查看消息何时未通过。 Currently it just hangs.目前它只是挂起。

void ComputeS5C()
{
    MPI_Request send_request, recv_request;
    MPI_Status status;
    int Cin[1] = {3};
    if(my_rank == 0){Cin[0] = 0;}
    else {
        MPI_Irecv(Cin, 1, MPI_INT, my_rank - 1, 0, MPI_COMM_WORLD, &recv_request);
        MPI_Wait(&recv_request, &status);
        fprintf(stderr, "RANK:%d   Message Received from rank%d: Cin=%d\n", my_rank, my_rank-1, Cin[0]);
    }

    int k;
    for(k = 0; k < Size_5; k++)
    {
        int s5clast;
        if(k==0)
        {
            s5clast = Cin[0];
        }
        else
        {
            s5clast = s5c[k-1];
        }

        s5c[k] = s5g[k] | (s5p[k]&s5clast);
    }

    //if not highest rank, pass the carryin upstream
    if(my_rank < world_size - 1){
        MPI_Isend(&s5c[k], 1, MPI_INT, my_rank+1, 1, MPI_COMM_WORLD, &send_request);
        fprintf(stderr, "RANK:%d   Message sent to rank%d: Cin=%d\n", my_rank, my_rank+1, s5c[k]);
    }
    MPI_Wait(&send_request, &status);
}

The error in your code has to do with the missmatch of tags .代码中的错误与tags不匹配有关。 Messages are sent using a tag = 1 and received using tag = 0 .使用tag = 1发送消息并使用tag = 0接收消息。 Sends and receives are not matching explaining why all processes are stuck waiting that sent messages get consumed.发送和接收不匹配解释了为什么所有进程都在等待发送的消息被消耗。 Change the tags so that they match.更改标签以使其匹配。

A note, when using MPI_Irecv you always need an MPI_Wait to be sure to know when it is safe to consume received data.的注意事项,使用时MPI_Irecv你总是需要一个MPI_Wait就一定要知道什么时候是安全食用接收到的数据。 I think in your example use of MPI_Recv is more approriate.我认为在您的示例中使用MPI_Recv更合适。

It seems that you communicate one rank after the other sequentially.似乎您按顺序一个接一个地进行通信。 Quite large overhead.相当大的开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM