|
Peano
|
Abstract super class for a job. More...
#include <Task.h>

Public Member Functions | |
| Task (int taskType, int priority) | |
| Construct task. | |
| virtual | ~Task () |
| int | getTaskType () const |
| int | getPriority () const |
| void | setPriority (int priority) |
| Set priority. | |
| virtual bool | canFuse () const |
| virtual void | run ()=0 |
| Run the task. | |
| virtual void | fuse (const std::vector< Task * > &otherTasks, int targetDevice=Host) |
| Fuse multiple tasks. | |
| virtual std::string | toString () const |
Static Public Attributes | |
| static constexpr int | DefaultPriority = 1024 |
| static constexpr int | Host = -1 |
| static constexpr int | DontFuse = -1 |
Protected Attributes | |
| const int | _taskType |
| int | _priority |
Construct task.
Each task in Peano has to have a task type. All tasks that do the same, i.e. are of the same type, should have the same task type integer marker. Peano's tarch can use multiple tasks of the same type and fuse/batch them into one task call. However, if you don't want Peano to even thing about task fusion, pass in DontFuse as argument for the type. In this case, the tasking subsystem becomes agnostic of the type.
In principle, it is totally up to the user to manage the task type numbers. However, they have to be unique. This quickly becomes challenging - notably if you combine multiple solvers. Therefore, Peano offers a factory mechanism peano4::parallel::getTaskType() to create task types, which Peano applications should use.
If you have a proper task class, I recommend that you introduce a static field for this class and you initialise it with the outcome of peano4::parallel::getTaskType(). If there's one dedicated code line in your code which produces exclusively all the tasks of one type, you can also do
Some codes also have task numbers. They need this, if they have to identify unique tasks among a set of tasks of the same type. Applications for that are task that are offloaded to other ranks. For the latter tasks, we have to match data sent back by another rank to the task that would have produced these results locally. Anyway, task numbers are not baked into the generic interface, as we don't need them for all tasks all the time, and I want to avoid that the construction of unique task numbers becomes too expensive.
Some extensions that work with task numbers provide factory methods for these, which is kind of good practice. ExaHyPE for example offers exahype2::EnclaveTask::reserveTaskNumber() which ensures that task numbers are unique among multiple threads and also recycled, such that they do not overflow.
| taskType | Unique task (type) number for this task. Pass in DontFuse if you don't want this task to be fused. |
| priority | Integer value that indicates what priority you want to assign a task. Value has to be non-negative. Use DefaultPriority if there is no bespoke priority. |
Definition at line 25 of file Task.cpp.
References _priority, _taskType, and assertion2.
Referenced by tarch::multicore::EmptyTask::EmptyTask(), exahype2::EnclaveTask::EnclaveTask(), tarch::multicore::taskfusion::LogReadyTask::LogReadyTask(), tarch::multicore::taskfusion::ProcessOneReadyTask::ProcessOneReadyTask(), tarch::multicore::taskfusion::ProcessSetOfReadyTasks::ProcessSetOfReadyTasks(), tarch::multicore::taskfusion::ProcessOneReadyTask::run(), tarch::multicore::TaskWithCopyOfFunctor::TaskWithCopyOfFunctor(), tarch::multicore::TaskWithoutCopyOfFunctor::TaskWithoutCopyOfFunctor(), and peano4::parallel::SpacetreeSet::TraverseTask::TraverseTask().

|
virtual |
|
virtual |
Fuse multiple tasks.
Fuse the task with a list of further tasks. The routine is guaranteed to be called only for tasks with the same taskType. As long as you take care that every task type has a unique number, you can downcast all the objects within otherTasks into the type this virtual function is called for.
This operation is invoked on a task. However, it is also given N=otherTasks.size further tasks of the same type. In the routine, you have to process the N+1 tasks in one rush, i.e. all tasks from otherTasks and the task represented by the actual object on which fuse is called. In this case, you return false, as the task on which fuse has been called can be destroyed by the runtime.
My default implementation executes all the passed tasks one by one.
fuse() has to complete all the instances within otherTasks, but it does not have to delete anything. This is done outside, i.e. the calling routine will delete otherTasks' instances as well as the one it has called fuse() for.
| otherTasks | List of tasks to fuse and process. Will all have the same type as the present object. It is the tasks responsibility to get these tasks done. |
| targetDevice | On which device should the task be processed? A negative number means local host anything greater or equal to zero denotes an accelerator. |
Definition at line 42 of file Task.cpp.
References assertion, canFuse(), and run().
Referenced by tarch::multicore::processFusedTask().


