gatb.core-API-0.0.0
|
Dispatching of commands. More...
#include <ICommand.hpp>
Public Member Functions | |
virtual size_t | dispatchCommands (std::vector< ICommand * > &commands, ICommand *postTreatment=0)=0 |
virtual size_t | getExecutionUnitsNumber ()=0 |
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) |
virtual void | setGroupSize (size_t groupSize)=0 |
virtual size_t | getGroupSize () const =0 |
Public Member Functions inherited from SmartPointer | |
void | use () |
void | forget () |
Public Member Functions inherited from ISmartPointer | |
virtual | ~ISmartPointer () |
Protected Member Functions | |
virtual system::ISynchronizer * | newSynchro ()=0 |
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 () |
Dispatching of commands.
Interface that launches several commands.
According to the implementation, the dispatching can be done in a serial or in a parallelized way.
Note that a post treatment command can be provided and will be launched when all the commands have finished.
Note that this interface could also be implemented for dispatching commands over a network in order to use a grid of computers. We could imagine that the commands dispatching consists in launching some RCP calls, or creating some web services calls. The important point is that, from the client point of view, her/his code should not change, except the actual kind of IDispatcher instance provided to the algorithm.
Sample of use:
|
pure 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 |
Implemented in Dispatcher, and SerialDispatcher.
|
pure virtual |
Returns the number of execution units for this dispatcher. For instance, it could be the number of cores in a multi cores architecture.
Implemented in Dispatcher, and SerialDispatcher.
|
pure virtual |
Get the number of items to be retrieved from the iterator by one thread in a synchronized way.
Implemented in Dispatcher, and SerialDispatcher.
|
inline |
Iterate a provided instance. The provided functor is cloned N times, where N is the number of threads to be created; each thread will use its own instance of functor.
One has to be aware that the copy constructor of the Functor type has to be well defined. For instance, if one wants to share a resource hold by the 'functor' argument, the copied Functor object may have a direct access to the shared resource, which potential issues with concurrent accesses on it. A way to avoid this kind of issue is to define a copy constructor that will create an instance of Functor with specific synchronization process (see ISynchronizer for that).
[in] | iterator | : the iterator to be iterated |
[in] | functor | : functor object to be cloned N times, one per thread |
[in] | groupSize | : number of items to be retrieved in a single lock/unlock block |
[in] | deleteSynchro | : if false, destructor of functors are called in each thread; if true, destructor of functors are called synchronously |
|
inline |
Iterate a provided instance. The provided functor is cloned N times, where N is the number of threads to be created; each thread will use its own instance of functor.
One has to be aware that the copy constructor of the Functor type has to be well defined. For instance, if one wants to share a resource hold by the 'functor' argument, the copied Functor object may have a direct access to the shared resource, which potential issues with concurrent accesses on it. A way to avoid this kind of issue is to define a copy constructor that will create an instance of Functor with specific synchronization process (see ISynchronizer for that).
[in] | iterator | : the iterator to be iterated |
[in] | functor | : functor object to be cloned N times, one per thread |
[in] | groupSize | : number of items to be retrieved in a single lock/unlock block |
[in] | deleteSynchro | : if false, destructor of functors are called in each thread; if true, destructor of functors are called synchronously |
|
inlineprotected |
Iterate a provided Iterator instance; each iterated items are processed through some functors. According to the dispatcher implementation, we can hence iterate in a parallel way on several cores. Since we can have concurrent access, the iteration is protected by a synchronizer. Note that it is possible to group items to be given to one functor; grouping may be important for performance issues since we reduce the number of synchronizer lock/unlock calls and so use in an optimal way the available cores.
[in] | iterator | : the iterator to be iterated |
[in] | functors | : vector of functors that are fed with iterated items |
[in] | groupSize | : number of items to be retrieved in a single lock/unlock block |
[in] | deleteSynchro | : if false, destructor of functors are called in each thread; if true, destructor of functors are called synchronously |
|
protectedpure virtual |
Factory method for synchronizer instantiation.
|
pure virtual |
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. |
Implemented in Dispatcher, and SerialDispatcher.