HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::TaskManager< T, U > Class Template Reference

Encapsulates an ITask to interact with an ITask's functionality. More...

#include <htgs/core/task/TaskManager.hpp>

Inheritance diagram for htgs::TaskManager< T, U >:
Inheritance graph
Collaboration diagram for htgs::TaskManager< T, U >:
Collaboration graph

Public Member Functions

 TaskManager (ITask< T, U > *taskFunction, size_t numThreads, bool isStartTask, size_t pipelineId, size_t numPipelines, std::string address)
 Constructs a TaskManager with an ITask as the task function and specific runtime parameters. More...
 
 TaskManager (ITask< T, U > *taskFunction, size_t numThreads, bool isStartTask, bool poll, size_t microTimeoutTime, size_t pipelineId, size_t numPipelines, std::string address)
 Constructs a TaskManager with an ITask as the task function and specific runtime parameters. More...
 
std::shared_ptr< AnyConnectorgetInputConnector () override
 Gets the input Connector. More...
 
std::shared_ptr< AnyConnectorgetOutputConnector () override
 Gets the output Connector. More...
 
void initialize () override
 Initializes the TaskManager.
 
void setRuntimeThread (TaskManagerThread *runtimeThread) override
 Sets the thread that is executing this TaskManager. More...
 
ITask< T, U > * getTaskFunction () override
 Gets the ITask function associated with the TaskManager. More...
 
AnyTaskManagercopy (bool deep) override
 Copies the TaskManager. More...
 
void executeTask () override
 Executes the TaskManager. More...
 
size_t getThreadsRemaining () override
 Gets the number of threads that are still running for the task. More...
 
void gatherProfileData (std::map< AnyTaskManager *, TaskManagerProfile *> *taskManagerProfiles) override
 Gathers profiling data for the TaskProfiler. More...
 
void setInputConnector (std::shared_ptr< AnyConnector > connector) override
 Sets the input BaseConnector. More...
 
void setOutputConnector (std::shared_ptr< AnyConnector > connector) override
 Sets the output BaseConnector. More...
 
void addResult (std::shared_ptr< U > result)
 Adds the result data to the output connector. More...
 
void terminateConnections () override
 Terminates all Connector edges. More...
 
- Public Member Functions inherited from htgs::AnyTaskManager
 AnyTaskManager (size_t numThreads, bool isStartTask, size_t pipelineId, size_t numPipelines, std::string address)
 Constructs an AnyTaskManager with an ITask as the task function and specific runtime parameters. More...
 
 AnyTaskManager (size_t numThreads, bool isStartTask, bool poll, size_t microTimeoutTime, size_t pipelineId, size_t numPipelines, std::string address)
 Constructs an AnyTaskManager with an ITask as the task function and specific runtime parameters. More...
 
virtual ~AnyTaskManager ()
 Destructor.
 
void printProfile ()
 Prints the profiling data to std::cout.
 
void updateAddressAndPipelines (std::string address, size_t pipelineId, size_t numPipelines)
 Sets the task graph communicator. More...
 
std::string getAddress ()
 Gets the address of the task manager. More...
 
void setNumPipelines (size_t numPipelines)
 Sets the number of pipelines associated with the TaskManager. More...
 
size_t getNumPipelines ()
 Gets the number of pipelines that this task manager belongs too. More...
 
void setPipelineId (size_t id)
 Sets the pipeline Id associated with the TaskManager. More...
 
size_t getPipelineId ()
 Gets the pipeline identifer for this task from 0 to number of pipelines - 1. More...
 
size_t getNumThreads () const
 Gets the number of threads associated with this TaskManager. More...
 
void setAlive (bool val)
 Sets the alive state for this task manager. More...
 
bool isAlive ()
 Gets whether the TaskManager is alive or not. More...
 
void setInitialized (bool val)
 Sets the initialized state for the task manager. More...
 
bool isInitialized ()
 Gets whether the TaskManager has initialized or not. More...
 
void setStartTask (bool val)
 Sets whether this task manager is a start task or not, which will immediately begin executing by sending nullptr data to the underlying task as soon as this task executes. More...
 
bool isStartTask ()
 Gets whether this task manager will begin executing immediately with nullptr data or not. More...
 
bool isPoll ()
 Gets whether the task manager is polling for data or not. More...
 
size_t getTimeout ()
 Gets the timeout period in microseconds for the task when the task is polling for data. More...
 
void incTaskComputeTime (int64_t val)
 Increments the compute time profile value. More...
 
void incWaitTime (int64_t val)
 Increments the wait time profile value. More...
 
void shutdown ()
 Shuts down the TaskManager.
 
std::string getName ()
 Gets the name of the ITask. More...
 
void debug ()
 Provides debug output. More...
 
std::string getNameWithPipelineId ()
 Gets the name of the ITask with it's pipeline ID. More...
 
std::string getDot (int flags)
 Gets the dot notation for this TaskManager.
 
void setThreadId (size_t id)
 Sets the thread id associated with the TaskManager. More...
 
size_t getThreadId ()
 Gets the thread id associated with the TaskManager. More...
 
unsigned long long int getComputeTime ()
 Gets the compute time for the task manager, removing the memory wait time. More...
 
unsigned long long int getExecuteTime ()
 Gets the total execution time for the task manager, including any waiting for memory within the execute function. More...
 
unsigned long long int getWaitTime ()
 Gets the wait time for the task manager. More...
 
size_t getMaxQueueSize ()
 Gets the maximum size the input queue became during execution. More...
 
void resetProfile ()
 Resets the profile data for this task.
 
unsigned long long int getTaskComputeTime ()
 Gets the task's compute time. More...
 

Private Attributes

std::shared_ptr< Connector< T > > inputConnector
 The input connector for the manager (queue to get data from)
 
std::shared_ptr< Connector< U > > outputConnector
 The output connector for the manager (queue to send data)
 
ITask< T, U > * taskFunction
 The task that is managed by the manager.
 
TaskManagerThreadruntimeThread
 The thread that is executing this task's runtime.
 

Detailed Description

template<class T, class U>
class htgs::TaskManager< T, U >

Encapsulates an ITask to interact with an ITask's functionality.

The TaskManager interacts with the TaskManagerThread to process an ITask's input and output data. The core logic of a TaskManager is implemented with the ITask representing the computational and logic functionality.

When the TaskManager is ready to be terminated the thread associated with the TaskManager and the output Connector will be notified.

Template Parameters
Tthe input data type for the TaskManager, T must derive from IData.
Uthe output data type for the TaskManager, U must derive from IData.
Note
This class should only be called by the HTGS API
#define PROFILE to enable profiling.

Constructor & Destructor Documentation

◆ TaskManager() [1/2]

template<class T, class U>
htgs::TaskManager< T, U >::TaskManager ( ITask< T, U > *  taskFunction,
size_t  numThreads,
bool  isStartTask,
size_t  pipelineId,
size_t  numPipelines,
std::string  address 
)
inline

Constructs a TaskManager with an ITask as the task function and specific runtime parameters.

Parameters
taskFunctionthe functionality for the TaskManager
numThreadsthe number of threads to operate with the TaskManager
isStartTaskwhether the TaskManager is a start task or not (immediately launches the ITask::execute when bound to a thread)
pipelineIdthe pipeline Id associated with the TaskManager
numPipelinesthe number of pipelines
addressthe address of the task graph that owns this task

◆ TaskManager() [2/2]

template<class T, class U>
htgs::TaskManager< T, U >::TaskManager ( ITask< T, U > *  taskFunction,
size_t  numThreads,
bool  isStartTask,
bool  poll,
size_t  microTimeoutTime,
size_t  pipelineId,
size_t  numPipelines,
std::string  address 
)
inline

Constructs a TaskManager with an ITask as the task function and specific runtime parameters.

Parameters
taskFunctionthe functionality for the TaskManager
numThreadsthe number of threads to operate with the TaskManager
isStartTaskwhether the TaskManager is a start task or not (immediately launches the ITask::execute when bound to a thread)
pollwhether the TaskManager should poll for data
microTimeoutTimethe timeout time in microseconds
pipelineIdthe pipeline Id associated with the TaskManager
numPipelinesthe number of pipelines
addressthe address of the task graph that owns this task

Member Function Documentation

◆ addResult()

