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