![]() |
Peano
|
A hard coded strategy that can realise a few standard tasking patterns. More...
#include <Hardcoded.h>
Public Member Functions | |
Hardcoded (int minTasksToFuse, int maxTasksToFuse, int deviceForFusedTasks, int maxNestedConcurrency, std::chrono::microseconds timeout) | |
Construct hardcoded scheme. | |
virtual | ~Hardcoded ()=default |
virtual void | startBSPSection (int nestedParallelismLevel) override |
Notifies the strategy that we enter a BSP section. | |
virtual void | endBSPSection (int nestedParallelismLevel) override |
Notifies the strategy that we leave a BSP (fork-join) section. | |
virtual FuseInstruction | fuse (int taskType) override |
How many tasks to fuse and to which device to deploy. | |
virtual ExecutionPolicy | paralleliseForkJoinSection (int nestedParallelismLevel, int numberOfTasks, int taskType) override |
Determine how to handle/realise parallelisation within fork/join region. | |
virtual void | updateFuseStatistics (int taskType, int queueSize, double averageNumberOfPendingReadyTasksPerProcessTaskExecution, double probabilityThatTaskIsCompleted) override |
Update task fusion status. | |
![]() | |
virtual | ~Strategy ()=default |
Static Public Member Functions | |
static Hardcoded * | createBSP () |
If you want to use sole BSP, you effectively switch off the tasking. | |
static Hardcoded * | createNative () |
Fall back to native tasking. | |
static Hardcoded * | createFuseAll (int numberOfTasksToFuse, bool fuseImmediately, bool processTasksWhileWaitingInBSPArea, int targetDevice) |
Create a strategy where tasks are always fused if possible given the configuration constraints. | |
Static Public Attributes | |
static constexpr int | NoNestedParallelism = 1 |
static constexpr std::chrono::microseconds | NoTimeout = std::chrono::microseconds(0) |
![]() | |
static constexpr int | EndOfBSPSection = -1 |
Private Attributes | |
int | _minTasksToFuse |
int | _maxTasksToFuse |
int | _deviceForFusedTasks |
int | _maxNestedConcurrency |
std::chrono::microseconds | _timeout |
Additional Inherited Members | |
![]() | |
enum class | ExecutionPolicy { RunSerially , RunParallel } |
Provide hint of execution policy. More... | |
A hard coded strategy that can realise a few standard tasking patterns.
Definition at line 19 of file Hardcoded.h.
tarch::multicore::orchestration::Hardcoded::Hardcoded | ( | int | minTasksToFuse, |
int | maxTasksToFuse, | ||
int | deviceForFusedTasks, | ||
int | maxNestedConcurrency, | ||
std::chrono::microseconds | timeout ) |
Construct hardcoded scheme.
Please read through Task fusion strategies for some hints and remarks on the strategies.
deviceForFusedTasks | Use tarch::multicore::Task::Host if you do not intend to use GPUs |
maxNestedConcurrency | Pass in NoNestedParallelism if you don't want nested parallelism. |
timeout | Pass in NoTimeout if you don't want timeouts. |
Definition at line 43 of file Hardcoded.cpp.
Referenced by createBSP().
|
virtualdefault |
|
static |
If you want to use sole BSP, you effectively switch off the tasking.
Technically, this is realised by a strategy which enqueues all tasks that are spawned into the pending task queue. No tasks are handed over to the actual back-end. Therefore, the tasks will be done lazily upon demand within processPendingTasks().
Definition at line 7 of file Hardcoded.cpp.
References Hardcoded(), tarch::multicore::Task::Host, NoNestedParallelism, and NoTimeout.
|
static |
Create a strategy where tasks are always fused if possible given the configuration constraints.
numberOfTasksToFuse | The remaining tasks(<numberOfTasksToFuse) will remain stuck in the background queue and will stay there until processed lazily. |
fuseImmediately | Fuse right when they are spawned. Otherwise, tasks end up in a local queue. If a thread runs out of work, it looks into this queue and then fuses. So the fuse happens later, but it does not hold back any task production thread. |
targetDevice | Non-negative number or tarch::multicore::Task::Host. |
Definition at line 28 of file Hardcoded.cpp.
|
static |
Fall back to native tasking.
Native tasking means simply that we do not hold back any tasks but immediately map them onto native tasks.
Definition at line 17 of file Hardcoded.cpp.
References tarch::multicore::Task::Host.
Referenced by peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithBlockingReceives(), peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithBlockingSends(), peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithBlockingSendsAndReceives(), peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithNonblockingReceives(), peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithNonblockingSends(), and peano4::parallel::tests::PingPongTest::testMultithreadedPingPongWithNonblockingSendsAndReceives().
|
overridevirtual |
Notifies the strategy that we leave a BSP (fork-join) section.
Implements tarch::multicore::orchestration::Strategy.
Definition at line 58 of file Hardcoded.cpp.
|
overridevirtual |
How many tasks to fuse and to which device to deploy.
taskType | Task type for which we want to know if to fuse or not. |
Implements tarch::multicore::orchestration::Strategy.
Definition at line 60 of file Hardcoded.cpp.
|
overridevirtual |
Determine how to handle/realise parallelisation within fork/join region.
Peano models its execution with multiple parallel, nested fork/join sections. You could also think of these as mini-BSP sections. This routine guides the orchestration how to map those BSP sections onto tasks.
The decision can be guided by basically arbitrary contextual factors. The most important one for me is the nesting factor. As we work mainly with OpenMP, where tasks are tied to one core, it makes limited sense to have nested parallel fors. Notably, it makes stuff slower. So usually, I return ExecutionPolicy::RunSerially with anything with a nesting level greater than 1.
nestedParallelismLevel | Please compare with tarch::multicore::spawnAndWait() which ensures that this flag equals 1 on the top level. A parameter of 0 would mean that no fork/join region has been opened. For such a parameter, the code would not query this function. |
taskType | If we enter a fork-join section, this section logically spawns a set of tasks, which are all of the same type. So the task type here is given implicitly by the code location. But each BSP section has a unique identifier. |
Implements tarch::multicore::orchestration::Strategy.
Definition at line 67 of file Hardcoded.cpp.
References tarch::multicore::orchestration::Strategy::RunParallel, and tarch::multicore::orchestration::Strategy::RunSerially.
|
overridevirtual |
Notifies the strategy that we enter a BSP section.
Implements tarch::multicore::orchestration::Strategy.
Definition at line 56 of file Hardcoded.cpp.
|
overridevirtual |
Update task fusion status.
Feed orchestration with some stats around the task queue of interest. This routine is not called every time a process read tasks kicks off, but only every now and then. Furthermore, please note that this routine is invoked iff the orchestration beforehand had decided to fuse tasks.
taskType | Number of the task that we are studying |
queueSize | Size of the queue at this observation point |
averageNumberOfPendingReadyTasksPerProcessTaskExecution | average over number of tasks in the queue whenever a process task has kicked off and the underlying real task has not completed yet. |
probabilityThatTaskIsCompleted | Probability that task result has been there already when the corresponding instance of ProcessReadyTask fires up. This is a biased value: If we try to look up if a task is already completed and the underlying dictionary is locked, then this counts as a "no hit" as well. |
Implements tarch::multicore::orchestration::Strategy.
Definition at line 81 of file Hardcoded.cpp.
|
private |
Definition at line 23 of file Hardcoded.h.
|
private |
Definition at line 24 of file Hardcoded.h.
|
private |
Definition at line 22 of file Hardcoded.h.
|
private |
Definition at line 21 of file Hardcoded.h.
|
private |
Definition at line 25 of file Hardcoded.h.
Referenced by exahype2.Project.Project::set_timeout().
|
staticconstexpr |
Definition at line 62 of file Hardcoded.h.
Referenced by createBSP().
|
staticconstexpr |
Definition at line 63 of file Hardcoded.h.
Referenced by createBSP().