HTGS  v2.0
The Hybrid Task Graph Scheduler
ProducerConsumerEdge.hpp
Go to the documentation of this file.
1 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the software in any medium, provided that you keep intact this entire notice. You may improve, modify and create derivative works of the software or any portion of the software, and you may copy and distribute such modifications or works. Modified works should carry a notice stating that you changed the software and should note the date and nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the source of the software.
2 // NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE.
3 // You are solely responsible for determining the appropriateness of using and distributing the software and you assume all risks associated with its use, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This software is not intended to be used in any situation where a failure could cause risk of injury or damage to property. The software developed by NIST employees is not subject to copyright protection within the United States.
4 
12 #ifndef HTGS_PRODUCERCONSUMEREDGE_HPP
13 #define HTGS_PRODUCERCONSUMEREDGE_HPP
14 
16 #include <htgs/api/ITask.hpp>
18 #ifdef WS_PROFILE
19 #include <htgs/core/graph/profile/CustomProfile.hpp>
20 #endif
21 
22 namespace htgs {
23 
39 template<class T, class U, class W>
41  public:
42 
48  ProducerConsumerEdge(ITask<T, U> *producer, ITask<U, W> *consumer) : producer(producer), consumer(consumer) {}
49 
50  ~ProducerConsumerEdge() override {}
51 
52  void applyEdge(AnyTaskGraphConf *graph) override {
53  TaskManager<T, U> *producerTaskManager = graph->getTaskManager(producer);
54  TaskManager<U, W> *consumerTaskManager = graph->getTaskManager(consumer);
55 
56  auto connector = consumerTaskManager->getInputConnector();
57 
58 #ifdef WS_PROFILE
59  bool newConnector = false;
60 #endif
61  if (connector == nullptr) {
62 #ifdef WS_PROFILE
63  newConnector = true;
64 #endif
65  connector = std::shared_ptr<Connector<U>>(new Connector<U>());
66  }
67 
68  if (producerTaskManager->getOutputConnector() != nullptr)
69  throw std::runtime_error(
70  "Error Producer Task: " + producerTaskManager->getName() + " for " + consumerTaskManager->getName()
71  + " is already connected to the graph! Are you trying to reuse the same instance and have "
72  + producerTaskManager->getName() + " produce to mutiple tasks?");
73 
74  connector->incrementInputTaskCount();
75 
76  consumerTaskManager->setInputConnector(connector);
77  producerTaskManager->setOutputConnector(connector);
78 #ifdef WS_PROFILE
79  // Add nodes
80  std::shared_ptr<ProfileData> producerData(new CreateNodeProfile(producer, graph, producer->getName()));
81  std::shared_ptr<ProfileData> consumerData(new CreateNodeProfile(consumer, graph, consumer->getName()));
82  std::shared_ptr<ProfileData> connectorData(new CreateConnectorProfile(connector.get(), graph, connector->getProducerCount(), ""));
83 
84  graph->sendProfileData(producerData);
85  graph->sendProfileData(consumerData);
86  graph->sendProfileData(connectorData);
87 
88  std::shared_ptr<ProfileData> producerConnectorData(new CreateEdgeProfile(producer, connector.get(), "", nullptr));
89  graph->sendProfileData(producerConnectorData);
90 
91  if (newConnector) {
92  std::shared_ptr<ProfileData> connectorConsumerData(new CreateEdgeProfile(connector.get(), consumer, "", nullptr));
93  graph->sendProfileData(connectorConsumerData);
94  }
95 
96 
97 
98 #endif
99  }
100 
102  return new ProducerConsumerEdge(graph->getCopy(producer), graph->getCopy(consumer));
103  }
104 
105  private:
108 
109 };
110 }
111 #endif //HTGS_PRODUCERCONSUMEREDGE_HPP
std::shared_ptr< AnyConnector > getInputConnector() override
Gets the input Connector.
Definition: TaskManager.hpp:119
ITask< T, U > * producer
The producer ITask.
Definition: ProducerConsumerEdge.hpp:106
ITask< U, W > * consumer
The consumer ITask.
Definition: ProducerConsumerEdge.hpp:107
ProducerConsumerEdge(ITask< T, U > *producer, ITask< U, W > *consumer)
Constructs a producer consumer edge.
Definition: ProducerConsumerEdge.hpp:48
ITask< T, U > * getCopy(ITask< T, U > *orig)
Gets the copy for an ITask based on some original ITask reference.
Definition: AnyTaskGraphConf.hpp:327
std::string getName()
Gets the name of the ITask.
Definition: AnyTaskManager.hpp:390
std::shared_ptr< AnyConnector > getOutputConnector() override
Gets the output Connector.
Definition: TaskManager.hpp:121
Manages the input/output of IData between Tasks.
Definition: Connector.hpp:62
TaskManager< T, U > * getTaskManager(ITask< T, U > *task)
Gets the task manager that is responsible for a particular ITask.
Definition: AnyTaskGraphConf.hpp:362
Implements the base class used by the TaskGraphConf, which removes the template arguments and impleme...
void applyEdge(AnyTaskGraphConf *graph) override
Applies an edge to a task graph.
Definition: ProducerConsumerEdge.hpp:52
An interface to process input data and forward results within a TaskGraph.
Definition: ITask.hpp:165
Encapsulates an ITask to interact with an ITask&#39;s functionality.
Definition: ITask.hpp:39
Implements the base class for the TaskGraphConf class, removing the template arguments and providing ...
Definition: AnyTaskGraphConf.hpp:66
void setInputConnector(std::shared_ptr< AnyConnector > connector) override
Sets the input BaseConnector.
Definition: TaskManager.hpp:318
EdgeDescriptor * copy(AnyTaskGraphConf *graph) override
Creates a copy of the edge descriptor to be added to other graphs, such as those within execution pip...
Definition: ProducerConsumerEdge.hpp:101
The edge descriptor is an interface used to describe how an edge is applied and copied to a task grap...
Definition: EdgeDescriptor.hpp:39
void setOutputConnector(std::shared_ptr< AnyConnector > connector) override
Sets the output BaseConnector.
Definition: TaskManager.hpp:330
Implements the edge descriptor interface to build edges for a task graph.
Implements the producer consumer edge that connects two tasks where one task is producing data and th...
Definition: ProducerConsumerEdge.hpp:40
An interface to process input data and forward results within a TaskGraph.
Definition: Bookkeeper.hpp:23
virtual std::string getName() override
Virtual function to get the name of an ITask.
Definition: ITask.hpp:236