Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
concurrency::AlgorithmNode Class Reference

#include <src/PrecedenceRulesGraph.h>

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

Public Member Functions

 AlgorithmNode (PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &algoName, bool inverted, bool allPass, bool IOBound)
 Constructor. More...
 
 ~AlgorithmNode ()
 Destructor. More...
 
void initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map) override
 Initialize. More...
 
bool accept (IGraphVisitor &visitor) override
 
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...
 
void setIOBound (bool value)
 Set the I/O-boundness flag. More...
 
bool isIOBound () const
 Check if algorithm is I/O-bound. 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
 
int updateState (AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
 Method to set algos to CONTROLREADY, if possible. More...
 
bool promoteToControlReadyState (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
 XXX: CF tests. More...
 
bool promoteToDataReadyState (const int &slotNum, const AlgorithmNode *requestor=nullptr) const
 
void updateDecision (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const override
 XXX: CF tests. More...
 
void printState (std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
 Print a string representing the control flow state. More...
 
- Public Member Functions inherited from concurrency::ControlFlowNode
 ControlFlowNode (PrecedenceRulesGraph &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...
 
bool m_isIOBound
 If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck) More...
 

Additional Inherited Members

- Public Attributes inherited from concurrency::ControlFlowNode
PrecedenceRulesGraphm_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 140 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 143 of file PrecedenceRulesGraph.h.

143  :
144  ControlFlowNode(graph, nodeIndex, algoName),
145  m_algoIndex(0),m_algoName(algoName),m_inverted(inverted),m_allPass(allPass),m_rank(-1),m_isIOBound(IOBound)
146  {};
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
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.
bool m_isIOBound
If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)
bool m_allPass
Whether the selection result is relevant or always "pass".
concurrency::AlgorithmNode::~AlgorithmNode ( )

Destructor.

Definition at line 221 of file PrecedenceRulesGraph.cpp.

222  {
223 
224  for ( auto node : m_outputs ) {
225  delete node;
226  }
227  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode&#39;...

Member Function Documentation

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

Implements concurrency::ControlFlowNode.

Definition at line 406 of file PrecedenceRulesGraph.cpp.

407  {
408 
409  if ( visitor.visitEnter( *this ) ) {
410  visitor.visit( *this );
411  return true; // visitor was accepted to promote the algorithm
412  }
413 
414  return false; // visitor was rejected (since the algorithm already produced a decision)
415  }
void concurrency::AlgorithmNode::addConsumerNode ( AlgorithmNode node)
inline

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

Definition at line 159 of file PrecedenceRulesGraph.h.

159 { 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 432 of file PrecedenceRulesGraph.cpp.

433  {
434 
435  if ( std::find( m_inputs.begin(), m_inputs.end(), node ) == m_inputs.end() ) m_inputs.push_back( node );
436  }
T find(T...args)
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode&#39;s.
void concurrency::AlgorithmNode::addOutputDataNode ( DataNode node)

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

Definition at line 425 of file PrecedenceRulesGraph.cpp.

426  {
427 
428  if ( std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
429  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode&#39;...
T find(T...args)
void concurrency::AlgorithmNode::addParentNode ( DecisionNode node)

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

Definition at line 418 of file PrecedenceRulesGraph.cpp.

419  {
420 
421  if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
422  }
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 157 of file PrecedenceRulesGraph.h.

157 { 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 161 of file PrecedenceRulesGraph.h.

161 { 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 292 of file PrecedenceRulesGraph.cpp.

293  {
294 
295  bool result = true; //return true if an algorithm has no data inputs
296  auto& states = m_graph->getAlgoStates( slotNum );
297 
298  for ( auto dataNode : m_inputs ) {
299  // return false if the input has no producers at all (normally this case must be
300  // forbidden, and must be invalidated at configuration time)
301  result = false;
302  for ( auto algoNode : dataNode->getProducers() )
303  if ( State::EVTACCEPTED == states[algoNode->getAlgoIndex()] ) {
304  result = true;
305  break; // skip checking other producers if one was found to be executed
306  }
307 
308  if (!result) break; // skip checking other inputs if this input was not produced yet
309  }
310 
311  return result;
312  }
PrecedenceRulesGraph * m_graph
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode&#39;s.
bool concurrency::AlgorithmNode::dataDependenciesSatisfied ( AlgsExecutionStates states) const

Definition at line 315 of file PrecedenceRulesGraph.cpp.

316  {
317 
318  bool result = true;
319  for ( auto dataNode : m_inputs ) {
320 
321  result = false;
322  for ( auto algoNode : dataNode->getProducers() )
323  if ( State::EVTACCEPTED == states[algoNode->getAlgoIndex()] ) {
324  result = true;
325  break;
326  }
327 
328  if ( !result ) break;
329  }
330 
331  return result;
332  }
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode&#39;s.
const unsigned int& concurrency::AlgorithmNode::getAlgoIndex ( ) const
inline

XXX: CF tests.

Definition at line 183 of file PrecedenceRulesGraph.h.

183 { 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 163 of file PrecedenceRulesGraph.h.

163 { 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 167 of file PrecedenceRulesGraph.h.

167 {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 176 of file PrecedenceRulesGraph.h.

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

Get all supplier nodes.

Definition at line 174 of file PrecedenceRulesGraph.h.

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

Get Algorithm rank.

Definition at line 180 of file PrecedenceRulesGraph.h.

180 {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 165 of file PrecedenceRulesGraph.h.

165 {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)
overridevirtual

Initialize.

Implements concurrency::ControlFlowNode.

Definition at line 230 of file PrecedenceRulesGraph.cpp.

231  {
232 
233  m_algoIndex = algname_index_map.at( m_algoName );
234  }
unsigned int m_algoIndex
The index of the algorithm.
std::string m_algoName
The name of the algorithm.
bool concurrency::AlgorithmNode::isIOBound ( ) const
inline

Check if algorithm is I/O-bound.

Definition at line 187 of file PrecedenceRulesGraph.h.

187 {return m_isIOBound;}
bool m_isIOBound
If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)
void concurrency::AlgorithmNode::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
overridevirtual

Print a string representing the control flow state.

Implements concurrency::ControlFlowNode.

Definition at line 335 of file PrecedenceRulesGraph.cpp.

337  {
338  output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
339  << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
340  << ")"
341  << ", in state: " << AlgsExecutionStates::stateNames[states[m_algoIndex]] << std::endl;
342  }
unsigned int m_algoIndex
The index of the algorithm.
T endl(T...args)
std::string stateToString(const int &stateId) const
Translation between state id and name.
STL class.
static std::map< State, std::string > stateNames
bool concurrency::AlgorithmNode::promoteToControlReadyState ( const int &  slotNum,
AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const
overridevirtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 237 of file PrecedenceRulesGraph.cpp.

239  {
240 
241  auto& state = states[m_algoIndex];
242  bool result = false;
243 
244  if ( State::INITIAL == state ) {
245  states.updateState( m_algoIndex, State::CONTROLREADY ).ignore();
246  // std::cout << "----> UPDATING ALGORITHM to CONTROLREADY: " << m_algoName << std::endl;
247  result = true;
248  } else if ( State::CONTROLREADY == state ) {
249  result = true;
250  }
251 
252  return result;
253  }
unsigned int m_algoIndex
The index of the algorithm.
void ignore() const
Definition: StatusCode.h:106
StatusCode updateState(unsigned int iAlgo, State newState)
bool concurrency::AlgorithmNode::promoteToDataReadyState ( const int &  slotNum,
const AlgorithmNode requestor = nullptr 
) const

Definition at line 256 of file PrecedenceRulesGraph.cpp.

257  {
258 
259  auto& states = m_graph->getAlgoStates( slotNum );
260  auto& state = states[m_algoIndex];
261  bool result = false;
262 
263  if ( State::CONTROLREADY == state ) {
264  if ( dataDependenciesSatisfied( slotNum ) ) {
265  // std::cout << "----> UPDATING ALGORITHM to DATAREADY: " << m_algoName << std::endl;
266  states.updateState( m_algoIndex, State::DATAREADY ).ignore();
267  result = true;
268 
269  // m_graph->addEdgeToExecutionPlan(requestor, this);
270 
271  /*
272  auto xtime = std::chrono::high_resolution_clock::now();
273  std::stringstream s;
274  s << getNodeName() << ", "
275  << (xtime-m_graph->getInitTime()).count() << "\n";
276  std::ofstream myfile;
277  myfile.open("DRTiming.csv", std::ios::app);
278  myfile << s.str();
279  myfile.close();
280  */
281  }
282  } else if ( State::DATAREADY == state ) {
283  result = true;
284  } else if ( State::SCHEDULED == state ) {
285  result = true;
286  }
287 
288  return result;
289  }
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.
PrecedenceRulesGraph * m_graph
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
void concurrency::AlgorithmNode::setIOBound ( bool  value)
inline

Set the I/O-boundness flag.

Definition at line 185 of file PrecedenceRulesGraph.h.

185 { m_isIOBound = value;}
bool m_isIOBound
If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)
void concurrency::AlgorithmNode::setRank ( float &  rank)
inline

Set Algorithm rank.

Definition at line 178 of file PrecedenceRulesGraph.h.

178 {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
overridevirtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 371 of file PrecedenceRulesGraph.cpp.

373  {
374 
375  const State& state = states[m_algoIndex];
376  int decision = -1;
377  requestor = this;
378 
379  // now derive the proper result to pass back
380  if ( true == m_allPass ) {
381  decision = 1;
382  } else if ( State::EVTACCEPTED == state ) {
383  decision = !m_inverted;
384  } else if ( State::EVTREJECTED == state ) {
385  decision = m_inverted;
386  } else {
387  decision = -1; // result not known yet
388  }
389 
390  node_decisions[m_nodeIndex] = decision;
391 
392  if ( -1 != decision ) {
393  for ( auto output : m_outputs )
394  for ( auto consumer : output->getConsumers() ) consumer->promoteToDataReadyState( slotNum, requestor );
395 
396  auto vis = concurrency::Supervisor( slotNum );
397  for ( auto p : m_parents ) {
398  //p->updateDecision( slotNum, states, node_decisions, requestor );
399  p->accept(vis);
400  }
401 
402  }
403  }
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode&#39;...
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
overridevirtual

Method to set algos to CONTROLREADY, if possible.

Implements concurrency::ControlFlowNode.

Definition at line 345 of file PrecedenceRulesGraph.cpp.

346  {
347  // check whether we already had a result earlier
348  // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
349  // since we reached this point in the control flow, this algorithm is supposed to run
350  // if it hasn't already
351  const State& state = states[m_algoIndex];
352  unsigned int decision = -1;
353  if ( State::INITIAL == state ) {
354  states.updateState( m_algoIndex, State::CONTROLREADY ).ignore();
355  }
356  // now derive the proper result to pass back
357  if ( true == m_allPass ) {
358  decision = 1;
359  } else if ( State::EVTACCEPTED == state ) {
360  decision = !m_inverted;
361  } else if ( State::EVTREJECTED == state ) {
362  decision = m_inverted;
363  } else {
364  decision = -1; // result not known yet
365  }
366  node_decisions[m_nodeIndex] = decision;
367  return decision;
368  }
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:106
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 212 of file PrecedenceRulesGraph.h.

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

The name of the algorithm.

Definition at line 214 of file PrecedenceRulesGraph.h.

bool concurrency::AlgorithmNode::m_allPass
private

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

Definition at line 218 of file PrecedenceRulesGraph.h.

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

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

Definition at line 226 of file PrecedenceRulesGraph.h.

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

Inputs of the algorithm, represented as DataNode's.

Definition at line 232 of file PrecedenceRulesGraph.h.

bool concurrency::AlgorithmNode::m_inverted
private

Whether the selection result is negated or not.

Definition at line 216 of file PrecedenceRulesGraph.h.

bool concurrency::AlgorithmNode::m_isIOBound
private

If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)

Definition at line 238 of file PrecedenceRulesGraph.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 230 of file PrecedenceRulesGraph.h.

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

XXX: CF tests.

Definition at line 220 of file PrecedenceRulesGraph.h.

float concurrency::AlgorithmNode::m_rank
private

Algorithm rank of any kind.

Definition at line 234 of file PrecedenceRulesGraph.h.

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

Representatives (including clones) of the node.

Definition at line 236 of file PrecedenceRulesGraph.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 224 of file PrecedenceRulesGraph.h.


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