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