COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
ListeningThread Class Reference

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
 

Detailed Description

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).

Author
Quentin Gasper

Definition at line 63 of file ListeningThread.hpp.

Constructor & Destructor Documentation

ListeningThread ( Uint  waitingTime = 10)

Constructor.

Definition at line 33 of file ListeningThread.cpp.

Member Function Documentation

void add_communicator ( Communicator  comm)

Adds a communicator to listen to.

This method can be called during the listening.

Parameters
commCommunicator to add.

Definition at line 42 of file ListeningThread.cpp.

void check_for_data ( )
private

Definition at line 160 of file ListeningThread.cpp.

void init ( )
private

Definition at line 119 of file ListeningThread.cpp.

void remove_comunicator ( Communicator  comm)

Definition at line 56 of file ListeningThread.cpp.

void run ( )
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:

  • call Irecv (non-blocking receive) on ready communicators (new ones and those that just received data)
  • wait #m_waitingTime ms
  • call check all communicators for new data When new data arrived, #newFrame signal is emitted.
    This process is repeated as long as 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.

Member Data Documentation

std::map<Communicator, ListeningInfo*> m_comms
private

Communicators.

The key is the communicator. The value holds information relative to the communicator.

Definition at line 121 of file ListeningThread.hpp.

bool m_listening
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.

boost::mutex m_mutex
private

Definition at line 132 of file ListeningThread.hpp.

Communicator m_receivingAcksComm
private

Definition at line 130 of file ListeningThread.hpp.

Uint m_sleep_duration
private

Definition at line 128 of file ListeningThread.hpp.

boost::thread m_thread
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.


The documentation for this class was generated from the following files:
Send comments to:
COOLFluiD Web Admin