
On Sun, Nov 28, 2010 at 1:25 PM, Philipp Kraus
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::optionalmpi::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