The Gaudi Framework  master (37c0b60a)
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 
16 namespace 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;
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 ) {
81  m_nodesSucceeded += 1;
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;
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;
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
concurrency::RankerByDataRealmEccentricity::reset
void reset() override
Definition: Rankers.h:63
std::pair
concurrency::AlgorithmNode::setRank
void setRank(float rank)
Set Algorithm rank.
Definition: PrecedenceRulesGraph.h:513
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:168
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
concurrency::ControlFlowNode::name
const std::string & name() const
Get node name.
Definition: PrecedenceRulesGraph.h:429
concurrency::AlgorithmNode::getOutputDataNodes
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Definition: PrecedenceRulesGraph.h:508
concurrency::AlgorithmNode
Definition: PrecedenceRulesGraph.h:484
concurrency::RankerByDataRealmEccentricity::m_currentDepth
uint m_currentDepth
Definition: Rankers.h:72
precedence::AlgoTraceProps::m_eccentricity
int m_eccentricity
Definition: PrecedenceRulesGraph.h:59
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:168
concurrency::RankerByDataRealmEccentricity::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:153
concurrency::RankerByCummulativeOutDegree::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:38
concurrency::RankerByCummulativeOutDegree::reset
void reset() override
Definition: Rankers.h:33
precedence::PrecTrace
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
Definition: PrecedenceRulesGraph.h:62
std::ifstream::open
T open(T... args)
precedence::AlgoTraceProps
Definition: PrecedenceRulesGraph.h:49
concurrency
Definition: PrecedenceRulesGraph.cpp:38
Rankers.h
concurrency::RankerByEccentricity::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:121
concurrency::RankerByCummulativeOutDegree::runThroughAdjacents
void runThroughAdjacents(boost::graph_traits< precedence::PrecTrace >::vertex_descriptor, precedence::PrecTrace)
Definition: Rankers.cpp:75
concurrency::RankerByTiming::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:87
Properties.v
v
Definition: Properties.py:122
precedence::AlgoTraceVertex
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
Definition: PrecedenceRulesGraph.h:63
concurrency::RankerByProductConsumption::visit
bool visit(AlgorithmNode &) override
Definition: Rankers.cpp:19
precedence::AlgoTraceProps::m_name
std::string m_name
Definition: PrecedenceRulesGraph.h:54
concurrency::RankerByCummulativeOutDegree::m_nodesSucceeded
int m_nodesSucceeded
Definition: Rankers.h:37
concurrency::RankerByDataRealmEccentricity::m_maxKnownDepth
uint m_maxKnownDepth
Definition: Rankers.h:73
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39
std::ifstream
STL class.