EFGraphVisitors.cpp
Go to the documentation of this file.
1 #include "EFGraphVisitors.h"
2 
3 namespace concurrency {
4 
5  //---------------------------------------------------------------------------
7 
8  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
9  return true;
10  return false;
11  }
12 
13  //---------------------------------------------------------------------------
15 
16  //std::cout << "1-st level Decision: " << node.getNodeName() << std::endl;
17  bool allChildDecisionsResolved = true;
18  for (auto child : node.getDaughters()) {
19  int& childDecision = child->m_graph->getNodeDecisions(m_slotNum)[child->getNodeIndex()];
20 
21  if (childDecision == 1 && node.m_modeOR && node.m_isLazy) {
23  return true;
24  }
25 
26  if (childDecision == -1) {
27  allChildDecisionsResolved = false;
28  }
29  }
30 
31  if (allChildDecisionsResolved)
33 
34  return allChildDecisionsResolved;
35  }
36 
37  //---------------------------------------------------------------------------
39 
40  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
41  return true;
42  return false;
43  }
44 
45 
46 
47  //---------------------------------------------------------------------------
49 
50  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
51  return true;
52  return false;
53  }
54 
55  //--------------------------------------------------------------------------
57 
60  int& decision = decisions[node.getNodeIndex()];
61 
62  if (State::INITIAL == states[node.getAlgoIndex()]) {
63  states.updateState(node.getAlgoIndex(), State::CONTROLREADY);
65  states.updateState(node.getAlgoIndex(), State::DATAREADY);
66  states.updateState(node.getAlgoIndex(), State::SCHEDULED);
67  states.updateState(node.getAlgoIndex(), State::EVTACCEPTED);
68  decision = 1;
70  //std::cout << "Algorithm decided: " << node.getNodeName() << std::endl;
71  return true;
72  }
73  } else if (State::CONTROLREADY == states[node.getAlgoIndex()] && node.dataDependenciesSatisfied(m_slotNum)) {
74  states.updateState(node.getAlgoIndex(), State::DATAREADY);
75  states.updateState(node.getAlgoIndex(), State::SCHEDULED);
76  states.updateState(node.getAlgoIndex(), State::EVTACCEPTED);
77  decision = 1;
79  //std::cout << "Algorithm decided: " << node.getNodeName() << std::endl;
80  return true;
81  }
82 
83  return false;
84  }
85 
86 
87 
88  //---------------------------------------------------------------------------
89  bool Trigger::visitEnter(DecisionNode& node) const {
90 
91  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
92  return true;
93  return false;
94  }
95 
96  //---------------------------------------------------------------------------
98 
99  //std::cout << "1-st level Decision: " << node.getNodeName() << std::endl;
100  bool allChildDecisionsResolved = true;
101  for (auto child : node.getDaughters()) {
102  int& childDecision = child->m_graph->getNodeDecisions(m_slotNum)[child->getNodeIndex()];
103 
104  if (childDecision == 1 && node.m_modeOR && node.m_isLazy) {
105  node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] = 1;
106  return true;
107  }
108 
109  if (childDecision == -1) {
110  allChildDecisionsResolved = false;
111  }
112  }
113 
114  if (allChildDecisionsResolved)
115  node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] = 1;
116 
117  return allChildDecisionsResolved;
118  }
119 
120  //---------------------------------------------------------------------------
121  bool Trigger::visitLeave(DecisionNode& node) const {
122 
123  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
124  return true;
125  return false;
126  }
127 
128 
129 
130  //---------------------------------------------------------------------------
131  bool Trigger::visitEnter(AlgorithmNode& node) const {
132 
133  if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
134  return true;
135  return false;
136  }
137 
138  //--------------------------------------------------------------------------
140 
141  bool result = false;
142 
143  auto& decisions = node.m_graph->getNodeDecisions(m_slotNum);
144  auto& states = node.m_graph->getAlgoStates(m_slotNum);
145 
146  if (node.promoteToControlReadyState(m_slotNum,states,decisions))
147  result = node.promoteToDataReadyState(m_slotNum);
148 
149  return result;
150  }
151 
152 
153  //--------------------------------------------------------------------------
155 
156  auto& products = node.getOutputDataNodes();
157  float rank = 0;
158 
159  for (auto p : products)
160  rank += p->getConsumers().size();
161 
162  node.setRank(rank);
163  /*std::stringstream s;
164  s << node.getNodeName() << ", " << rank << "\n";
165  std::ofstream myfile;
166  myfile.open("AlgoRank.csv", std::ios::app);
167  myfile << s.str();
168  myfile.close();*/
169 
170  return true;
171  }
172 
173  //--------------------------------------------------------------------------
175 
176  std::ifstream myfile;
177  myfile.open("InputExecutionPlan.graphml", std::ios::in);
178 
179  boost::ExecPlan execPlan;
180 
181  boost::dynamic_properties dp;
182  dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
183  dp.property("index", boost::get(&boost::AlgoNodeStruct::m_index, execPlan));
184  dp.property("dataRank", boost::get(&boost::AlgoNodeStruct::m_rank, execPlan));
185  dp.property("runtime", boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan));
186 
187  boost::read_graphml(myfile, execPlan, dp);
188 
189  typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
191  typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
192 
193  for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
194  AlgoVertex v = *vp.first;
195  auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
196  if (index[v] == node.getNodeName()) {
197  runThroughAdjacents(v,execPlan);
198  float rank = m_nodesSucceeded;
199  node.setRank(rank);
200  reset();
201  //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
202  }
203  }
204 
205  return true;
206  }
207 
208  //--------------------------------------------------------------------------
209  void RankerByCummulativeOutDegree::runThroughAdjacents(boost::graph_traits<boost::ExecPlan>::vertex_descriptor vertex,
211  typename boost::graph_traits<boost::ExecPlan>::adjacency_iterator itVB;
212  typename boost::graph_traits<boost::ExecPlan>::adjacency_iterator itVE;
213 
214  for (boost::tie(itVB, itVE) = adjacent_vertices(vertex, graph); itVB != itVE; ++itVB) {
215  m_nodesSucceeded += 1;
216  runThroughAdjacents(*itVB, graph);
217  }
218 
219  }
220 
221  //--------------------------------------------------------------------------
223 
224  std::ifstream myfile;
225  myfile.open("InputExecutionPlan.graphml", std::ios::in);
226 
227  boost::ExecPlan execPlan;
228 
229  boost::dynamic_properties dp;
230  dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
231  dp.property("index", boost::get(&boost::AlgoNodeStruct::m_index, execPlan));
232  dp.property("dataRank", boost::get(&boost::AlgoNodeStruct::m_rank, execPlan));
233  dp.property("runtime", boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan));
234 
235  boost::read_graphml(myfile, execPlan, dp);
236 
237  typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
239  typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
240 
241  for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
242  AlgoVertex v = *vp.first;
243  auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
244  if (index[v] == node.getNodeName()) {
245  auto index_runtime = boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan);
246  float rank = index_runtime[v];
247  node.setRank(rank);
248  //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
249  }
250  }
251  return true;
252  }
253 
254  //--------------------------------------------------------------------------
256 
257  std::ifstream myfile;
258  myfile.open("Eccentricity.graphml", std::ios::in);
259 
260  boost::ExecPlan execPlan;
261 
262  boost::dynamic_properties dp;
263  dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
264  dp.property("Eccentricity", boost::get(&boost::AlgoNodeStruct::m_eccentricity, execPlan));
265 
266  boost::read_graphml(myfile, execPlan, dp);
267 
268  typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
270  typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
271 
272  for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
273  AlgoVertex v = *vp.first;
274  auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
275  if (index[v] == node.getNodeName()) {
276  auto index_eccentricity = boost::get(&boost::AlgoNodeStruct::m_eccentricity, execPlan);
277  float rank = index_eccentricity[v];
278  node.setRank(rank);
279  //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
280  }
281  }
282  return true;
283  }
284 
285  //--------------------------------------------------------------------------
287 
288  // Find eccentricity of the node (only within the data realm of the execution flow graph)
289  recursiveVisit(node);
290 
291  float rank = m_maxKnownDepth;
292  node.setRank(rank);
293 
294  // Reset visitor for next nodes, if any
295  reset();
296 
297  return true;
298  }
299 
300  //--------------------------------------------------------------------------
302 
303  m_currentDepth += 1;
304 
305  auto& products = node.getOutputDataNodes();
306 
307  if (products.empty())
308  if ( (m_currentDepth - 1) > m_maxKnownDepth)
309  m_maxKnownDepth = m_currentDepth - 1;
310 
311  for (auto p : products)
312  for ( auto algoNode : p->getConsumers())
313  recursiveVisit(*algoNode);
314 
315  m_currentDepth -= 1;
316 
317  }
318 }
bool m_isLazy
Whether to evaluate lazily - i.e. whether to stop once result known.
bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
XXX: CF tests.
const unsigned int & getAlgoIndex() const
XXX: CF tests.
T open(T...args)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct > ExecPlan
bool visit(DecisionNode &node) override
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
void setRank(float &rank)
Set Algorithm rank.
void recursiveVisit(AlgorithmNode &node)
Depth-first node parser to calculate node eccentricity (only within the data realm of the execution f...
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
bool visit(DecisionNode &) override
std::vector< int > & getNodeDecisions(const int &slotNum) const
bool visit(DecisionNode &) override
ExecutionFlowGraph * m_graph
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
bool visitEnter(DecisionNode &node) const override
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
bool visitLeave(DecisionNode &node) const override
const std::vector< ControlFlowNode * > & getDaughters() const
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
bool visitEnter(DecisionNode &node) const override
bool visitLeave(DecisionNode &node) const override
bool visit(DecisionNode &) override
void runThroughAdjacents(boost::graph_traits< boost::ExecPlan >::vertex_descriptor vertex, boost::ExecPlan graph)
bool visit(DecisionNode &) override
const std::string & getNodeName() const
const unsigned int & getNodeIndex() const
XXX: CF tests.
bool visit(DecisionNode &) override
STL class.
bool visit(DecisionNode &node) override
bool promoteToDataReadyState(const int &slotNum, const AlgorithmNode *requestor=nullptr) const
StatusCode updateState(unsigned int iAlgo, State newState)