SPH
Public Member Functions | List of all members
IScheduler Class Referenceabstract

Interface that allows unified implementation of sequential and parallelized versions of algorithms. More...

#include <Scheduler.h>

Inheritance diagram for IScheduler:
Polymorphic OmpScheduler SequentialScheduler Tbb ThreadPool

Public Member Functions

virtual SharedPtr< ITasksubmit (const Function< void()> &task)=0
 Submits a task to be potentially executed asynchronously. More...
 
virtual Optional< SizegetThreadIdx () const =0
 Returns the index of the calling thread. More...
 
virtual Size getThreadCnt () const =0
 Returns the number of threads used by this scheduler. More...
 
virtual Size getRecommendedGranularity () const =0
 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)
 Processes the given range concurrently. More...
 
- Public Member Functions inherited from Polymorphic
virtual ~Polymorphic ()
 

Detailed Description

Interface that allows unified implementation of sequential and parallelized versions of algorithms.

Currently suitable only for task-based schedulers, cannot be used for OpenMP, MPI, etc.

Definition at line 27 of file Scheduler.h.

Member Function Documentation

◆ getRecommendedGranularity()

virtual Size IScheduler::getRecommendedGranularity ( ) const
pure virtual

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

Implemented in Tbb, SequentialScheduler, ThreadPool, and OmpScheduler.

◆ getThreadCnt()

virtual Size IScheduler::getThreadCnt ( ) const
pure virtual

Returns the number of threads used by this scheduler.

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

Implemented in Tbb, SequentialScheduler, ThreadPool, and OmpScheduler.

◆ getThreadIdx()

virtual Optional<Size> IScheduler::getThreadIdx ( ) const
pure virtual

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].

Implemented in Tbb, SequentialScheduler, ThreadPool, and OmpScheduler.

◆ parallelFor()

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

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 in Tbb, and OmpScheduler.

Definition at line 46 of file Scheduler.cpp.

◆ submit()

virtual SharedPtr<ITask> IScheduler::submit ( const Function< void()> &  task)
pure virtual

Submits a task to be potentially executed asynchronously.

Returns
Handle to the task created from the functor.

Implemented in Tbb, SequentialScheduler, ThreadPool, and OmpScheduler.


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