Open CASCADE Technology  7.3.0
Data Structures
OSD_Parallel Class Reference

Simple tool for code parallelization. More...

#include <OSD_Parallel.hxx>

Data Structures

class  FunctorInterface
 Interface class representing functor object. Intended to add polymorphic behavour to For and ForEach functionality enabling execution of arbitrary function in parallel mode. More...
 
class  UniversalIterator
 Fixed-type iterator, implementing STL forward iterator interface, used for iteration over objects subject to parallel processing. It stores pointer to instance of polymorphic iterator inheriting from IteratorInterface, which contains actual type-specific iterator. More...
 

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, equivalent to: 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, equivalent to: More...
 

Detailed Description

Simple tool for code parallelization.

OSD_Parallel class provides simple interface for parallel processing of tasks that can be formulated in terms of "for" or "foreach" loops.

To use this tool it is necessary to:

Iterators should satisfy requirements of STL forward iterator. Functor

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

The operator () should be implemented in a thread-safe way so that the same functor object can process different data items in parallel threads.

Iteration by index (For) is expected to be more efficient than using iterators (ForEach).

Implementation uses TBB if OCCT is built with support of TBB; otherwise it uses ad-hoc parallelization tool. In general, if TBB is available, it is more efficient to use it directly instead of using OSD_Parallel.

Member Function Documentation

◆ For()

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

Simple primitive for parallelization of "for" loops, equivalent to:

for (int anIter = theBegin; anIter != theEnd; ++anIter) {
theFunctor(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 >
static void OSD_Parallel::ForEach ( InputIterator  theBegin,
InputIterator  theEnd,
const Functor &  theFunctor,
const Standard_Boolean  isForceSingleThreadExecution = Standard_False 
)
inlinestatic

Simple primitive for parallelization of "foreach" loops, equivalent to:

for (auto anIter = theBegin; anIter != theEnd; ++anIter) {
theFunctor(*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: