Open CASCADE Technology  7.2.0
Data Structures
OSD_Parallel Class Reference

Simplifies code parallelization. More...

#include <OSD_Parallel.hxx>

Static Public Member Functions

public methods
static Standard_Integer NbLogicalProcessors ()
 Returns number of logical proccesrs. More...
 
template<typename InputIterator , typename Functor >
static void ForEach (InputIterator theBegin, InputIterator theEnd, const Functor &theFunctor, const Standard_Boolean isForceSingleThreadExecution=Standard_False)
 Simple primitive for parallelization of "foreach" loops, e.g.: More...
 
template<typename Functor >
static void For (const Standard_Integer theBegin, const Standard_Integer theEnd, const Functor &theFunctor, const Standard_Boolean isForceSingleThreadExecution=Standard_False)
 Simple primitive for parallelization of "for" loops, e.g.: More...
 

Detailed Description

Simplifies code parallelization.

The Class provides an interface of parallel processing "for" and "foreach" loops. These primitives encapsulates complete logic for creating and managing parallel context of loops. Moreover the primitives may be a wrapper for some primitives from 3rd-party library - TBB. To use it is necessary to implement TBB like interface which is based on functors.

class Functor
{
public:
void operator() ([proccesing instance]) const
{
//...
}
};

In the body of the operator () should be implemented thread-safe logic of computations that can be performed in parallel context. If parallelized loop iterates on the collections with direct access by index (such as Vector, Array), it is more efficient to use the primitive ParallelFor (because it has no critical section).

Member Function Documentation

◆ For()

template<typename Functor >
void OSD_Parallel::For ( const Standard_Integer  theBegin,
const Standard_Integer  theEnd,
const Functor &  theFunctor,
const Standard_Boolean  isForceSingleThreadExecution = Standard_False 
)
static

Simple primitive for parallelization of "for" loops, e.g.:

for (int anIter = theBegin; anIter < theEnd; ++anIter) {}
Parameters
theBeginthe first index (incusive)
theEndthe last index (exclusive)
theFunctorfunctor providing an interface "void operator(int theIndex){}" performing task for specified index
isForceSingleThreadExecutionif true, then no threads will be created

◆ ForEach()

template<typename InputIterator , typename Functor >
void OSD_Parallel::ForEach ( InputIterator  theBegin,
InputIterator  theEnd,
const Functor &  theFunctor,
const Standard_Boolean  isForceSingleThreadExecution = Standard_False 
)
static

Simple primitive for parallelization of "foreach" loops, e.g.:

for (std::iterator anIter = theBegin; anIter != theEnd; ++anIter) {}
Parameters
theBeginthe first index (incusive)
theEndthe last index (exclusive)
theFunctorfunctor providing an interface "void operator(InputIterator theIter){}" performing task for specified iterator position
isForceSingleThreadExecutionif true, then no threads will be created

◆ NbLogicalProcessors()

static Standard_Integer OSD_Parallel::NbLogicalProcessors ( )
static

Returns number of logical proccesrs.


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