13 #ifndef HTGS_ANYTASKGRAPHCONF_HPP 14 #define HTGS_ANYTASKGRAPHCONF_HPP 29 #include <htgs/core/graph/profile/ProfileData.hpp> 38 typedef std::map<AnyITask *, AnyTaskManager *>
ITaskMap;
44 typedef std::pair<AnyITask *, AnyTaskManager *>
ITaskPair;
77 pipelineId(pipelineId), numPipelines(numPipelines) {
82 if (baseAddress ==
"")
83 this->
address = std::to_string(pipelineId);
85 this->
address = baseAddress +
":" + std::to_string(this->pipelineId);
103 if (task !=
nullptr) {
104 HTGS_DEBUG_VERBOSE(
"AnyTaskGraphConf: " <<
this <<
" Freeing memory for TaskManager: " << task);
168 virtual void sendProfileData(std::shared_ptr<ProfileData> profileData) = 0;
191 tMan->gatherProfileData(taskManagerProfiles);
202 template<
class V,
class W>
204 std::shared_ptr<IRule<V, W>> iRuleShr;
206 std::shared_ptr<AnyIRule> baseRulePtr = this->
iRuleMap->find(iRule)->second;
207 iRuleShr = std::static_pointer_cast<
IRule<V, W>>(baseRulePtr);
209 iRuleShr = std::shared_ptr<IRule<V, W>>(iRule);
223 std::shared_ptr<IMemoryAllocator<V>> allocP;
226 allocP = std::shared_ptr<IMemoryAllocator<V>>(allocator);
247 auto endTime = std::chrono::high_resolution_clock::now();
249 static_cast<unsigned long long int>(std::chrono::duration_cast<std::chrono::microseconds>(endTime -
graphCreationTimestamp).count());
263 auto endTime = std::chrono::high_resolution_clock::now();
266 static_cast<unsigned long long int>(std::chrono::duration_cast<std::chrono::microseconds>(endTime -
graphExecutingTimestamp).count());
282 if(!tm->isInitialized()) {
326 template<
class T,
class U>
329 if (tCopy.first == orig) {
330 return (
ITask<T, U> *) tCopy.second->getTaskFunction();
346 if (tCopy.first == orig) {
347 return tCopy.second->getTaskFunction();
361 template<
class T,
class U>
367 if (tSched->getTaskFunction() == task) {
373 if (taskManager ==
nullptr) {
378 task->getMicroTimeoutTime(),
382 this->taskManagers->push_back(taskManager);
398 if (tMan == taskManager)
402 this->taskManagers->push_back(taskManager);
410 tMan->printProfile();
443 void writeDotToFile(std::string file,
int flags = 0, std::string graphTitle =
"", std::string customTitleText =
"") {
449 <<
"DOT visualization without connectors does not support showing all threading. Adding DOTGEN_FLAG_SHOW_CONNECTORS flag." 451 flags = flags | DOTGEN_FLAG_SHOW_CONNECTORS;
456 bool graphColored =
false;
459 std::string name =
"color-compute-time-" + file;
460 std::ofstream f(name);
461 f <<
genDotGraph(flags, DOTGEN_COLOR_COMP_TIME, graphTitle, customTitleText);
464 std::cout <<
"Writing dot file for task graph with compute time coloring to " << name << std::endl;
470 std::string name =
"color-wait-time-" + file;
472 std::ofstream f(name);
473 f <<
genDotGraph(flags, DOTGEN_COLOR_WAIT_TIME, graphTitle, customTitleText);
476 std::cout <<
"Writing dot file for task graph with wait time coloring to " << name << std::endl;
482 std::string name =
"color-max-q-sz-" + file;
484 std::ofstream f(name);
485 f <<
genDotGraph(flags, DOTGEN_COLOR_MAX_Q_SZ, graphTitle, customTitleText);
488 std::cout <<
"Writing dot file for task graph with max Q size coloring to " << name << std::endl;
495 std::ofstream f(file);
496 f <<
genDotGraph(flags, 0, graphTitle, customTitleText);
499 std::cout <<
"Writing dot file for task graph to " << file << std::endl;
551 std::ostringstream oss;
554 oss << bTask->getDot(flags);
569 virtual std::string
genDotGraph(
int flags,
int colorFlag, std::string graphTitle =
"", std::string customTitleText =
"") = 0;
577 for (
auto task : *tasks) {
589 if (tCopy.first == iTask) {
606 if (taskSched->getTaskFunction() == task)
626 taskCopyMap->insert(ITaskPair(origITask, taskManagerCopy));
658 #endif //HTGS_ANYTASKGRAPHCONF_HPP std::chrono::time_point< std::chrono::high_resolution_clock > graphExecutingTimestamp
Timestamp for how long the graph executed.
Definition: AnyTaskGraphConf.hpp:647
virtual AnyTaskManager * copy(bool deep)=0
Copies the TaskManager.
std::mutex initializeMutex
Mutex used to signal initializational.
Definition: AnyTaskGraphConf.hpp:652
size_t getNumThreads() const
Gets the number of threads associated with this TaskManager.
Definition: AnyTaskManager.hpp:298
Implements the parent ITask, which removes the template arguments of an ITask.
Definition: AnyITask.hpp:48
void addTaskManager(AnyTaskManager *taskManager)
Adds a task manager to the task graph.
Definition: AnyTaskGraphConf.hpp:396
unsigned long long int graphCreationTime
The total time to create the graph.
Definition: AnyTaskGraphConf.hpp:649
ITask< T, U > * getCopy(ITask< T, U > *orig)
Gets the copy for an ITask based on some original ITask reference.
Definition: AnyTaskGraphConf.hpp:327
unsigned long long int getGraphComputeTime() const
Gets the total time the graph was computing.
Definition: AnyTaskGraphConf.hpp:536
IRuleMap * iRuleMap
A mapping for each IRule pointer to the shared pointer for that IRule.
Definition: AnyTaskGraphConf.hpp:642
bool hasTask(AnyITask *task)
Checks whether an ITask is in the graph or not.
Definition: AnyTaskGraphConf.hpp:604
#define DOTGEN_COLOR_WAIT_TIME
Creates color map using wait time.
Definition: TaskGraphDotGenFlags.hpp:68
std::list< AnyTaskManager * > * taskManagers
The list of task managers for the task graph.
Definition: AnyTaskGraphConf.hpp:632
#define DOTGEN_COLOR_COMP_TIME
Creates color map using compute time.
Definition: TaskGraphDotGenFlags.hpp:56
void waitForInitialization()
Waits for all task managers to finish initializing.
Definition: AnyTaskGraphConf.hpp:275
void copyTasks(std::list< AnyTaskManager *> *tasks)
Creates a copy of each task from the list of AnyTaskManagers passed as a parameter.
Definition: AnyTaskGraphConf.hpp:576
std::unordered_multimap< std::string, std::shared_ptr< AnyConnector > > TaskNameConnectorMap
Defines multiple mappings between the task name and its connector.
Definition: AnyTaskGraphConf.hpp:50
std::string getAddress()
Gets the address for the task graph.
Definition: AnyTaskGraphConf.hpp:516
std::shared_ptr< IRule< V, W > > getIRule(IRule< V, W > *iRule)
Gets the shared_ptr reference for a particular IRule.
Definition: AnyTaskGraphConf.hpp:203
void gatherProfilingData(std::map< AnyTaskManager *, TaskManagerProfile *> *taskManagerProfiles)
Gathers profiling data for this task graph's task managers, which is added into the task manager prof...
Definition: AnyTaskGraphConf.hpp:189
unsigned long long int getGraphCreationTime() const
Gets the total time the graph was getting created.
Definition: AnyTaskGraphConf.hpp:543
void writeDotToFile(std::string file, int flags=0, std::string graphTitle="", std::string customTitleText="")
Writes the dot representation of the task graph to disk with additional options such as profiling...
Definition: AnyTaskGraphConf.hpp:443
void shutdown()
Called when all the threads in this graph have finished executing.
Definition: AnyTaskGraphConf.hpp:262
#define HTGS_DEBUG_VERBOSE(msg)
Prints a debug message to std:cerr with VERBOSE level.
Definition: debug_message.hpp:75
std::string address
The address for this task graph and its tasks.
Definition: AnyTaskGraphConf.hpp:637
std::pair< AnyITask *, AnyTaskManager * > ITaskPair
Defines a pair to be added into an ITaskMap.
Definition: AnyTaskGraphConf.hpp:44
virtual AnyITask * getTaskFunction()=0
Gets the ITask function associated with the TaskManager.
virtual ~AnyTaskGraphConf()
Destructor.
Definition: AnyTaskGraphConf.hpp:101
unsigned long long int graphComputeTime
The total time to execute the graph.
Definition: AnyTaskGraphConf.hpp:648
TaskNameConnectorMap * taskConnectorNameMap
Maps the tsak name to the task's connector.
Definition: AnyTaskGraphConf.hpp:638
Implements parent ITask, removing template arguments.
std::chrono::time_point< std::chrono::high_resolution_clock > graphCreationTimestamp
Timestamp when graph constructor was called.
Definition: AnyTaskGraphConf.hpp:646
void printProfile()
Prints profile data to console for all task managers.
Definition: AnyTaskGraphConf.hpp:408
Provides an interface to send data along RuleManager edges for processing state and dependencies...
Definition: ExecutionPipeline.hpp:34
std::map< AnyITask *, AnyTaskManager * > ITaskMap
Creates a mapping between an ITask and a task manager.
Definition: AnyTaskGraphConf.hpp:38
std::map< AnyIRule *, std::shared_ptr< AnyIRule > > IRuleMap
Defines a mapping between an IRule pointer and the shared pointer of that IRule.
Definition: Types.hpp:75
bool isPoll()
Gets whether the task manager is polling for data or not.
Definition: AnyTaskManager.hpp:351
void initialize()
Initializes the task graph just prior to spawning threads.
Definition: AnyTaskGraphConf.hpp:238
virtual std::shared_ptr< AnyConnector > getInputConnector()=0
Pure virtual function that gets the task manager that is consuming data from the graph's input...
TaskManager< T, U > * getTaskManager(ITask< T, U > *task)
Gets the task manager that is responsible for a particular ITask.
Definition: AnyTaskGraphConf.hpp:362
std::list< AnyTaskManager * > * getTaskManagers()
Virtual function that initiates updating the task graph communicator.
Definition: AnyTaskGraphConf.hpp:180
Provides an interface to send data along RuleManager edges for processing state and dependencies...
bool isStartTask()
Gets whether this task manager will begin executing immediately with nullptr data or not...
Definition: AnyTaskManager.hpp:343
virtual void finishedSetup()
Called when the task graph has finished setting up its tasks and launched all threads for the graph...
Definition: AnyTaskGraphConf.hpp:257
The parent class for a Task that removes the template arguments.
Definition: AnyTaskManager.hpp:45
std::string genDotGraphContent(int flags)
Generate the content only of the graph (excludes all graph definitions and attributes) ...
Definition: AnyTaskGraphConf.hpp:550
virtual void updateTaskManagersAddressingAndPipelines()=0
Updates the task managers addresses, pipelineIds and the number of pipelines for all tasks in the Tas...
ITaskMap * taskCopyMap
The ITask copy map that maps an original ITask to a task manager copy.
Definition: AnyTaskGraphConf.hpp:631
std::map< AnyMemoryAllocator *, std::shared_ptr< AnyMemoryAllocator > > MemAllocMap
Defines a mapping between a BaseMemoryAllocator and its shared_ptr.
Definition: Types.hpp:87
TaskNameConnectorMap * getTaskConnectorNameMap() const
Gets the task name connector map that maps the task name to its input connector.
Definition: AnyTaskGraphConf.hpp:313
An interface to process input data and forward results within a TaskGraph.
Definition: ITask.hpp:165
size_t numPipelines
The number of pipelines from this graph.
Definition: AnyTaskGraphConf.hpp:635
Defines common types used throughout the HTGS API and some of which that are used by users of HTGS su...
AnyTaskManager * getTaskManagerCopy(AnyITask *iTask)
Gets the task manager copy for a given ITask.
Definition: AnyTaskGraphConf.hpp:587
Abstract class that describes how memory is allocated and freed.
Definition: IMemoryAllocator.hpp:67
std::mutex * getInitializationMutex()
Gets the initialization mutex, used for signaling when initialization is done.
Definition: AnyTaskGraphConf.hpp:305
virtual std::string genDotGraph(int flags, int colorFlag, std::string graphTitle="", std::string customTitleText="")=0
Generates the dot graph as a string.
Encapsulates an ITask to interact with an ITask's functionality.
Definition: ITask.hpp:39
#define DOTGEN_COLOR_MAX_Q_SZ
Creates color map using maximum queue size.
Definition: TaskGraphDotGenFlags.hpp:62
size_t pipelineId
The pipelineId for the task graph.
Definition: AnyTaskGraphConf.hpp:634
Implements the base class for the TaskGraphConf class, removing the template arguments and providing ...
Definition: AnyTaskGraphConf.hpp:66
Implements the TaskManagerProfile class that is used to gather profile data for a task manager...
std::pair< AnyMemoryAllocator *, std::shared_ptr< AnyMemoryAllocator > > MemAllocPair
Defines a pair to be added to the MemAllocMap.
Definition: Types.hpp:93
size_t numberOfSubGraphs
The number of sub-graphs that will be spawned.
Definition: AnyTaskGraphConf.hpp:640
virtual AnyTaskGraphConf * copy()=0
Creates an exact copy of this task graph.
void createCopy(AnyTaskManager *taskManager)
Creates a copy of a task manager and adds the copy and a mapping between the task manager copy and th...
Definition: AnyTaskGraphConf.hpp:620
Implements a TaskManager that interacts with an ITask and holds the input and output Connector for th...
size_t getNumberOfSubGraphs() const
Gets the number of sub graphs within this task graph.
Definition: AnyTaskGraphConf.hpp:528
std::shared_ptr< IMemoryAllocator< V > > getMemoryAllocator(IMemoryAllocator< V > *allocator)
Gets the shared_ptr reference for a particular IMemoryAllocator.
Definition: AnyTaskGraphConf.hpp:222
std::pair< std::string, std::shared_ptr< AnyConnector > > TaskNameConnectorPair
Defines a pair to be added into a TaskNameConnectorMap.
Definition: AnyTaskGraphConf.hpp:56
Implements the edge descriptor interface to build edges for a task graph.
std::pair< AnyIRule *, std::shared_ptr< AnyIRule > > IRulePair
Defines a pair to be added to the IRuleMap.
Definition: Types.hpp:81
#define DOTGEN_FLAG_SHOW_ALL_THREADING
Shows all threading fully expanded during dot generation.
Definition: TaskGraphDotGenFlags.hpp:26
size_t getPipelineId()
Gets the pipeline ID for the task graph configuration.
Definition: AnyTaskGraphConf.hpp:418
MemAllocMap * memAllocMap
A mapping for each IMemoryAllocator to its associated shared_ptr.
Definition: AnyTaskGraphConf.hpp:643
std::condition_variable initializeCondition
The condition variable to signal to check if initialization has finished.
Definition: AnyTaskGraphConf.hpp:651
AnyTaskGraphConf(size_t pipelineId, size_t numPipelines, std::string baseAddress)
Constructs the AnyTaskGraphConf.
Definition: AnyTaskGraphConf.hpp:76
virtual std::shared_ptr< AnyConnector > getOutputConnector()=0
Virtual function that gets the connector used for graph output.
AnyITask * getCopy(AnyITask *orig)
Gets the copy for an AnyITask based on some original AnyITask reference.
Definition: AnyTaskGraphConf.hpp:344
An interface to process input data and forward results within a TaskGraph.
Definition: Bookkeeper.hpp:23
size_t getNumPipelines()
Gets the number of pipelines that exist for this task graph.
Definition: AnyTaskGraphConf.hpp:424
std::condition_variable * getInitializationCondition()
Notifies the task graph to check if all task managers have been initialized or not.
Definition: AnyTaskGraphConf.hpp:297
#define DOTGEN_FLAG_SHOW_CONNECTOR_VERBOSE
Shows verbose information within each connector in the graph.
Definition: TaskGraphDotGenFlags.hpp:92