SPH
Classes | Functions | Variables
Scheduler.h File Reference

Interface for executing tasks (potentially) asynchronously. More...

#include "common/ForwardDecl.h"
#include "objects/utility/IteratorAdapters.h"
#include "objects/wrappers/Function.h"

Go to the source code of this file.

Classes

class  ITask
 Handle used to control tasks submitted into the scheduler. More...
 
class  IScheduler
 Interface that allows unified implementation of sequential and parallelized versions of algorithms. More...
 
class  SequentialScheduler
 Dummy scheduler that simply executes the submitted tasks sequentially on calling thread. More...
 

Functions

template<typename TFunctor >
INLINE void parallelFor (IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
 Executes a functor concurrently from all available threads. More...
 
template<typename TFunctor >
INLINE void parallelFor (IScheduler &scheduler, const Size from, const Size to, const Size granularity, TFunctor &&functor)
 Executes a functor concurrently with given granularity. More...
 
template<typename TFunctor >
INLINE void parallelFor (IScheduler &scheduler, const IndexSequence &sequence, TFunctor &&functor)
 Executes a functor concurrently from all available threads. More...
 

Variables

SequentialScheduler SEQUENTIAL
 Global instance of the sequential scheduler. More...
 

Detailed Description

Interface for executing tasks (potentially) asynchronously.

Author
Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
Date
2016-2021

Definition in file Scheduler.h.

Function Documentation

◆ parallelFor() [1/3]

template<typename TFunctor >
INLINE void parallelFor ( IScheduler scheduler,
const IndexSequence sequence,
TFunctor &&  functor 
)

Executes a functor concurrently from all available threads.

Overload using an index sequence.

Definition at line 130 of file Scheduler.h.

◆ parallelFor() [2/3]

template<typename TFunctor >
INLINE void parallelFor ( IScheduler scheduler,
const Size  from,
const Size  to,
const Size  granularity,
TFunctor &&  functor 
)

Executes a functor concurrently with given granularity.

Overload allowing to specify the granularity.

Parameters
schedulerScheduler used for parallelization.
fromFirst processed index.
toOne-past-last processed index.
granularityNumber of indices processed by the functor at once. It shall be a positive number less than or equal to (to-from).
functorFunctor executed concurrently, takes an index as an argument.

Definition at line 113 of file Scheduler.h.

◆ parallelFor() [3/3]

template<typename TFunctor >
INLINE void parallelFor ( IScheduler scheduler,
const Size  from,
const Size  to,
TFunctor &&  functor 
)

Executes a functor concurrently from all available threads.

Syntax mimics typical usage of for loop; functor is executed with index as parameter, starting at 'from' and ending one before 'to', so that total number of executions is (to-from). The function blocks until parallel for is completed.

Parameters
schedulerScheduler used for parallelization. If SequentialScheduler, this is essentailly ordinary for loop (with bigger overhead).
fromFirst processed index.
toOne-past-last processed index.
functorFunctor executed (to-from) times in different threads; takes an index as an argument.

Definition at line 98 of file Scheduler.h.

Variable Documentation

◆ SEQUENTIAL

SequentialScheduler SEQUENTIAL
extern

Global instance of the sequential scheduler.

It can be used to specify sequential execution policy for parallel algorithms, without creating unnecessary local instances of SequentialScheduler.

Definition at line 43 of file Scheduler.cpp.