| int tarch::multicore::Task::getPriority | ( | ) | const |
Definition at line 33 of file Task.cpp.
References _priority.
Referenced by tarch::multicore::taskfusion::handleFusableTask_LazyEvaluation(), tarch::multicore::taskfusion::handleFusableTask_ProducerConsumerTaskSequence(), and operator<().

| int tarch::multicore::Task::getTaskType | ( | ) | const |
Definition at line 40 of file Task.cpp.
References _taskType.
Referenced by tarch::multicore::taskfusion::handleFusableTask().

|
pure virtual |
Run the task.
Implemented in exahype2::EnclaveTask, peano4::parallel::SpacetreeSet::TraverseTask, tarch::multicore::EmptyTask, tarch::multicore::taskfusion::LogReadyTask, tarch::multicore::taskfusion::ProcessOneReadyTask, tarch::multicore::taskfusion::ProcessSetOfReadyTasks, tarch::multicore::TaskWithCopyOfFunctor, and tarch::multicore::TaskWithoutCopyOfFunctor.
References Host.
Referenced by fuse(), tarch::multicore::taskfusion::handleFusableTask(), and tarch::multicore::taskfusion::ProcessOneReadyTask::run().

Set priority.
| priority | Has to be non-negative |
Definition at line 35 of file Task.cpp.
References _priority, _taskType, and assertion3.
Referenced by tarch::multicore::taskfusion::handleFusableTask_LazyEvaluation(), and tarch::multicore::taskfusion::handleFusableTask_ProducerConsumerTaskSequence().

|
virtual |
Reimplemented in tarch::multicore::EmptyTask, and tarch::multicore::TaskWithCopyOfFunctor.
Definition at line 51 of file Task.cpp.
Referenced by exahype2::EnclaveTask::EnclaveTask().

|
protected |
Definition at line 24 of file Task.h.
Referenced by getPriority(), setPriority(), and Task().
|
protected |
Definition at line 23 of file Task.h.
Referenced by canFuse(), getTaskType(), setPriority(), and Task().
|
staticconstexpr |
Definition at line 27 of file Task.h.
Referenced by exahype2::EnclaveTask::EnclaveTask(), tarch::multicore::taskfusion::LogReadyTask::LogReadyTask(), tarch::multicore::taskfusion::ProcessOneReadyTask::ProcessOneReadyTask(), tarch::multicore::taskfusion::ProcessSetOfReadyTasks::ProcessSetOfReadyTasks(), and peano4::parallel::SpacetreeSet::TraverseTask::TraverseTask().
|
staticconstexpr |
Definition at line 29 of file Task.h.
Referenced by canFuse(), tarch::multicore::EmptyTask::EmptyTask(), tarch::multicore::taskfusion::LogReadyTask::LogReadyTask(), tarch::multicore::taskfusion::ProcessOneReadyTask::ProcessOneReadyTask(), tarch::multicore::taskfusion::ProcessSetOfReadyTasks::ProcessSetOfReadyTasks(), and peano4::parallel::SpacetreeSet::TraverseTask::TraverseTask().
|
staticconstexpr |
Definition at line 28 of file Task.h.
Referenced by tarch::multicore::orchestration::Hardcoded::createBSP(), tarch::multicore::orchestration::createDefaultStrategy(), tarch::multicore::orchestration::Hardcoded::createNative(), tarch::multicore::taskfusion::handleFusableTask(), run(), and tarch::multicore::orchestration::AllOnGPU::toggleDevice().