forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TProofBench.cxx
1604 lines (1438 loc) · 53.5 KB
/
TProofBench.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/proof:$Id$
// Author: G.Ganis, S.Ryu Feb 2011
/*************************************************************************
* Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/**
\defgroup proofbench PROOF benchmark utilities
\ingroup proof
Set of utilities to benchmark a PROOF facility.
See also https://root.cern.ch/proof-benchmark-framework-tproofbench .
*/
/** \class TProofBench
\ingroup proofbench
Steering class for PROOF benchmarks
*/
#include "RConfigure.h"
#include "TProofBench.h"
#include "Getline.h"
#include "TProofBenchRunCPU.h"
#include "TProofBenchRunDataRead.h"
#include "TProofBenchDataSet.h"
#include "TProofNodes.h"
#include "TClass.h"
#include "TFile.h"
#include "TFileCollection.h"
#include "TFileInfo.h"
#include "THashList.h"
#include "TKey.h"
#include "TObjString.h"
#include "TProof.h"
#include "TROOT.h"
#include "TSortedList.h"
#include "TTimeStamp.h"
#include "TUrl.h"
#include "TCanvas.h"
#include "TF1.h"
#include "TGraphErrors.h"
#include "TH1F.h"
#include "TMath.h"
#include "TProfile.h"
#include "TStyle.h"
#include "TLegend.h"
#ifdef WIN32
#include <io.h>
#endif
ClassImp(TProofBench);
// Functions for fitting
TF1 *TProofBench::fgFp1 = 0;
TF1 *TProofBench::fgFp1n = 0;
TF1 *TProofBench::fgFp2 = 0;
TF1 *TProofBench::fgFp2n = 0;
TF1 *TProofBench::fgFp3 = 0;
TF1 *TProofBench::fgFp3n = 0;
TF1 *TProofBench::fgFio = 0;
TF1 *TProofBench::fgFioV = 0;
static Int_t gFioVn0 = -1; // Number of real cores for fgFioV
static Int_t gFioVn1 = -1; // Number of real+hyper cores for fgFioV
TList *TProofBench::fgGraphs = new TList;
////////////////////////////////////////////////////////////////////////////////
/// Simple polynomial 1st degree
Double_t funp1(Double_t *xx, Double_t *par)
{
Double_t res = par[0] + par[1] * xx[0];
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// Simple polynomial 2nd degree
Double_t funp2(Double_t *xx, Double_t *par)
{
Double_t res = par[0] + par[1] * xx[0] + par[2] * xx[0] * xx[0];
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// Normalized 1st degree
Double_t funp1n(Double_t *xx, Double_t *par)
{
Double_t res = par[0] / xx[0] + par[1];
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// Normalized 2nd degree
Double_t funp2n(Double_t *xx, Double_t *par)
{
Double_t res = par[0] / xx[0] + par[1] + par[2] * xx[0];
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// I/O saturated rate function
Double_t funio(Double_t *xx, Double_t *par)
{
Double_t sat = par[0] / par[1] * (xx[0] * par[1] / par[2] - 1.);
if (xx[0] < par[2] / par[1]) sat = 0.;
Double_t res = par[0] * xx[0] / (1. + sat);
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// I/O saturated rate function with varying Rcpu
Double_t funiov(Double_t *xx, Double_t *par)
{
// par[0] = rio
// par[1] = b1
// par[2] = b2
// par[3] = nc
// par[4] = ri
Double_t rio = par[0] / par[3] * xx[0];
if (xx[0] > par[3]) rio = par[0];
Double_t rcpu = par[1] * xx[0];
if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(xx[0] - gFioVn0);
if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
Double_t res = 1. / (1./par[4] + 1./rio + 1./rcpu);
return res;
}
////////////////////////////////////////////////////////////////////////////////
/// Function with varying Rcpu
Double_t funcpuv(Double_t *xx, Double_t *par)
{
// par[0] = offset
// par[1] = rate contribution from real cores
// par[2] = rate contribution from hyper cores
Double_t n = (xx[0] - par[0]);
Double_t rcpu = par[1] * n;
if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(n - gFioVn0);
if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
return rcpu;
}
////////////////////////////////////////////////////////////////////////////////
/// Function with varying Rcpu normalized
Double_t funcpuvn(Double_t *xx, Double_t *par)
{
// par[0] = offset
// par[1] = rate contribution from real cores
// par[2] = rate contribution from hyper cores
Double_t n = (xx[0] - par[0]);
Double_t rcpu = par[1] * n;
if (xx[0] > gFioVn0) rcpu = par[1]*gFioVn0 + par[2]*(n - gFioVn0);
if (xx[0] > gFioVn1) rcpu = par[1]*gFioVn0 + par[2]*(gFioVn1 - gFioVn0);
return rcpu / xx[0];
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor: check PROOF and load selectors PAR
TProofBench::TProofBench(const char *url, const char *outfile, const char *proofopt)
: fUnlinkOutfile(kFALSE), fProofDS(0), fOutFile(0),
fNtries(4), fHistType(0), fNHist(16), fReadType(0),
fDataSet("BenchDataSet"), fNFilesWrk(2), fReleaseCache(kTRUE),
fDataGenSel(kPROOF_BenchSelDataGenDef),
fRunCPU(0), fRunDS(0), fDS(0), fDebug(kFALSE), fDescription(0)
{
SetBit(kInvalidObject);
if (!url) {
Error("TProofBench", "specifying a PROOF master url is mandatory - cannot continue");
return;
}
if (!(fProof = TProof::Open(url, proofopt)) || (fProof && !fProof->IsValid())) {
Error("TProofBench", "could not open a valid PROOF session - cannot continue");
return;
}
// Get the size of the cluster
fNumWrkMax = fProof->GetParallel();
if (fProof->UseDynamicStartup() && TProof::GetEnvVars()) {
// It must be passed as PROOF option 'workers=N' and recorded in the envs vars
TNamed *n = (TNamed *) TProof::GetEnvVars()->FindObject("PROOF_NWORKERS");
if (!n) {
Error("TProofBench", "dynamic mode: you must specify the max number of workers");
fProof->Close();
SafeDelete(fProof);
return;
}
TString sn(n->GetTitle());
if (sn.IsDigit()) fNumWrkMax = sn.Atoi();
if (!sn.IsDigit()) {
Error("TProofBench", "dynamic mode: wrong specification of the max number of"
" workers ('%s')", n->GetTitle());
fProof->Close();
SafeDelete(fProof);
return;
}
}
if (fNumWrkMax <= 0) {
Error("TProofBench", "wrong max number of workers ('%d')", fNumWrkMax);
fProof->Close();
SafeDelete(fProof);
return;
}
// By default we use the same instance for dataset actions
fProofDS = fProof;
// The object is now valid
ResetBit(kInvalidObject);
// Identifying string
TUrl u(url);
TString host(TString::Format("PROOF at %s", u.GetHost()));
if (!strcmp(u.GetProtocol(), "lite")) host.Form("PROOF-Lite on %s", gSystem->HostName());
fDescription = new TNamed("PB_description",
TString::Format("%s, %d workers", host.Data(), fNumWrkMax).Data());
Printf(" Run description: %s", fDescription->GetTitle());
// Set output file
if (SetOutFile(outfile, kFALSE) != 0)
Warning("TProofBench", "problems opening '%s' - ignoring: use SetOutFile to try"
" again or with another file", outfile);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor
TProofBench::~TProofBench()
{
CloseOutFile();
if (fUnlinkOutfile) gSystem->Unlink(fOutFileName);
SafeDelete(fReadType);
SafeDelete(fRunCPU);
SafeDelete(fRunDS);
SafeDelete(fDescription);
}
////////////////////////////////////////////////////////////////////////////////
/// Set the otuput file
/// Return 0 on success, -1 on error
Int_t TProofBench::OpenOutFile(Bool_t wrt, Bool_t verbose)
{
// Remove any bad file
if (fOutFile && fOutFile->IsZombie()) SafeDelete(fOutFile);
Int_t rc = 0;
if (!fOutFile && fOutFileName.Length() > 0) {
const char *mode = 0;
if (wrt)
mode = gSystem->AccessPathName(fOutFileName) ? "RECREATE" : "UPDATE";
else
mode = "READ";
if (!(fOutFile = TFile::Open(fOutFileName, mode)) || (fOutFile && fOutFile->IsZombie())) {
if (verbose)
Warning("OpenOutFile", "problems opening '%s' - ignoring: use SetOutFile to try"
" again or with another file", fOutFileName.Data());
rc = -1;
}
if (fOutFile) {
gROOT->GetListOfFiles()->Remove(fOutFile);
if (!strcmp(mode, "RECREATE")) {
// Save the description string
fOutFile->cd();
fDescription->Write();
}
}
}
return rc;
}
////////////////////////////////////////////////////////////////////////////////
/// Set the output file
/// Return 0 on success, -1 on error
Int_t TProofBench::SetOutFile(const char *outfile, Bool_t verbose)
{
Int_t rc = 0;
// Close existing file, if any
if (fOutFile) {
if (!fOutFile->IsZombie()) fOutFile->Close();
SafeDelete(fOutFile);
}
fOutFileName = outfile;
if (fOutFileName == "<default>") {
// Default output file: proofbench-<master>-<DayMonthYear-hhmm>.root
TDatime dat;
const char *lite = (fProof->IsLite()) ? "-lite" : "";
fOutFileName.Form("proofbench-%s%s-%dw-%d-%.2d%.2d.root",
fProof->GetMaster(), lite, fNumWrkMax,
dat.GetDate(), dat.GetHour(), dat.GetMinute());
Info("SetOutFile", "using default output file: '%s'", fOutFileName.Data());
fUnlinkOutfile = kTRUE;
}
if (!fOutFileName.IsNull()) {
if ((rc = OpenOutFile(kTRUE, kFALSE)) != 0 && verbose)
Warning("SetOutFile", "problems opening '%s' - ignoring: use SetOutFile to try"
" again or with another file", outfile);
}
return rc;
}
////////////////////////////////////////////////////////////////////////////////
/// Close output file
void TProofBench::CloseOutFile()
{
if (SetOutFile(0) != 0)
Warning("CloseOutFile", "problems closing '%s'", fOutFileName.Data());
}
////////////////////////////////////////////////////////////////////////////////
/// Perform the CPU run
/// Return 0 on success, -1 on error
Int_t TProofBench::RunCPU(Long64_t nevents, Int_t start, Int_t stop, Int_t step)
{
// Open the file for the results
if (OpenOutFile(kTRUE) != 0) {
Error("RunCPU", "problems opening '%s' to save the result", fOutFileName.Data());
return -1;
}
fUnlinkOutfile = kFALSE;
SafeDelete(fRunCPU);
TPBHistType *htype = new TPBHistType(TPBHistType::kHist1D); // Owned by the input list
fRunCPU = new TProofBenchRunCPU(htype, fNHist, fOutFile);
if (!fCPUSel.IsNull()) fRunCPU->SetSelName(fCPUSel);
if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
if (!fCPUPar.IsNull()) fRunCPU->SetParList(fCPUPar);
fRunCPU->Run(nevents, start, stop, step, fNtries, fDebug, -1);
// Close the file
if (SetOutFile(0) != 0)
Warning("RunCPU", "problems closing '%s'", fOutFileName.Data());
// Done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Perform the CPU run scanning over the number of workers per node
/// Return 0 on success, -1 on error
Int_t TProofBench::RunCPUx(Long64_t nevents, Int_t start, Int_t stop)
{
// Open the file for the results
if (OpenOutFile(kTRUE) != 0) {
Error("RunCPUx", "problems opening '%s' to save the result", fOutFileName.Data());
return -1;
}
fUnlinkOutfile = kFALSE;
SafeDelete(fRunCPU);
TPBHistType *htype = new TPBHistType(TPBHistType::kHist1D); // Owned by the input list
fRunCPU = new TProofBenchRunCPU(htype, fNHist, fOutFile);
if (!fCPUSel.IsNull()) fRunCPU->SetSelName(fCPUSel);
if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
if (!fCPUPar.IsNull()) fRunCPU->SetParList(fCPUPar);
fRunCPU->Run(nevents, start, stop, -2, fNtries, fDebug, -1);
// Close the file
if (SetOutFile(0) != 0)
Warning("RunCPUx", "problems closing '%s'", fOutFileName.Data());
// Done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Draw the CPU speedup plot.
/// opt = 'typewhat', e.g. 'std:max:'
/// type = 'std:' draw standard evt/s plot
/// 'stdx:' draw standard evt/s plot, 1 worker per node
/// 'norm:' draw normalized plot
/// 'normx:' draw normalized plot, 1 worker per node
/// what = 'max:' draw max rate
/// 'avg:' draw average rate
/// 'all:' draw max and average rate on same plot (default)
/// dofit = 0 no fit
/// 1 fit with the relevant '1st degree related' function
/// 2 fit with the relevant '2nd degree related' function
/// 3 fit with varying rcpu function
/// n0 = for dofit == 3, number of real cores
/// n1 = for dofit == 3, number of total cores (real + hyperthreaded)
///
void TProofBench::DrawCPU(const char *outfile, const char *opt, Bool_t verbose,
Int_t dofit, Int_t n0, Int_t n1)
{
// Get the TProfile an create the graphs
TFile *fout = TFile::Open(outfile, "READ");
if (!fout || (fout && fout->IsZombie())) {
::Error("DrawCPU", "could not open file '%s' ...", outfile);
return;
}
// Get description
TString description("<not available>");
TNamed *nmdesc = (TNamed *) fout->Get("PB_description");
if (nmdesc) description = nmdesc->GetTitle();
// Parse option
TString oo(opt);
Bool_t isNorm = (oo.Contains("norm")) ? kTRUE : kFALSE;
Bool_t isX = (oo.Contains("stdx:") || oo.Contains("normx:")) ? kTRUE : kFALSE;
Bool_t doAvg = kTRUE, doMax = kTRUE;
if (oo.Contains("avg:")) doMax = kFALSE;
if (oo.Contains("max:")) doAvg = kFALSE;
const char *dirn = (isX) ? "RunCPUx" : "RunCPU";
TDirectory *d = (TDirectory *) fout->Get(dirn);
if (!d) {
::Error("DrawCPU", "could not find directory '%s' ...", dirn);
fout->Close();
delete fout;
return;
}
d->cd();
TString hprofn, hmaxn;
const char *lx = (isX) ? "_x" : "";
const char *ln = (isNorm) ? "Norm" : "Prof";
hprofn.Form("%s%s_CPU_QR_Evts", ln, lx);
hmaxn.Form("%s%s_CPU_PS_MaxEvts", ln, lx);
Double_t xmin = -1., xmax = -1.;
Double_t ami = -1., amx = -1., mmi = -1., mmx = -1.;
Int_t kamx = -1, kmmx = -1, nbins = -1;
Double_t ymx = -1., ymi = -1.;
TProfile *pf = 0;
Int_t kmx = -1;
TProfile *pfav = 0;
TGraphErrors *grav = 0;
if (doAvg) {
if (!(grav = GetGraph(d, hprofn, nbins, xmin, xmax, ami, amx, kamx, pfav))) {
::Error("DrawCPU", "could not find '%s' ...", hprofn.Data());
fout->Close();
delete fout;
return;
}
ymx = amx;
ymi = ami;
pf = pfav;
kmx = kamx;
}
TProfile *pfmx = 0;
TGraphErrors *grmx = 0;
if (doMax) {
if (!(grmx = GetGraph(d, hmaxn, nbins, xmin, xmax, mmi, mmx, kmmx, pfmx))) {
::Warning("DrawCPU", "could not find '%s': feature added in 5.34/11", hmaxn.Data());
if (!grav) {
// Nothing to do if not asked for the average
fout->Close();
delete fout;
return;
}
doMax = kFALSE;
}
if (mmx > ymx) ymx = mmx;
if ((ymi > 0 && mmi < ymi) || (ymi < 0.)) ymi = mmi;
pf = pfmx;
kmx = kmmx;
}
// Create the canvas
TCanvas *cpu = new TCanvas("cpu", "Rate vs wrks",204,69,1050,502);
cpu->Range(-3.106332,0.7490716,28.1362,1.249867);
TH1F *hgr = new TH1F("Graph-CPU"," CPU speed-up", nbins*4, xmin, xmax);
hgr->SetMaximum(ymx + (ymx-ymi)*0.2);
hgr->SetMinimum(0);
if (isNorm) hgr->SetMaximum(ymx*1.2);
hgr->SetDirectory(0);
hgr->SetStats(0);
hgr->GetXaxis()->SetTitle(pf->GetXaxis()->GetTitle());
hgr->GetXaxis()->CenterTitle(true);
hgr->GetXaxis()->SetLabelSize(0.05);
hgr->GetXaxis()->SetTitleSize(0.06);
hgr->GetXaxis()->SetTitleOffset(0.62);
hgr->GetYaxis()->SetTitleSize(0.08);
hgr->GetYaxis()->SetTitleOffset(0.52);
hgr->GetYaxis()->SetTitle("Rate (events/s)");
TLegend *leg = 0;
if (isNorm) {
leg = new TLegend(0.7, 0.8, 0.9, 0.9);
} else {
leg = new TLegend(0.1, 0.8, 0.3, 0.9);
}
gStyle->SetOptTitle(0);
TGraphErrors *gr = 0;
if (doAvg) {
grav->SetFillColor(1);
grav->SetLineColor(13);
grav->SetMarkerColor(4);
grav->SetMarkerStyle(21);
grav->SetMarkerSize(1.2);
grav->SetHistogram(hgr);
if (verbose) grav->Print();
grav->Draw("alp");
leg->AddEntry(grav, "Average", "P");
gr = grav;
}
if (doMax) {
grmx->SetFillColor(1);
grmx->SetLineColor(13);
grmx->SetMarkerColor(2);
grmx->SetMarkerStyle(29);
grmx->SetMarkerSize(1.8);
grmx->SetHistogram(hgr);
if (verbose) grmx->Print();
if (doAvg) {
grmx->Draw("lpSAME");
} else {
grmx->Draw("alp");
}
leg->AddEntry(grmx, "Maximum", "P");
gr = grmx;
}
leg->Draw();
gPad->Update();
if (dofit > 0) {
// Make sure the fitting functions are defined
Double_t xmi = 0.9;
if (nbins > 5) xmi = 1.5;
AssertFittingFun(xmi, nbins + .1);
// Starting point for the parameters and fit
Double_t normrate = -1.;
if (dofit == 1) {
if (isNorm) {
fgFp1n->SetParameter(0, pf->GetBinContent(1));
fgFp1n->SetParameter(1, pf->GetBinContent(nbins-1));
gr->Fit(fgFp1n);
if (verbose) fgFp1n->Print();
normrate = fgFp1n->GetParameter(1);
} else {
fgFp1->SetParameter(0, 0.);
fgFp1->SetParameter(1, pf->GetBinContent(1));
gr->Fit(fgFp1);
if (verbose) fgFp1->Print();
normrate = fgFp1->Derivative(1.);
}
} else if (dofit == 2) {
if (isNorm) {
fgFp2n->SetParameter(0, pf->GetBinContent(1));
fgFp2n->SetParameter(1, pf->GetBinContent(nbins-1));
fgFp2n->SetParameter(2, 0.);
gr->Fit(fgFp2n);
if (verbose) fgFp2n->Print();
normrate = fgFp2n->GetParameter(1);
} else {
fgFp2->SetParameter(0, 0.);
fgFp2->SetParameter(1, pf->GetBinContent(1));
fgFp2->SetParameter(2, 0.);
gr->Fit(fgFp2);
if (verbose) fgFp2->Print();
normrate = fgFp2->Derivative(1.);
}
} else {
// Starting point for the parameters and fit
gFioVn0 = (n0 > 0) ? n0 : (Int_t) (nbins + .1)/2.;
gFioVn1 = (n1 > 0) ? n1 : (Int_t) (nbins + .1);
if (isNorm) {
fgFp3n->SetParameter(0, 0.);
fgFp3n->SetParameter(1, pf->GetBinContent(1));
fgFp3n->SetParameter(2, pf->GetBinContent(nbins-1));
gr->Fit(fgFp3n);
if (verbose) fgFp3n->Print();
normrate = pf->GetBinContent(1);
} else {
fgFp3->SetParameter(0, 0.);
fgFp3->SetParameter(1, 0.);
fgFp3->SetParameter(2, pf->GetBinContent(1));
gr->Fit(fgFp3);
if (verbose) fgFp3->Print();
normrate = fgFp3->Derivative(1.);
}
}
// Notify the cluster performance parameters
if (!isNorm) {
printf("* ************************************************************ *\n");
printf("* *\r");
printf("* Cluster: %s\n", description.Data());
printf("* Performance measurement from scalability plot: *\n");
printf("* *\r");
printf("* rate max: %.3f\tmegaRNGPS (@ %d workers)\n", ymx/1000000, kmx);
printf("* *\r");
printf("* per-worker rate: %.3f\tmegaRNGPS \n", normrate/1000000);
printf("* ************************************************************ *\n");
} else {
printf("* ************************************************************ *\n");
printf("* *\r");
printf("* Cluster: %s\n", description.Data());
printf("* *\r");
printf("* Per-worker rate from normalized plot: %.3f\tmegaRNGPS\n", normrate/1000000);
printf("* ************************************************************ *\n");
}
}
// Close the file
fout->Close();
if (grav) fgGraphs->Add(grav);
if (grmx) fgGraphs->Add(grmx);
}
////////////////////////////////////////////////////////////////////////////////
/// Get from TDirectory 'd' the TProfile named 'pfn' and create the graph.
/// Return also the max y in mx.
TGraphErrors *TProofBench::GetGraph(TDirectory *d, const char *pfn, Int_t &nb,
Double_t &xmi, Double_t &xmx,
Double_t &ymi, Double_t &ymx, Int_t &kmx, TProfile *&pf)
{
// Sanity checks
if (!d || !pfn || (pfn && strlen(pfn) <= 0)) {
::Error("TProofBench::GetGraph", "directory or name not defined!");
return (TGraphErrors *)0;
}
TList *keylist = d->GetListOfKeys();
TKey *key = 0;
TIter nxk(keylist);
while ((key = (TKey *) nxk())) {
if (TString(key->GetName()).BeginsWith(pfn)) {
pf = (TProfile *) d->Get(key->GetName());
break;
}
}
// Sanity checks
if (!pf) {
::Error("TProofBench::GetGraph", "TProfile for '%s' not found in directory '%s'", pfn, d->GetName());
return (TGraphErrors *)0;
}
nb = pf->GetNbinsX();
TGraphErrors *gr = new TGraphErrors(nb);
gr->SetName(TString::Format("Graph_%s", pfn));
Double_t xx, ex, yy, ey;
ymi = pf->GetBinContent(1);
ymx = ymi;
xmi = pf->GetBinCenter(1) - pf->GetBinWidth(1)/2. ;
xmx = pf->GetBinCenter(nb) + pf->GetBinWidth(nb)/2. ;
kmx = -1;
for (Int_t k = 1;k <= nb; k++) {
xx = pf->GetBinCenter(k);
ex = pf->GetBinWidth(k) * .001;
yy = pf->GetBinContent(k);
ey = pf->GetBinError(k);
if (k == 1) {
ymi = yy;
ymx = yy;
kmx = k;
} else {
if (yy < ymi) ymi = yy;
if (yy > ymx) { ymx = yy; kmx = k; }
}
gr->SetPoint(k-1, xx, yy);
gr->SetPointError(k-1, ex, ey);
}
// Done
return gr;
}
////////////////////////////////////////////////////////////////////////////////
/// Make sure that the fitting functions are defined
void TProofBench::AssertFittingFun(Double_t mi, Double_t mx)
{
if (!fgFp1) {
fgFp1 = new TF1("funp1", funp1, mi, mx, 2);
fgFp1->SetParNames("offset", "slope");
}
if (!fgFp1n) {
fgFp1n = new TF1("funp1n", funp1n, mi, mx, 2);
fgFp1n->SetParNames("decay", "norm rate");
}
if (!fgFp2) {
fgFp2 = new TF1("funp2", funp2, mi, mx, 3);
fgFp2->SetParNames("offset", "slope", "deviation");
}
if (!fgFp2n) {
fgFp2n = new TF1("funp2n", funp2n, mi, mx, 3);
fgFp2n->SetParNames("decay", "norm rate", "deviation");
}
if (!fgFp3) {
fgFp3 = new TF1("funcpuv", funcpuv, mi, mx, 3);
fgFp3->SetParNames("offset", "slope real", "slope hyper");
}
if (!fgFp3n) {
fgFp3n = new TF1("funcpuvn", funcpuvn, mi, mx, 3);
fgFp3n->SetParNames("offset", "slope real", "slope hyper");
}
if (!fgFio) {
fgFio = new TF1("funio", funio, mi, mx, 3);
fgFio->SetParNames("R1", "RIO", "TotIO");
}
if (!fgFioV) {
fgFioV = new TF1("funiov", funiov, mi, mx, 5);
fgFioV->SetParNames("rio", "b1", "b2", "nc", "ri");
}
}
////////////////////////////////////////////////////////////////////////////////
class fileDesc : public TNamed {
public:
Long_t fMtime; // Modification time
TString fDesc; // Test description string, if any
fileDesc(const char *n, const char *o,
Long_t t, const char *d) : TNamed(n, o), fMtime(t), fDesc(d) { }
Int_t Compare(const TObject *o) const {
const fileDesc *fd = static_cast<const fileDesc *>(o);
if (!fd || (fd && fd->fMtime == fMtime)) return 0;
if (fMtime < fd->fMtime) return -1;
return 1;
}
};
////////////////////////////////////////////////////////////////////////////////
/// Get performance specs. Check file 'path', or files in directory 'path'
/// (default current directory).
/// The degree of the polynomial used for the fit is 'degfit' (default 1).
void TProofBench::GetPerfSpecs(const char *path, Int_t degfit)
{
// Locate the file (ask if many)
TString pp(path), fn, oo;
if (pp.IsNull()) pp = gSystem->WorkingDirectory();
FileStat_t st;
if (gSystem->GetPathInfo(pp.Data(), st) != 0) {
::Error("TProofBench::GetPerfSpecs", "path '%s' could not be stat'ed - abort", pp.Data());
return;
}
TSortedList filels;
if (R_ISDIR(st.fMode)) {
// Scan the directory
void *dirp = gSystem->OpenDirectory(pp.Data());
if (!dirp) {
::Error("TProofBench::GetPerfSpecs", "directory path '%s' could nto be open - abort", pp.Data());
return;
}
const char *ent = 0;
while ((ent = gSystem->GetDirEntry(dirp))) {
if (!strcmp(ent, ".") || !strcmp(ent, "..")) continue;
fn.Form("%s/%s", pp.Data(), ent);
if (gSystem->GetPathInfo(fn.Data(), st) != 0) continue;
if (!R_ISREG(st.fMode)) continue;
fn += "?filetype=raw";
TFile *f = TFile::Open(fn);
if (!f) continue;
char rr[5] = {0};
if (!f->ReadBuffer(rr, 4)) {
if (!strncmp(rr, "root", 4)) {
SafeDelete(f);
fn.ReplaceAll("?filetype=raw", "");
if ((f = TFile::Open(fn))) {
TString desc("<no decription>");
TNamed *nmdesc = (TNamed *) f->Get("PB_description");
if (nmdesc) desc = nmdesc->GetTitle();
if (f->GetListOfKeys()->FindObject("RunCPU"))
filels.Add(new fileDesc(fn, "std:", st.fMtime, desc.Data()));
if (f->GetListOfKeys()->FindObject("RunCPUx"))
filels.Add(new fileDesc(fn, "stdx:", st.fMtime, desc.Data()));
} else {
::Warning("TProofBench::GetPerfSpecs", "problems opening '%s'", fn.Data());
}
}
}
SafeDelete(f);
}
} else if (!R_ISREG(st.fMode)) {
::Error("TProofBench::GetPerfSpecs",
"path '%s' not a regular file nor a directory - abort", pp.Data());
return;
} else {
// This is the file
fn = pp;
// Check it
TString emsg;
Bool_t isOk = kFALSE;
if (gSystem->GetPathInfo(fn.Data(), st) == 0) {
fn += "?filetype=raw";
TFile *f = TFile::Open(fn);
if (f) {
char rr[5] = {0};
if (!(f->ReadBuffer(rr, 4))) {
if (!strncmp(rr, "root", 4)) {
fn.ReplaceAll("?filetype=raw", "");
if ((f = TFile::Open(fn))) {
if (f->GetListOfKeys()->FindObject("RunCPU")) oo = "std:";
if (f->GetListOfKeys()->FindObject("RunCPUx")) oo = "stdx:";
SafeDelete(f);
if (!oo.IsNull()) {
isOk = kTRUE;
} else {
emsg.Form("path '%s' does not contain the relevant dirs - abort", fn.Data());
}
} else {
emsg.Form("path '%s' cannot be open - abort", fn.Data());
}
} else {
emsg.Form("'%s' is not a ROOT file - abort", fn.Data());
}
} else {
emsg.Form("could not read first 4 bytes from '%s' - abort", fn.Data());
}
SafeDelete(f);
} else {
emsg.Form("path '%s' cannot be open in raw mode - abort", fn.Data());
}
} else {
emsg.Form("path '%s' cannot be stated - abort", fn.Data());
}
if (!isOk) {
::Error("TProofBench::GetPerfSpecs", "%s", emsg.Data());
return;
}
}
fileDesc *nm = 0;
// Ask the user, if more then 1
if (filels.GetSize() == 1) {
nm = (fileDesc *) filels.First();
fn = nm->GetName();
oo = nm->GetTitle();
} else if (filels.GetSize() > 1) {
TIter nxf(&filels);
Int_t idx = 0;
Printf("Several possible files found:");
while ((nm = (fileDesc *) nxf())) {
Printf(" %d\t%s\t%s\t%s (file: %s)", idx++, nm->GetTitle(),
TTimeStamp(nm->fMtime).AsString("s"), nm->fDesc.Data(), nm->GetName());
}
TString a(Getline(TString::Format("Make your choice [%d] ", idx-1)));
if (a.IsNull() || a[0] == '\n') a.Form("%d", idx-1);
idx = a.Atoi();
if ((nm = (fileDesc *) filels.At(idx))) {
fn = nm->GetName();
oo = nm->GetTitle();
} else {
::Error("TProofBench::GetPerfSpecs", "chosen index '%d' does not exist - abort", idx);
return;
}
} else {
if (fn.IsNull()) {
::Error("TProofBench::GetPerfSpecs",
"path '%s' is a directory but no ROOT file found in it - abort", pp.Data());
return;
}
}
// Now get the specs
TProofBench::DrawCPU(fn.Data(), oo.Data(), kFALSE, degfit);
}
////////////////////////////////////////////////////////////////////////////////
/// Perform a test using dataset 'dset'
/// Return 0 on success, -1 on error
/// Open the file for the results
Int_t TProofBench::RunDataSet(const char *dset,
Int_t start, Int_t stop, Int_t step)
{
if (OpenOutFile(kTRUE) != 0) {
Error("RunDataSet", "problems opening '%s' to save the result", fOutFileName.Data());
return -1;
}
fUnlinkOutfile = kFALSE;
if (fReleaseCache) ReleaseCache(dset);
SafeDelete(fRunDS);
TPBReadType *readType = fReadType;
if (!readType) readType = new TPBReadType(TPBReadType::kReadOpt);
fRunDS = new TProofBenchRunDataRead(fDS, readType, fOutFile);
if (!fDataSel.IsNull()) fRunDS->SetSelName(fDataSel);
if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
if (!fDataPar.IsNull()) fRunDS->SetParList(fDataPar);
fRunDS->SetReleaseCache(fReleaseCache);
fRunDS->Run(dset, start, stop, step, fNtries, fDebug, -1);
if (!fReadType) SafeDelete(readType);
// Close the file
if (SetOutFile(0) != 0)
Warning("RunDataSet", "problems closing '%s'", fOutFileName.Data());
// Done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Perform a test using dataset 'dset' scanning over the number of workers
/// per node.
/// Return 0 on success, -1 on error
/// Open the file for the results
Int_t TProofBench::RunDataSetx(const char *dset, Int_t start, Int_t stop)
{
if (OpenOutFile(kTRUE) != 0) {
Error("RunDataSetx", "problems opening '%s' to save the result", fOutFileName.Data());
return -1;
}
fUnlinkOutfile = kFALSE;
ReleaseCache(dset);
SafeDelete(fRunDS);
TPBReadType *readType = fReadType;
if (!readType) readType = new TPBReadType(TPBReadType::kReadOpt);
fRunDS = new TProofBenchRunDataRead(fDS, readType, fOutFile);
if (!fDataSel.IsNull()) fRunDS->SetSelName(fDataSel);
if (!fSelOption.IsNull()) fRunDS->SetSelOption(fSelOption);
if (!fDataPar.IsNull()) fRunDS->SetParList(fDataPar);
fRunDS->Run(dset, start, stop, -2, fNtries, fDebug, -1);
if (!fReadType) SafeDelete(readType);
// Close the file
if (SetOutFile(0) != 0)
Warning("RunDataSetx", "problems closing '%s'", fOutFileName.Data());
// Done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Draw the CPU speedup plot.
/// opt = 'typewhat', e.g. 'std:max:'
/// type = 'std:' draw standard plot
/// 'stdx:' draw standard plot, 1 worker per node
/// 'norm:' draw normalized plot
/// 'normx:' draw normalized plot, 1 worker per node
/// what = 'max:' draw max rate
/// 'avg:' draw average rate
/// 'all:' draw max and average rate on same plot (default)
/// type = 'mbs' MB/s scaling plots (default)
/// 'evts' Event/s scaling plots
/// dofit = 0 no fit
/// 1 fit with default 3 parameter saturated I/O formula
/// 2 fit with 4 parameter saturated I/O formula (varying Rcpu)
/// n0 = for dofit == 2, number of real cores
/// n1 = for dofit == 2, number of total cores (real + hyperthreaded)
///
void TProofBench::DrawDataSet(const char *outfile,
const char *opt, const char *type, Bool_t verbose,
Int_t dofit, Int_t n0, Int_t n1)
{
// Get the TProfile an create the graphs
TFile *fout = TFile::Open(outfile, "READ");
if (!fout || (fout && fout->IsZombie())) {
::Error("DrawDataSet", "could not open file '%s' ...", outfile);
return;
}
// Get description
TString description("<not available>");
TNamed *nmdesc = (TNamed *) fout->Get("PB_description");
if (nmdesc) description = nmdesc->GetTitle();
// Parse option
TString oo(opt);
Bool_t isNorm = (oo.Contains("norm")) ? kTRUE : kFALSE;
Bool_t isX = (oo.Contains("stdx:") || oo.Contains("normx:")) ? kTRUE : kFALSE;
Bool_t doAvg = (oo.Contains("all:") || oo.Contains("avg:")) ? kTRUE : kFALSE;
Bool_t doMax = (oo.Contains("all:") || oo.Contains("max:")) ? kTRUE : kFALSE;