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::string & getNodeName () 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 194 of file ExecutionFlowGraph.cpp.

194  {
195 
196  for (auto node : m_outputs) {
197  delete node;
198  }
199  }
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 367 of file ExecutionFlowGraph.cpp.

367  {
368 
369  if (visitor.visitEnter(*this)) {
370  bool result = visitor.visit(*this);
371  if (result) return false;
372  }
373 
374  return true;
375 
376  }
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 393 of file ExecutionFlowGraph.cpp.

393  {
394 
395  if (std::find(m_inputs.begin(),m_inputs.end(),node) == m_inputs.end())
396  m_inputs.push_back(node);
397  }
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 386 of file ExecutionFlowGraph.cpp.

386  {
387 
388  if (std::find(m_outputs.begin(),m_outputs.end(),node) == m_outputs.end())
389  m_outputs.push_back(node);
390  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
void concurrency::AlgorithmNode::addParentNode ( DecisionNode node)

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

Definition at line 379 of file ExecutionFlowGraph.cpp.

379  {
380 
381  if (std::find(m_parents.begin(), m_parents.end(), node) == m_parents.end())
382  m_parents.push_back(node);
383  }
std::vector< DecisionNode * > m_parents
XXX: CF tests.
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); }
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 262 of file ExecutionFlowGraph.cpp.

262  {
263 
264  bool result = true;
265  auto& states = m_graph->getAlgoStates(slotNum);
266 
267  for (auto dataNode : m_inputs) {
268  result = false;
269  for (auto algoNode : dataNode->getProducers())
270  if (State::EVTACCEPTED == states[algoNode->getAlgoIndex()]) {
271  result = true;
272  break;
273  }
274  if (!result) break;
275  }
276 
277  return result;
278  }
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 281 of file ExecutionFlowGraph.cpp.

281  {
282 
283  bool result = true;
284  for (auto dataNode : m_inputs) {
285 
286  result = false;
287  for (auto algoNode : dataNode->getProducers())
288  if (State::EVTACCEPTED == states[algoNode->getAlgoIndex()]) {
289  result = true;
290  break;
291  }
292 
293  if (!result) break;
294  }
295 
296  return result;
297  }
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 202 of file ExecutionFlowGraph.cpp.

202  {
203 
204  m_algoIndex = algname_index_map.at(m_algoName);
205  }
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 300 of file ExecutionFlowGraph.cpp.

303  {
304  output << std::string(recursionLevel, ' ') << m_nodeName << " (" << m_nodeIndex << ")" << ", w/ decision: "
305  << stateToString(node_decisions[m_nodeIndex]) << "(" << node_decisions[m_nodeIndex] << ")"
306  << ", in state: " << states[m_algoIndex] << std::endl;
307  }
std::string stateToString(const int &stateId) const
Translation between state id and name.
unsigned int m_algoIndex
The index of the algorithm.
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 208 of file ExecutionFlowGraph.cpp.

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

Definition at line 227 of file ExecutionFlowGraph.cpp.

227  {
228 
229  auto& states = m_graph->getAlgoStates(slotNum);
230  auto& state = states[m_algoIndex];
231  bool result = false;
232 
233  if (State::CONTROLREADY == state) {
234  if (dataDependenciesSatisfied(slotNum)) {
235  //std::cout << "----> UPDATING ALGORITHM to DATAREADY: " << m_algoName << std::endl;
236  states.updateState(m_algoIndex, State::DATAREADY);
237  result = true;
238 
239  //m_graph->addEdgeToExecutionPlan(requestor, this);
240 
241  /*
242  auto xtime = std::chrono::high_resolution_clock::now();
243  std::stringstream s;
244  s << getNodeName() << ", "
245  << (xtime-m_graph->getInitTime()).count() << "\n";
246  std::ofstream myfile;
247  myfile.open("DRTiming.csv", std::ios::app);
248  myfile << s.str();
249  myfile.close();
250  */
251  }
252  } else if (State::DATAREADY == state) {
253  result = true;
254  } else if (State::SCHEDULED == state) {
255  result = true;
256  }
257 
258  return result;
259  }
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 334 of file ExecutionFlowGraph.cpp.

337  {
338 
339  const State& state = states[m_algoIndex];
340  int decision = -1;
341  requestor = this;
342 
343  // now derive the proper result to pass back
344  if (true == m_allPass) {
345  decision = 1;
346  } else if (State::EVTACCEPTED == state) {
347  decision = !m_inverted;
348  } else if (State::EVTREJECTED == state) {
349  decision = m_inverted;
350  } else {
351  decision = -1; // result not known yet
352  }
353 
354  node_decisions[m_nodeIndex] = decision;
355 
356  if (-1 != decision) {
357  for (auto output : m_outputs)
358  for (auto consumer : output->getConsumers())
359  consumer->promoteToDataReadyState(slotNum, requestor);
360 
361  for (auto p : m_parents)
362  p->updateDecision(slotNum, states, node_decisions, requestor);
363  }
364  }
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 310 of file ExecutionFlowGraph.cpp.

311  {
312  // check whether we already had a result earlier
313  // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
314  // since we reached this point in the control flow, this algorithm is supposed to run
315  // if it hasn't already
316  const State& state = states[m_algoIndex];
317  unsigned int decision = -1;
318  if (State::INITIAL == state) {states.updateState(m_algoIndex, State::CONTROLREADY);}
319  // now derive the proper result to pass back
320  if (true == m_allPass) {
321  decision = 1;
322  } else if (State::EVTACCEPTED == state) {
323  decision = !m_inverted;
324  } else if (State::EVTREJECTED == state) {
325  decision = m_inverted;
326  } else {
327  decision = -1; // result not known yet
328  }
329  node_decisions[m_nodeIndex] = decision;
330  return decision;
331  }
unsigned int m_algoIndex
The index of the algorithm.
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".
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: