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