CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #ifndef SCHRONOMANAGER_HH
32 #define SCHRONOMANAGER_HH 1
33 
34 #include "gVariables.hh"
35 #include "sOutputManager.hh"
36 
37 // Typedef for times and durations
38 typedef std::chrono::time_point<std::chrono::system_clock> ChronoTime;
39 typedef std::chrono::duration<int64_t,std::nano> DurationNano;
40 typedef std::chrono::milliseconds Ms;
41 typedef std::chrono::seconds Secs;
42 typedef std::chrono::minutes Mins;
43 typedef std::chrono::hours Hs;
44 
51 {
52  // -----------------------------------------------------------------------------------------
53  // Constructor & Destructor
54  public :
61  {
62  if (mp_Instance == NULL) mp_Instance = new sChronoManager;
63  return mp_Instance;
64  };
71 
72  // -----------------------------------------------------------------------------------------
73  // Public functions
74  public:
80  int CheckParameters();
86  int Initialize();
91  void Display();
92 
93  // -----------------------------------------------------------------------------------------
94  // Public inline functions for updating timers
95  public:
101  inline void StartIterativeDataUpdateStep1(int a_thread)
102  {mp_startIterativeDataUpdateStep1[a_thread] = std::chrono::system_clock::now();}
108  inline void StopIterativeDataUpdateStep1(int a_thread)
109  {mp_durationIterativeDataUpdateStep1[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep1[a_thread];}
115  inline void StartIterativeDataUpdateStep2(int a_thread)
116  {mp_startIterativeDataUpdateStep2[a_thread] = std::chrono::system_clock::now();}
122  inline void StopIterativeDataUpdateStep2(int a_thread)
123  {mp_durationIterativeDataUpdateStep2[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep2[a_thread];}
129  inline void StartIterativeDataUpdateStep3(int a_thread)
130  {mp_startIterativeDataUpdateStep3[a_thread] = std::chrono::system_clock::now();}
136  inline void StopIterativeDataUpdateStep3(int a_thread)
137  {mp_durationIterativeDataUpdateStep3[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep3[a_thread];}
143  inline void StartIterativeDataUpdateStep4(int a_thread)
144  {mp_startIterativeDataUpdateStep4[a_thread] = std::chrono::system_clock::now();}
150  inline void StopIterativeDataUpdateStep4(int a_thread)
151  {mp_durationIterativeDataUpdateStep4[a_thread] += std::chrono::system_clock::now() - mp_startIterativeDataUpdateStep4[a_thread];}
156  inline void StartConvolution()
157  {m_startConvolution = std::chrono::system_clock::now();}
162  inline void StopConvolution()
163  {m_durationConvolution += std::chrono::system_clock::now() - m_startConvolution;}
170  inline void StartCustomStep(int a_thread, int a_step)
171  {mpp_startCustomSteps[a_step][a_thread] = std::chrono::system_clock::now();}
176  inline void StopCustomStep(int a_thread, int a_step)
177  {mpp_durationCustomSteps[a_step][a_thread] += std::chrono::system_clock::now() - mpp_startCustomSteps[a_step][a_thread];}
178 
179  // -----------------------------------------------------------------------------------------
180  // Public Get & Set functions
181  public:
188  inline void SetNbThreads(int a_nbThreadsForProjection, int a_nbThreadsForImageComputation)
189  {m_nbThreadsForProjection = a_nbThreadsForProjection; m_nbThreadsForImageComputation = a_nbThreadsForImageComputation;
196  inline void SetNbCustomSteps(int a_nbCustomSteps)
197  {m_nbCustomSteps = a_nbCustomSteps;}
203  inline void SetVerbose(int a_verbose)
204  {m_verbose = a_verbose;}
205 
206  // -------------------------------------------------------------------
207  // Private constructor
208  private:
214  sChronoManager();
215  // Prevent the compiler to generate methods to copy the object
217  void operator=(sChronoManager const&){};
218 
219  // -------------------------------------------------------------------
220  // Private data members
221  private:
222  static sChronoManager *mp_Instance;
223  // Number of threads
227  // Permanent profiled steps
238  // Custom profiled steps
242  // Verbose
244 };
245 
246 #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.