HTGS  v2.0
The Hybrid Task Graph Scheduler
AnyConnector.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_ANYCONNECTOR_HPP
13 #define HTGS_ANYCONNECTOR_HPP
14 
15 #include <atomic>
16 #include <sstream>
17 
18 #include <htgs/api/IData.hpp>
20 
21 namespace htgs {
22 
39 class AnyConnector {
40  public:
41 
46 
50  virtual ~AnyConnector() {}
51 
52 #ifdef PROFILE_QUEUE
53 
58  virtual std::string getQueueTiming() = 0;
59 #endif
60 
68  this->producerTaskCount--;
69  }
70 
75  size_t getProducerCount() {
76  return this->producerTaskCount;
77  }
78 
86 
91  std::string getDotId() {
92  std::ostringstream inConn;
93  inConn << "x" << this;
94  std::string inConnStr = inConn.str();
95 
96  return inConnStr;
97  }
98 
104  std::string genDot(int flags) {
105  return getDotId() + "[label=\""
106  + ((flags & DOTGEN_FLAG_SHOW_CONNECTOR_VERBOSE) == 0 ? std::to_string(this->getProducerCount()) : "Active Producers: " + std::to_string(this->getProducerCount()))
107  + ((flags & DOTGEN_FLAG_SHOW_CURRENT_Q_SZ) == 0 && (flags & DOTGEN_FLAG_SHOW_CONNECTOR_VERBOSE) == 0 ? "" : "\\n Queue Size: " + std::to_string(this->getQueueSize()))
108 #ifdef PROFILE_QUEUE
109  + ", enqLock, deqLock, enqWait, deqWait::" + getQueueTiming()
110 #endif
111  + "\",shape=box,style=rounded,color=black,width=.2,height=.2];\n";
112 
113  }
114 
119  virtual std::string typeName() = 0;
120 
127  virtual bool isInputTerminated() = 0;
128 
137  virtual void wakeupConsumer() = 0;
138 
146  virtual AnyConnector *copy() = 0;
147 
153  virtual void produceAnyData(std::shared_ptr<IData> data) = 0;
154 
160  virtual void profileProduce(size_t numThreads) = 0;
161 
168  virtual void profileConsume(size_t numThreads, bool showQueueSize) = 0;
169 
174  virtual size_t getMaxQueueSize() = 0;
175 
180  virtual size_t getQueueSize() = 0;
181 
185  virtual void resetMaxQueueSize() = 0;
186 
187  private:
188  std::atomic_size_t producerTaskCount;
189 
190 };
191 }
192 
193 #endif //HTGS_ANYCONNECTOR_HPP
virtual void profileConsume(size_t numThreads, bool showQueueSize)=0
Provides profile output for the consume operation.
std::atomic_size_t producerTaskCount
The number of producers adding data to the connector.
Definition: AnyConnector.hpp:188
virtual void profileProduce(size_t numThreads)=0
Provide profile output for the produce operation.
AnyConnector()
Constructor initializing the producer task count to 0.
Definition: AnyConnector.hpp:45
virtual ~AnyConnector()
Virtual destructor.
Definition: AnyConnector.hpp:50
virtual void produceAnyData(std::shared_ptr< IData > data)=0
Produces any data into the queue.
std::string genDot(int flags)
Generates the dot representation for this connector.
Definition: AnyConnector.hpp:104
Parent class for Connector, which removes the template type of the Connector.
Definition: AnyConnector.hpp:39
void incrementInputTaskCount()
Increments the number of tasks producing data for the Connector.
Definition: AnyConnector.hpp:85
virtual AnyConnector * copy()=0
Creates a copy of the BaseConnector.
virtual bool isInputTerminated()=0
Checks whether the producer for this Connector has finished pushing data onto its queue...
void producerFinished()
Indicates to the Connector that the producer has finished producing data for the Connector.
Definition: AnyConnector.hpp:67
virtual size_t getQueueSize()=0
Gets the size of the queue that this connector has in its data queue.
virtual void wakeupConsumer()=0
Awakens all Tasks that are consuming data from this connector.
Implements the IData class, which is used for all data types entering/leaving a task graph...
size_t getProducerCount()
Gets the number of producers producing data for the connector.
Definition: AnyConnector.hpp:75
std::string getDotId()
Gets the id used for dot graphs for GraphViz.
Definition: AnyConnector.hpp:91
virtual size_t getMaxQueueSize()=0
Gets the maximum queue size that this connector has in its data queue.
virtual void resetMaxQueueSize()=0
Resets the max queue size profile.
virtual std::string typeName()=0
Gets the demangled type name of the connector.
Definition: Bookkeeper.hpp:23
Defines DOTGEN flags used for dot file generation.
#define DOTGEN_FLAG_SHOW_CONNECTOR_VERBOSE
Shows verbose information within each connector in the graph.
Definition: TaskGraphDotGenFlags.hpp:92
#define DOTGEN_FLAG_SHOW_CURRENT_Q_SZ
Displays the current queue size within each connector.
Definition: TaskGraphDotGenFlags.hpp:86