Boost logo

Boost Users :

Subject: Re: [Boost-users] mpi non-blocking communication
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-12-02 12:00:27


Hi Philipp,

On Thu, Dec 2, 2010 at 4:12 PM, Philipp Kraus
<philipp.kraus_at_[hidden]> wrote:
> There is only one problem at the time:  The CPU 0 does not catch every
> message.
> The main method:
>
> MPI::Init_thread( argc, argv, MPI_THREAD_SERIALIZED );
> mpi::communicator loMPICom;
> tl::logger::getInstance()->startListener(loMPICom);
> tl::logger::getInstance()->write(loMPICom, tl::logger::warn, "test all");
> tl::logger::getInstance()->shutdownListener(loMPICom);
> MPI::Finalize();
>
>
> So every process shoudl create a message and the CPU 0 should catch them
> all. The write method sends the data with isend (non-blocking).
> The CPU 0 runs a thread in background with
>
> while (m_listenerrunnging) {
>        while (boost::optional<mpi::status> l_status =
> p_mpi.iprobe(mpi::any_source, LOGGER_MPI_TAG)) {
>                        std::string l_str;
>                p_mpi.recv(  l_status->source(), l_status->tag(), l_str );
>        }
>        boost::this_thread::yield();
> }
>

This code for the background thread will only probe for new messages
until m_listenerrunnging is true; as soon as it turns to false (in
logger::getInstance()->shutdownListener?), it will stop and receive no
more messages.

You probably want to make it run until all messages have arrived. How
you do this depends on your application: if you know how many messages
will be coming, just count them; if you don't, make ranks !=1 send an
"end of transmission" message when they are done and only shutdown the
listener when all "end of transmission" messages have been received.
There might be other methods that are more suited to your application.

> If I run the program some times, I receive at one run 1 message,
> sometimes 4 or 5, but it's not deterministic.

MPI guarantees reliable delivery of messages but not within a specific
timeframe. IOW, messages will be received *if you wait long enough*.
If you shut down the receiver end too early, messages will be lost.

Cheers,
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