SPH
Public Member Functions | Static Public Member Functions | List of all members
Tbb Class Reference

Scheduler encapsulating Intel Thread Building Blocks (TBB). More...

#include <Tbb.h>

Inheritance diagram for Tbb:
IScheduler Polymorphic

Public Member Functions

 Tbb (const Size numThreads=0, const Size granularity=1000)
 
 ~Tbb ()
 
void setGranularity (const Size newGranularity)
 
void setThreadCnt (const Size numThreads)
 
virtual SharedPtr< ITasksubmit (const Function< void()> &task) override
 Submits a task to be potentially executed asynchronously. More...
 
virtual Optional< SizegetThreadIdx () const override
 Returns the index of the calling thread. More...
 
virtual Size getThreadCnt () const override
 Returns the number of threads used by this scheduler. More...
 
virtual Size getRecommendedGranularity () const override
 Returns a value of granularity that is expected to perform well with the current thread count. More...
 
virtual void parallelFor (const Size from, const Size to, const Size granularity, const Function< void(Size n1, Size n2)> &functor) override
 Processes the given range concurrently. More...
 
- Public Member Functions inherited from Polymorphic
virtual ~Polymorphic ()
 

Static Public Member Functions

static SharedPtr< TbbgetGlobalInstance ()
 

Detailed Description

Scheduler encapsulating Intel Thread Building Blocks (TBB).

TBB libraries need to be linked in order to use this scheduler.

Definition at line 18 of file Tbb.h.

Constructor & Destructor Documentation

◆ Tbb()

Tbb::Tbb ( const Size  numThreads = 0,
const Size  granularity = 1000 
)

◆ ~Tbb()

Tbb::~Tbb ( )

Member Function Documentation

◆ getGlobalInstance()

static SharedPtr<Tbb> Tbb::getGlobalInstance ( )
static

◆ getRecommendedGranularity()

virtual Size Tbb::getRecommendedGranularity ( ) const
overridevirtual

Returns a value of granularity that is expected to perform well with the current thread count.

Implements IScheduler.

◆ getThreadCnt()

virtual Size Tbb::getThreadCnt ( ) const
overridevirtual

Returns the number of threads used by this scheduler.

Note that this number is constant during the lifetime of the scheduler.

Implements IScheduler.

◆ getThreadIdx()

virtual Optional<Size> Tbb::getThreadIdx ( ) const
overridevirtual

Returns the index of the calling thread.

If this thread was not invoked by the scheduler, returns NOTHING. The returned index is interval [0, getThreadCnt()-1].

Implements IScheduler.

◆ parallelFor()

virtual void Tbb::parallelFor ( const Size  from,
const Size  to,
const Size  granularity,
const Function< void(Size n1, Size n2)> &  functor 
)
overridevirtual

Processes the given range concurrently.

Default implementation simply divides the range into chunks with size specified by granularity and submits them into the scheduler. It can be overriden by the derived class to provide an optimized variant of the parallel for.

Parameters
fromFirst index of the processed range.
toOne-past-last index of the processed range.
granularityRecommended size of the chunks passed to the functor.
functorFunctor executed concurrently by the worker threads. Takes the first and the one-past-last index of the chunk to process sequentially within the thread.

Reimplemented from IScheduler.

◆ setGranularity()

void Tbb::setGranularity ( const Size  newGranularity)

◆ setThreadCnt()

void Tbb::setThreadCnt ( const Size  numThreads)

◆ submit()

virtual SharedPtr<ITask> Tbb::submit ( const Function< void()> &  task)
overridevirtual

Submits a task to be potentially executed asynchronously.

Returns
Handle to the task created from the functor.

Implements IScheduler.


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