|
Boost Users : |
Subject: Re: [Boost-users] mpi non-blocking communication
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-11-28 07:42:04
On Sun, Nov 28, 2010 at 1:25 PM, Philipp Kraus
<philipp.kraus_at_[hidden]> wrote:
> I understand the recv in this way, that it waits until a message is send. I
> think if I have no messages, the receive blocks the loop, do it?
> I would like to create the code in that way:
>
> while (...) {
> while mpi-message-is-there
> Â Â do something
> }
>
Indeed, `recv` is a blocking call. To receive a message only if one
is available, you need to probe for it first, and then receive.
Something along these lines::
while(...) {
while(boost::optional<mpi::status> status =
p_comm.iprobe(mpi::any_source, TAG)) {
// a message is available, receive it
mpi::recv(status->source(), status->tag(), l_str);
// process `l_str`
};
// ...
};
Caveat: use `status->source()` and `status->tag()` in the recv call to
ensure you recv the message that you probed for (this may still fail
if you're running iprobe/recv loops in several threads concurrently
within the same MPI process).
Best regards,
Riccardo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net