Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "PlotMEIFBenchmarks.hh"
0002 
0003 PlotMEIFBenchmarks::PlotMEIFBenchmarks(const TString& arch, const TString& sample, const TString& build)
0004     : arch(arch), sample(sample), build(build) {
0005   // setup style for plotting
0006   setupStyle();
0007 
0008   // get file
0009   file = TFile::Open("benchmarkMEIF_" + arch + "_" + sample + "_" + build + ".root");
0010 
0011   // setup enum
0012   setupARCHEnum(arch);
0013 
0014   // setup arch options
0015   setupArch();
0016 
0017   // setup events
0018   setupEvents();
0019 }
0020 
0021 PlotMEIFBenchmarks::~PlotMEIFBenchmarks() { delete file; }
0022 
0023 void PlotMEIFBenchmarks::RunMEIFBenchmarkPlots() {
0024   // title options
0025   const TString nvu = Form("%iint", arch_opt.vumax);
0026 
0027   // x-axis title
0028   const TString xtitleth = "Number of Threads";
0029 
0030   // y-axis title
0031   const TString ytitletime = "Averarge Time per Event [s]";
0032   const TString ytitlespeedup = "Average Speedup per Event";
0033 
0034   // Do the overlaying!
0035   PlotMEIFBenchmarks::MakeOverlay(
0036       "time",
0037       build + " " + sample + " Multiple Events in Flight Benchmark on " + arch + " [nVU=" + nvu + "]",
0038       xtitleth,
0039       ytitletime,
0040       arch_opt.thmin,
0041       arch_opt.thmax,
0042       arch_opt.thmeiftimemin,
0043       arch_opt.thmeiftimemax);
0044 
0045   PlotMEIFBenchmarks::MakeOverlay(
0046       "speedup",
0047       build + " " + sample + " Multiple Events in Flight Speedup on " + arch + " [nVU=" + nvu + "]",
0048       xtitleth,
0049       ytitlespeedup,
0050       arch_opt.thmin,
0051       arch_opt.thmax,
0052       arch_opt.thmeifspeedupmin,
0053       arch_opt.thmeifspeedupmax);
0054 }
0055 
0056 void PlotMEIFBenchmarks::MakeOverlay(const TString& text,
0057                                      const TString& title,
0058                                      const TString& xtitle,
0059                                      const TString& ytitle,
0060                                      const Double_t xmin,
0061                                      const Double_t xmax,
0062                                      const Double_t ymin,
0063                                      const Double_t ymax) {
0064   // special setups
0065   const Bool_t isSpeedup = text.Contains("speedup", TString::kExact);
0066 
0067   // canvas
0068   auto canv = new TCanvas();
0069   canv->cd();
0070   canv->SetGridy();
0071   if (!isSpeedup)
0072     canv->SetLogy();
0073   canv->DrawFrame(xmin, ymin, xmax, ymax, "");
0074 
0075   // legend
0076   const Double_t x1 = (isSpeedup ? 0.20 : 0.60);
0077   const Double_t y1 = 0.65;
0078   auto leg = new TLegend(x1, y1, x1 + 0.25, y1 + 0.2);
0079   leg->SetBorderSize(0);
0080 
0081   // get tgraphs for meif and draw
0082   TGVec graphs(nevents);
0083   for (auto i = 0U; i < nevents; i++) {
0084     const auto& event = events[i];
0085     auto& graph = graphs[i];
0086 
0087     const TString nEV = Form("%i", event.nev);
0088     graph = (TGraph*)file->Get("g_" + build + "_MEIF_nEV" + nEV + "_" + text);
0089 
0090     if (graph) {
0091       // restyle a bit
0092       graph->SetTitle(title + ";" + xtitle + ";" + ytitle);
0093 
0094       graph->SetLineWidth(2);
0095       graph->SetLineColor(event.color);
0096       graph->SetMarkerStyle(kFullCircle);
0097       graph->SetMarkerColor(event.color);
0098       graph->GetXaxis()->SetRangeUser(xmin, xmax);
0099       graph->GetYaxis()->SetRangeUser(ymin, ymax);
0100 
0101       // draw and add to legend
0102       graph->Draw(i > 0 ? "LP SAME" : "ALP");
0103       leg->AddEntry(graph, Form("%i Events", event.nev), "LP");
0104     }
0105   }
0106 
0107   // Draw ideal scaling line
0108   TF1* scaling = NULL;
0109   if (isSpeedup) {
0110     scaling = new TF1("ideal_scaling", "x", arch_opt.thmin, arch_opt.thmeifspeedupmax);
0111     scaling->SetLineColor(kBlack);
0112     scaling->SetLineStyle(kDashed);
0113     scaling->SetLineWidth(2);
0114     scaling->Draw("SAME");
0115     leg->AddEntry(scaling, "Ideal Scaling", "l");
0116   }
0117 
0118   // draw legend last
0119   leg->Draw("SAME");
0120 
0121   // Save the png
0122   const TString outname = arch + "_" + sample + "_" + build + "_MEIF_" + text;
0123   canv->SaveAs(outname + ".png");
0124 
0125   // Save log-x version
0126   canv->SetLogx();
0127   for (auto i = 0U; i < nevents; i++) {
0128     auto& graph = graphs[i];
0129 
0130     // reset axes for logx
0131     if (graph) {
0132       graph->GetXaxis()->SetRangeUser(xmin, xmax);
0133       graph->GetYaxis()->SetRangeUser(ymin, ymax);
0134     }
0135   }
0136   canv->Update();
0137   canv->SaveAs(outname + "_logx.png");
0138 
0139   // delete everything
0140   for (auto& graph : graphs)
0141     delete graph;
0142   if (isSpeedup)
0143     delete scaling;
0144   delete leg;
0145   delete canv;
0146 }