Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:23

0001 #!/usr/bin/env python
0002 
0003 import re
0004 import sys
0005 import array
0006 
0007 import ROOT
0008 ROOT.gROOT.SetBatch(True)
0009 ROOT.PyConfig.IgnoreCommandLineOptions = True
0010 
0011 
0012 colors = [
0013     ROOT.kBlue,
0014     ROOT.kRed+1,
0015     ROOT.kBlack
0016 ]
0017 
0018 def findBounds(x, ys, xmin=None, ymin=None, xmax=None, ymax=None):
0019     if xmin is None:
0020         xmin = min(x)
0021     if xmax is None:
0022         xmax = max(x)
0023     if ymin is None:
0024         ymin = min([min(y) for y in ys])
0025     if ymax is None:
0026         ymax = max([max(y) for y in ys]) * 1.1
0027 
0028     return (xmin, ymin, xmax, ymax)
0029 
0030 
0031 def makePlot(name, x, ys, ytitle,
0032              title=None,
0033              legends=None,
0034              ideal1=None,
0035              bounds={},
0036              legendYmax=0.99
0037          ):
0038     canv = ROOT.TCanvas()
0039     canv.cd()
0040     canv.SetTickx(1)
0041     canv.SetTicky(1)
0042     canv.SetGridy(1)
0043 
0044     bounds = findBounds(x, ys, **bounds)
0045     frame = canv.DrawFrame(*bounds)
0046 
0047     frame.GetXaxis().SetTitle("Number of threads")
0048     frame.GetYaxis().SetTitle(ytitle)
0049     if title is not None:
0050         frame.SetTitle(title)
0051     frame.Draw("")
0052 
0053     leg = None
0054     if legends is not None:
0055         leg = ROOT.TLegend(0.77,legendYmax-0.19,0.99,legendYmax)
0056 
0057     graphs = []
0058 
0059     if ideal1 is not None:
0060         ymax = bounds[3]
0061         ideal_y = [ideal1, ymax]
0062         ideal_x = [1, ymax/ideal1]
0063         gr = ROOT.TGraph(2, array.array("d", ideal_x), array.array("d", ideal_y))
0064         gr.SetLineColor(ROOT.kBlack)
0065         gr.SetLineStyle(3)
0066         gr.Draw("same")
0067         if leg:
0068             leg.AddEntry(gr, "Ideal scaling", "l")
0069         graphs.append(gr)
0070 
0071     for i, y in enumerate(ys):
0072         gr = ROOT.TGraph(len(x), array.array("d", x), array.array("d", y))
0073         color = colors[i]
0074         gr.SetLineColor(color)
0075         gr.SetMarkerColor(color)
0076         gr.SetMarkerStyle(ROOT.kFullCircle)
0077         gr.SetMarkerSize(1)
0078 
0079         gr.Draw("LP SAME")
0080         if leg:
0081             leg.AddEntry(gr, legends[i], "lp")
0082 
0083         graphs.append(gr)
0084 
0085     if leg:
0086         leg.Draw("same")
0087 
0088     canv.SaveAs(name+".png")
0089     canv.SaveAs(name+".pdf")
0090 
0091 
0092 def main(argv):
0093     (inputfile, outputfile, graph_label) = argv[1:4]
0094 
0095     re_mt = re.compile("nTH(?P<th>\d+)_nEV(?P<ev>\d+)")
0096     re_mp = re.compile("nJOB(?P<job>\d+)")
0097 
0098     mt = {}
0099     mp = {}
0100 
0101     f = open(inputfile)
0102     for line in f:
0103         if not "AVX512" in line:
0104             continue
0105         comp = line.split(" ")
0106         m = re_mt.search(comp[0])
0107         if m:
0108             if m.group("th") != m.group("ev"):
0109                 raise Exception("Can't handle yet different numbers of threads (%s) and events (%s)" % (m.group("th"), m.group("ev")))
0110             mt[int(m.group("th"))] = float(comp[1])
0111             continue
0112         m = re_mp.search(comp[0])
0113         if m:
0114             mp[int(m.group("job"))] = float(comp[1])
0115     f.close()
0116 
0117     ncores = sorted(list(set(mt.keys() + mp.keys())))
0118     mt_y = [mt[n] for n in ncores]
0119     mp_y = [mp[n] for n in ncores]
0120     ideal1 = mt_y[0]/ncores[0]
0121     ideal1_mp = mp_y[0]/ncores[0]
0122 
0123     makePlot(outputfile+"_throughput", ncores,
0124              [mt_y, mp_y],
0125              "Throughput (events/s)",
0126              title=graph_label,
0127              legends=["Multithreading", "Multiprocessing"],
0128              ideal1=ideal1,
0129              bounds=dict(ymin=0, xmin=0),
0130              legendYmax=0.5
0131     )
0132 
0133     eff = [mt_y[i]/mp_y[i] for i in xrange(0, len(ncores))]
0134     makePlot(outputfile+"_efficiency", ncores,
0135              [eff],
0136              "Multithreading efficiency (MT/MP)",
0137              title=graph_label,
0138              bounds=dict(ymin=0.9, ymax=1.1)
0139     )
0140 
0141     eff_vs_ideal_mt = [mt_y[i]/(ideal1*n) for i, n in enumerate(ncores)]
0142     eff_vs_ideal_mp = [mp_y[i]/(ideal1*n) for i, n in enumerate(ncores)]
0143     makePlot(outputfile+"_efficiency_ideal", ncores,
0144              [eff_vs_ideal_mt, eff_vs_ideal_mp],
0145              "Efficiency wrt. ideal",
0146              title=graph_label,
0147              legends=["Multithreading", "Multiprocessing"],
0148              bounds=dict(ymin=0.8, ymax=1.01, xmax=65),
0149              legendYmax=0.9
0150     )
0151 
0152     speedup_mt = [mt_y[i]/ideal1 for i in xrange(0, len(ncores))]
0153     speedup_mp = [mp_y[i]/ideal1 for i in xrange(0, len(ncores))]
0154     makePlot(outputfile+"_speedup", ncores,
0155              [speedup_mt, speedup_mp],
0156              "Speedup wrt. 1 thread",
0157              title=graph_label,
0158              legends=["Multithreading", "Multiprocessing"],
0159              ideal1=1,
0160              bounds=dict(ymin=0, xmin=0),
0161              legendYmax=0.5
0162     )
0163 
0164 
0165 if __name__ == "__main__":
0166     main(sys.argv)