![]() |
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 bool | run ()=0 |
virtual bool | fuse (const std::list< 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.
Eachtask 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.
It is totally up to the user to manage the task type numbers. Peano for example offers a factory mechanism peano4::parallel::getTaskType() to create task types, which Peano applications should use. However, the generation of the task types is not baked into the tarch.
Some codes also have task numbers. They need this, if they have to identify tasks uniquely. Applications for that are task dependencies or tasks 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. If you should need unique task numbers, I recommend you use reserveTaskNumber().
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 assertion2.
|
virtual |
Definition at line 31 of file Task.cpp.
Referenced by tarch::multicore::spawnTask().
|
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. So if you carefully distinguish your tasks, you can downcast all the arguments, as you might know the real type.
This operation is invoked on a task. However, it is also given N=otherTasks.size further tasks of the same type. You have two options now:
No matter which route you follow, you always have to delete all the tasks stores within otherTasks, as these have to be processed by fuse().
My default implementation executes all the passed tasks and then returns the original task back, i.e. this one is not executed. This is the first execution pattern described above.
See above: fuse() has to delete all the instances within otherTasks. The calling routine does not have to delete anything there anymore. But it has to destroy the owning object, i.e. the object on which is has called fuse(), manually no matter whether we return true or false.
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. So either span some new tasks or handle them straightaway. |
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, and run().
Referenced by tarch::multicore::native::processFusedTask().
int tarch::multicore::Task::getPriority | ( | ) | const |
Definition at line 33 of file Task.cpp.
Referenced by operator<(), and tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().
int tarch::multicore::Task::getTaskType | ( | ) | const |
Definition at line 40 of file Task.cpp.
Referenced by tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().
|
pure virtual |
Implemented in exahype2::EnclaveTask, peano4::parallel::SpacetreeSet::TraverseTask, tarch::multicore::TaskWithCopyOfFunctor, tarch::multicore::EmptyTask, tarch::multicore::TaskWithoutCopyOfFunctor, tarch::multicore::taskfusion::LogReadyTask, and tarch::multicore::taskfusion::ProcessReadyTask.
Referenced by fuse(), and tarch::multicore::taskfusion::ProcessReadyTask::run().
Set priority.
priority | Has to be non-negative |
Definition at line 35 of file Task.cpp.
References assertion3.
Referenced by tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().
|
virtual |
Reimplemented in tarch::multicore::TaskWithCopyOfFunctor, and tarch::multicore::EmptyTask.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |