Peano
Loading...
Searching...
No Matches
tarch::multicore::Task Class Referenceabstract

Abstract super class for a job. More...

#include <Task.h>

Inheritance diagram for tarch::multicore::Task:

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
 

Detailed Description

Abstract super class for a job.

Definition at line 21 of file Task.h.

Constructor & Destructor Documentation

◆ Task()

tarch::multicore::Task::Task ( int taskType,
int priority )

Construct task.

Task types and task numbers

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().

Parameters
taskTypeUnique task (type) number for this task. Pass in DontFuse if you don't want this task to be fused.
priorityInteger 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.

◆ ~Task()

virtual tarch::multicore::Task::~Task ( )
virtual

Definition at line 68 of file Task.h.

Member Function Documentation

◆ canFuse()

bool tarch::multicore::Task::canFuse ( ) const
virtual
Returns
true if the taskType is not DontFuse.

Definition at line 31 of file Task.cpp.

Referenced by tarch::multicore::spawnTask().

Here is the caller graph for this function:

◆ fuse()

bool tarch::multicore::Task::fuse ( const std::list< Task * > & otherTasks,
int targetDevice = Host )
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:

  • You can process the N tasks in one rush. In this case, the original task, i.e. the object on which fuse() is called, remains intact and has not been processed yet. You have to return true.
  • You can 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 straightaway by the runtime.

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().

Default implementation

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.

Memory ownership

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.

Returns
Is the present task still to be executed or can the runtime destroy it straightaway?
Parameters
otherTasksList 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.
targetDeviceOn 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPriority()

int tarch::multicore::Task::getPriority ( ) const

Definition at line 33 of file Task.cpp.

Referenced by operator<(), and tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().

Here is the caller graph for this function:

◆ getTaskType()

int tarch::multicore::Task::getTaskType ( ) const

Definition at line 40 of file Task.cpp.

Referenced by tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().

Here is the caller graph for this function:

◆ run()

virtual bool tarch::multicore::Task::run ( )
pure virtual
Returns
This task has to be executed again. In most cases, you should return false, to indicate that this task has finished.

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().

Here is the caller graph for this function:

◆ setPriority()

void tarch::multicore::Task::setPriority ( int priority)

Set priority.

Parameters
priorityHas to be non-negative

Definition at line 35 of file Task.cpp.

References assertion3.

Referenced by tarch::multicore::taskfusion::translateFusableTaskIntoTaskSequence().

Here is the caller graph for this function:

◆ toString()

std::string tarch::multicore::Task::toString ( ) const
virtual

Reimplemented in tarch::multicore::TaskWithCopyOfFunctor, and tarch::multicore::EmptyTask.

Definition at line 53 of file Task.cpp.

Field Documentation

◆ _priority

int tarch::multicore::Task::_priority
protected

Definition at line 24 of file Task.h.

◆ _taskType

const int tarch::multicore::Task::_taskType
protected

Definition at line 23 of file Task.h.

◆ DefaultPriority

constexpr int tarch::multicore::Task::DefaultPriority = 1024
staticconstexpr

Definition at line 27 of file Task.h.

◆ DontFuse

constexpr int tarch::multicore::Task::DontFuse = -1
staticconstexpr

Definition at line 29 of file Task.h.

◆ Host


The documentation for this class was generated from the following files: