VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
DtParallelExecutionContainer< Texec > Class Template Reference

DtParallelExecutionContainer is implementation of DtExecutionContainer which executes methods on all contained objects in parallel on multiple threads. More...

Inheritance diagram for DtParallelExecutionContainer< Texec >:
Inheritance graph
[legend]

Classes

class  ExecutableItem
 This class is used by TBB to manage the work units to perform. More...

Public Types

typedef std::vector< Texec * > PecContainerType
 Container is a vector because that is simple to divide into ranges.
typedef PecContainerType::iterator PecIteratorType

Public Member Functions

 DtParallelExecutionContainer (bool parallel=true)
 Construct a new container, default to parallel execution and grain_size of 10.
virtual ~DtParallelExecutionContainer ()
 Virtual destructor does NOT destroy contents.
virtual void add (Texec *item)
 Add a reference to the container.
virtual void remove (Texec *item)
 Remove a reference from the container.
virtual void clear ()
 Clear the container.
virtual void deleteAndClear ()
 Delete all referenced objects and then clear the container.
virtual bool empty () const
 Check if container is empty.
virtual bool contains (Texec *item)
 Check if container contains item.
virtual PecIteratorType begin ()
 Note: linux toolchain doesn't support const_iterator.
virtual PecIteratorType end ()
 End iterator over the container.
virtual void executeMethod (void(Texec::*theMethodPtr)())
 Execute method on all contained objects.
virtual void setParallel (bool parallel)
 Set execution to either parallel or serial.
virtual bool isParallel () const
 Get execution mode.
virtual void setGrainSize (int theGrainSize)
 Set the number of serial executions within one parallel execution.
virtual int getGrainSize () const
 Get the number of serial executions within one parallel execution.

Protected Member Functions

virtual void executeMethodParallel (void(Texec::*theMethodPtr)())
 Execute method on all contained objects in parallel using multiple threads.
virtual void executeMethodSerial (void(Texec::*theMethodPtr)())
 Execute method on all contained objects sequentially in a single thread.

Protected Attributes

PecContainerType myExecVec
 The execution container.

Private Attributes

bool myUseParallel
 true if using parallel execution, false for serial
int myGrainSize
 grainSize to use for parallel execution.

Detailed Description

template<class Texec>
class DtParallelExecutionContainer< Texec >

DtParallelExecutionContainer is implementation of DtExecutionContainer which executes methods on all contained objects in parallel on multiple threads.

Note that DtParallelExecutionContainer objects are not themselves threadsafe, so you can't add items to, or remove items from the collection in different threads. Intel Thread Building Blocks (TBB) provide the parallel execution mechanism. Execution may be set to either parallel (default) or serial. Order of execution is not guaranteed in parallel mode, but is guaranteed to be order-as-added in serial execution (some derived classes require this, don't change this). In paralell execution only, contained objects are divided into groups of grainSize. Items within each group are executed sequentially, but in parallel with other groups. As recommened by TBB, each group should represent 100,000 machine cycles. For very short methods, consider a larger grainSize.

Member Typedef Documentation

template<class Texec>
typedef std::vector<Texec *> DtParallelExecutionContainer< Texec >::PecContainerType

Container is a vector because that is simple to divide into ranges.

template<class Texec>
typedef PecContainerType::iterator DtParallelExecutionContainer< Texec >::PecIteratorType

Constructor & Destructor Documentation

template<class Texec>
DtParallelExecutionContainer< Texec >::DtParallelExecutionContainer ( bool  parallel = true)
inline

Construct a new container, default to parallel execution and grain_size of 10.

template<class Texec>
virtual DtParallelExecutionContainer< Texec >::~DtParallelExecutionContainer ( )
inlinevirtual

Virtual destructor does NOT destroy contents.

Call deleteAndClear explicitly to delete contents.

Member Function Documentation

template<class Texec>
virtual void DtParallelExecutionContainer< Texec >::add ( Texec *  item)
inlinevirtual

Add a reference to the container.

Parameters
itemthe item to add to the container.

Implements DtExecutionContainer< Texec >.

template<class Texec>
virtual void DtParallelExecutionContainer< Texec >::remove ( Texec *  item)
inlinevirtual

Remove a reference from the container.

Parameters
itemthe item to remove from the container.

Implements DtExecutionContainer< Texec >.

template<class Texec>
virtual void DtParallelExecutionContainer< Texec >::clear ( )
inlinevirtual

Clear the container.

Implements DtExecutionContainer< Texec >.

template<class Texec >
void DtParallelExecutionContainer< Texec >::deleteAndClear ( )
inlinevirtual

Delete all referenced objects and then clear the container.

Items are deleted sequentially, not in parallel, so item's destructor isn't required to be thread safe.

Implements DtExecutionContainer< Texec >.

template<class Texec>
virtual bool DtParallelExecutionContainer< Texec >::empty ( ) const
inlinevirtual

Check if container is empty.

Returns
true if container is empty.
template<class Texec>
virtual bool DtParallelExecutionContainer< Texec >::contains ( Texec *  item)
inlinevirtual

Check if container contains item.

Parameters
itemthe item to check.
Returns
true if item is in container.
template<class Texec>
virtual PecIteratorType DtParallelExecutionContainer< Texec >::begin ( )
inlinevirtual

Note: linux toolchain doesn't support const_iterator.

:( Begin iterator over the container.

Referenced by DtParallelExecutionContainer< DtPreprocessor >::contains().

template<class Texec>
virtual PecIteratorType DtParallelExecutionContainer< Texec >::end ( )
inlinevirtual

End iterator over the container.

Referenced by DtParallelExecutionContainer< DtPreprocessor >::contains().

template<class Texec>
void DtParallelExecutionContainer< Texec >::executeMethod ( void(Texec::*)()  theMethodPtr)
inlinevirtual

Execute method on all contained objects.

Serial or parallel execution determined by setParallel(bool parallel).

Parameters
theMethodPtrthe method to execute.

Implements DtExecutionContainer< Texec >.

template<class Texec>
virtual void DtParallelExecutionContainer< Texec >::setParallel ( bool  parallel)
inlinevirtual

Set execution to either parallel or serial.

Parameters
paralleltrue for parallel execution, false for serial execution.
template<class Texec>
virtual bool DtParallelExecutionContainer< Texec >::isParallel ( ) const
inlinevirtual

Get execution mode.

Returns
parallel true for parallel execution, false for serial execution.
template<class Texec>
virtual void DtParallelExecutionContainer< Texec >::setGrainSize ( int  theGrainSize)
inlinevirtual

Set the number of serial executions within one parallel execution.

template<class Texec>
virtual int DtParallelExecutionContainer< Texec >::getGrainSize ( ) const
inlinevirtual

Get the number of serial executions within one parallel execution.

template<class Texec>
void DtParallelExecutionContainer< Texec >::executeMethodParallel ( void(Texec::*)()  theMethodPtr)
inlineprotectedvirtual

Execute method on all contained objects in parallel using multiple threads.

Parameters
theMethodPtrthe method to execute.
template<class Texec>
void DtParallelExecutionContainer< Texec >::executeMethodSerial ( void(Texec::*)()  theMethodPtr)
inlineprotectedvirtual

Execute method on all contained objects sequentially in a single thread.

Parameters
theMethodPtrthe method to execute.

Member Data Documentation

template<class Texec>
PecContainerType DtParallelExecutionContainer< Texec >::myExecVec
protected
template<class Texec>
bool DtParallelExecutionContainer< Texec >::myUseParallel
private
template<class Texec>
int DtParallelExecutionContainer< Texec >::myGrainSize
private

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

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)