The Gaudi Framework  v28r3 (cc1cf868)
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...
 
const std::vector< DecisionNode * > & getParentDecisionHubs () const
 Get all parent decision hubs. 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 isOptimist () const
 Check if positive control flow decision is enforced. More...
 
bool isLiar () const
 Check if control flow logic is always inverted. More...
 
bool dataDependenciesSatisfied (const int &slotNum) const
 Method to check whether the Algorithm has its all data dependency satisfied. More...
 
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 390 of file PrecedenceRulesGraph.cpp.

391  {
392 
393  if ( visitor.visitEnter( *this ) ) {
394  visitor.visit( *this );
395  return true; // visitor was accepted to promote the algorithm
396  }
397 
398  return false; // visitor was rejected (since the algorithm already produced a decision)
399  }
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 416 of file PrecedenceRulesGraph.cpp.

417  {
418 
419  if ( std::find( m_inputs.begin(), m_inputs.end(), node ) == m_inputs.end() ) m_inputs.push_back( node );
420  }
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 409 of file PrecedenceRulesGraph.cpp.

410  {
411 
412  if ( std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
413  }
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 402 of file PrecedenceRulesGraph.cpp.

403  {
404 
405  if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
406  }
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.
const unsigned int& concurrency::AlgorithmNode::getAlgoIndex ( ) const
inline

XXX: CF tests.

Definition at line 185 of file PrecedenceRulesGraph.h.

185 { 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 178 of file PrecedenceRulesGraph.h.

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

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

Get all parent decision hubs.

Definition at line 169 of file PrecedenceRulesGraph.h.

169 {return m_parents;}
std::vector< DecisionNode * > m_parents
XXX: CF tests.
const float& concurrency::AlgorithmNode::getRank ( ) const
inline

Get Algorithm rank.

Definition at line 182 of file PrecedenceRulesGraph.h.

182 {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 189 of file PrecedenceRulesGraph.h.

189 {return m_isIOBound;}
bool m_isIOBound
If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)
bool concurrency::AlgorithmNode::isLiar ( ) const
inline

Check if control flow logic is always inverted.

Definition at line 193 of file PrecedenceRulesGraph.h.

193 {return m_inverted;};
bool m_inverted
Whether the selection result is negated or not.
bool concurrency::AlgorithmNode::isOptimist ( ) const
inline

Check if positive control flow decision is enforced.

Definition at line 191 of file PrecedenceRulesGraph.h.

191 {return m_allPass;};
bool m_allPass
Whether the selection result is relevant or always "pass".
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 315 of file PrecedenceRulesGraph.cpp.

317  {
318  output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
319  << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
320  << ")"
321  << ", in state: " << AlgsExecutionStates::stateNames[states[m_algoIndex]] << std::endl;
322  }
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 187 of file PrecedenceRulesGraph.h.

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

180 {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 351 of file PrecedenceRulesGraph.cpp.

353  {
354 
355  const State& state = states[m_algoIndex];
356  int decision = -1;
357  //requestor = this;
358 
359  // now derive the proper result to pass back
360  if ( true == m_allPass ) {
361  decision = 1;
362  } else if ( State::EVTACCEPTED == state ) {
363  decision = !m_inverted;
364  } else if ( State::EVTREJECTED == state ) {
365  decision = m_inverted;
366  } else {
367  decision = -1; // result not known yet
368  }
369 
370  node_decisions[m_nodeIndex] = decision;
371 
372  if ( -1 != decision ) {
373  auto& slot = (*m_graph->m_eventSlots)[slotNum];
374  auto promoter = DataReadyPromoter(slot);
375  for ( auto output : m_outputs )
376  for ( auto consumer : output->getConsumers() )
377  if (State::CONTROLREADY == states[consumer->getAlgoIndex()])
378  consumer->accept(promoter);
379 
380  auto vis = concurrency::Supervisor(slot);
381  for ( auto p : m_parents ) {
382  //p->updateDecision( slotNum, states, node_decisions, requestor );
383  p->accept(vis);
384  }
385 
386  }
387  }
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.
std::vector< EventSlot > * m_eventSlots
PrecedenceRulesGraph * m_graph
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 325 of file PrecedenceRulesGraph.cpp.

326  {
327  // check whether we already had a result earlier
328  // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
329  // since we reached this point in the control flow, this algorithm is supposed to run
330  // if it hasn't already
331  const State& state = states[m_algoIndex];
332  unsigned int decision = -1;
333  if ( State::INITIAL == state ) {
334  states.updateState( m_algoIndex, State::CONTROLREADY ).ignore();
335  }
336  // now derive the proper result to pass back
337  if ( true == m_allPass ) {
338  decision = 1;
339  } else if ( State::EVTACCEPTED == state ) {
340  decision = !m_inverted;
341  } else if ( State::EVTREJECTED == state ) {
342  decision = m_inverted;
343  } else {
344  decision = -1; // result not known yet
345  }
346  node_decisions[m_nodeIndex] = decision;
347  return decision;
348  }
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 217 of file PrecedenceRulesGraph.h.

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

The name of the algorithm.

Definition at line 219 of file PrecedenceRulesGraph.h.

bool concurrency::AlgorithmNode::m_allPass
private

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

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

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

Inputs of the algorithm, represented as DataNode's.

Definition at line 237 of file PrecedenceRulesGraph.h.

bool concurrency::AlgorithmNode::m_inverted
private

Whether the selection result is negated or not.

Definition at line 221 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 243 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 235 of file PrecedenceRulesGraph.h.

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

XXX: CF tests.

Definition at line 225 of file PrecedenceRulesGraph.h.

float concurrency::AlgorithmNode::m_rank
private

Algorithm rank of any kind.

Definition at line 239 of file PrecedenceRulesGraph.h.

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

Representatives (including clones) of the node.

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


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