CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
sChronoManager.hh
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef SCHRONOMANAGER_HH
31 #define SCHRONOMANAGER_HH 1
32 
33 #include "gVariables.hh"
34 #include "sOutputManager.hh"
35 
36 // Typedef for times and durations
37 typedef std::chrono::time_point<std::chrono::system_clock> ChronoTime;
38 typedef std::chrono::duration<int64_t,std::nano> DurationNano;
39 typedef std::chrono::milliseconds Ms;
40 typedef std::chrono::seconds Secs;
41 typedef std::chrono::minutes Mins;
42 typedef std::chrono::hours Hs;
43 
50 {
51  // -----------------------------------------------------------------------------------------
52  // Constructor & Destructor
53  public :
60  {
61  if (mp_Instance == NULL) mp_Instance = new sChronoManager;
62  return mp_Instance;
63  };
70 
71  // -----------------------------------------------------------------------------------------
72  // Public functions
73  public:
79  int CheckParameters();
85  int Initialize();
90  void Display();
91 
92  // -----------------------------------------------------------------------------------------
93  // Public inline functions for updating timers
94  public:
100  inline void StartIterativeDataUpdateStep1(int a_thread)
101  {mp_startIterativeDataUpdateStep1[a_thread] = std::chrono::system_clock::now();}
107  inline void StopIterativeDataUpdateStep1(int a_thread)
108  {mp_durationIterativeDataUpdateStep1[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep1[a_thread];}
114  inline void StartIterativeDataUpdateStep2(int a_thread)
115  {mp_startIterativeDataUpdateStep2[a_thread] = std::chrono::system_clock::now();}
121  inline void StopIterativeDataUpdateStep2(int a_thread)
122  {mp_durationIterativeDataUpdateStep2[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep2[a_thread];}
128  inline void StartIterativeDataUpdateStep3(int a_thread)
129  {mp_startIterativeDataUpdateStep3[a_thread] = std::chrono::system_clock::now();}
135  inline void StopIterativeDataUpdateStep3(int a_thread)
136  {mp_durationIterativeDataUpdateStep3[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep3[a_thread];}
142  inline void StartIterativeDataUpdateStep4(int a_thread)
143  {mp_startIterativeDataUpdateStep4[a_thread] = std::chrono::system_clock::now();}
149  inline void StopIterativeDataUpdateStep4(int a_thread)
150  {mp_durationIterativeDataUpdateStep4[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep4[a_thread];}
155  inline void StartConvolution()
156  {m_startConvolution = std::chrono::system_clock::now();}
161  inline void StopConvolution()
162  {m_durationConvolution += std::chrono::system_clock::now() - m_startConvolution;}
169  inline void StartCustomStep(int a_thread, int a_step)
170  {mpp_startCustomSteps[a_step][a_thread] = std::chrono::system_clock::now();}
175  inline void StopCustomStep(int a_thread, int a_step)
176  {mpp_durationCustomSteps[a_step][a_thread] += std::chrono::system_clock::now() - mpp_startCustomSteps[a_step][a_thread];}
177 
178  // -----------------------------------------------------------------------------------------
179  // Public Get & Set functions
180  public:
187  inline void SetNbThreads(int a_nbThreadsForProjection, int a_nbThreadsForImageComputation)
188  {m_nbThreadsForProjection = a_nbThreadsForProjection; m_nbThreadsForImageComputation = a_nbThreadsForImageComputation;
195  inline void SetNbCustomSteps(int a_nbCustomSteps)
196  {m_nbCustomSteps = a_nbCustomSteps;}
202  inline void SetVerbose(int a_verbose)
203  {m_verbose = a_verbose;}
204 
205  // -------------------------------------------------------------------
206  // Private constructor
207  private:
213  sChronoManager();
214  // Prevent the compiler to generate methods to copy the object
216  void operator=(sChronoManager const&){};
217 
218  // -------------------------------------------------------------------
219  // Private data members
220  private:
221  static sChronoManager *mp_Instance;
222  // Number of threads
226  // Permanent profiled steps
237  // Custom profiled steps
241  // Verbose
243 };
244 
245 #endif
void SetNbThreads(int a_nbThreadsForProjection, int a_nbThreadsForImageComputation)
Set the number of threads for both projection and image computations.
void StopIterativeDataUpdateStep1(int a_thread)
Stop the timer for duration of iterative data update step 1.
This header file is mainly used to declare some macro definitions and all includes needed from the st...
ChronoTime * mp_startIterativeDataUpdateStep3
int m_nbThreadsForImageComputation
void SetNbCustomSteps(int a_nbCustomSteps)
Set the number of custom steps for profiling.
int CheckParameters()
Check validity of all parameters.
void StartCustomStep(int a_thread, int a_step)
Start the timer for duration of custom step of the given index for the given thread.
std::chrono::seconds Secs
sChronoManager()
The constructor of sChronoManager.
std::chrono::hours Hs
void StopIterativeDataUpdateStep3(int a_thread)
Stop the timer for duration of iterative data update step 3.
DurationNano * mp_durationIterativeDataUpdateStep2
std::chrono::time_point< std::chrono::system_clock > ChronoTime
std::chrono::duration< int64_t, std::nano > DurationNano
std::chrono::minutes Mins
ChronoTime ** mpp_startCustomSteps
ChronoTime * mp_startIterativeDataUpdateStep4
DurationNano m_durationConvolution
void StartIterativeDataUpdateStep1(int a_thread)
Start the timer for duration of iterative data update step 1.
static sChronoManager * mp_Instance
void StopIterativeDataUpdateStep4(int a_thread)
Stop the timer for duration of iterative data update step 4.
void StartIterativeDataUpdateStep2(int a_thread)
Start the timer for duration of iterative data update step 2.
DurationNano * mp_durationIterativeDataUpdateStep1
DurationNano * mp_durationIterativeDataUpdateStep3
DurationNano * mp_durationIterativeDataUpdateStep4
~sChronoManager()
The destructor of sChronoManager.
void StartIterativeDataUpdateStep3(int a_thread)
Start the timer for duration of iterative data update step 3.
void StopIterativeDataUpdateStep2(int a_thread)
Stop the timer for duration of iterative data update step 2.
void StartConvolution()
Start the timer for duration of convolution.
void StartIterativeDataUpdateStep4(int a_thread)
Start the timer for duration of iterative data update step 4.
int Initialize()
Initialize all thread-safe buffers for profiling.
Declaration of class sOutputManager.
void StopConvolution()
Stop the timer for duration of convolution.
ChronoTime * mp_startIterativeDataUpdateStep1
DurationNano ** mpp_durationCustomSteps
void StopCustomStep(int a_thread, int a_step)
Stop the timer for duration of custom step of the given index for the given thread.
This class is designed to manage some profiling of the code.
ChronoTime * mp_startIterativeDataUpdateStep2
std::chrono::milliseconds Ms
sChronoManager(sChronoManager const &)
void SetVerbose(int a_verbose)
Set the verbose level.
static sChronoManager * GetInstance()
Instantiate the singleton if not already done, then return the pointer to its instance.
ChronoTime m_startConvolution
void operator=(sChronoManager const &)
void Display()
Display the results of the duration buffers.