YANE-Framework 1.1.0
Classes | Public Member Functions | Protected Member Functions | Protected Attributes

yane::Utils::ParallelComputing Class Reference

Class to do parallel computations. More...

Collaboration diagram for yane::Utils::ParallelComputing:
[legend]

List of all members.

Classes

struct  T_TASKINFO
 Struct to specify computations. More...

Public Member Functions

void addItem (int index, double weight)
 Adds an item to the list of work to do.
void addItem (void *ptr, double weight)
 Adds an item to the list of work to do.
void clearItems ()
 Clears all added items.
 ParallelComputing (const std::string &name, DebugMaster *dm, int threads)
 Constructor.
void startComputing ()
 Starts the computation.
 ~ParallelComputing ()
 Destructor.

Protected Member Functions

virtual void compute (ParallelComputing::T_TASKINFO *task, DebugClient *debugclient)=0
 Computation which needs to be overwirtten.

Protected Attributes

DebugClient_debugclient
 Debugclient of the manager.

Detailed Description

This class is used to do parallel computations. To provide your own functionality overwrite compute(task). Task contains eather an index int or a pointer, depending on how the items has been added. The ParallelComputing class creates its own threads and schedules / distributes the items to the threads by calling compute() with the task as argument. After the computation the list of items to compute isn't cleared! Usually this class is used as following:


Constructor & Destructor Documentation

LIB_EXPORT yane::Utils::ParallelComputing::ParallelComputing ( const std::string &  name,
DebugMaster dm,
int  threads 
)

This creates the manager object.

Parameters:
nameName prefix of the created threads
dmDebugmaster to debug on.
threadsCount of threads to create and use.
LIB_EXPORT yane::Utils::ParallelComputing::~ParallelComputing ( )

Destroys the object.


Member Function Documentation

LIB_EXPORT void yane::Utils::ParallelComputing::addItem ( int  index,
double  weight 
)

Adds an item to the current list of

Parameters:
indexNumber of the item, e.g. the range of the computation.
weightWeight of the item, i.e. computation time
LIB_EXPORT void yane::Utils::ParallelComputing::addItem ( void *  ptr,
double  weight 
)

Adds an item to the current list.

Parameters:
ptrPointer to some data, e.g. a struct of computation info.
weightWeight of the item, i.e. computation time
LIB_EXPORT void yane::Utils::ParallelComputing::clearItems ( )

This class deletes all items added by addItem before.

virtual void yane::Utils::ParallelComputing::compute ( ParallelComputing::T_TASKINFO task,
DebugClient debugclient 
) [protected, pure virtual]

Overwrite this function to provide your own functionality for every thread.

Parameters:
taskTask data with which the compute function is called (eather an int or a pointer to data).
LIB_EXPORT void yane::Utils::ParallelComputing::startComputing ( )

Starts the computation by distributing the items to the threads and starting compute() for every thread. Without a clear() after that the items stay in the list.


Member Data Documentation

Use the debugclient to debug data.