Open CASCADE Technology  7.5.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_Boolean ToUseOcctThreads ()
 Returns TRUE if OCCT threads should be used instead of auxiliary threads library; default value is FALSE if alternative library has been enabled while OCCT building and TRUE otherwise. More...
 
static void SetUseOcctThreads (Standard_Boolean theToUseOcct)
 Sets if OCCT threads should be used instead of auxiliary threads library. Has no effect if OCCT has been built with no auxiliary threads library. More...
 
static Standard_Integer NbLogicalProcessors ()
 Returns number of logical processors. More...
 
template<typename InputIterator , typename Functor >
static void ForEach (InputIterator theBegin, InputIterator theEnd, const Functor &theFunctor, const Standard_Boolean isForceSingleThreadExecution=Standard_False, Standard_Integer theNbItems=-1)
 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 (inclusive)
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,
Standard_Integer  theNbItems = -1 
)
inlinestatic

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

for (auto anIter = theBegin; anIter != theEnd; ++anIter) {
theFunctor(*anIter);
}
Parameters
theBeginthe first index (inclusive)
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
theNbItemsnumber of items passed by iterator, -1 if unknown

◆ NbLogicalProcessors()

static Standard_Integer OSD_Parallel::NbLogicalProcessors ( )
static

Returns number of logical processors.

◆ SetUseOcctThreads()

static void OSD_Parallel::SetUseOcctThreads ( Standard_Boolean  theToUseOcct)
static

Sets if OCCT threads should be used instead of auxiliary threads library. Has no effect if OCCT has been built with no auxiliary threads library.

◆ ToUseOcctThreads()

static Standard_Boolean OSD_Parallel::ToUseOcctThreads ( )
static

Returns TRUE if OCCT threads should be used instead of auxiliary threads library; default value is FALSE if alternative library has been enabled while OCCT building and TRUE otherwise.


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