| The Gaudi Framework v27r1

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

- File List
- File Members

EFGraphVisitors.cpp
Go to the documentation of this file.
1 #include "EFGraphVisitors.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_isLazy) {
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 true;
93 return false;
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_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 //--------------------------------------------------------------------------
139 bool Trigger::visit(AlgorithmNode& node) {
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 //--------------------------------------------------------------------------
154 bool RankerByProductConsumption::visit(AlgorithmNode& node) {
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 //--------------------------------------------------------------------------
174 bool RankerByCummulativeOutDegree::visit(AlgorithmNode& node) {
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;
190 std::pair<itV, itV> vp;
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,
210 boost::ExecPlan graph) {
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 //--------------------------------------------------------------------------
222 bool RankerByTiming::visit(AlgorithmNode& node) {
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;
238 std::pair<itV, itV> vp;
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 //--------------------------------------------------------------------------
255 bool RankerByEccentricity::visit(AlgorithmNode& node) {
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;
269 std::pair<itV, itV> vp;
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 //--------------------------------------------------------------------------
286 bool RankerByDataRealmEccentricity::visit(AlgorithmNode& node) {
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 //--------------------------------------------------------------------------
301 void RankerByDataRealmEccentricity::recursiveVisit(AlgorithmNode& node) {
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 }
concurrency::DecisionNode::m_isLazy
bool m_isLazy
Whether to evaluate lazily - i.e. whether to stop once result known.
Definition: ExecutionFlowGraph.h:127
boost::AlgoNodeStruct::m_index
int m_index
Definition: ExecutionFlowGraph.h:31
concurrency::Trigger::visitEnter
virtual bool visitEnter(DecisionNode &node) const
Definition: EFGraphVisitors.cpp:89
concurrency::Trigger::visitLeave
virtual bool visitLeave(DecisionNode &node) const
Definition: EFGraphVisitors.cpp:121
concurrency::AlgorithmNode::getAlgoIndex
const unsigned int & getAlgoIndex() const
XXX: CF tests.
Definition: ExecutionFlowGraph.h:180
concurrency::AlgorithmNode::promoteToControlReadyState
virtual bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX: CF tests.
Definition: ExecutionFlowGraph.cpp:209
concurrency::DecisionNode
Definition: ExecutionFlowGraph.h:86
std::ifstream::open
T open(T...args)
concurrency::RankerByDataRealmEccentricity::reset
virtual void reset()
Definition: EFGraphVisitors.h:194
boost::ExecPlan
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct > ExecPlan
Definition: ExecutionFlowGraph.h:37
concurrency::AlgorithmNode::dataDependenciesSatisfied
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
Definition: ExecutionFlowGraph.cpp:264
concurrency
Definition: EFGraphVisitors.cpp:3
concurrency::RunSimulator::visit
virtual bool visit(DecisionNode &node)
Definition: EFGraphVisitors.cpp:14
concurrency::RankerByDataRealmEccentricity::m_currentDepth
uint m_currentDepth
Definition: EFGraphVisitors.h:204
concurrency::AlgorithmNode::setRank
void setRank(float &rank)
Set Algorithm rank.
Definition: ExecutionFlowGraph.h:175
concurrency::RankerByDataRealmEccentricity::recursiveVisit
void recursiveVisit(AlgorithmNode &node)
Depth-first node parser to calculate node eccentricity (only within the data realm of the execution f...
Definition: EFGraphVisitors.cpp:301
concurrency::RunSimulator::visitLeave
virtual bool visitLeave(DecisionNode &node) const
Definition: EFGraphVisitors.cpp:38
concurrency::AlgorithmNode::getOutputDataNodes
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Definition: ExecutionFlowGraph.h:171
boost::AlgoNodeStruct::m_rank
int m_rank
Definition: ExecutionFlowGraph.h:32
concurrency::ExecutionFlowGraph::getNodeDecisions
std::vector< int > & getNodeDecisions(const int &slotNum) const
Definition: ExecutionFlowGraph.h:339
concurrency::RankerByProductConsumption::visit
virtual bool visit(DecisionNode &)
Definition: EFGraphVisitors.h:76
concurrency::ControlFlowNode::m_graph
ExecutionFlowGraph * m_graph
Definition: ExecutionFlowGraph.h:77
boost::AlgoNodeStruct::m_runtime
double m_runtime
Definition: ExecutionFlowGraph.h:33
concurrency::RankerByCummulativeOutDegree::reset
virtual void reset()
Definition: EFGraphVisitors.h:112
concurrency::RankerByEccentricity::visit
virtual bool visit(DecisionNode &)
Definition: EFGraphVisitors.h:156
plotSpeedupsPyRoot.graph
tuple graph
Definition: plotSpeedupsPyRoot.py:134
concurrency::ExecutionFlowGraph::getAlgoStates
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
Definition: ExecutionFlowGraph.h:337
boost::AlgoNodeStruct::m_eccentricity
double m_eccentricity
Definition: ExecutionFlowGraph.h:34
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: ExecutionFlowGraph.h:123
concurrency::RankerByDataRealmEccentricity::visit
virtual bool visit(DecisionNode &)
Definition: EFGraphVisitors.h:184
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::DecisionNode::getDaughters
const std::vector< ControlFlowNode * > & getDaughters() const
Definition: ExecutionFlowGraph.h:115
boost::AlgoVertex
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
Definition: ExecutionFlowGraph.h:38
boost::AlgoNodeStruct::m_name
std::string m_name
Definition: ExecutionFlowGraph.h:30
concurrency::RunSimulator::visitEnter
virtual bool visitEnter(DecisionNode &node) const
Definition: EFGraphVisitors.cpp:6
concurrency::Trigger::visit
virtual bool visit(DecisionNode &node)
Definition: EFGraphVisitors.cpp:97
EFGraphVisitors.h
std::pair
concurrency::RankerByTiming::visit
virtual bool visit(DecisionNode &)
Definition: EFGraphVisitors.h:130
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: EFGraphVisitors.cpp:209
concurrency::IGraphVisitor::m_nodesSucceeded
int m_nodesSucceeded
Definition: IGraphVisitor.h:23
concurrency::RankerByDataRealmEccentricity::m_maxKnownDepth
uint m_maxKnownDepth
Definition: EFGraphVisitors.h:205
concurrency::RankerByCummulativeOutDegree::visit
virtual bool visit(DecisionNode &)
Definition: EFGraphVisitors.h:102
concurrency::AlgorithmNode
Definition: ExecutionFlowGraph.h:137
concurrency::ControlFlowNode::getNodeName
const std::string & getNodeName() const
Definition: ExecutionFlowGraph.h:71
concurrency::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
XXX: CF tests.
Definition: ExecutionFlowGraph.h:70
std::ifstream
STL class.
concurrency::AlgorithmNode::promoteToDataReadyState
bool promoteToDataReadyState(const int &slotNum, const AlgorithmNode *requestor=nullptr) const
Definition: ExecutionFlowGraph.cpp:228
AlgsExecutionStates::updateState
StatusCode updateState(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:14