CbmRoot
LxParall.cxx
Go to the documentation of this file.
1 #include "LxParall.h"
2 #include "Lx.h"
3 #include <iostream>
4 #include <omp.h>
5 #include <sys/time.h>
6 
7 using namespace std;
8 
10 
12  : generateInvMass(false)
13  , generateBackground(false)
14  , generateChi2(false)
15  , linkWithSts(true)
16  , useMCPInsteadOfHits(false)
17  , calcMiddlePoints(true)
18  , cutCoeff(4.0)
19  , ev_start(0)
20  , ev_end(0)
21  , hitFileName("") {}
22 
24  friend class LxParallFinder;
25 
26 public:
29  if (finder) {
30  finder->FinishTask();
31  delete finder;
32  }
33  }
34 
35 private:
39 };
40 
41 //#define LXPARALL_SEPARATE_SINGLE
42 
43 Double_t LxParallFinder::Reconstruct(Int_t numThreads) {
44  omp_set_num_threads(numThreads);
45 
46  timeval bTime, eTime;
47  gettimeofday(&bTime, 0);
48 
49  Int_t i;
50  Int_t createdFinderInstances = 0;
51  Int_t totalRunTime = 0;
52  FinderCapsule finderCapsule;
53 
54 #ifdef LXPARALL_SEPARATE_SINGLE
55  if (1 == numThreads) {
56  for (i = ev_start; i < ev_end; ++i) {
57  if (0 == finderCapsule.finder) {
58  finderCapsule.finder = new LxFinder;
59  finderCapsule.finder->SetLinkWithSts(linkWithSts);
62  finderCapsule.finder->SetCutCoeff(cutCoeff);
64  finderCapsule.finder->SetGenInvMass(generateInvMass);
65  finderCapsule.finder->SetVerbosity(0);
66  finderCapsule.finder->SetParallMode(true);
67  finderCapsule.finder->SetHitFileName(hitFileName);
68  finderCapsule.finder->Init();
69  createdFinderInstances++;
70  }
71 
72  finderCapsule.finder->ReadEvent(i);
73  Int_t runTime = 0;
74  finderCapsule.finder->Exec(reinterpret_cast<Option_t*>(&runTime));
75  totalRunTime += runTime;
76  }
77  } else {
78 #endif //LXPARALL_SEPARATE_SINGLE
79 #pragma omp parallel for firstprivate(finderCapsule)
80  for (i = ev_start; i < ev_end; ++i) {
81  if (0 == finderCapsule.finder) {
82  finderCapsule.finder = new LxFinder;
83  finderCapsule.finder->SetLinkWithSts(linkWithSts);
86  finderCapsule.finder->SetCutCoeff(cutCoeff);
88  finderCapsule.finder->SetGenInvMass(generateInvMass);
89  finderCapsule.finder->SetVerbosity(0);
90  finderCapsule.finder->SetParallMode(true);
91  finderCapsule.finder->SetHitFileName(hitFileName);
92  finderCapsule.finder->Init();
93 #pragma omp atomic
94  createdFinderInstances++;
95  }
96 
97  finderCapsule.finder->ReadEvent(i);
98  Int_t runTime = 0;
99  finderCapsule.finder->Exec(reinterpret_cast<Option_t*>(&runTime));
100 #pragma omp atomic
101  totalRunTime += runTime;
102  }
103 #ifdef LXPARALL_SEPARATE_SINGLE
104  }
105 #endif //LXPARALL_SEPARATE_SINGLE
106 
107  gettimeofday(&eTime, 0);
108  int exeDuration =
109  (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec;
110  cout << "Execution duration was: " << exeDuration << endl;
111  cout << "Created finder instances: " << createdFinderInstances << endl;
112  cout << "Total run time: " << totalRunTime << endl;
113  Double_t result = totalRunTime;
114  result /= (ev_end - ev_start) * numThreads;
115  cout << "Average run time: " << result << endl;
116  return result;
117 }
LxFinder
Definition: Simple/Lx.h:73
LxParallFinder::LxParallFinder
LxParallFinder()
LxFinder::SetGenBackground
void SetGenBackground(bool value)
Definition: Simple/Lx.h:88
LxParallFinder::linkWithSts
bool linkWithSts
Definition: LxParall.h:38
LxParallFinder::ev_start
Int_t ev_start
Definition: LxParall.h:42
LxFinder::FinishTask
void FinishTask()
Definition: Simple/Lx.cxx:1581
LxFinder::Exec
void Exec(Option_t *opt)
Definition: Simple/Lx.cxx:762
LxParallFinder::Reconstruct
Double_t Reconstruct(Int_t numThreads)
Definition: LxParall.cxx:43
LxFinder::SetVerbosity
void SetVerbosity(Int_t v)
Definition: Simple/Lx.h:104
FinderCapsule::FinderCapsule
FinderCapsule(const FinderCapsule &)
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
LxParallFinder::hitFileName
TString hitFileName
Definition: LxParall.h:44
LxFinder::SetCutCoeff
void SetCutCoeff(scaltype value)
Definition: Simple/Lx.h:98
LxParallFinder::calcMiddlePoints
bool calcMiddlePoints
Definition: LxParall.h:40
linkWithSts
bool linkWithSts
Definition: riplet/Lx.cxx:57
LxFinder::ReadEvent
bool ReadEvent(Int_t evNum)
Definition: Simple/Lx.cxx:1816
LxParallFinder::generateBackground
bool generateBackground
Definition: LxParall.h:36
FinderCapsule::FinderCapsule
FinderCapsule()
Definition: LxParall.cxx:27
LxFinder::SetUseMCPInsteadOfHits
void SetUseMCPInsteadOfHits(bool value)
Definition: Simple/Lx.h:94
LxFinder::SetLinkWithSts
void SetLinkWithSts(bool value)
Definition: Simple/Lx.h:92
FinderCapsule::operator=
FinderCapsule & operator=(const FinderCapsule &)
ClassImp
ClassImp(LxParallFinder) LxParallFinder
Definition: LxParall.cxx:9
Lx.h
LxFinder::Init
InitStatus Init()
Definition: Simple/Lx.cxx:346
LxFinder::SetHitFileName
void SetHitFileName(TString v)
Definition: Simple/Lx.h:108
cutCoeff
Double_t cutCoeff
Definition: riplet/Lx.cxx:60
generateChi2
bool generateChi2
Definition: riplet/Lx.cxx:56
LxParallFinder::useMCPInsteadOfHits
bool useMCPInsteadOfHits
Definition: LxParall.h:39
LxParallFinder::generateInvMass
bool generateInvMass
Definition: LxParall.h:35
FinderCapsule
Definition: LxParall.cxx:23
LxFinder::SetCalcMiddlePoints
void SetCalcMiddlePoints(bool value)
Definition: Simple/Lx.h:96
LxParallFinder::cutCoeff
scaltype cutCoeff
Definition: LxParall.h:41
calcMiddlePoints
bool calcMiddlePoints
Definition: riplet/Lx.cxx:59
FinderCapsule::finder
LxFinder * finder
Definition: LxParall.cxx:36
LxParall.h
LxFinder::SetGenInvMass
void SetGenInvMass(bool value)
Definition: Simple/Lx.h:86
generateInvMass
bool generateInvMass
Definition: riplet/Lx.cxx:54
generateBackground
bool generateBackground
Definition: riplet/Lx.cxx:55
LxParallFinder
Definition: LxParall.h:7
LxFinder::SetParallMode
void SetParallMode(bool v)
Definition: Simple/Lx.h:106
useMCPInsteadOfHits
bool useMCPInsteadOfHits
Definition: riplet/Lx.cxx:58
LxParallFinder::ev_end
Int_t ev_end
Definition: LxParall.h:43
FinderCapsule::~FinderCapsule
~FinderCapsule()
Definition: LxParall.cxx:28