Waiting requests which have been already completed

≯℡__Kan透↙ 提交于 2019-12-25 03:35:11

问题


I am trying to implement an asynchronous messaging mechanism (a checkpointing mechanism) using boost mpi library. In my code, receivers wait a message from the others via irecv. After the irecv, they do not call wait function. Instead, they call the test function. If test is successful, they will process the received message and start a new irecv. Else, they will advance until the checkpoint. During the checkpoint, they wait all of the in transit messages to be completed using wait function. In other words, checkpoints are stable synchronization points.

I simplified my code below and hope it is clear:

Receiver side:

mpiReceiveRequest = RepastProcess::instance()->getCommunicator()->irecv(1, 100, receivedData);

for(int i=0; i<=20; i++){
    if(i%5 == 0){   // checkpoints
        while(true){
            mpiReceiveRequest.wait();
            if(receivedData > 0)
                mpiReceiveRequest = world.irecv(1, 100, receivedData);
            else
                break;
        }

    }

    else{
        if(mpiReceiveRequest.test()){
            if(receivedData > 0)
                mpiReceiveRequest = world.irecv(1, 100, receivedData);
        }
    }
}

Sender side:

for(int i=0; i<=20; i++){
    int randomNumber = // select a random number between 1-20
    if(i > randomNumber)
        world.isend(0, 100, i);
    else
        world.isend(0, 100, -1);
}    

As you can see above, I had to call wait function for completed requests. I mean, I call the wait function for an already successfully tested message. Now, problem is a segmentation fault because of this call. And, there are some explanations about test function in boost::mpi api. It says that

you should Note that once @c test() returns a @c status object, the request has completed and @c wait() should not be called.

Actually, I can store the requests which could not pass the test function. Then, I can call wait function for only these requests. However, I am wondering that if there can be another simpler solution for overcoming this issue.


回答1:


The only solution that I could find is storing the requests which could not pass the test function, then waiting them using wait or wait_all function of boost library.



来源:https://stackoverflow.com/questions/31301557/waiting-requests-which-have-been-already-completed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!