COOLFluiD
Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
|
Listener for MPI messages. More...
#include <ListeningThread.hpp>
Public Member Functions | |
ListeningThread (Uint waitingTime=10) | |
Constructor. More... | |
void | add_communicator (Communicator comm) |
Adds a communicator to listen to. More... | |
void | remove_comunicator (Communicator comm) |
void | stop_listening () |
Stops the listening. More... | |
void | start_listening () |
Starts the listening process. More... | |
void | set_sleep_duration (Uint time) |
Uint | sleep_duration () const |
boost::thread & | thread () |
Public Attributes | |
boost::signals2::signal< void(const Communicator &, boost::shared_ptr< XML::XmlDoc >) > | new_signal |
Private Member Functions | |
void | run () |
void | check_for_data () |
void | init () |
Private Attributes | |
std::map< Communicator, ListeningInfo * > | m_comms |
Communicators. More... | |
bool | m_listening |
Indicates whether the thread is listening. More... | |
Uint | m_sleep_duration |
Communicator | m_receivingAcksComm |
boost::mutex | m_mutex |
boost::thread | m_thread |
Listener for MPI messages.
This class has been designed to be used as a Boost thread. When it is running, it continuously listens to one or more MPI intercommunicators. If there are more than one intercommunicator, all of them are listened simultanuously. The thread is started by calling start_listening()
and stopped with stop_listening
. A thread cannot be started if it is already running. It is not recommended to have an communicator to be listened by two threads at the same time as the behaviour can be undefined.
Internally, the thread makes a non-blocking MPI receive on all communicators and then sleeps during some time (defined by the user). When it wakes up, it checks all the communicators and, for each of them that has new data, calls the new_signal
signal; and then makes a new non-blocking receive.
The fact that the thread sleeps is for performance reasons: it is to avoid the code to run useless instruction and use not needed CPU time while waiting. It is to the user to determine the best "sleeping time". The default is 10 milliseconds.
However, be careful when defining this sleeping time. The biggest it is, the longuest is the response time for requests. If the sleeping time is too small, the CPU usage might be too high if no data arrives during a long time.
New intercommunicators can be added on the run as well as the sleeping time can be modified. Thoes changes will be taken into account at the next iteration (after the next check).
Definition at line 63 of file ListeningThread.hpp.
ListeningThread | ( | Uint | waitingTime = 10 | ) |
Constructor.
Definition at line 33 of file ListeningThread.cpp.
void add_communicator | ( | Communicator | comm | ) |
Adds a communicator to listen to.
This method can be called during the listening.
comm | Communicator to add. |
Definition at line 42 of file ListeningThread.cpp.
|
private |
Definition at line 160 of file ListeningThread.cpp.
|
private |
Definition at line 119 of file ListeningThread.cpp.
void remove_comunicator | ( | Communicator | comm | ) |
Definition at line 56 of file ListeningThread.cpp.
|
private |
Definition at line 148 of file ListeningThread.cpp.
void set_sleep_duration | ( | Uint | time | ) |
Definition at line 98 of file ListeningThread.cpp.
Uint sleep_duration | ( | ) | const |
Definition at line 105 of file ListeningThread.cpp.
void start_listening | ( | ) |
Starts the listening process.
If there is at least one communicator to listen to, the process has three main steps:
#m_waitingTime
ms #newFrame
signal is emitted. stop_listening()
is not called. If a new communicator is added, it will be taken in account on the next iteration. Definition at line 86 of file ListeningThread.cpp.
void stop_listening | ( | ) |
Stops the listening.
Calling this method will exit the thread execution if it is running.
Definition at line 73 of file ListeningThread.cpp.
boost::thread & thread | ( | ) |
Definition at line 112 of file ListeningThread.cpp.
|
private |
Communicators.
The key is the communicator. The value holds information relative to the communicator.
Definition at line 121 of file ListeningThread.hpp.
|
private |
Indicates whether the thread is listening.
If true
, the thread is listening, otherwise it is not.
Definition at line 126 of file ListeningThread.hpp.
|
private |
Definition at line 132 of file ListeningThread.hpp.
|
private |
Definition at line 130 of file ListeningThread.hpp.
|
private |
Definition at line 128 of file ListeningThread.hpp.
|
private |
Definition at line 134 of file ListeningThread.hpp.
boost::signals2::signal< void(const Communicator &, boost::shared_ptr<XML::XmlDoc>) > new_signal |
Definition at line 67 of file ListeningThread.hpp.
Send comments to: COOLFluiD Web Admin |