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