The Gaudi Framework  master (f40d7e03)
Loading...
Searching...
No Matches
Rankers.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include "Rankers.h"
12
13// C++
14#include <fstream>
15
16namespace concurrency {
17
18 //--------------------------------------------------------------------------
20
21 auto& products = node.getOutputDataNodes();
22 float rank = 0;
23
24 for ( auto p : products ) rank += p->getConsumers().size();
25
26 node.setRank( rank );
27 /*std::stringstream s;
28 s << node.getNodeName() << ", " << rank << "\n";
29 std::ofstream myfile;
30 myfile.open("AlgoRank.csv", std::ios::app);
31 myfile << s.str();
32 myfile.close();*/
33
34 return true;
35 }
36
37 //--------------------------------------------------------------------------
39
40 std::ifstream myfile;
41 myfile.open( "InputExecutionPlan.graphml", std::ios::in );
42
43 precedence::PrecTrace execPlan;
44
45 using boost::get;
47
48 boost::dynamic_properties dp;
49 dp.property( "name", get( &AlgoTraceProps::m_name, execPlan ) );
50 dp.property( "index", get( &AlgoTraceProps::m_index, execPlan ) );
51 dp.property( "dataRank", get( &AlgoTraceProps::m_rank, execPlan ) );
52 dp.property( "runtime", get( &AlgoTraceProps::m_runtime, execPlan ) );
53
54 boost::read_graphml( myfile, execPlan, dp );
55
56 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
57 std::pair<itV, itV> vp;
58
59 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
60 precedence::AlgoTraceVertex v = *vp.first;
61 auto index = get( &AlgoTraceProps::m_name, execPlan );
62 if ( index[v] == node.name() ) {
63 runThroughAdjacents( v, execPlan );
64 float rank = m_nodesSucceeded;
65 node.setRank( rank );
66 reset();
67 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
68 }
69 }
70
71 return true;
72 }
73
74 //--------------------------------------------------------------------------
76 boost::graph_traits<precedence::PrecTrace>::vertex_descriptor vertex, precedence::PrecTrace graph ) {
77 typename boost::graph_traits<precedence::PrecTrace>::adjacency_iterator itVB;
78 typename boost::graph_traits<precedence::PrecTrace>::adjacency_iterator itVE;
79
80 for ( boost::tie( itVB, itVE ) = adjacent_vertices( vertex, graph ); itVB != itVE; ++itVB ) {
82 runThroughAdjacents( *itVB, graph );
83 }
84 }
85
86 //--------------------------------------------------------------------------
88
89 std::ifstream myfile;
90 myfile.open( "InputExecutionPlan.graphml", std::ios::in );
91
92 precedence::PrecTrace execPlan;
93 using boost::get;
95
96 boost::dynamic_properties dp;
97 dp.property( "name", get( &AlgoTraceProps::m_name, execPlan ) );
98 dp.property( "index", get( &AlgoTraceProps::m_index, execPlan ) );
99 dp.property( "dataRank", get( &AlgoTraceProps::m_rank, execPlan ) );
100 dp.property( "runtime", get( &AlgoTraceProps::m_runtime, execPlan ) );
101
102 boost::read_graphml( myfile, execPlan, dp );
103
104 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
105 std::pair<itV, itV> vp;
106
107 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
108 precedence::AlgoTraceVertex v = *vp.first;
109 auto index = get( &AlgoTraceProps::m_name, execPlan );
110 if ( index[v] == node.name() ) {
111 auto index_runtime = get( &AlgoTraceProps::m_runtime, execPlan );
112 float rank = index_runtime[v];
113 node.setRank( rank );
114 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
115 }
116 }
117 return true;
118 }
119
120 //--------------------------------------------------------------------------
122
123 std::ifstream myfile;
124 myfile.open( "Eccentricity.graphml", std::ios::in );
125
126 precedence::PrecTrace execPlan;
127
128 boost::dynamic_properties dp;
129 using boost::get;
130
131 dp.property( "name", get( &precedence::AlgoTraceProps::m_name, execPlan ) );
132 dp.property( "Eccentricity", get( &precedence::AlgoTraceProps::m_eccentricity, execPlan ) );
133
134 boost::read_graphml( myfile, execPlan, dp );
135
136 typedef boost::graph_traits<precedence::PrecTrace>::vertex_iterator itV;
137 std::pair<itV, itV> vp;
138
139 for ( vp = boost::vertices( execPlan ); vp.first != vp.second; ++vp.first ) {
140 precedence::AlgoTraceVertex v = *vp.first;
141 auto index = get( &precedence::AlgoTraceProps::m_name, execPlan );
142 if ( index[v] == node.name() ) {
143 auto index_eccentricity = get( &precedence::AlgoTraceProps::m_eccentricity, execPlan );
144 float rank = index_eccentricity[v];
145 node.setRank( rank );
146 // std::cout << "Rank of " << index[v] << " is " << rank << std::endl;
147 }
148 }
149 return true;
150 }
151
152 //--------------------------------------------------------------------------
154
155 // Find eccentricity of the node (only within the data realm of the execution flow graph)
156 recursiveVisit( node );
157
158 float rank = m_maxKnownDepth;
159 node.setRank( rank );
160
161 // Reset visitor for next nodes, if any
162 reset();
163
164 return true;
165 }
166
167 //--------------------------------------------------------------------------
169
170 m_currentDepth += 1;
171
172 auto& products = node.getOutputDataNodes();
173
174 if ( products.empty() )
176
177 for ( auto p : products )
178 for ( auto algoNode : p->getConsumers() ) recursiveVisit( *algoNode );
179
180 m_currentDepth -= 1;
181 }
182
183} // namespace concurrency
void setRank(float rank)
Set Algorithm rank.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
const std::string & name() const
Get node name.
void runThroughAdjacents(boost::graph_traits< precedence::PrecTrace >::vertex_descriptor, precedence::PrecTrace)
Definition Rankers.cpp:75
bool visit(AlgorithmNode &) override
Definition Rankers.cpp:38
void recursiveVisit(AlgorithmNode &)
Depth-first node parser to calculate node eccentricity (only within the data realm of the precedence ...
Definition Rankers.cpp:168
bool visit(AlgorithmNode &) override
Definition Rankers.cpp:153
bool visit(AlgorithmNode &) override
Definition Rankers.cpp:121
bool visit(AlgorithmNode &) override
Definition Rankers.cpp:19
bool visit(AlgorithmNode &) override
Definition Rankers.cpp:87
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex