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