gatb.core-API-1.4.2
Dispatcher Class Reference

Launches commands in different threads. More...

#include <Command.hpp>

Inheritance diagram for Dispatcher:
Inheritance graph

Public Member Functions

 Dispatcher (size_t nbUnits=0, size_t groupSize=0)
 
size_t dispatchCommands (std::vector< ICommand * > &commands, ICommand *postTreatment=0)
 
size_t getExecutionUnitsNumber ()
 
void setGroupSize (size_t groupSize)
 
size_t getGroupSize () const
 
- Public Member Functions inherited from IDispatcher
template<typename Item , typename Functor >
Status iterate (Iterator< Item > *iterator, const Functor &functor, size_t groupSize=1000, bool deleteSynchro=false)
 
template<typename Item , typename Functor >
Status iterate (const Iterator< Item > &iterator, const Functor &functor, size_t groupSize=1000, bool deleteSynchro=false)
 
- Public Member Functions inherited from SmartPointer
void use ()
 
void forget ()
 
- Public Member Functions inherited from ISmartPointer
virtual ~ISmartPointer ()
 

Additional Inherited Members

- Protected Member Functions inherited from IDispatcher
template<typename Item , typename Functor >
Status iterate (Iterator< Item > *iterator, std::vector< Functor * > &functors, size_t groupSize=1000, bool deleteSynchro=false)
 
- Protected Member Functions inherited from SmartPointer
 SmartPointer ()
 
virtual ~SmartPointer ()
 

Detailed Description

Launches commands in different threads.

This implementation launches commands through different threads => parallelization.

This implementation of IDispatcher is central in a tool design because it allows to uses all available cores. If one knows the number N of available cores on the computer, one has just to split some job by creating N ICommand instances and then just dispatch these commands through a Dispatcher: each command will be launched in a separated thread, and, thanks to the operating system architecture, each thread should be processed on an available core.

Note: it wouldn't be reasonable to use more ICommand instances than available cores. By default, if the number of dispatching units is not provided in the constructor of Dispatcher, it retrieves the number of available cores through the a call to system functions, and uses it as default value. This means that default constructor will use by default the whole CPU multicore power.

Constructor & Destructor Documentation

Dispatcher ( size_t  nbUnits = 0,
size_t  groupSize = 0 
)

Constructor.

Parameters
[in]nbUnits: number of threads to be used. If 0 is provided, one tries to guess the number of available cores.
[in]groupSize: number of items to be retrieved from the iterator by one thread in a synchronized way

Member Function Documentation

size_t dispatchCommands ( std::vector< ICommand * > &  commands,
ICommand postTreatment = 0 
)
virtual

Dispatch commands execution in some separate contexts (threads for instance). Once the commands are launched, this dispatcher waits for the commands finish. Then, it may have to execute a post treatment command (if any).

Parameters
[in]commands: commands to be executed
[in]postTreatment: command to be executed after all the commands are done
Returns
time elapsed in msec

Implements IDispatcher.

size_t getExecutionUnitsNumber ( )
inlinevirtual

Returns the number of execution units for this dispatcher. For instance, it could be the number of cores in a multi cores architecture.

Returns
the number of execution units.

Implements IDispatcher.

size_t getGroupSize ( ) const
inlinevirtual

Get the number of items to be retrieved from the iterator by one thread in a synchronized way.

Returns
the number of items.

Implements IDispatcher.

void setGroupSize ( size_t  groupSize)
inlinevirtual

Set the number of items to be retrieved from the iterator by one thread in a synchronized way.

Parameters
[in]groupSize: number of items to be retrieved.

Implements IDispatcher.


The documentation for this class was generated from the following files: