HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::TaskGraphRuntime Class Reference

Spawns threads and binds them to the appropriate ITask within a TaskGraph. More...

#include <htgs/api/TaskGraphRuntime.hpp>

Collaboration diagram for htgs::TaskGraphRuntime:
Collaboration graph

Public Member Functions

 TaskGraphRuntime (AnyTaskGraphConf *graph)
 Constructs a Runtime for a TaskGraph. More...
 
 ~TaskGraphRuntime ()
 Destructor.
 
void waitForRuntime ()
 Waits for the Runtime to finish executing. More...
 
void executeAndWaitForRuntime ()
 Executes the Runtime and then waits for it to finish processing.
 
void terminateAll ()
 Terminates the Runtime. More...
 
void executeRuntime ()
 Executes the Runtime.
 

Private Attributes

std::list< std::thread * > threads
 A list of all threads spawned for the Runtime.
 
AnyTaskGraphConfgraph
 The TaskGraph associated with the Runtime.
 
std::list< TaskManagerThread * > runtimeThreads
 The list of TaskManagers bound to each thread.
 
bool executed
 Whether the Runtime has been executed.
 

Detailed Description

Spawns threads and binds them to the appropriate ITask within a TaskGraph.

Each thread is bound to a separate ITask instance. If an ITask has more than one thread associated with it, then the Runtime will create a deep copy of the ITask, which is bound to the thread. This means that each thread has a different ITask instance.

This process is done for every ITask in the TaskGraph that the Runtime is responsible for.

If an ITask is an ExecutionPipeline, then the thread responsible for the ExecutionPipeline will create additional TaskGraphRuntimes, one for each TaskGraph within the ExecutionPipeline.

A Runtime can be executed asynchronously with executeRuntime(), allowing for interaction with the main TaskGraph to submit/receive data to/from the TaskGraph.

To wait for the Runtime to finish processing all of the data for a TaskGraph, use waitForRuntime(). Be sure to indicate that the input data stream for the graph is closing prior to calling waitForRuntime() (see below).

To execute and wait for the Runtime, use executeAndWaitForRuntime(). If data is being produced for the task graph, then the TaskGraph::finishedProducingData function must be called prior to waiting for the runtime in order for the task graph to know that the input to the graph has finished and the tasks processing that input can be notified.

Example Usage:

...
// If adding data to the TaskGraph, must use TaskGraph::setGraphConsumerTask
taskGraph->setGraphConsumerTask(someTask);
// To receive data from the TaskGraph use TaskGraph::addGraphOutputProducer
taskGraph->addGraphProducerTask(someOutputTask);
// Launch the runtime, will return after all threads have been configured for the taskGraph
runTime->executeRuntime();
// Add data to the TaskGraph
for(int elem = 0 ; elem < numElems; elem++)
taskGraph->produceData(new Data1(elem));
// Indicate finished producing data
taskGraph->finishedProducingData();
// Process the output until there is no more output to process
while(!taskGraph->isInputTerminated())
{
std::shared_ptr<Data2> data = taskGraph->consumeData();
if (data != nullptr) {
// Do post processing
}
}
// Wait for the Runtime to finish
runTime->waitForRuntime();

Constructor & Destructor Documentation

◆ TaskGraphRuntime()

htgs::TaskGraphRuntime::TaskGraphRuntime ( AnyTaskGraphConf graph)
inline

Constructs a Runtime for a TaskGraph.

Parameters
graphthe graph the Runtime is representing

Member Function Documentation

◆ terminateAll()

void htgs::TaskGraphRuntime::terminateAll ( )
inline

Terminates the Runtime.

This function will only mark the thread to be terminated, but will only end once the thread has finished processing its last data. Will not terminate threads that are in a WAIT state.

◆ waitForRuntime()

void htgs::TaskGraphRuntime::waitForRuntime ( )
inline

Waits for the Runtime to finish executing.

Should call execute first, otherwise this function will return immediately.


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