Peano
|
A hard coded strategy that can realise a few standard tasking patterns. More...
#include <Hardcoded.h>
Public Member Functions | |
Hardcoded (int numberOfTasksToHoldBack, int minTasksToFuse, int maxTasksToFuse, int deviceForFusedTasks, bool fuseTasksImmediatelyWhenSpawned, int maxNestedConcurrency) | |
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 shall system hold back from tasking runtime in user-defined queues. | |
virtual ExecutionPolicy | paralleliseForkJoinSection (int nestedParallelismLevel, int numberOfTasks, int taskType) override |
Determine how to handle/realise parallelisation within fork/join region. | |
Public Member Functions inherited from tarch::multicore::orchestration::Strategy | |
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 * | createBackfill () |
Backfill strategy from the IWOMP paper. | |
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. | |
Private Attributes | |
int | _numberOfTasksToHoldBack |
int | _minTasksToFuse |
int | _maxTasksToFuse |
int | _deviceForFusedTasks |
bool | _fuseTasksImmediatelyWhenSpawned |
int | _maxNestedConcurrency |
Additional Inherited Members | |
Public Types inherited from tarch::multicore::orchestration::Strategy | |
enum class | ExecutionPolicy { RunSerially , RunParallel } |
Provide hint of execution policy. More... | |
Static Public Attributes inherited from tarch::multicore::orchestration::Strategy | |
static constexpr int | EndOfBSPSection = -1 |
A hard coded strategy that can realise a few standard tasking patterns.
Definition at line 21 of file Hardcoded.h.
tarch::multicore::orchestration::Hardcoded::Hardcoded | ( | int | numberOfTasksToHoldBack, |
int | minTasksToFuse, | ||
int | maxTasksToFuse, | ||
int | deviceForFusedTasks, | ||
bool | fuseTasksImmediatelyWhenSpawned, | ||
int | maxNestedConcurrency ) |
Construct hardcoded scheme.
Definition at line 56 of file Hardcoded.cpp.
Referenced by createBSP().
|
virtualdefault |
|
static |
Backfill strategy from the IWOMP paper.
Definition at line 29 of file Hardcoded.cpp.
References tarch::multicore::Task::Host.
|
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(), and tarch::multicore::Task::Host.
|
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 40 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 18 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 73 of file Hardcoded.cpp.
|
overridevirtual |
How many tasks shall system hold back from tasking runtime in user-defined queues.
Tell the runtime system how many tasks to hold back: If there are more tasks than the result, the tasking system will map them onto native tasks. As long as we have fewer tasks than this number, the runtime system will store tasks in its internal queue and not pass them on. Holding tasks back gives us the opportunity to fuse tasks, and it reduces pressure from the underlying task system. It also is an implicit priorisation, i.e. tasks that we hold back are ready, but as we do not pass them on to the tasking runtime, they implicitly have ultra-low priority.
My data suggest that it is a very delicate decision to hold back tasks, as you run risk all the time that you starve threads even though work would be available. I recommend to hold back tasks - in line with the text above - iff
The routine is not const, as I want strategies give the opportunity to adopt decisions after each call.
This routine is called once per task spawned (to know if we maybe should immediately map it onto a native task), and then at each end of the BSP section. When it is called for a particular task, we pass in a proper task type. That is, the decision of the strategy may depend on the type of the task for which we ask. At the end of a BSP section, we pass in tarch::multicore::orchestration::Strategy::EndOfBSPSection instead of a particular task type.
tarch::multicore::spawnAndWait() is the routine which triggers the query for the end of a BSP section. If we have N tasks and N is bigger than the result of this outine, it will map tasks onto native tasks through internal::mapPendingTasksOntoNativeTasks().
tarch::multicore::spawnTask() is the routine which queries this routine for each and every task.
taskType | Either actual task type if we get a task or EndOfBSPSection if it is not asked for a particular task type or, well, at the end of a fork-join part. How many tasks to fuse and to which device to deploy |
Return a triple modelled via a FuseInstruction object.
taskType | Either actual task type if we get a task or EndOfBSPSection if it is not asked for a particular task type or, well, at the end of a fork-join part. |
Implements tarch::multicore::orchestration::Strategy.
Definition at line 75 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 81 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 71 of file Hardcoded.cpp.
|
private |
Definition at line 26 of file Hardcoded.h.
|
private |
Definition at line 27 of file Hardcoded.h.
|
private |
Definition at line 28 of file Hardcoded.h.
|
private |
Definition at line 25 of file Hardcoded.h.
|
private |
Definition at line 24 of file Hardcoded.h.
|
private |
Definition at line 23 of file Hardcoded.h.