concurrency::AlgorithmNode Class Reference

#include <src/ExecutionFlowGraph.h>

Inheritance diagram for concurrency::AlgorithmNode:
Collaboration diagram for concurrency::AlgorithmNode:

Public Member Functions

 AlgorithmNode (ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &algoName, bool inverted, bool allPass)
 Constructor. More...
 
 ~AlgorithmNode ()
 Destructor. More...
 
virtual void initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map)
 Initialize. More...
 
virtual bool accept (IGraphVisitor &visitor)
 
void addParentNode (DecisionNode *node)
 XXX: CF tests. Method to add a parent node. More...
 
void addSupplierNode (AlgorithmNode *node)
 Associate an AlgorithmNode, which is a data supplier for this one. More...
 
void addConsumerNode (AlgorithmNode *node)
 Associate an AlgorithmNode, which is a data consumer of this one. More...
 
void attachAlgorithm (IAlgorithm *ialgo)
 Attach Algorithm representative. More...
 
const std::vector< IAlgorithm * > & getAlgorithmRepresentatives () const
 get Algorithm representatives More...
 
const std::vector< AlgorithmNode * > & getSupplierNodes () const
 Get all supplier nodes. More...
 
const std::vector< AlgorithmNode * > & getConsumerNodes () const
 Get all consumer nodes. More...
 
void addOutputDataNode (DataNode *node)
 Associate an AlgorithmNode, which is a data supplier for this one. More...
 
void addInputDataNode (DataNode *node)
 Associate an AlgorithmNode, which is a data consumer of this one. More...
 
const std::vector< DataNode * > & getOutputDataNodes () const
 Get all supplier nodes. More...
 
const std::vector< DataNode * > & getInputDataNodes () const
 Get all consumer nodes. More...
 
void setRank (float &rank)
 Set Algorithm rank. More...
 
const float & getRank () const
 Get Algorithm rank. More...
 
const unsigned int & getAlgoIndex () const
 XXX: CF tests. More...
 
bool dataDependenciesSatisfied (const int &slotNum) const
 Method to check whether the Algorithm has its all data dependency satisfied. More...
 
bool dataDependenciesSatisfied (AlgsExecutionStates &states) const
 
virtual int updateState (AlgsExecutionStates &states, std::vector< int > &node_decisions) const
 Method to set algos to CONTROLREADY, if possible. More...
 
