| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

PRGraphVisitors.cpp
Go to the documentation of this file.
1 #include "PRGraphVisitors.h"
2
3 namespace concurrency {
4
5 //---------------------------------------------------------------------------
6 bool RunSimulator::visitEnter(DecisionNode& node) const {
7
8 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
9 return true;
10 return false;
11 }
12
13 //---------------------------------------------------------------------------
14 bool RunSimulator::visit(DecisionNode& node) {
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_modePromptDecision) {
22 node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] = 1;
23 return true;
24 }
25
26 if (childDecision == -1) {
27 allChildDecisionsResolved = false;
28 }
29 }
30
31 if (allChildDecisionsResolved)
32 node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] = 1;
33
34 return allChildDecisionsResolved;
35 }
36
37 //---------------------------------------------------------------------------
38 bool RunSimulator::visitLeave(DecisionNode& node) const {
39
40 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
41 return true;
42 return false;
43 }
44
45
46
47 //---------------------------------------------------------------------------
48 bool RunSimulator::visitEnter(AlgorithmNode& node) const {
49
50 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != 1)
51 return true;
52 return false;
53 }
54
55 //--------------------------------------------------------------------------
56 bool RunSimulator::visit(AlgorithmNode& node) {
57
58 std::vector<int>& decisions = node.m_graph->getNodeDecisions(m_slotNum);
59 AlgsExecutionStates& states = node.m_graph->getAlgoStates(m_slotNum);
60 int& decision = decisions[node.getNodeIndex()];
61
62 if (State::INITIAL == states[node.getAlgoIndex()]) {
63 states.updateState(node.getAlgoIndex(), State::CONTROLREADY);
64 if (node.dataDependenciesSatisfied(m_slotNum)) {
65 states.updateState(node.getAlgoIndex(), State::DATAREADY);
66 states.updateState(node.getAlgoIndex(), State::SCHEDULED);
67 states.updateState(node.getAlgoIndex(), State::EVTACCEPTED);
68 decision = 1;
69 ++m_nodesSucceeded;
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;
78 ++m_nodesSucceeded;
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 false;
93 return true;
94 }
95
96 //---------------------------------------------------------------------------
97 bool Trigger::visit(DecisionNode& node) {
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_modePromptDecision) {
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
122 //---------------------------------------------------------------------------
123 bool Trigger::visitEnter(AlgorithmNode& node) const {
124
125 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != -1)
126 return false;
127 return true;
128 }
129
130 //--------------------------------------------------------------------------
131 bool Trigger::visit(AlgorithmNode& node) {
132
133 bool result = false;
134
135 auto& decisions = node.m_graph->getNodeDecisions(m_slotNum);
136 auto& states = node.m_graph->getAlgoStates(m_slotNum);
137
138 // Try to shift an algorithm with I->CF, and then, if successful, with CF->DF
139 if (node.promoteToControlReadyState(m_slotNum,states,decisions))
140 result = node.promoteToDataReadyState(m_slotNum);
141
142 //returns true only when an algorithm is DF-ready
143 // i.e., the visitor reached its final goal with the algorithm
144 return result;
145 }
146
147
148 //---------------------------------------------------------------------------
149 bool Supervisor::visitEnter(DecisionNode& node) const {
150
151 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != -1)
152 return false;
153 return true;
154 }
155
156 //---------------------------------------------------------------------------
157 bool Supervisor::visit(DecisionNode& node) {
158
159 bool foundNonResolvedChild = false;
160 bool foundNegativeChild = false;
161 bool foundPositiveChild = false;
162 int decision = -1;
163
164 for (auto child : node.getDaughters()) {
165 int& childDecision = child->m_graph->getNodeDecisions(m_slotNum)[child->getNodeIndex()];
166
167 if (childDecision == -1)
168 foundNonResolvedChild = true;
169 else if (childDecision == 1)
170 foundPositiveChild = true;
171 else
172 foundNegativeChild = true;
173
174 if (node.m_modePromptDecision) {
175 if (node.m_modeOR && foundPositiveChild) {
176 decision = 1;
177 break;
178 } else if (!node.m_modeOR && foundNegativeChild) {
179 decision = 0;
180 break;
181 }
182 } else {
183 if (foundNonResolvedChild)
184 break;
185 }
186 } // end monitoring children
187
188 if (!foundNonResolvedChild && decision == -1) {
189 if (node.m_modeOR) // OR
190 if (foundPositiveChild) decision = 1;
191 else decision = 0;
192 else // AND
193 if (foundNegativeChild) decision = 0;
194 else decision = 1;
195 }
196
197 if (node.m_allPass && !foundNonResolvedChild)
198 decision = 1;
199
200 if (decision != -1) {
201 node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] = decision;
202 return true;
203 }
204 return false;
205 }
206
207
208
209 //---------------------------------------------------------------------------
210 bool Supervisor::visitEnter(AlgorithmNode& node) const {
211
212 if (node.m_graph->getNodeDecisions(m_slotNum)[node.getNodeIndex()] != -1)
213 return false;
214 return true;
215 }
216
217 //--------------------------------------------------------------------------
218 bool Supervisor::visit(AlgorithmNode& node) {
219
220 bool result = false;
221
222 auto& decisions = node.m_graph->getNodeDecisions(m_slotNum);
223 auto& states = node.m_graph->getAlgoStates(m_slotNum);
224
225 // Try to shift an algorithm with I->CF, and then, if successful, with CF->DF
226 if (node.promoteToControlReadyState(m_slotNum,states,decisions))
227 result = node.promoteToDataReadyState(m_slotNum);
228
229 //returns true only when an algorithm is DF-ready
230 // i.e., the visitor reached its final goal with the algorithm
231 return result;
232 }
233
234
235 //--------------------------------------------------------------------------
236 bool RankerByProductConsumption::visit(AlgorithmNode& node) {
237
238 auto& products = node.getOutputDataNodes();
239 float rank = 0;
240
241 for (auto p : products)
242 rank += p->getConsumers().size();
243
244 node.setRank(rank);
245 /*std::stringstream s;
246 s << node.getNodeName() << ", " << rank << "\n";
247 std::ofstream myfile;
248 myfile.open("AlgoRank.csv", std::ios::app);
249 myfile << s.str();
250 myfile.close();*/
251
252 return true;
253 }
254
255 //--------------------------------------------------------------------------
256 bool RankerByCummulativeOutDegree::visit(AlgorithmNode& node) {
257
258 std::ifstream myfile;
259 myfile.open("InputExecutionPlan.graphml", std::ios::in);
260
261 boost::ExecPlan execPlan;
262
263 boost::dynamic_properties dp;
264 dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
265 dp.property("index", boost::get(&boost::AlgoNodeStruct::m_index, execPlan));
266 dp.property("dataRank", boost::get(&boost::AlgoNodeStruct::m_rank, execPlan));
267 dp.property("runtime", boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan));
268
269 boost::read_graphml(myfile, execPlan, dp);
270
271 typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
272 std::pair<itV, itV> vp;
273 typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
274
275 for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
276 AlgoVertex v = *vp.first;
277 auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
278 if (index[v] == node.getNodeName()) {
279 runThroughAdjacents(v,execPlan);
280 float rank = m_nodesSucceeded;
281 node.setRank(rank);
282 reset();
283 //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
284 }
285 }
286
287 return true;
288 }
289
290 //--------------------------------------------------------------------------
291 void RankerByCummulativeOutDegree::runThroughAdjacents(boost::graph_traits<boost::ExecPlan>::vertex_descriptor vertex,
292 boost::ExecPlan graph) {
293 typename boost::graph_traits<boost::ExecPlan>::adjacency_iterator itVB;
294 typename boost::graph_traits<boost::ExecPlan>::adjacency_iterator itVE;
295
296 for (boost::tie(itVB, itVE) = adjacent_vertices(vertex, graph); itVB != itVE; ++itVB) {
297 m_nodesSucceeded += 1;
298 runThroughAdjacents(*itVB, graph);
299 }
300
301 }
302
303 //--------------------------------------------------------------------------
304 bool RankerByTiming::visit(AlgorithmNode& node) {
305
306 std::ifstream myfile;
307 myfile.open("InputExecutionPlan.graphml", std::ios::in);
308
309 boost::ExecPlan execPlan;
310
311 boost::dynamic_properties dp;
312 dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
313 dp.property("index", boost::get(&boost::AlgoNodeStruct::m_index, execPlan));
314 dp.property("dataRank", boost::get(&boost::AlgoNodeStruct::m_rank, execPlan));
315 dp.property("runtime", boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan));
316
317 boost::read_graphml(myfile, execPlan, dp);
318
319 typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
320 std::pair<itV, itV> vp;
321 typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
322
323 for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
324 AlgoVertex v = *vp.first;
325 auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
326 if (index[v] == node.getNodeName()) {
327 auto index_runtime = boost::get(&boost::AlgoNodeStruct::m_runtime, execPlan);
328 float rank = index_runtime[v];
329 node.setRank(rank);
330 //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
331 }
332 }
333 return true;
334 }
335
336 //--------------------------------------------------------------------------
337 bool RankerByEccentricity::visit(AlgorithmNode& node) {
338
339 std::ifstream myfile;
340 myfile.open("Eccentricity.graphml", std::ios::in);
341
342 boost::ExecPlan execPlan;
343
344 boost::dynamic_properties dp;
345 dp.property("name", boost::get(&boost::AlgoNodeStruct::m_name, execPlan));
346 dp.property("Eccentricity", boost::get(&boost::AlgoNodeStruct::m_eccentricity, execPlan));
347
348 boost::read_graphml(myfile, execPlan, dp);
349
350 typedef boost::graph_traits<boost::ExecPlan>::vertex_iterator itV;
351 std::pair<itV, itV> vp;
352 typedef boost::graph_traits<boost::ExecPlan>::vertex_descriptor AlgoVertex;
353
354 for (vp = boost::vertices(execPlan); vp.first != vp.second; ++vp.first) {
355 AlgoVertex v = *vp.first;
356 auto index = boost::get(&boost::AlgoNodeStruct::m_name, execPlan);
357 if (index[v] == node.getNodeName()) {
358 auto index_eccentricity = boost::get(&boost::AlgoNodeStruct::m_eccentricity, execPlan);
359 float rank = index_eccentricity[v];
360 node.setRank(rank);
361 //std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
362 }
363 }
364 return true;
365 }
366
367 //--------------------------------------------------------------------------
368 bool RankerByDataRealmEccentricity::visit(AlgorithmNode& node) {
369
370 // Find eccentricity of the node (only within the data realm of the execution flow graph)
371 recursiveVisit(node);
372
373 float rank = m_maxKnownDepth;
374 node.setRank(rank);
375
376 // Reset visitor for next nodes, if any
377 reset();
378
379 return true;
380 }
381
382 //--------------------------------------------------------------------------
383 void RankerByDataRealmEccentricity::recursiveVisit(AlgorithmNode& node) {
384
385 m_currentDepth += 1;
386
387 auto& products = node.getOutputDataNodes();
388
389 if (products.empty())
390 if ( (m_currentDepth - 1) > m_maxKnownDepth)
391 m_maxKnownDepth = m_currentDepth - 1;
392
393 for (auto p : products)
394 for ( auto algoNode : p->getConsumers())
395 recursiveVisit(*algoNode);
396
397 m_currentDepth -= 1;
398
399 }
400 }
boost::AlgoNodeStruct::m_index
int m_index
Definition: PrecedenceRulesGraph.h:31
concurrency::AlgorithmNode::promoteToControlReadyState
bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
XXX: CF tests.
Definition: PrecedenceRulesGraph.cpp:237
concurrency::AlgorithmNode::getAlgoIndex
const unsigned int & getAlgoIndex() const
XXX: CF tests.
Definition: PrecedenceRulesGraph.h:183
PRGraphVisitors.h
concurrency::DecisionNode
Definition: PrecedenceRulesGraph.h:86
std::ifstream::open
T open(T...args)
concurrency::RunSimulator::reset
void reset() override
Definition: PRGraphVisitors.h:31
boost::ExecPlan
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct > ExecPlan
Definition: PrecedenceRulesGraph.h:37
concurrency::Trigger::visit
bool visit(DecisionNode &node) override
Definition: PRGraphVisitors.cpp:97
concurrency::AlgorithmNode::dataDependenciesSatisfied
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
Definition: PrecedenceRulesGraph.cpp:292
concurrency
Definition: ExecutionFlowManager.cpp:3
concurrency::AlgorithmNode::setRank
void setRank(float &rank)
Set Algorithm rank.
Definition: PrecedenceRulesGraph.h:178
concurrency::RankerByDataRealmEccentricity::recursiveVisit
void recursiveVisit(AlgorithmNode &node)
Depth-first node parser to calculate node eccentricity (only within the data realm of the precedence ...
Definition: PRGraphVisitors.cpp:383
concurrency::AlgorithmNode::getOutputDataNodes
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Definition: PrecedenceRulesGraph.h:174
boost::AlgoNodeStruct::m_rank
int m_rank
Definition: PrecedenceRulesGraph.h:32
concurrency::RankerByTiming::visit
bool visit(DecisionNode &) override
Definition: PRGraphVisitors.h:157
concurrency::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: PrecedenceRulesGraph.h:130
concurrency::RankerByProductConsumption::visit
bool visit(DecisionNode &) override
Definition: PRGraphVisitors.h:103
concurrency::PrecedenceRulesGraph::getNodeDecisions
std::vector< int > & getNodeDecisions(const int &slotNum) const
Definition: PrecedenceRulesGraph.h:348
boost::AlgoNodeStruct::m_runtime
double m_runtime
Definition: PrecedenceRulesGraph.h:33
concurrency::Supervisor::visit
bool visit(DecisionNode &node) override
Definition: PRGraphVisitors.cpp:157
boost::AlgoNodeStruct::m_eccentricity
double m_eccentricity
Definition: PrecedenceRulesGraph.h:34
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:128
concurrency::RunSimulator::visitEnter
bool visitEnter(DecisionNode &node) const override
Definition: PRGraphVisitors.cpp:6
concurrency::IGraphVisitor::m_slotNum
int m_slotNum
Definition: IGraphVisitor.h:24
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
concurrency::ControlFlowNode::m_graph
PrecedenceRulesGraph * m_graph
Definition: PrecedenceRulesGraph.h:77
concurrency::DecisionNode::getDaughters
const std::vector< ControlFlowNode * > & getDaughters() const
Definition: PrecedenceRulesGraph.h:115
boost::AlgoVertex
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
Definition: PrecedenceRulesGraph.h:38
boost::AlgoNodeStruct::m_name
std::string m_name
Definition: PrecedenceRulesGraph.h:30
concurrency::Trigger::visitEnter
bool visitEnter(DecisionNode &node) const override
Definition: PRGraphVisitors.cpp:89
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:126
concurrency::RunSimulator::visitLeave
bool visitLeave(DecisionNode &node) const override
Definition: PRGraphVisitors.cpp:38
std::pair
concurrency::PrecedenceRulesGraph::getAlgoStates
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
Definition: PrecedenceRulesGraph.h:346
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:134
concurrency::RankerByCummulativeOutDegree::visit
bool visit(DecisionNode &) override
Definition: PRGraphVisitors.h:129
std::vector< int >
GaudiPython.Persistency.get
def get(type_)
Definition: Persistency.py:23
concurrency::RankerByCummulativeOutDegree::runThroughAdjacents
void runThroughAdjacents(boost::graph_traits< boost::ExecPlan >::vertex_descriptor vertex, boost::ExecPlan graph)
Definition: PRGraphVisitors.cpp:291
concurrency::Supervisor::visitEnter
bool visitEnter(DecisionNode &node) const override
Definition: PRGraphVisitors.cpp:149
concurrency::RankerByEccentricity::visit
bool visit(DecisionNode &) override
Definition: PRGraphVisitors.h:183
concurrency::IGraphVisitor::m_nodesSucceeded
int m_nodesSucceeded
Definition: IGraphVisitor.h:23
concurrency::AlgorithmNode
Definition: PrecedenceRulesGraph.h:140
concurrency::ControlFlowNode::getNodeName
const std::string & getNodeName() const
Definition: PrecedenceRulesGraph.h:71
concurrency::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
XXX: CF tests.
Definition: PrecedenceRulesGraph.h:70
concurrency::RankerByDataRealmEccentricity::visit
bool visit(DecisionNode &) override
Definition: PRGraphVisitors.h:211
std::ifstream
STL class.
concurrency::RunSimulator::visit
bool visit(DecisionNode &node) override
Definition: PRGraphVisitors.cpp:14
concurrency::AlgorithmNode::promoteToDataReadyState
bool promoteToDataReadyState(const int &slotNum, const AlgorithmNode *requestor=nullptr) const
Definition: PrecedenceRulesGraph.cpp:256
AlgsExecutionStates::updateState
StatusCode updateState(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:14