8 #include "gVariables.hh" 9 #include "vAlgorithm.hh" 10 #include "iEventHistoCT.hh" 67 if (a_nbIterationsSubsets==
"")
return 0;
76 string buf = a_nbIterationsSubsets;
80 while ((pos_comma=buf.find_first_of(
","))!=string::npos)
83 string sub_buf = buf.substr(0,pos_comma);
85 size_t pos_column = sub_buf.find_first_of(
":");
86 if (pos_column==string::npos || pos_column==0)
88 Cerr(
"***** vAlgorithm::SetNbIterationsAndSubsets() -> Syntax problem in number of iterations and subsets !" << endl);
91 int iter = atoi( sub_buf.substr(0,pos_column).c_str() );
95 int subs = atoi( sub_buf.substr(pos_column+1).c_str() );
97 for (
int it=0; it<iter; it++) mp_nbSubsets[
m_nbIterations+it] = subs;
100 buf = buf.substr(pos_comma+1);
104 size_t pos_column = buf.find_first_of(
":");
105 if (pos_column==string::npos || pos_column==0)
107 Cerr(
"***** vAlgorithm::SetNbIterationsAndSubsets() -> Syntax problem in number of iterations and subsets !" << endl);
110 int iter = atoi( buf.substr(0,pos_column).c_str() );
114 int subs = atoi( buf.substr(pos_column+1).c_str() );
115 mp_nbSubsets = (
int*)realloc(mp_nbSubsets,(
m_nbIterations+iter)*
sizeof(int));
116 for (
int it=0; it<iter; it++) mp_nbSubsets[
m_nbIterations+it] = subs;
122 Cout(
"vAlgorithm::SetNbIterationsAndSubsets() -> Selected numbers of subsets for each iteration:" << endl);
123 Cout(
" Iteration / number of subsets "<< endl);
124 for (
int it=0 ; it<
m_nbIterations/nb_sub_iter ; it++)
Cout(
" " << it+1 <<
" / " << mp_nbSubsets[it*nb_sub_iter] << endl); }
147 if (a_outputIterations==
"")
155 string buf = a_outputIterations;
159 int current_iteration = -1;
160 while ((pos_comma=buf.find_first_of(
","))!=string::npos)
163 string sub_buf = buf.substr(0,pos_comma);
165 size_t pos_column = sub_buf.find_first_of(
":");
166 if (pos_column==string::npos || pos_column==0)
168 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Syntax problem in output iteration numbers !" << endl);
171 int step_iteration = atoi( sub_buf.substr(0,pos_column).c_str() );
172 step_iteration *= nb_sub_iter;
173 if (step_iteration<=0)
175 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Iteration step must be strictly positive (here it is " << step_iteration <<
") !" << endl);
178 int stop_iteration = atoi( sub_buf.substr(pos_column+1).c_str() );
179 stop_iteration *= nb_sub_iter;
180 if (stop_iteration<=current_iteration)
182 Cerr(
"***** oIterationAlgorithm::SetOutputIterations() -> Output iteration number must be increasing through provided couples !" << endl);
186 for (
int it=current_iteration+step_iteration; it<stop_iteration; it+=step_iteration)
if (it<m_nbIterations)
mp_outputIterations[it] =
true;
187 current_iteration = stop_iteration-1;
188 buf = buf.substr(pos_comma+1);
192 size_t pos_column = buf.find_first_of(
":");
193 if (pos_column==string::npos || pos_column==0)
204 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Syntax problem in output iteration numbers !" << endl);
208 int step_iteration = atoi( buf.substr(0,pos_column).c_str() );
209 step_iteration *= nb_sub_iter;
210 if (step_iteration<=0)
212 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Iteration step must be strictly positive (here it is " << step_iteration <<
") !" << endl);
215 int stop_iteration = atoi( buf.substr(pos_column+1).c_str() );
216 stop_iteration *= nb_sub_iter;
217 if (stop_iteration<=current_iteration)
219 Cerr(
"***** oIterationAlgorithm::SetOutputIterations() -> Output iteration number must be increasing through provided couples !" << endl);
223 for (
int it=current_iteration+step_iteration; it<stop_iteration; it+=step_iteration)
if (it<m_nbIterations)
mp_outputIterations[it] =
true;
269 MPI_Barrier(MPI_COMM_WORLD);
277 if (
m_verbose>=1)
Cout(
"vAlgorithm::IterateCPU() -> Start algorithm for " << m_nbIterations / nb_sub_iter <<
" iterations" << endl);
280 clock_t clock_start_whole = clock();
281 time_t time_start_whole = time(NULL);
287 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepBeforeIterationLoop() function !" << endl);
298 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepBeforeSubsetLoop() function !" << endl);
303 for (
int subset=0 ; subset<mp_nbSubsets[iteration] ; subset++)
309 Cout(
"vAlgorithm::IterateCPU() -> Start iteration " << iteration / nb_sub_iter + 1 <<
"/" << m_nbIterations / nb_sub_iter
310 <<
" sub step " << iteration%nb_sub_iter+1 <<
"/" << nb_sub_iter
311 <<
" subset " << subset+1 <<
"/" << mp_nbSubsets[iteration] << endl);
315 clock_t clock_start_subset = clock();
316 time_t time_start_subset = time(NULL);
321 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepPreProcessInsideSubsetLoop() function !" << endl);
327 MPI_Barrier(MPI_COMM_WORLD);
331 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
336 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepInnerLoopInsideSubsetLoop() function !" << endl);
343 MPI_Barrier(MPI_COMM_WORLD);
349 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepPostProcessInsideSubsetLoop() function !" << endl);
354 clock_t clock_stop_subset = clock();
355 time_t time_stop_subset = time(NULL);
356 if (
m_verbose>=2)
Cout (
"vAlgorithm::IterateCPU() -> Time spent for subset " << subset+1 <<
" | User: " << time_stop_subset-time_start_subset
357 <<
" sec | CPU: " << (clock_stop_subset-clock_start_subset)/((
FLTNB)CLOCKS_PER_SEC) <<
" sec" << endl);
366 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepAfterSubsetLoop() function !" << endl);
376 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepAfterIterationLoop() function !" << endl);
381 clock_t clock_stop_whole = clock();
382 time_t time_stop_whole = time(NULL);
383 if (
m_verbose>=1)
Cout(
"vAlgorithm::IterateCPU() -> Total time spent | User: " << time_stop_whole-time_start_whole
384 <<
" sec | CPU: " << (clock_stop_whole-clock_start_whole)/((
FLTNB)CLOCKS_PER_SEC) <<
" sec" << endl);
397 if (
m_verbose>=2)
Cout(
"vAlgorithm::StepBeforeIterationLoop ... " << endl);
402 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop() -> Image space has not been created or was not checked !" << endl);
415 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop()-> Error during attenuation image initialization !" << endl);
421 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop() -> An error occurred while initializing the sensitivity image !" << endl);
427 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop()-> Error during multimodal image initialization !" << endl);
486 if (
m_verbose>=2)
Cout(
"vAlgorithm::StepAfterIterationLoop ... " << endl);
518 (void)a_specificOptions;
virtual int InitSpecificOptions(string a_specificOptions)
int SetNbIterationsAndSubsets(const string &a_nbIterationsSubsets)
oImageDimensionsAndQuantification * mp_ID
vector< string > m_pathToMultiModalImg
void DeallocateImage()
Free memory for the main image matrices.
oImageSpace * mp_ImageSpace
int InitMultiModalImage(const vector< string > &a_pathToMultiModalImage)
int RunCPU()
Perform the iterative loop of the algorithm. Function designed to be executed on the CPU only...
void DeallocateMultiModalImage()
Free memory for the multimodal image.
virtual int StepBeforeSubsetLoop(int a_iteration)
int Run()
Just call either the RunCPU or the RunGPU function as asked for.
bool m_saveSensitivityHistoFlag
void DeallocateSensitivityImage()
Free memory for the sensitivity image matrices.
oOptimizerManager * mp_OptimizerManager
void InstantiateImage()
Allocate memory for the main image matrices.
void InstantiateSensitivityImage(const string &a_pathToSensitivityImage)
int InitAttenuationImage(const string &a_pathToAtnImage)
virtual int StepImageOutput(int a_iteration, int a_subset=-1)=0
void DeallocateVisitedVoxelsImage()
Free memory for the image matrix containing binary information regarding which 3D voxels have been vi...
virtual int StepInnerLoopInsideSubsetLoop(int a_iteration, int a_subset, int a_bed)=0
oImageProcessingManager * mp_ImageProcessingManager
virtual int StepPostProcessInsideSubsetLoop(int a_iteration, int a_subset)
vAlgorithm()
vAlgorithm constructor. Initialize the member variables to their default values.
bool m_saveDynamicBasisCoefficients
string m_pathToSensitivityImg
void InstantiateVisitedVoxelsImage()
Memory allocation and initialization for the image matrix containing binary information regarding whi...
string m_pathToInitialImg
virtual int StepPreProcessInsideSubsetLoop(int a_iteration, int a_subset)
virtual int StepBeforeIterationLoop()
This function is called at the beginning of the RunCPU function.
bool m_saveImageAfterSubsets
virtual ~vAlgorithm()
vAlgorithm destructor.
oImageConvolverManager * mp_ImageConvolverManager
void InstantiateForwardImage()
Allocate memory for the forward image matrices.
int GetNbSubIterationsInOneIteration()
Get the number of sub iterations in one iteration.
oProjectorManager * mp_ProjectorManager
virtual int StepAfterSubsetLoop(int a_iteration)
oDeformationManager * mp_DeformationManager
virtual int StepAfterIterationLoop()
This function is called at the end of the RunCPU function.
void DeallocateOutputImage()
Free memory for the Image matrices dedicated to output writing on disk.
int SetOutputIterations(const string &a_outputIterations)
bool * mp_outputIterations
vDataFile ** m2p_DataFile
bool Checked()
Simply check that the image dimensions and verbosity has been set.
int m_nbSkippedIterations
int InitSensitivityImage(const string &a_pathToSensitivityImage)
void DeallocateForwardImage()
Free memory for the forward image matrices.
oDynamicModelManager * mp_DynamicModelManager
void InstantiateOutputImage()
Instanciate Image matrices dedicated to output writing on disk.