All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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, 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 (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...
 
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
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,
bool  IOBound 
)
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),m_isIOBound(IOBound)
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_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 207 of file ExecutionFlowGraph.cpp.

208  {
209 
210  for ( auto node : m_outputs ) {
211  delete node;
212  }
213  }
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 387 of file ExecutionFlowGraph.cpp.

388  {
389 
390  if ( visitor.visitEnter( *this ) ) {
391  bool result = visitor.visit( *this );
392  if ( result ) return false;
393  }
394 
395  return true;
396  }
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 413 of file ExecutionFlowGraph.cpp.

414  {
415 
416  if ( std::find( m_inputs.begin(), m_inputs.end(), node ) == m_inputs.end() ) m_inputs.push_back( node );
417  }
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 406 of file ExecutionFlowGraph.cpp.

407  {
408 
409  if ( std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
410  }
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 399 of file ExecutionFlowGraph.cpp.

400  {
401 
402  if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
403  }
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 278 of file ExecutionFlowGraph.cpp.

279  {
280 
281  bool result = true; //return true if an algorithm has no data inputs
282  auto& states = m_graph->getAlgoStates( slotNum );
283 
284  for ( auto dataNode : m_inputs ) {
285  // return false if the input has no producers at all (normally this case must be
286  // forbidden, and must be invalidated at configuration time)
287  result = false;
288  for ( auto algoNode : dataNode->getProducers() )
289  if ( State::EVTACCEPTED == states[algoNode->getAlgoIndex()] ) {
290  result = true;
291  break; // skip checking other producers if one was found to be executed
292  }
293 
294  if (!result) break; // skip checking other inputs if this input was not produced yet
295  }
296 
297  return result;
298  }
ExecutionFlowGraph * 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 301 of file ExecutionFlowGraph.cpp.

302  {
303 
304  bool result = true;
305  for ( auto dataNode : m_inputs ) {
306 
307  result = false;
308  for ( auto algoNode : dataNode->getProducers() )
309  if ( State::EVTACCEPTED == states[algoNode->getAlgoIndex()] ) {
310  result = true;
311  break;
312  }
313 
314  if ( !result ) break;
315  }
316 
317  return result;
318  }
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 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&#39;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&#39;...
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)
overridevirtual

Initialize.

Implements concurrency::ControlFlowNode.

Definition at line 216 of file ExecutionFlowGraph.cpp.

217  {
218 
219  m_algoIndex = algname_index_map.at( m_algoName );
220  }
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 184 of file ExecutionFlowGraph.h.

184 {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 321 of file ExecutionFlowGraph.cpp.

323  {
324  output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
325  << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
326  << ")"
327  << ", in state: " << AlgsExecutionStates::stateNames[states[m_algoIndex]] << std::endl;
328  }
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
overridevirtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 223 of file ExecutionFlowGraph.cpp.

225  {
226 
227  auto& state = states[m_algoIndex];
228  bool result = false;
229 
230  if ( State::INITIAL == state ) {
231  states.updateState( m_algoIndex, State::CONTROLREADY ).ignore();
232  // std::cout << "----> UPDATING ALGORITHM to CONTROLREADY: " << m_algoName << std::endl;
233  result = true;
234  } else if ( State::CONTROLREADY == state ) {
235  result = true;
236  }
237 
238  return result;
239  }
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 242 of file ExecutionFlowGraph.cpp.

243  {
244 
245  auto& states = m_graph->getAlgoStates( slotNum );
246  auto& state = states[m_algoIndex];
247  bool result = false;
248 
249  if ( State::CONTROLREADY == state ) {
250  if ( dataDependenciesSatisfied( slotNum ) ) {
251  // std::cout << "----> UPDATING ALGORITHM to DATAREADY: " << m_algoName << std::endl;
252  states.updateState( m_algoIndex, State::DATAREADY ).ignore();
253  result = true;
254 
255  // m_graph->addEdgeToExecutionPlan(requestor, this);
256 
257  /*
258  auto xtime = std::chrono::high_resolution_clock::now();
259  std::stringstream s;
260  s << getNodeName() << ", "
261  << (xtime-m_graph->getInitTime()).count() << "\n";
262  std::ofstream myfile;
263  myfile.open("DRTiming.csv", std::ios::app);
264  myfile << s.str();
265  myfile.close();
266  */
267  }
268  } else if ( State::DATAREADY == state ) {
269  result = true;
270  } else if ( State::SCHEDULED == state ) {
271  result = true;
272  }
273 
274  return result;
275  }
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::setIOBound ( bool  value)
inline

Set the I/O-boundness flag.

Definition at line 182 of file ExecutionFlowGraph.h.

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

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 357 of file ExecutionFlowGraph.cpp.

359  {
360 
361  const State& state = states[m_algoIndex];
362  int decision = -1;
363  requestor = this;
364 
365  // now derive the proper result to pass back
366  if ( true == m_allPass ) {
367  decision = 1;
368  } else if ( State::EVTACCEPTED == state ) {
369  decision = !m_inverted;
370  } else if ( State::EVTREJECTED == state ) {
371  decision = m_inverted;
372  } else {
373  decision = -1; // result not known yet
374  }
375 
376  node_decisions[m_nodeIndex] = decision;
377 
378  if ( -1 != decision ) {
379  for ( auto output : m_outputs )
380  for ( auto consumer : output->getConsumers() ) consumer->promoteToDataReadyState( slotNum, requestor );
381 
382  for ( auto p : m_parents ) p->updateDecision( slotNum, states, node_decisions, requestor );
383  }
384  }
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 331 of file ExecutionFlowGraph.cpp.

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

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

The name of the algorithm.

Definition at line 211 of file ExecutionFlowGraph.h.

bool concurrency::AlgorithmNode::m_allPass
private

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

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

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

Inputs of the algorithm, represented as DataNode's.

Definition at line 229 of file ExecutionFlowGraph.h.

bool concurrency::AlgorithmNode::m_inverted
private

Whether the selection result is negated or not.

Definition at line 213 of file ExecutionFlowGraph.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 235 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 227 of file ExecutionFlowGraph.h.

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

XXX: CF tests.

Definition at line 217 of file ExecutionFlowGraph.h.

float concurrency::AlgorithmNode::m_rank
private

Algorithm rank of any kind.

Definition at line 231 of file ExecutionFlowGraph.h.

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

Representatives (including clones) of the node.

Definition at line 233 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 221 of file ExecutionFlowGraph.h.


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