All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ExecutionFlowManager.cpp
Go to the documentation of this file.
1 #include "ExecutionFlowManager.h"
2 
3 namespace concurrency {
4 
5  //---------------------------------------------------------------------------
7  const std::unordered_map<std::string,unsigned int>& algname_index_map){
9  StatusCode sc = graph->initialize(algname_index_map);
10  if (!sc.isSuccess())
11  error() << "Could not initialize the flow graph." << endmsg;
12 
13  return sc;
14  }
15 
16  //---------------------------------------------------------------------------
18  const std::unordered_map<std::string,unsigned int>& algname_index_map,
19  std::vector<EventSlot>& eventSlots,
20  const std::string& mode){
21  m_PRGraph = graph;
22  StatusCode sc = graph->initialize(algname_index_map, eventSlots);
23  if (!sc.isSuccess()) {
24  error() << "Could not initialize the execution flow graph." << endmsg;
25  return sc;
26  }
27 
28  // Rank algorithms if any known optimization mode is supplied
29  if (mode == "PCE") {
31  m_PRGraph->rankAlgorithms(ranker);
32  } else if (mode == "COD") {
34  m_PRGraph->rankAlgorithms(ranker);
35  } else if (mode == "E") {
36  auto ranker = concurrency::RankerByEccentricity();
37  m_PRGraph->rankAlgorithms(ranker);
38  } else if (mode == "T") {
39  auto ranker = concurrency::RankerByTiming();
40  m_PRGraph->rankAlgorithms(ranker);
41  } else if (mode == "DRE") {
43  m_PRGraph->rankAlgorithms(ranker);
44  } else if (!mode.empty()){
45  error() << "Requested optimization mode '" << mode << "' is not known." << endmsg;
47  }
48 
49  return sc;
50  }
51 
52  //---------------------------------------------------------------------------
54 
55  std::vector<int>& nodeDecisions = m_PRGraph->getNodeDecisions(0);
56 
57  std::vector<int> fixedNodeDecisions;
58  int cntr = 0;
59  std::vector<int> counters;
60  while (!rootDecisionResolved(nodeDecisions)) {
61  cntr += 1;
62  int prevAlgosNum = visitor.m_nodesSucceeded;
63  debug() << " Proceeding with iteration #" << cntr << endmsg;
64  fixedNodeDecisions = m_PRGraph->getNodeDecisions(0);
65  m_PRGraph->m_headNode->accept(visitor);
66  if ( fixedNodeDecisions == nodeDecisions) {
67  error() << " No progress on iteration " << cntr << " detected" << endmsg;
68  debug() << nodeDecisions << endmsg;
69  break;
70  }
71  info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded << endmsg;
72 
74  s << cntr << ", " << (visitor.m_nodesSucceeded-prevAlgosNum) << "\n";
75 
76  std::ofstream myfile;
77  myfile.open("RunSimulation.csv", std::ios::app);
78  myfile << s.str();
79  myfile.close();
80 
81 
82  if (visitor.m_nodesSucceeded != prevAlgosNum)
83  counters.push_back(visitor.m_nodesSucceeded);
84  }
85 
86  info() << "Asymptotical concurrency speedup depth: " << (float) visitor.m_nodesSucceeded / (float) counters.size() << endmsg;
87 
88  // Reset algorithm states and node decisions
90  nodeDecisions.assign(nodeDecisions.size(),-1);
91 
92  }
93 
94  //---------------------------------------------------------------------------
96  std::vector<int>& node_decisions) const {
97  m_PRGraph->updateEventState(algo_states, node_decisions);
98  }
99 
100  //---------------------------------------------------------------------------
102  const int& slotNum,
103  AlgsExecutionStates& algo_states,
104  std::vector<int>& node_decisions) const {
105  m_PRGraph->updateDecision(algo_name, slotNum, algo_states, node_decisions);
106  }
107 
108  //---------------------------------------------------------------------------
110  std::vector<int>& node_decisions,
111  const int& slotNum) const {
112  m_PRGraph->m_headNode->promoteToControlReadyState(slotNum, algo_states, node_decisions);
113  }
114 
115  //---------------------------------------------------------------------------
116  bool ExecutionFlowManager::algoDataDependenciesSatisfied(const std::string& algo_name, const int& slotNum) const {
117  return m_PRGraph->getAlgorithmNode(algo_name)->dataDependenciesSatisfied(slotNum);
118  }
119 
120  //---------------------------------------------------------------------------
122 
123  return (-1 != node_decisions[m_PRGraph->m_headNode->getNodeIndex()]) ? true : false;
124  }
125 
126  //---------------------------------------------------------------------------
128 
129  //auto& states = m_PRGraph->getAlgoStates(visitor.m_slotNum);
130  //auto& decisions = m_PRGraph->getNodeDecisions(visitor.m_slotNum);
131 
132  //m_PRGraph->m_headNode->promoteToControlReadyState(slotNum,states,decisions);
133 
134  m_PRGraph->m_headNode->accept(visitor);
135 
136  }
137 }
void simulateExecutionFlow(IGraphVisitor &visitor) const
T empty(T...args)
T open(T...args)
void updateEventState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions) const
Update the state of algorithms to controlready, where possible.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool algoDataDependenciesSatisfied(const std::string &algo_name, const int &slotNum) const
Check all data dependencies of an algorithm are satisfied.
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
void touchReadyAlgorithms(IGraphVisitor &visitor) const
Promote all algorithms, ready to be executed, to DataReady state.
StatusCode initialize(PrecedenceRulesGraph *graph, const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize the control flow manager It greps the topalg list and the index map for the algo names...
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
std::vector< int > & getNodeDecisions(const int &slotNum) const
STL class.
bool accept(IGraphVisitor &visitor) override
T push_back(T...args)
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
A method to update algorithm node decision, and propagate it upwards.
bool rootDecisionResolved(const std::vector< int > &node_decisions) const
Check whether root decision was resolved.
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
void promoteToControlReadyState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions, const int &slotNum=-1) const
XXX: CF tests.
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T str(T...args)
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
T size(T...args)
StatusCode initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize graph.
T assign(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
string s
Definition: gaudirun.py:245
bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
const unsigned int & getNodeIndex() const
XXX: CF tests.
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244