CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
src/management/sChronoManager.cc
Go to the documentation of this file.
1 
9 #include "sChronoManager.hh"
10 
11 // =====================================================================
12 // ---------------------------------------------------------------------
13 // ---------------------------------------------------------------------
14 // =====================================================================
15 
17 
18 // =====================================================================
19 // ---------------------------------------------------------------------
20 // ---------------------------------------------------------------------
21 // =====================================================================
22 
24 {
25  // Simply default all members
26  mp_Instance = NULL;
29  m_nbThreadsMax = 0;
30  // Permanent profiled steps
39  // Custom profiled steps
40  m_nbCustomSteps = 0;
42  mpp_startCustomSteps = NULL;
43  // Verbose
44  m_verbose = 0;
45 }
46 
47 // =====================================================================
48 // ---------------------------------------------------------------------
49 // ---------------------------------------------------------------------
50 // =====================================================================
51 
53 {
54  // Check number of threads
56  {
57  Cerr("***** sChronoManager::CheckParameters() -> Number of threads for projections is incorrectly set !" << endl);
58  return 1;
59  }
61  {
62  Cerr("***** sChronoManager::CheckParameters() -> Number of threads for image computation is incorrectly set !" << endl);
63  return 1;
64  }
65  // Check number of custom steps
66  if (m_nbCustomSteps<0)
67  {
68  Cerr("***** sChronoManager::CheckParameters() -> Number of custom steps is incorrectly set !" << endl);
69  return 1;
70  }
71  // Verbose
72  if (m_verbose<0)
73  {
74  Cerr("***** sChronoManager::CheckParameters() -> Verbose cannot be negative !" << endl);
75  return 1;
76  }
77  // Normal end
78  return 0;
79 }
80 
81 // =====================================================================
82 // ---------------------------------------------------------------------
83 // ---------------------------------------------------------------------
84 // =====================================================================
85 
87 {
88  // Verbose
89  if (m_verbose>=VERBOSE_LIGHT) Cout("sChronoManager::Initialize() -> Initialize all duration counters for profiling" << endl);
90  // Initialize buffers for data update steps
99  for (int th=0; th<m_nbThreadsForProjection; th++)
100  {
101  mp_durationIterativeDataUpdateStep1[th] = chrono::duration<int64_t,nano>::zero();
102  mp_durationIterativeDataUpdateStep2[th] = chrono::duration<int64_t,nano>::zero();
103  mp_durationIterativeDataUpdateStep3[th] = chrono::duration<int64_t,nano>::zero();
104  mp_durationIterativeDataUpdateStep4[th] = chrono::duration<int64_t,nano>::zero();
105  }
106  // Initialize convolution
107  m_durationConvolution = chrono::duration<int64_t,nano>::zero();
108  // Initialize buffers for custom profiling
109  if (m_nbCustomSteps>0)
110  {
113  for (int nb=0; nb<m_nbCustomSteps; nb++)
114  {
117  for (int th=0; th<m_nbThreadsMax; th++) mpp_durationCustomSteps[nb][th] = chrono::duration<int64_t,nano>::zero();
118  }
119  }
120  // Normal end
121  return 0;
122 }
123 
124 // =====================================================================
125 // ---------------------------------------------------------------------
126 // ---------------------------------------------------------------------
127 // =====================================================================
128 
130 {
132  {
133  // Verbose
134  Cout("sChronoManager::Display() -> Results from the profiling" << endl);
135  // Sum over all threads
136  for (int th=1; th<m_nbThreadsForProjection; th++)
137  {
142  }
143  for (int nb=0; nb<m_nbCustomSteps; nb++) for (int th=1; th<m_nbThreadsMax; th++)
145  // Divide by number of threads (not for the custom steps as we cannot know if they are multi-threaded
146  // using the number of threads for projection or image computation)
151  // Display data update steps
152  Cout(" --> Profiling of the data update step:" << endl);
153  Cout(" | Datafile management: " << setfill( '0' )
154  << setw( 2 ) << chrono::duration_cast<Hs> ( mp_durationIterativeDataUpdateStep1[0] ).count() << " hours "
155  << setw( 2 ) << chrono::duration_cast<Mins>( mp_durationIterativeDataUpdateStep1[0] % Hs( 1 ) ).count() << " mins "
156  << setw( 2 ) << chrono::duration_cast<Secs>( mp_durationIterativeDataUpdateStep1[0] % Mins( 1 ) ).count() << " secs "
157  << setw( 3 ) << chrono::duration_cast<Ms> ( mp_durationIterativeDataUpdateStep1[0] % Secs( 1 ) ).count() << " ms" << endl);
158  Cout(" | Dynamic management: " << setfill( '0' )
159  << setw( 2 ) << chrono::duration_cast<Hs> ( mp_durationIterativeDataUpdateStep2[0] ).count() << " hours "
160  << setw( 2 ) << chrono::duration_cast<Mins>( mp_durationIterativeDataUpdateStep2[0] % Hs( 1 ) ).count() << " mins "
161  << setw( 2 ) << chrono::duration_cast<Secs>( mp_durationIterativeDataUpdateStep2[0] % Mins( 1 ) ).count() << " secs "
162  << setw( 3 ) << chrono::duration_cast<Ms> ( mp_durationIterativeDataUpdateStep2[0] % Secs( 1 ) ).count() << " ms" << endl);
163  Cout(" | Projection management: " << setfill( '0' )
164  << setw( 2 ) << chrono::duration_cast<Hs> ( mp_durationIterativeDataUpdateStep3[0] ).count() << " hours "
165  << setw( 2 ) << chrono::duration_cast<Mins>( mp_durationIterativeDataUpdateStep3[0] % Hs( 1 ) ).count() << " mins "
166  << setw( 2 ) << chrono::duration_cast<Secs>( mp_durationIterativeDataUpdateStep3[0] % Mins( 1 ) ).count() << " secs "
167  << setw( 3 ) << chrono::duration_cast<Ms> ( mp_durationIterativeDataUpdateStep3[0] % Secs( 1 ) ).count() << " ms" << endl);
168  Cout(" | Optimizer management: " << setfill( '0' )
169  << setw( 2 ) << chrono::duration_cast<Hs> ( mp_durationIterativeDataUpdateStep4[0] ).count() << " hours "
170  << setw( 2 ) << chrono::duration_cast<Mins>( mp_durationIterativeDataUpdateStep4[0] % Hs( 1 ) ).count() << " mins "
171  << setw( 2 ) << chrono::duration_cast<Secs>( mp_durationIterativeDataUpdateStep4[0] % Mins( 1 ) ).count() << " secs "
172  << setw( 3 ) << chrono::duration_cast<Ms> ( mp_durationIterativeDataUpdateStep4[0] % Secs( 1 ) ).count() << " ms" << endl);
173  // Display convolution performances
174  Cout(" --> Profiling of the convolution steps: " << setfill( '0' )
175  << setw( 2 ) << chrono::duration_cast<Hs> ( m_durationConvolution ).count() << " hours "
176  << setw( 2 ) << chrono::duration_cast<Mins>( m_durationConvolution % Hs( 1 ) ).count() << " mins "
177  << setw( 2 ) << chrono::duration_cast<Secs>( m_durationConvolution % Mins( 1 ) ).count() << " secs "
178  << setw( 3 ) << chrono::duration_cast<Ms> ( m_durationConvolution % Secs( 1 ) ).count() << " ms" << endl);
179  // Display custom update steps
180  for (int nb=0; nb<m_nbCustomSteps; nb++)
181  {
182  Cout(" --> Custom update step " << nb+1 << ": " << setfill( '0' )
183  << setw( 2 ) << chrono::duration_cast<Hs> ( mpp_durationCustomSteps[nb][0] ).count() << " hours "
184  << setw( 2 ) << chrono::duration_cast<Mins>( mpp_durationCustomSteps[nb][0] % Hs( 1 ) ).count() << " mins "
185  << setw( 2 ) << chrono::duration_cast<Secs>( mpp_durationCustomSteps[nb][0] % Mins( 1 ) ).count() << " secs "
186  << setw( 3 ) << chrono::duration_cast<Ms> ( mpp_durationCustomSteps[nb][0] % Secs( 1 ) ).count() << " ms" << endl);
187  }
188  }
189 }
190 
191 // =====================================================================
192 // ---------------------------------------------------------------------
193 // ---------------------------------------------------------------------
194 // =====================================================================
std::chrono::seconds Secs
#define Cerr(MESSAGE)
int CheckParameters()
Check validity of all parameters.
std::chrono::time_point< std::chrono::system_clock > ChronoTime
sChronoManager()
The constructor of sChronoManager.
std::chrono::hours Hs
int Initialize()
Initialize all thread-safe buffers for profiling.
std::chrono::duration< int64_t, std::nano > DurationNano
This class is designed to manage some profiling of the code.
std::chrono::minutes Mins
#define Cout(MESSAGE)
void Display()
Display the results of the duration buffers.