VTK  9.0.20210615
Static Public Member Functions | List of all members
vtkSMPTools Class Reference

A set of parallel (multi-threaded) utility functions. More...

#include <vtkSMPTools.h>

Static Public Member Functions

template<typename Functor >
static void For (vtkIdType first, vtkIdType last, Functor &f)
 Execute a for operation in parallel. More...
 
template<typename Functor >
static void For (vtkIdType first, vtkIdType last, Functor const &f)
 Execute a for operation in parallel. More...
 
static const char * GetBackend ()
 Get the backend in use. More...
 
static void Initialize (int numThreads=0)
 Initialize the underlying libraries for execution. More...
 
static int GetEstimatedNumberOfThreads ()
 Get the estimated number of threads being used by the backend. More...
 
template<typename T >
static void ScopeWithMaxThread (int numThreads, T &&lambda)
 Change the number of threads locally within this scope and call a functor which should contains a vtkSMPTools method. More...
 
template<typename T >
static void ScopeWithMaxThread (T &&lambda)
 Change the number of threads locally within this scope and call a functor which should contains a vtkSMPTools method. More...
 
template<typename InputIt , typename OutputIt , typename Functor >
static void Transform (InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
 A convenience method for transforming data. More...
 
template<typename InputIt1 , typename InputIt2 , typename OutputIt , typename Functor >
static void Transform (InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
 A convenience method for transforming data. More...
 
template<typename Iterator , typename T >
static void Fill (Iterator begin, Iterator end, const T &value)
 A convenience method for filling data. More...
 
template<typename RandomAccessIterator >
static void Sort (RandomAccessIterator begin, RandomAccessIterator end)
 A convenience method for sorting data. More...
 
template<typename RandomAccessIterator , typename Compare >
static void Sort (RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
 A convenience method for sorting data. More...
 
template<typename Functor >
static void For (vtkIdType first, vtkIdType last, vtkIdType grain, Functor &f)
 Execute a for operation in parallel. More...
 
template<typename Functor >
static void For (vtkIdType first, vtkIdType last, vtkIdType grain, Functor const &f)
 Execute a for operation in parallel. More...
 

Detailed Description

A set of parallel (multi-threaded) utility functions.

vtkSMPTools provides a set of utility functions that can be used to parallelize parts of VTK code using multiple threads. There are several back-end implementations of parallel functionality (currently Sequential, TBB and X-Kaapi) that actual execution is delegated to.

Definition at line 155 of file vtkSMPTools.h.

Member Function Documentation

◆ For() [1/4]

template<typename Functor >
static void vtkSMPTools::For ( vtkIdType  first,
vtkIdType  last,
vtkIdType  grain,
Functor &  f 
)
inlinestatic

Execute a for operation in parallel.

First and last define the range over which to operate (which is defined by the operator). The operation executed is defined by operator() of the functor object. The grain gives the parallel engine a hint about the coarseness over which to parallelize the function (as defined by last-first of each execution of operator() ).

Definition at line 169 of file vtkSMPTools.h.

◆ For() [2/4]

template<typename Functor >
static void vtkSMPTools::For ( vtkIdType  first,
vtkIdType  last,
vtkIdType  grain,
Functor const &  f 
)
inlinestatic

Execute a for operation in parallel.

First and last define the range over which to operate (which is defined by the operator). The operation executed is defined by operator() of the functor object. The grain gives the parallel engine a hint about the coarseness over which to parallelize the function (as defined by last-first of each execution of operator() ).

Definition at line 187 of file vtkSMPTools.h.

◆ For() [3/4]

template<typename Functor >
static void vtkSMPTools::For ( vtkIdType  first,
vtkIdType  last,
Functor &  f 
)
inlinestatic

Execute a for operation in parallel.

First and last define the range over which to operate (which is defined by the operator). The operation executed is defined by operator() of the functor object. The grain gives the parallel engine a hint about the coarseness over which to parallelize the function (as defined by last-first of each execution of operator() ). Uses a default value for the grain.

Definition at line 204 of file vtkSMPTools.h.

◆ For() [4/4]

template<typename Functor >
static void vtkSMPTools::For ( vtkIdType  first,
vtkIdType  last,
Functor const &  f 
)
inlinestatic

Execute a for operation in parallel.

First and last define the range over which to operate (which is defined by the operator). The operation executed is defined by operator() of the functor object. The grain gives the parallel engine a hint about the coarseness over which to parallelize the function (as defined by last-first of each execution of operator() ). Uses a default value for the grain.

Definition at line 219 of file vtkSMPTools.h.

◆ GetBackend()

static const char* vtkSMPTools::GetBackend ( )
static

Get the backend in use.

◆ Initialize()

static void vtkSMPTools::Initialize ( int  numThreads = 0)
static

Initialize the underlying libraries for execution.

This is not required as it is automatically defined by the libaries. However, it can be used to control the maximum number of thread used. Make sure to call it before the parallel operation.

If Initialize is called without argument it will try to use the VTK_SMP_MAX_THREADS env variable to set the maximum number of threads.

◆ GetEstimatedNumberOfThreads()

static int vtkSMPTools::GetEstimatedNumberOfThreads ( )
static

Get the estimated number of threads being used by the backend.

This should be used as just an estimate since the number of threads may vary dynamically and a particular task may not be executed on all the available threads.

◆ ScopeWithMaxThread() [1/2]

template<typename T >
static void vtkSMPTools::ScopeWithMaxThread ( int  numThreads,
T &&  lambda 
)
static

Change the number of threads locally within this scope and call a functor which should contains a vtkSMPTools method.

Usage example:

◆ ScopeWithMaxThread() [2/2]

template<typename T >
static void vtkSMPTools::ScopeWithMaxThread ( T &&  lambda)
static

Change the number of threads locally within this scope and call a functor which should contains a vtkSMPTools method.

This version of Scope doesn't take a number of threads as parameter and will uses the VTK_SMP_MAX_THREADS env variable.

Usage example:

◆ Transform() [1/2]

template<typename InputIt , typename OutputIt , typename Functor >
static void vtkSMPTools::Transform ( InputIt  inBegin,
InputIt  inEnd,
OutputIt  outBegin,
Functor  transform 
)
inlinestatic

A convenience method for transforming data.

It is a drop in replacement for std::transform(), it does a unary operation on the input ranges. The data array must have the same length. The performed transformation is defined by operator() of the functor object.

Usage example with vtkDataArray:

const auto range0 = vtk::DataArrayValueRange<1>(array0);
auto range1 = vtk::DataArrayValueRange<1>(array1);
range0.cbegin(), range0.cend(), range1.begin(), [](double x) { return x - 1; });

Please visit vtkDataArrayRange.h documentation for more information and optimisation.

Definition at line 291 of file vtkSMPTools.h.

◆ Transform() [2/2]

template<typename InputIt1 , typename InputIt2 , typename OutputIt , typename Functor >
static void vtkSMPTools::Transform ( InputIt1  inBegin1,
InputIt1  inEnd,
InputIt2  inBegin2,
OutputIt  outBegin,
Functor  transform 
)
inlinestatic

A convenience method for transforming data.

It is a drop in replacement for std::transform(), it does a binary operation on the input ranges. The data array must have the same length. The performed transformation is defined by operator() of the functor object.

Usage example with vtkDataArray:

const auto range0 = vtk::DataArrayValueRange<1>(array0);
auto range1 = vtk::DataArrayValueRange<1>(array1);
range0.cbegin(), range0.cend(), range1.cbegin(), range1.begin(),
[](double x, double y) { return x * y; });

Please visit vtkDataArrayRange.h documentation for more information and optimisation.

Definition at line 313 of file vtkSMPTools.h.

◆ Fill()

template<typename Iterator , typename T >
static void vtkSMPTools::Fill ( Iterator  begin,
Iterator  end,
const T &  value 
)
inlinestatic

A convenience method for filling data.

It is a drop in replacement for std::fill(), it assign the given value to the element in ranges.

Usage example with vtkDataArray:

// Fill range with its first tuple value
auto range = vtk::DataArrayTupleRange<1>(array);
const auto value = *range.begin();

Please visit vtkDataArrayRange.h documentation for more information and optimisation.

Definition at line 334 of file vtkSMPTools.h.

◆ Sort() [1/2]

template<typename RandomAccessIterator >
static void vtkSMPTools::Sort ( RandomAccessIterator  begin,
RandomAccessIterator  end 
)
inlinestatic

A convenience method for sorting data.

It is a drop in replacement for std::sort(). Under the hood different methods are used. For example, tbb::parallel_sort is used in TBB.

Definition at line 345 of file vtkSMPTools.h.

◆ Sort() [2/2]

template<typename RandomAccessIterator , typename Compare >
static void vtkSMPTools::Sort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
Compare  comp 
)
inlinestatic

A convenience method for sorting data.

It is a drop in replacement for std::sort(). Under the hood different methods are used. For example, tbb::parallel_sort is used in TBB. This version of Sort() takes a comparison class.

Definition at line 357 of file vtkSMPTools.h.


The documentation for this class was generated from the following file:
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkX3D::range
@ range
Definition: vtkX3D.h:244
vtkSMPTools::Fill
static void Fill(Iterator begin, Iterator end, const T &value)
A convenience method for filling data.
Definition: vtkSMPTools.h:334
vtkSMPTools::Transform
static void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
A convenience method for transforming data.
Definition: vtkSMPTools.h:291
vtkSMPTools::ScopeWithMaxThread
static void ScopeWithMaxThread(int numThreads, T &&lambda)
Change the number of threads locally within this scope and call a functor which should contains a vtk...
vtkSMPTools::For
static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor &f)
Execute a for operation in parallel.
Definition: vtkSMPTools.h:169
vtkX3D::size
@ size
Definition: vtkX3D.h:259