简体   繁体   中英

Is there a C++ equivalent of a logical when?

Is there a way to condition something with a trigger? Specifically, I have an MPI Implementation and Want to send some data immediately after the receipt of some other. Until now I have used:

MPI_Wait(&recv_request,&status)
MPI_ISend(...)

I was wondering if there was a way to skip the waiting and do some computations and only come back when the recv_request has been triggered.

The solution within MPI is to use MPI_Test .

int flag;
MPI_Test(&recv_request, &flag, &status);
while (!flag) {
    do_work();
    MPI_Test(&recv_request, &flag, &status);
}
// At this point, the request state is the same as for a completed MPI_Wait

The work granularity of do_work is a trade-off. If each call is too little work, the overhead of continuous testing will be large and little work will be done. If it is too much work in each call, the latency will be increased. The latency compared to MPI_Wait is always worse if you use MPI_Test .

Now there are other ways to do this by using threads, but that can be more complicated and especially requires a MPI implementation that is compatible with the necessary thread level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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