简体   繁体   English

MPI_Irecv不接收循环后发送的消息

[英]MPI_Irecv doesn't receive message sent after loop

I've been doing a parallel implementation of the dining philosophers problem and have come to a problem which I cannot solve. 我一直在并行执行餐饮哲学家问题,但遇到了我无法解决的问题。 Basically, I have a for loop in which a process checks for any new messages and then sleeps for half a second (it repeats this a random number of times). 基本上,我有一个for循环,其中一个进程检查是否有新消息,然后休眠半秒钟(它随机重复此次数)。 After that part it tries to gather all the needed forks in order to start the "eating" part of the programm. 在那部分之后,它尝试收集所有需要的派生,以启动程序的“进餐”部分。

The problem is that for some reason, if I send a MPI message from inside the for loop, the target process recieves it normally, but if I send a message after the loop, it doesn't. 问题是由于某种原因,如果我从for循环内部发送MPI消息,则目标进程将正常接收该消息,但是如果我在循环之后发送一条消息,则不会。 Let me show how that looks in code, hopefully it will make things a bit more clear: 让我展示一下它在代码中的外观,希望它将使事情变得更加清晰:

for (int i = 0; i < think; i++) {
        Sleep(500);

        // Recieve messages
        MPI_Irecv(&rcv, 1, MPI_INT, MPI_ANY_SOURCE, NEED_FORK, MPI_COMM_WORLD, &req);
        MPI_Test(&req, &flag, &status);

        if(flag != 0) {
            // Do stuff
        }
        MPI_Send(&myid, 1, MPI_INT, target, NEED_FORK, MPI_COMM_WORLD); // He recieves this
    }
MPI_Send(&myid, 1, MPI_INT, target, NEED_FORK, MPI_COMM_WORLD); // He doesn't recieve this

The problem is that, for some reason, the targert process doesn't recieve any message sent after the for loop finished, while it recieves any message sent before or during the loop. 问题在于,由于某种原因,targert进程无法接收在for循环完成之后发送的任何消息,而可以接收在循环之前或循环期间发送的任何消息。 I really have no idea what to do to make this work and would greatly appreciate any help... 我真的不知道该怎么做才能完成这项工作,非常感谢您的帮助...

Here is my answer on similar question. 这是我对类似问题的回答。 Even code looks similar. 甚至代码看起来也差不多。 Infinite loop using MPI_Irecv and MPI_Test 使用MPI_Irecv和MPI_Test的无限循环

Please look closely on calling MPI_Test and MPI_Irecv inside loop. 请仔细查看在循环内调用MPI_Test和MPI_Irecv。

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

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