Skip to content

Task Graph API

bprail edited this page Apr 17, 2016 · 2 revisions

The task graph API provides programmatic access to a Task Graph file. This API follows the C++11 standards. There are two categories of objects provided by this API: the TaskGraph and TaskGraphInfo have a single instance each. In contrast, each Task retrieved from the graph is instantiated by the call and should be deleted when finished. Programmers are also cautioned that the task graph file is a compressed form of the actual graph, and accessing large portions of the graph simultaneously can require significant memory consumption.

Initializing a TaskGraph object

The TaskGraph object uses the factory pattern, rather than directly calling its constructor. Programmers can either directly pass in the filename. Some older backends first construct a ct_file, although this API is deprecated.

TaskGraph* tg = TaskGraph::initFromFile(filename);

Basic Information

With a TaskGraph object, programs can query:

  • getTaskGraphInfo() -> Returns the TaskGraphInfo object for this TaskGraph
  • getNumberOfTasks() -> Returns the total number of tasks in this graph
  • getNumberOfContexts() -> Returns the unique number of Contexts in this graph
  • getROIStart() / getROIEnd() -> See Support for Region of Interest (ROI)

Traversing a Task Graph

There are two approaches to iterating through the tasks in the graph. Each task graph contains a valid order of all tasks that respects the dependencies between tasks. The first approach follows this order explicitly.

  • Task* getNextTask(); -> Returns the next task in the current order
  • void setTaskOrderCurrent(TaskId tid); -> Moves the position in the order to the specified task (often used to skip to the ROI)
  • void resetTaskOrder(); -> Set the position in the order to the beginning (equivalent to setTaskOrderCurrnet(0:0))

The second approach is to explicitly request each task from the graph. The caution in this approach is that an analysis may need to explicitly test for the dependencies (i.e., edges) between tasks to avoid analyzing them out of order. This approach is useful for following specific sequences in the graph to the exclusion of others, such as sync tasks or a single Context.

  • Task* getTaskById(TaskId id); -> Instantiate a Contech::Task with id in the TaskGraph