| The Gaudi Framework v32r1 (f65d50dc)

Rankers.cpp
Go to the documentation of this file.
1 #include "Rankers.h"
2
3 namespace concurrency {
4
5 //--------------------------------------------------------------------------
6 bool RankerByProductConsumption::visit( AlgorithmNode& node ) {
7
8 auto& products = node.getOutputDataNodes();
9 float rank = 0;
10
11 for ( auto p : products ) rank += p->getConsumers().size();
12
13 node.setRank( rank );
14 /*std::stringstream s;
15 s << node.getNodeName() << ", " << rank << "\n";
16 std::ofstream myfile;
17 myfile.open("AlgoRank.csv", std::ios::app);
18 myfile << s.str();
19 myfile.close();*/
20
21 return true;
22 }
23
24 //--------------------------------------------------------------------------
25 bool RankerByCummulativeOutDegree::visit( AlgorithmNode& node ) {
26
27 std::ifstream myfile;
28 myfile.open( "InputExecutionPlan.graphml", std::ios::in );
29
30 precedence::PrecTrace execPlan;
31
32 using boost::get;
33 using precedence::AlgoTraceProps;
34
35 boost::dynamic_properties dp;
36 dp.property( "name", get( &AlgoTraceProps::m_name, execPlan ) );
37 dp.property( "index", get( &AlgoTraceProps::m_index, execPlan ) );
38 dp.property( "dataRank", get( &AlgoTraceProps::m_rank, execPlan ) );
39 dp.property( "runtime", get( &AlgoTraceProps::m_runtime, execPlan ) );
40
41 boost::read_graphml( myfile, execPlan, dp );
42
43 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
44 std::pair<itV, itV> vp;
45
46 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
47 precedence::AlgoTraceVertex v = *vp.first;
48 auto index = get( &AlgoTraceProps::m_name, execPlan );
49 if ( index[v] == node.getNodeName() ) {
50 runThroughAdjacents( v, execPlan );
51 float rank = m_nodesSucceeded;
52 node.setRank( rank );
53 reset();
54 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
55 }
56 }
57
58 return true;
59 }
60
61 //--------------------------------------------------------------------------
62 void RankerByCummulativeOutDegree::runThroughAdjacents(
63 boost::graph_traits<precedence::PrecTrace>::vertex_descriptor vertex, precedence::PrecTrace graph ) {
64 typename boost::graph_traits<precedence::PrecTrace>::adjacency_iterator itVB;
65 typename boost::graph_traits<precedence::PrecTrace>::adjacency_iterator itVE;
66
67 for ( boost::tie( itVB, itVE ) = adjacent_vertices( vertex, graph ); itVB != itVE; ++itVB ) {
68 m_nodesSucceeded += 1;
69 runThroughAdjacents( *itVB, graph );
70 }
71 }
72
73 //--------------------------------------------------------------------------
74 bool RankerByTiming::visit( AlgorithmNode& node ) {
75
76 std::ifstream myfile;
77 myfile.open( "InputExecutionPlan.graphml", std::ios::in );
78
79 precedence::PrecTrace execPlan;
80 using boost::get;
81 using precedence::AlgoTraceProps;
82
83 boost::dynamic_properties dp;
84 dp.property( "name", get( &AlgoTraceProps::m_name, execPlan ) );
85 dp.property( "index", get( &AlgoTraceProps::m_index, execPlan ) );
86 dp.property( "dataRank", get( &AlgoTraceProps::m_rank, execPlan ) );
87 dp.property( "runtime", get( &AlgoTraceProps::m_runtime, execPlan ) );
88
89 boost::read_graphml( myfile, execPlan, dp );
90
91 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
92 std::pair<itV, itV> vp;
93
94 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
95 precedence::AlgoTraceVertex v = *vp.first;
96 auto index = get( &AlgoTraceProps::m_name, execPlan );
97 if ( index[v] == node.getNodeName() ) {
98 auto index_runtime = get( &AlgoTraceProps::m_runtime, execPlan );
99 float rank = index_runtime[v];
100 node.setRank( rank );
101 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
102 }
103 }
104 return true;
105 }
106
107 //--------------------------------------------------------------------------
108 bool RankerByEccentricity::visit( AlgorithmNode& node ) {
109
110 std::ifstream myfile;
111 myfile.open( "Eccentricity.graphml", std::ios::in );
112
113 precedence::PrecTrace execPlan;
114
115 boost::dynamic_properties dp;
116 using boost::get;
117
118 dp.property( "name", get( &precedence::AlgoTraceProps::m_name, execPlan ) );
119 dp.property( "Eccentricity", get( &precedence::AlgoTraceProps::m_eccentricity, execPlan ) );
120
121 boost::read_graphml( myfile, execPlan, dp );
122
123 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
124 std::pair<itV, itV> vp;
125
126 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
127 precedence::AlgoTraceVertex v = *vp.first;
128 auto index = get( &precedence::AlgoTraceProps::m_name, execPlan );
129 if ( index[v] == node.getNodeName() ) {
130 auto index_eccentricity = get( &precedence::AlgoTraceProps::m_eccentricity, execPlan );
131 float rank = index_eccentricity[v];
132 node.setRank( rank );
133 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
134 }
135 }
136 return true;
137 }
138
139 //--------------------------------------------------------------------------
140 bool RankerByDataRealmEccentricity::visit( AlgorithmNode& node ) {
141
142 // Find eccentricity of the node (only within the data realm of the execution flow graph)
143 recursiveVisit( node );
144
145 float rank = m_maxKnownDepth;
146 node.setRank( rank );
147
148 // Reset visitor for next nodes, if any
149 reset();
150
151 return true;
152 }
153
154 //--------------------------------------------------------------------------
155 void RankerByDataRealmEccentricity::recursiveVisit( AlgorithmNode& node ) {
156
157 m_currentDepth += 1;
158
159 auto& products = node.getOutputDataNodes();
160
161 if ( products.empty() )
162 if ( ( m_currentDepth - 1 ) > m_maxKnownDepth ) m_maxKnownDepth = m_currentDepth - 1;
163
164 for ( auto p : products )
165 for ( auto algoNode : p->getConsumers() ) recursiveVisit( *algoNode );
166
167 m_currentDepth -= 1;
168 }
169
170 } // namespace concurrency
concurrency::ControlFlowNode::getNodeName
const std::string & getNodeName() const
Get node name.
Definition: PrecedenceRulesGraph.h:420
std::ifstream::open
T open(T... args)
precedence::AlgoTraceVertex
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
Definition: PrecedenceRulesGraph.h:51
precedence::AlgoTraceProps::m_eccentricity
int m_eccentricity
Definition: PrecedenceRulesGraph.h:47
concurrency
Definition: PrecedenceRulesGraph.cpp:27
concurrency::RankerByDataRealmEccentricity::m_currentDepth
uint m_currentDepth
Definition: Rankers.h:62
concurrency::AlgorithmNode::setRank
void setRank(float &rank)
Set Algorithm rank.
Definition: PrecedenceRulesGraph.h:506
concurrency::RankerByDataRealmEccentricity::reset
void reset() override
Definition: Rankers.h:53
concurrency::RankerByProductConsumption::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:6
concurrency::RankerByDataRealmEccentricity::recursiveVisit
void recursiveVisit(AlgorithmNode &)
Depth-first node parser to calculate node eccentricity (only within the data realm of the precedence ...
Definition: Rankers.cpp:155
precedence::AlgoTraceProps
Definition: PrecedenceRulesGraph.h:39
concurrency::RankerByCummulativeOutDegree::m_nodesSucceeded
int m_nodesSucceeded
Definition: Rankers.h:27
concurrency::RankerByCummulativeOutDegree::reset
void reset() override
Definition: Rankers.h:23
concurrency::RankerByTiming::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:74
concurrency::RankerByEccentricity::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:108
concurrency::RankerByCummulativeOutDegree::runThroughAdjacents
void runThroughAdjacents(boost::graph_traits< precedence::PrecTrace >::vertex_descriptor, precedence::PrecTrace)
Definition: Rankers.cpp:62
precedence::PrecTrace
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
Definition: PrecedenceRulesGraph.h:50
std::pair
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:140
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:332
concurrency::AlgorithmNode::getOutputDataNodes
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Definition: PrecedenceRulesGraph.h:501
precedence::AlgoTraceProps::m_name
std::string m_name
Definition: PrecedenceRulesGraph.h:43
concurrency::RankerByDataRealmEccentricity::m_maxKnownDepth
uint m_maxKnownDepth
Definition: Rankers.h:63
Rankers.h
concurrency::AlgorithmNode
Definition: PrecedenceRulesGraph.h:475
concurrency::RankerByCummulativeOutDegree::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:25
concurrency::RankerByDataRealmEccentricity::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:140
std::ifstream
STL class.