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

Scheduler encapsulating OpenMP directives. More...

#include <OpenMp.h>

Inheritance diagram for OmpScheduler:
IScheduler Polymorphic

Public Member Functions

 OmpScheduler (const Size numThreads=0)
 
void setGranularity (const Size newGranularity)
 
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< OmpSchedulergetGlobalInstance ()
 

Detailed Description

Scheduler encapsulating OpenMP directives.

Need to be compiled with -fopenmp.

Definition at line 10 of file OpenMp.h.

Constructor & Destructor Documentation

◆ OmpScheduler()

OmpScheduler::OmpScheduler ( const Size  numThreads = 0)

Member Function Documentation

◆ getGlobalInstance()

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

◆ getRecommendedGranularity()

virtual Size OmpScheduler::getRecommendedGranularity ( ) const
overridevirtual

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

Implements IScheduler.

◆ getThreadCnt()

virtual Size OmpScheduler::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> OmpScheduler::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 OmpScheduler::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 OmpScheduler::setGranularity ( const Size  newGranularity)
inline

Definition at line 19 of file OpenMp.h.

◆ submit()

virtual SharedPtr<ITask> OmpScheduler::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: