ork::Task Class Reference
[taskgraph]

An abstract Task. More...

#include <Task.h>

Inheritance diagram for ork::Task:
ork::Object ork::TaskGraph

List of all members.

Public Types

enum  reason {
  DEPENDENCY_CHANGED,
  DATA_CHANGED,
  DATA_NEEDED
}
 

Possible reasons for which a task must be reexecuted.

More...

Public Member Functions

 Task (const char *type, bool gpuTask, unsigned int deadline)
 Creates a new task.
virtual ~Task ()
 Deletes this task.
virtual void * getContext () const
 Returns the execution context of this task.
bool isGpuTask () const
 Returns true if this task is a GPU task.
unsigned int getDeadline () const
 Returns the frame number before which this task must be completed.
void setDeadline (unsigned int deadline)
 Sets the frame number before which this task must be completed.
virtual int getComplexity () const
 Returns the complexity of this task.
virtual void init (set< Task * > &initialized)
 Prepares this task before its execution.
virtual void begin ()
 Sets the execution context for this task.
virtual bool run ()
 Executes this task.
virtual void end ()
 Restores the execution context after this task.
virtual bool isDone ()
 Returns true if this task is completed.
virtual void setIsDone (bool done, unsigned int t, reason r=DATA_NEEDED)
 Sets the execution state of this task.
unsigned int getCompletionDate ()
 Returns the time at which this task was completed.
unsigned int getPredecessorsCompletionDate ()
 Returns the last completion date of the predecessors of this task.
virtual void setPredecessorsCompletionDate (unsigned int t)
 Sets the last completion date of the predecessors of this task.
float getExpectedDuration ()
 Returns the expected duration of this task in micro seconds.
void setActualDuration (float duration)
 Sets the actual duration of this task.
void addListener (TaskListener *l)
 Adds a listener to this task.
void removeListener (TaskListener *l)
 Removes a listener from this task.

Static Public Member Functions

static void logStatistics ()
 Logs the statistics about the execution time of the tasks, depending on their type.

Protected Member Functions

virtual const type_info * getTypeInfo ()
 Returns the type of this task.

Protected Attributes

unsigned int completionDate
 time at which this task was completed.
vector< TaskListener * > listeners
 the listeners of this tasks.

Detailed Description

An abstract Task.

A task can be a CPU or GPU task, it has a deadline measured as the frame number before which the task must be done. A task also has a complexity, which is used to predict the duration of this task from the measure of the duration of previous tasks of the same type. A task can be made of several tasks organized in a graph (see TaskGraph). Finally a GPU task can have an execution context (for instance an OpenGL state) which must be setup before the task is run. In order to reduce the number of context switches, the context setup and cleanup are isolated in the begin and end methods, while the task itself is implemented in the run method. The context itself is returned by the getContext method, which allows tasks that share the same context to be executed in a group. For instance if t1, t2 and t3 are GPU tasks with the same context, they can be executed with t1.begin, t1.run, t2.run, t3.run and t3.end instead of t1.begin, t1.run, t1.end, t2.begin, t2.run, t2.end, t3.begin, t3.run, and t3.end, which saves two context switches.


Member Enumeration Documentation

Possible reasons for which a task must be reexecuted.

Enumerator:
DEPENDENCY_CHANGED 

data used by this task and produced by a predecessor task has changed

DATA_CHANGED 

data used by this task but not produced by another task has changed

DATA_NEEDED 

result of this task is needed again by a successor task of this task


Constructor & Destructor Documentation

ork::Task::Task ( const char *  type,
bool  gpuTask,
unsigned int  deadline 
)

Creates a new task.

Parameters:
type the type of the task.
gpuTask if the task must be executed on GPU.
deadline the frame number before which the task must be executed. 0 means that the task must be executed immediately.
virtual ork::Task::~Task (  )  [virtual]

Deletes this task.


Member Function Documentation

void ork::Task::addListener ( TaskListener l  ) 

Adds a listener to this task.

Parameters:
l a task listener.
virtual void ork::Task::begin (  )  [virtual]

Sets the execution context for this task.

All tasks that share the same execution context must do the same work in this method, i.e. if t1 and t2 return the same object in getContext, then t1.begin and t2.begin should be equivalent.

virtual void ork::Task::end (  )  [virtual]

Restores the execution context after this task.

All tasks that share the same execution context must do the same work in this method, i.e. if t1 and t2 return the same object in getContext, then t1.end and t2.end should be equivalent.

unsigned int ork::Task::getCompletionDate (  ) 

Returns the time at which this task was completed.

This completion date is not reinitialized when the task is marked as not done, to force its reexecution. It is not changed either if the task result does not change after a reexecution (see run). Hence this date gives the last modification date of the result of this task.

virtual int ork::Task::getComplexity (  )  const [virtual]

Returns the complexity of this task.

This number is used to estimate the duration d of this task as d=k*complexity, where k is estimated based on the actual duration and complexity of previous tasks of the same type (see getTypeInfo).

virtual void* ork::Task::getContext (  )  const [virtual]

Returns the execution context of this task.

This context is used to sort GPU tasks that share the same context, in order to save context switches. The context is unused for CPU tasks, and can be NULL.

unsigned int ork::Task::getDeadline (  )  const

Returns the frame number before which this task must be completed.

float ork::Task::getExpectedDuration (  ) 

Returns the expected duration of this task in micro seconds.

The result is based on the complexity of this task (see getComplexity).

unsigned int ork::Task::getPredecessorsCompletionDate (  ) 

Returns the last completion date of the predecessors of this task.

virtual const type_info* ork::Task::getTypeInfo (  )  [protected, virtual]

Returns the type of this task.

This type is used to group the execution time statistics of tasks of the same type.

virtual void ork::Task::init ( set< Task * > &  initialized  )  [virtual]

Prepares this task before its execution.

This method is called when the task is scheduled to be executed. It can perform work that cannot be executed during the task execution itself, such as scheduling new tasks for execution (indeed, once a set of tasks has been scheduled for execution, this set cannot be modified, i.e. a task cannot schedule the execution of a task that was not previously in this set). The default implementation of this task does nothing.

Parameters:
initialized the tasks already initialized. This set is used to avoid initializing several times the same task (for tasks that belong to several task graphs).
virtual bool ork::Task::isDone (  )  [virtual]

Returns true if this task is completed.

bool ork::Task::isGpuTask (  )  const

Returns true if this task is a GPU task.

static void ork::Task::logStatistics (  )  [static]

Logs the statistics about the execution time of the tasks, depending on their type.

void ork::Task::removeListener ( TaskListener l  ) 

Removes a listener from this task.

Parameters:
l a task listener.
virtual bool ork::Task::run (  )  [virtual]

Executes this task.

Returns:
true if the result of this execution is different from the result of the last execution of this task. Indeed a task can be executed several times (see Scheduler::reschedule), and its result may or may not change at each execution. If the result does not change, then a task that depends on this task will not be reexecuted if its own data has not changed (i.e. if the reason for its rescheduling was DEPENDENCY_CHANGED -- we assume in this framework that the result of any task is deterministic and depends only on its own data and on the result of the predecessor tasks). The default implementation of this method returns true, which is the safe default result (returning true even if the result of the task has not changed is not a problem, but returning false while the result has changed will cause problems).
void ork::Task::setActualDuration ( float  duration  ) 

Sets the actual duration of this task.

This actual duration is used to improve the estimator for the duration of tasks of this type (see getTypeInfo). For internal use only. This method is called by schedulers, it must not called directly by users.

Parameters:
duration the actual duration of this task in micro seconds.
void ork::Task::setDeadline ( unsigned int  deadline  ) 

Sets the frame number before which this task must be completed.

For internal use only. This method is called by schedulers, it must not called directly by users.

virtual void ork::Task::setIsDone ( bool  done,
unsigned int  t,
reason  r = DATA_NEEDED 
) [virtual]

Sets the execution state of this task.

If the task is completed and its execution state is set to "not done" then it will be executed again. For internal use only. This method is called by schedulers, it must not called directly by users.

Parameters:
done true if task is completed, false otherwise.
t if done is true, the task's completion date (a frame number).
r if done is false, indicates why the task must be reexecuted.

Reimplemented in ork::TaskGraph.

virtual void ork::Task::setPredecessorsCompletionDate ( unsigned int  t  )  [virtual]

Sets the last completion date of the predecessors of this task.

For internal use only. This method is called by schedulers, it must not called directly by users.

Parameters:
t the completion date of a predecessor task of this task.

Reimplemented in ork::TaskGraph.


Member Data Documentation

unsigned int ork::Task::completionDate [protected]

time at which this task was completed.

vector<TaskListener*> ork::Task::listeners [protected]

the listeners of this tasks.


Generated on Mon Oct 18 09:36:12 2010 for ork by  doxygen 1.6.1