简体   繁体   English

在逻辑上,C ++是否等效?

[英]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. 具体来说,我有一个MPI实现,希望在收到其他一些数据后立即发送一些数据。 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. 我想知道是否有一种方法可以跳过等待并进行一些计算,只有在recv_request触发recv_request返回。

The solution within MPI is to use MPI_Test . MPI中的解决方案是使用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. do_work的工作粒度是一个折衷。 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 . 如果使用MPI_Test则与MPI_Wait相比,延迟总是更糟。

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. 现在,还有其他方法可以通过使用线程来执行此操作,但是这可能会更加复杂,并且特别需要与必要线程级别兼容的MPI实现。

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

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