gatb.core-API-0.0.0
|
Launches commands in different threads. More...
#include <Command.hpp>
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 () |
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.
Dispatcher | ( | size_t | nbUnits = 0 , |
size_t | groupSize = 0 |
||
) |
Constructor.
[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 |
|
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).
[in] | commands | : commands to be executed |
[in] | postTreatment | : command to be executed after all the commands are done |
Implements IDispatcher.
|
inlinevirtual |
Returns the number of execution units for this dispatcher. For instance, it could be the number of cores in a multi cores architecture.
Implements IDispatcher.
|
inlinevirtual |
Get the number of items to be retrieved from the iterator by one thread in a synchronized way.
Implements IDispatcher.
|
inlinevirtual |
Set the number of items to be retrieved from the iterator by one thread in a synchronized way.
[in] | groupSize | : number of items to be retrieved. |
Implements IDispatcher.