Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
plotSpeedupsPyRoot.py
Go to the documentation of this file.
1 from ROOT import *
2 '''
3 Script to parse all the logs and produce the speedup plot.
4 Usage:
5 plotSpeedupsPyRoot.py --> vanilla plot
6 plotSpeedupsPyRoot.py 1 --> HT scaled plot
7 The variable fname_template contains the template of the file names to be
8 opened and parsed and is FIXED for all the logs.
9 The word "seconds" is looked for in the log and then the total runtime of the
10 event loop is extracted. This allows to discard the time spent in calibration
11 and so on.
12 '''
13 
14 # Configuration ----------------------------------------------------------------
15 fname_template = "measurement_BrunelScenario_n100_eif%s_aif100_nthreads%s_c%s_dqFalse_v5.log"
16 # Number of events in flight
17 neif_l = [1, 2, 3, 5, 20, 30]
18 # Number of Threads
19 nts = [2, 3, 5, 10, 11, 12, 13, 15, 23]
20 # Clone Flag
21 cFlags = ["True", "False"]
22 
23 ScalarTime = 1640.87
24 
25 # Style
26 LegendDrawOpts = "lp"
27 LineColours = [kRed, kBlue, kGreen + 2, kOrange, kPink + 10, kViolet + 10]
28 MarkerStyles = [
29  kFullCircle, kOpenCross, kFullTriangleUp, kOpenStar, kFullCross,
30  kOpenCircle
31 ]
32 MarkerSize = 4
33 LineWidth = 6
34 LineStyle = 7
35 graph_counter = 0
36 
37 PhCores = 11
38 TotalCores = 24
39 HtCoreWeight = 0.4
40 
41 LabelsFont = 12
42 LabelsSize = .6
43 
44 # --------------------
45 
46 
47 def scaleCores(n_threads):
48  effective_n_threads = n_threads
49  if effective_n_threads > PhCores:
50  ht_cores = n_threads - PhCores
51  effective_n_threads = PhCores + ht_cores * HtCoreWeight
52  return effective_n_threads
53 
54 
55 # --------------------
56 
57 
58 def getText(x, y, text, scale, angle, colour, font):
59  lat = TLatex(
60  x, y,
61  "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text))
62  if angle != 0.:
63  lat.SetTextAngle(angle)
64  return lat
65 
66 
67 # --------------------
68 
69 
70 def formatGraphs(graph, graphc):
71  global graph_counter
72  graphc.SetLineStyle(LineStyle)
73  graphs = (graph, graphc)
74  for g in graphs:
75  g.SetLineWidth(LineWidth)
76  g.SetMarkerSize(MarkerSize)
77  g.SetMarkerStyle(MarkerStyles[graph_counter])
78  g.SetLineColor(LineColours[graph_counter])
79  g.SetMarkerColor(LineColours[graph_counter])
80  graph_counter += 1
81 
82 
83 # --------------------
84 
85 
86 def createFname(neif, nt, cFlag):
87  return fname_template % (neif, nt, cFlag)
88 
89 
90 # --------------------
91 
92 
93 def xtractTiming(neif, nt, cFlag):
94  filename = createFname(neif, nt, cFlag)
95  ifile = open(filename, "r")
96  seconds = -1
97  for line in ifile:
98  if "seconds" in line:
99  line = line[:-1]
100  seconds = float(line.split(" ")[-1])
101  break
102  ifile.close()
103  if seconds == -1:
104  seconds = xtractTiming(neif, nts[nts.index(nt) - 1], cFlag)
105  return seconds
106 
107 
108 # --------------------
109 
110 import sys
111 scaleThreads = False
112 if len(sys.argv) > 1:
113  scaleThreads = True
114 
115 # main loop: just printouts
116 for neif in neif_l:
117  print "Events in flight: %s" % neif
118  for tn in nts:
119  print "%s %s %s" % (tn, xtractTiming(neif, tn, False),
120  xtractTiming(neif, tn, True))
121 
122 len_nt = len(nts) + 1
123 # Prepare ideal speedup graph
124 idealSpeedup = TGraph(2)
125 idealSpeedup.SetPoint(0, 1, 1)
126 idealSpeedup.SetPoint(1, TotalCores, TotalCores)
127 scaled_s = ""
128 if scaleThreads:
129  scaled_s = " (scaled for HT)"
130 idealSpeedup.SetTitle(
131  "GaudiHive Speedup (Brunel, 100 evts);Thread Pool Size%s;Speedup wrt Serial Case"
132  % scaled_s)
133 idealSpeedup.SetLineWidth(4)
134 idealSpeedup.SetLineColor(kGray - 2)
135 idealSpeedup.SetLineStyle(2)
136 
137 # Main Loop: fill all graphs
138 neif_graphs = []
139 for neif in neif_l: # One graph per number of events in flight
140  graph = TGraph(len_nt)
141  graph.SetName("%s" % neif)
142  graph.SetPoint(0, 1, 1)
143 
144  graphc = TGraph(len_nt)
145  graphc.SetName("%s clone" % neif)
146  graphc.SetPoint(0, 1, 1)
147  counter = 1
148  for tn in nts:
149  scaled_tn = tn
150  if scaleThreads:
151  scaled_tn = scaleCores(tn)
152  time = xtractTiming(neif, tn, False)
153  graph.SetPoint(counter, scaled_tn, ScalarTime / time)
154  timec = xtractTiming(neif, tn, True)
155  graphc.SetPoint(counter, scaled_tn, ScalarTime / timec)
156  counter += 1
157  formatGraphs(graph, graphc)
158  neif_graphs.append([neif, graph, graphc])
159 
160 neif_graphs.reverse()
161 
162 # Now that all are complete, let's make the plot
163 canvas = TCanvas("Speedup", "Speedup", 2048, 1800)
164 canvas.cd()
165 canvas.SetGrid()
166 idealSpeedup.Draw("APL")
167 idealSpeedup.GetYaxis().SetRangeUser(0.1, TotalCores + 1) # only one 0
168 
169 # Line
170 line = TLine(11, 0, 11, 25)
171 line.SetLineColor(kRed)
172 line.SetLineWidth(4)
173 line.SetLineStyle(2)
174 line.Draw()
175 
176 for neif, graph, graphc in neif_graphs:
177  graph.Draw("SamePL")
178  graphc.Draw("SamePL")
179 
180 # Prepare Legend
181 legend = TLegend(.1, .45, .38, .9)
182 legend.SetFillColor(kWhite)
183 legend.SetHeader("# Simultaneous Evts")
184 for neif, graph, graphc in neif_graphs:
185  legend.AddEntry(graph, "%s" % neif, LegendDrawOpts)
186  legend.AddEntry(graphc, "%s (clone)" % neif, LegendDrawOpts)
187 legend.Draw()
188 
189 # Labels
190 ph_cores = getText(10.5, 15, "Physical Cores", LabelsSize, 90, 2, LabelsFont)
191 ph_cores.Draw()
192 ht_cores = getText(12., 15, "Hardware Threaded Regime", LabelsSize, 90, 2,
193  LabelsFont)
194 ht_cores.Draw()
195 is_text = getText(16, 16.5, "Ideal (linear) Speedup", LabelsSize, 45, 918,
196  LabelsFont)
197 is_text.Draw()
198 ht_weight = 0
199 if scaleThreads:
200  ht_weight = getText(
201  18.5, 8,
202  "#splitline{Hardware threaded}{cores weight: %s}" % HtCoreWeight,
203  LabelsSize, 0, 600, LabelsFont)
204  ht_weight.Draw()
205 
206 if scaleThreads:
207  scaled_s = "_HTScaled"
208 canvas.Print("GaudiHivePerfBrunelAllPoints%s.png" % scaled_s)
def createFname(neif, nt, cFlag)
def getText(x, y, text, scale, angle, colour, font)
def formatGraphs(graph, graphc)
def scaleCores(n_threads)
def xtractTiming(neif, nt, cFlag)