SPH
|
Interface that allows unified implementation of sequential and parallelized versions of algorithms. More...
#include <Scheduler.h>
Public Member Functions | |
virtual SharedPtr< ITask > | submit (const Function< void()> &task)=0 |
Submits a task to be potentially executed asynchronously. More... | |
virtual Optional< Size > | getThreadIdx () 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 () |
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.
|
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.
|
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.
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.
|
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.
from | First index of the processed range. |
to | One-past-last index of the processed range. |
granularity | Recommended size of the chunks passed to the functor. |
functor | Functor 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.
Submits a task to be potentially executed asynchronously.
Implemented in Tbb, SequentialScheduler, ThreadPool, and OmpScheduler.