The Gaudi Framework  master (82fdf313)
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, "#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
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, "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
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("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
149len_nt = len(nts) + 1
150# Prepare ideal speedup graph
151idealSpeedup = ROOT.TGraph(2)
152idealSpeedup.SetPoint(0, 1, 1)
153idealSpeedup.SetPoint(1, TotalCores, TotalCores)
154scaled_s = ""
155if scaleThreads:
156 scaled_s = " (scaled for HT)"
157idealSpeedup.SetTitle(
158 "GaudiHive Speedup (Brunel, 100 evts);Thread Pool Size%s;Speedup wrt Serial Case"
159 % scaled_s
160)
161idealSpeedup.SetLineWidth(4)
162idealSpeedup.SetLineColor(ROOT.kGray - 2)
163idealSpeedup.SetLineStyle(2)
164
165# Main Loop: fill all graphs
166neif_graphs = []
167for 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
188neif_graphs.reverse()
189
190# Now that all are complete, let's make the plot
191canvas = ROOT.TCanvas("Speedup", "Speedup", 2048, 1800)
192canvas.cd()
193canvas.SetGrid()
194idealSpeedup.Draw("APL")
195idealSpeedup.GetYaxis().SetRangeUser(0.1, TotalCores + 1) # only one 0
196
197# Line
198line = ROOT.TLine(11, 0, 11, 25)
199line.SetLineColor(ROOT.kRed)
200line.SetLineWidth(4)
201line.SetLineStyle(2)
202line.Draw()
203
204for neif, graph, graphc in neif_graphs:
205 graph.Draw("SamePL")
206 graphc.Draw("SamePL")
207
208# Prepare Legend
209legend = ROOT.TLegend(0.1, 0.45, 0.38, 0.9)
210legend.SetFillColor(ROOT.kWhite)
211legend.SetHeader("# Simultaneous Evts")
212for neif, graph, graphc in neif_graphs:
213 legend.AddEntry(graph, "%s" % neif, LegendDrawOpts)
214 legend.AddEntry(graphc, "%s (clone)" % neif, LegendDrawOpts)
215legend.Draw()
216
217# Labels
218ph_cores = getText(10.5, 15, "Physical Cores", LabelsSize, 90, 2, LabelsFont)
219ph_cores.Draw()
220ht_cores = getText(12.0, 15, "Hardware Threaded Regime", LabelsSize, 90, 2, LabelsFont)
221ht_cores.Draw()
222is_text = getText(16, 16.5, "Ideal (linear) Speedup", LabelsSize, 45, 918, LabelsFont)
223is_text.Draw()
224ht_weight = 0
225if 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
237if scaleThreads:
238 scaled_s = "_HTScaled"
239canvas.Print("GaudiHivePerfBrunelAllPoints%s.png" % scaled_s)
createFname(neif, nt, cFlag)
formatGraphs(graph, graphc)
xtractTiming(neif, nt, cFlag)
getText(x, y, text, scale, angle, colour, font)