template<class T, class U>
void htgs::TaskManager< T, U >::addResult ( std::shared_ptr< U >  result)
inline

Adds the result data to the output connector.

Parameters
resultthe result that is added to the output for this task

◆ copy()

template<class T, class U>
AnyTaskManager* htgs::TaskManager< T, U >::copy ( bool  deep)
inlineoverridevirtual

Copies the TaskManager.

Parameters
deepwhether a deep copy is required
Returns
the TaskManager copy

Implements htgs::AnyTaskManager.

◆ executeTask()

template<class T, class U>
void htgs::TaskManager< T, U >::executeTask ( )
inlineoverridevirtual

Executes the TaskManager.

Using the following procedure: 0. If the ITask is a start task, then send ITask::executeTask with nullptr and set that it is no longer a startTask

  1. Checks if the ITask::isTerminated, if it is then reduce thread pool count for the runtime and wakeup any tasks waiting on this TaskManager's input queue. If the thread pool count is zero, then indicate that this task is no longer producing data and wakup all consumers waiting on the output connector. Also indicate this task is no longer releasing memory and wakeup all memory managers that this task is releasing memory to.
  2. Get input from input Connector. (optional polls for data, if timeout period expires, then will recheck if the ITask is terminated and try to get input again)
  3. If the data is not nullptr, then sends the data to the ITask::executeTask function.
Note
#define PROFILE to enable profiling.

Implements htgs::AnyTaskManager.

◆ gatherProfileData()

template<class T, class U>
void htgs::TaskManager< T, U >::gatherProfileData ( std::map< AnyTaskManager< T, U > *, TaskManagerProfile *> *  taskManagerProfiles)
inlineoverridevirtual

Gathers profiling data for the TaskProfiler.

Parameters
taskManagerProfilesthe mapping of the task manager to its TaskManagerProfile

Implements htgs::AnyTaskManager.

◆ getInputConnector()

template<class T, class U>
std::shared_ptr<AnyConnector> htgs::TaskManager< T, U >::getInputConnector ( )
inlineoverridevirtual

Gets the input Connector.

Returns
the input connector

Implements htgs::AnyTaskManager.

◆ getOutputConnector()

template<class T, class U>
std::shared_ptr<AnyConnector> htgs::TaskManager< T, U >::getOutputConnector ( )
inlineoverridevirtual

Gets the output Connector.

Returns
the output connector

Implements htgs::AnyTaskManager.

◆ getTaskFunction()

template<class T, class U>
ITask<T, U>* htgs::TaskManager< T, U >::getTaskFunction ( )
inlineoverridevirtual

Gets the ITask function associated with the TaskManager.

Returns
the ITask

Implements htgs::AnyTaskManager.

◆ getThreadsRemaining()

template<class T, class U>
size_t htgs::TaskManager< T, U >::getThreadsRemaining ( )
inlineoverridevirtual

Gets the number of threads that are still running for the task.

Returns
the number of threads remaining

Implements htgs::AnyTaskManager.

◆ setInputConnector()

template<class T, class U>
void htgs::TaskManager< T, U >::setInputConnector ( std::shared_ptr< AnyConnector connector)
inlineoverridevirtual

Sets the input BaseConnector.

Parameters
connectorthe input connector

Implements htgs::AnyTaskManager.

◆ setOutputConnector()

template<class T, class U>
void htgs::TaskManager< T, U >::setOutputConnector ( std::shared_ptr< AnyConnector connector)
inlineoverridevirtual

Sets the output BaseConnector.

Parameters
connectorthe output connector

Implements htgs::AnyTaskManager.

◆ setRuntimeThread()

template<class T, class U>
void htgs::TaskManager< T, U >::setRuntimeThread ( TaskManagerThread runtimeThread)
inlineoverridevirtual

Sets the thread that is executing this TaskManager.

Parameters
runtimeThreadthe thread that is executing the TaskManager

Implements htgs::AnyTaskManager.

◆ terminateConnections()

template<class T, class U>
void htgs::TaskManager< T, U >::terminateConnections ( )
inlineoverridevirtual

Terminates all Connector edges.

This is called after all threads have shutdown.

Implements htgs::AnyTaskManager.


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