virtual bool promoteToControlReadyState (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
 XXX: CF tests. More...
 
bool promoteToDataReadyState (const int &slotNum, const AlgorithmNode *requestor=nullptr) const
 
virtual void updateDecision (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const
 XXX: CF tests. More...
 
virtual void printState (std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
 Print a string representing the control flow state. More...
 
- Public Member Functions inherited from concurrency::ControlFlowNode
 ControlFlowNode (ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
 Constructor. More...
 
virtual ~ControlFlowNode ()
 Destructor. More...
 
const unsigned int & getNodeIndex () const
 XXX: CF tests. More...
 
const std::stringgetNodeName () const
 

Private Attributes

unsigned int m_algoIndex
 The index of the algorithm. More...
 
std::string m_algoName
 The name of the algorithm. More...
 
bool m_inverted
 Whether the selection result is negated or not. More...
 
bool m_allPass
 Whether the selection result is relevant or always "pass". More...
 
std::vector< DecisionNode * > m_parents
 XXX: CF tests. More...
 
std::vector< AlgorithmNode * > m_suppliers
 Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input needed for the algorithm. More...
 
std::vector< AlgorithmNode * > m_consumers
 AlgorithmNodes that represent algorithms which need the output of the algorithm. More...
 
std::vector< DataNode * > m_outputs
 Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode's. More...
 
std::vector< DataNode * > m_inputs
 Inputs of the algorithm, represented as DataNode's. More...
 
float m_rank
 Algorithm rank of any kind. More...
 
std::vector< IAlgorithm * > m_representatives
 Representatives (including clones) of the node. More...
 

Additional Inherited Members

- Public Attributes inherited from concurrency::ControlFlowNode
ExecutionFlowGraphm_graph
 
- Protected Member Functions inherited from concurrency::ControlFlowNode
std::string stateToString (const int &stateId) const
 Translation between state id and name. More...
 
- Protected Attributes inherited from concurrency::ControlFlowNode
unsigned int m_nodeIndex
 
std::string m_nodeName
 

Detailed Description

Definition at line 137 of file ExecutionFlowGraph.h.

Constructor & Destructor Documentation

concurrency::AlgorithmNode::AlgorithmNode ( ExecutionFlowGraph graph,
unsigned int  nodeIndex,
const std::string algoName,
bool  inverted,
bool  allPass 
)
inline

Constructor.

Definition at line 140 of file ExecutionFlowGraph.h.

140  :
141  ControlFlowNode(graph, nodeIndex, algoName),
142  m_algoIndex(0),m_algoName(algoName),m_inverted(inverted),m_allPass(allPass),m_rank(-1)
143  {};
unsigned int m_algoIndex
The index of the algorithm.
std::string m_algoName
The name of the algorithm.
bool m_inverted
Whether the selection result is negated or not.
float m_rank
Algorithm rank of any kind.
ControlFlowNode(ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
bool m_allPass
Whether the selection result is relevant or always "pass".
concurrency::AlgorithmNode::~AlgorithmNode ( )

Destructor.

Definition at line 195 of file ExecutionFlowGraph.cpp.

195  {
196 
197  for (auto node : m_outputs) {
198  delete node;
199  }
200  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...

Member Function Documentation

bool concurrency::AlgorithmNode::accept ( IGraphVisitor visitor)
virtual

Implements concurrency::ControlFlowNode.

Definition at line 372 of file ExecutionFlowGraph.cpp.

372  {
373 
374  if (visitor.visitEnter(*this)) {
375  bool result = visitor.visit(*this);
376  if (result) return false;
377  }
378 
379  return true;
380 
381  }
void concurrency::AlgorithmNode::addConsumerNode ( AlgorithmNode node)
inline

Associate an AlgorithmNode, which is a data consumer of this one.

Definition at line 156 of file ExecutionFlowGraph.h.

156 { m_consumers.push_back(node); }
std::vector< AlgorithmNode * > m_consumers
AlgorithmNodes that represent algorithms which need the output of the algorithm.
void concurrency::AlgorithmNode::addInputDataNode ( DataNode node)

Associate an AlgorithmNode, which is a data consumer of this one.

Definition at line 398 of file ExecutionFlowGraph.cpp.

398  {
399 
400  if (std::find(m_inputs.begin(),m_inputs.end(),node) == m_inputs.end())
401  m_inputs.push_back(node);
402  }
T find(T...args)
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
void concurrency::AlgorithmNode::addOutputDataNode ( DataNode node)

Associate an AlgorithmNode, which is a data supplier for this one.

Definition at line 391 of file ExecutionFlowGraph.cpp.

391  {
392 
393  if (std::find(m_outputs.begin(),m_outputs.end(),node) == m_outputs.end())
394  m_outputs.push_back(node);
395  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
T find(T...args)
void concurrency::AlgorithmNode::addParentNode ( DecisionNode node)

XXX: CF tests. Method to add a parent node.

Definition at line 384 of file ExecutionFlowGraph.cpp.

384  {
385 
386  if (std::find(m_parents.begin(), m_parents.end(), node) == m_parents.end())
387  m_parents.push_back(node);
388  }
std::vector< DecisionNode * > m_parents
XXX: CF tests.
T find(T...args)
void concurrency::AlgorithmNode::addSupplierNode ( AlgorithmNode node)
inline

Associate an AlgorithmNode, which is a data supplier for this one.

Definition at line 154 of file ExecutionFlowGraph.h.

154 { m_suppliers.push_back(node); }
std::vector< AlgorithmNode * > m_suppliers
Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input ...
void concurrency::AlgorithmNode::attachAlgorithm ( IAlgorithm ialgo)
inline

Attach Algorithm representative.

Definition at line 158 of file ExecutionFlowGraph.h.

158 { m_representatives.push_back(ialgo); }
T push_back(T...args)
std::vector< IAlgorithm * > m_representatives
Representatives (including clones) of the node.
bool concurrency::AlgorithmNode::dataDependenciesSatisfied ( const int &  slotNum) const

Method to check whether the Algorithm has its all data dependency satisfied.

Definition at line 264 of file ExecutionFlowGraph.cpp.

264  {
265 
266  bool result = true;
267  auto& states = m_graph->getAlgoStates(slotNum);
268 
269  for (auto dataNode : m_inputs) {
270  result = false;
271  for (auto algoNode : dataNode->getProducers())
272  if (State::EVTACCEPTED == states[algoNode->getAlgoIndex()]) {
273  result = true;
274  break;
275  }
276  if (!result) break;
277  }
278 
279  return result;
280  }
ExecutionFlowGraph * m_graph
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
bool concurrency::AlgorithmNode::dataDependenciesSatisfied ( AlgsExecutionStates states) const

Definition at line 283 of file ExecutionFlowGraph.cpp.

283  {
284 
285  bool result = true;
286  for (auto dataNode : m_inputs) {
287 
288  result = false;
289  for (auto algoNode : dataNode->getProducers())
290  if (State::EVTACCEPTED == states[algoNode->getAlgoIndex()]) {
291  result = true;
292  break;
293  }
294 
295  if (!result) break;
296  }
297 
298  return result;
299  }
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
const unsigned int& concurrency::AlgorithmNode::getAlgoIndex ( ) const
inline

XXX: CF tests.

Definition at line 180 of file ExecutionFlowGraph.h.

180 { return m_algoIndex; }
unsigned int m_algoIndex
The index of the algorithm.
const std::vector<IAlgorithm*>& concurrency::AlgorithmNode::getAlgorithmRepresentatives ( ) const
inline

get Algorithm representatives

Definition at line 160 of file ExecutionFlowGraph.h.

160 { return m_representatives; }
std::vector< IAlgorithm * > m_representatives
Representatives (including clones) of the node.
const std::vector<AlgorithmNode*>& concurrency::AlgorithmNode::getConsumerNodes ( ) const
inline

Get all consumer nodes.

Definition at line 164 of file ExecutionFlowGraph.h.

164 {return m_consumers;}
std::vector< AlgorithmNode * > m_consumers
AlgorithmNodes that represent algorithms which need the output of the algorithm.
const std::vector<DataNode*>& concurrency::AlgorithmNode::getInputDataNodes ( ) const
inline

Get all consumer nodes.

Definition at line 173 of file ExecutionFlowGraph.h.

173 {return m_inputs;}
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
const std::vector<DataNode*>& concurrency::AlgorithmNode::getOutputDataNodes ( ) const
inline

Get all supplier nodes.

Definition at line 171 of file ExecutionFlowGraph.h.

171 {return m_outputs;}
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
const float& concurrency::AlgorithmNode::getRank ( ) const
inline

Get Algorithm rank.

Definition at line 177 of file ExecutionFlowGraph.h.

177 {return m_rank;}
float m_rank
Algorithm rank of any kind.
const std::vector<AlgorithmNode*>& concurrency::AlgorithmNode::getSupplierNodes ( ) const
inline

Get all supplier nodes.

Definition at line 162 of file ExecutionFlowGraph.h.

162 {return m_suppliers;}
std::vector< AlgorithmNode * > m_suppliers
Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input ...
void concurrency::AlgorithmNode::initialize ( const std::unordered_map< std::string, unsigned int > &  algname_index_map)
virtual

Initialize.

Implements concurrency::ControlFlowNode.

Definition at line 203 of file ExecutionFlowGraph.cpp.

203  {
204 
205  m_algoIndex = algname_index_map.at(m_algoName);
206  }
unsigned int m_algoIndex
The index of the algorithm.
std::string m_algoName
The name of the algorithm.
void concurrency::AlgorithmNode::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
virtual

Print a string representing the control flow state.

Implements concurrency::ControlFlowNode.

Definition at line 302 of file ExecutionFlowGraph.cpp.

305  {
306  output << std::string(recursionLevel, ' ') << m_nodeName
307  << " (" << m_nodeIndex << ")" << ", w/ decision: "
308  << stateToString(node_decisions[m_nodeIndex])
309  << "(" << node_decisions[m_nodeIndex] << ")"
310  << ", in state: " << AlgsExecutionStates::stateNames[states[m_algoIndex]]
311  << std::endl;
312  }
std::string stateToString(const int &stateId) const
Translation between state id and name.
unsigned int m_algoIndex
The index of the algorithm.
T endl(T...args)
STL class.
static std::map< State, std::string > stateNames
bool concurrency::AlgorithmNode::promoteToControlReadyState ( const int &  slotNum,
AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const
virtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 209 of file ExecutionFlowGraph.cpp.

211  {
212 
213  auto& state = states[m_algoIndex];
214  bool result = false;
215 
216  if (State::INITIAL == state) {
217  states.updateState(m_algoIndex, State::CONTROLREADY).ignore();
218  //std::cout << "----> UPDATING ALGORITHM to CONTROLREADY: " << m_algoName << std::endl;
219  result = true;
220  } else if (State::CONTROLREADY == state) {
221  result = true;
222  }
223 
224  return result;
225  }
unsigned int m_algoIndex
The index of the algorithm.
void ignore() const
Definition: StatusCode.h:108
StatusCode updateState(unsigned int iAlgo, State newState)
bool concurrency::AlgorithmNode::promoteToDataReadyState ( const int &  slotNum,
const AlgorithmNode requestor = nullptr 
) const

Definition at line 228 of file ExecutionFlowGraph.cpp.

229  {
230 
231  auto& states = m_graph->getAlgoStates(slotNum);
232  auto& state = states[m_algoIndex];
233  bool result = false;
234 
235  if (State::CONTROLREADY == state) {
236  if (dataDependenciesSatisfied(slotNum)) {
237  //std::cout << "----> UPDATING ALGORITHM to DATAREADY: " << m_algoName << std::endl;
238  states.updateState(m_algoIndex, State::DATAREADY).ignore();
239  result = true;
240 
241  //m_graph->addEdgeToExecutionPlan(requestor, this);
242 
243  /*
244  auto xtime = std::chrono::high_resolution_clock::now();
245  std::stringstream s;
246  s << getNodeName() << ", "
247  << (xtime-m_graph->getInitTime()).count() << "\n";
248  std::ofstream myfile;
249  myfile.open("DRTiming.csv", std::ios::app);
250  myfile << s.str();
251  myfile.close();
252  */
253  }
254  } else if (State::DATAREADY == state) {
255  result = true;
256  } else if (State::SCHEDULED == state) {
257  result = true;
258  }
259 
260  return result;
261  }
unsigned int m_algoIndex
The index of the algorithm.
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
ExecutionFlowGraph * m_graph
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
void concurrency::AlgorithmNode::setRank ( float &  rank)
inline

Set Algorithm rank.

Definition at line 175 of file ExecutionFlowGraph.h.

175 {m_rank = rank;}
float m_rank
Algorithm rank of any kind.
void concurrency::AlgorithmNode::updateDecision ( const int &  slotNum,
AlgsExecutionStates states,
std::vector< int > &  node_decisions,
const AlgorithmNode requestor = nullptr 
) const
virtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 339 of file ExecutionFlowGraph.cpp.

342  {
343 
344  const State& state = states[m_algoIndex];
345  int decision = -1;
346  requestor = this;
347 
348  // now derive the proper result to pass back
349  if (true == m_allPass) {
350  decision = 1;
351  } else if (State::EVTACCEPTED == state) {
352  decision = !m_inverted;
353  } else if (State::EVTREJECTED == state) {
354  decision = m_inverted;
355  } else {
356  decision = -1; // result not known yet
357  }
358 
359  node_decisions[m_nodeIndex] = decision;
360 
361  if (-1 != decision) {
362  for (auto output : m_outputs)
363  for (auto consumer : output->getConsumers())
364  consumer->promoteToDataReadyState(slotNum, requestor);
365 
366  for (auto p : m_parents)
367  p->updateDecision(slotNum, states, node_decisions, requestor);
368  }
369  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
unsigned int m_algoIndex
The index of the algorithm.
std::vector< DecisionNode * > m_parents
XXX: CF tests.
bool m_inverted
Whether the selection result is negated or not.
State
Execution states of the algorithms.
bool m_allPass
Whether the selection result is relevant or always "pass".
int concurrency::AlgorithmNode::updateState ( AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const
virtual

Method to set algos to CONTROLREADY, if possible.

Implements concurrency::ControlFlowNode.

Definition at line 315 of file ExecutionFlowGraph.cpp.

316  {
317  // check whether we already had a result earlier
318  // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
319  // since we reached this point in the control flow, this algorithm is supposed to run
320  // if it hasn't already
321  const State& state = states[m_algoIndex];
322  unsigned int decision = -1;
323  if (State::INITIAL == state) {states.updateState(m_algoIndex, State::CONTROLREADY).ignore();}
324  // now derive the proper result to pass back
325  if (true == m_allPass) {
326  decision = 1;
327  } else if (State::EVTACCEPTED == state) {
328  decision = !m_inverted;
329  } else if (State::EVTREJECTED == state) {
330  decision = m_inverted;
331  } else {
332  decision = -1; // result not known yet
333  }
334  node_decisions[m_nodeIndex] = decision;
335  return decision;
336  }
unsigned int m_algoIndex
The index of the algorithm.
bool m_inverted
Whether the selection result is negated or not.
void ignore() const
Definition: StatusCode.h:108
State
Execution states of the algorithms.
bool m_allPass
Whether the selection result is relevant or always "pass".
StatusCode updateState(unsigned int iAlgo, State newState)

Member Data Documentation

unsigned int concurrency::AlgorithmNode::m_algoIndex
private

The index of the algorithm.

Definition at line 205 of file ExecutionFlowGraph.h.

std::string concurrency::AlgorithmNode::m_algoName
private

The name of the algorithm.

Definition at line 207 of file ExecutionFlowGraph.h.

bool concurrency::AlgorithmNode::m_allPass
private

Whether the selection result is relevant or always "pass".

Definition at line 211 of file ExecutionFlowGraph.h.

std::vector<AlgorithmNode*> concurrency::AlgorithmNode::m_consumers
private

AlgorithmNodes that represent algorithms which need the output of the algorithm.

Definition at line 219 of file ExecutionFlowGraph.h.

std::vector<DataNode*> concurrency::AlgorithmNode::m_inputs
private

Inputs of the algorithm, represented as DataNode's.

Definition at line 225 of file ExecutionFlowGraph.h.

bool concurrency::AlgorithmNode::m_inverted
private

Whether the selection result is negated or not.

Definition at line 209 of file ExecutionFlowGraph.h.

std::vector<DataNode*> concurrency::AlgorithmNode::m_outputs
private

Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode's.

Definition at line 223 of file ExecutionFlowGraph.h.

std::vector<DecisionNode*> concurrency::AlgorithmNode::m_parents
private

XXX: CF tests.

Definition at line 213 of file ExecutionFlowGraph.h.

float concurrency::AlgorithmNode::m_rank
private

Algorithm rank of any kind.

Definition at line 227 of file ExecutionFlowGraph.h.

std::vector<IAlgorithm*> concurrency::AlgorithmNode::m_representatives
private

Representatives (including clones) of the node.

Definition at line 229 of file ExecutionFlowGraph.h.

std::vector<AlgorithmNode*> concurrency::AlgorithmNode::m_suppliers
private

Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input needed for the algorithm.

Definition at line 217 of file ExecutionFlowGraph.h.


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