Commit 6b401955 authored by David Rohr's avatar David Rohr
Browse files

remove some unnecessary memory allocation, replace by persistently allocated buffers

parent 6e7cc545
......@@ -362,25 +362,11 @@ int bioem::compareRefMaps(int iProjectionOut, int iConv, const myfloat_t* conv_m
{
if (FFTAlgo)
{
#pragma omp parallel
#pragma omp parallel for
for (int iRefMap = startMap; iRefMap < RefMap.ntotRefMap; iRefMap ++)
{
mycomplex_t *localCCT;
myfloat_t *lCC;
localCCT = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D);
lCC = (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param.param_device.NumberPixels * param.param_device.NumberPixels);
const int num_threads = omp_get_num_threads();
const int thread_id = omp_get_thread_num();
const int mapsPerThread = (RefMap.ntotRefMap - startMap + num_threads - 1) / num_threads;
const int iStart = startMap + thread_id * mapsPerThread;
const int iEnd = min(RefMap.ntotRefMap, startMap + (thread_id + 1) * mapsPerThread);
for (int iRefMap = iStart; iRefMap < iEnd; iRefMap ++)
{
calculateCCFFT(iRefMap, iProjectionOut, iConv, sumC, sumsquareC, localmultFFT, localCCT, lCC);
}
myfftw_free(localCCT);
myfftw_free(lCC);
const int num = omp_get_thread_num();
calculateCCFFT(iRefMap, iProjectionOut, iConv, sumC, sumsquareC, localmultFFT, localCCT[num], lCC[num]);
}
}
else
......@@ -420,7 +406,7 @@ int bioem::createProjection(int iMap, mycomplex_t* mapFFT)
myfloat_t alpha, gam, beta;
myfloat_t* localproj;
localproj = (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param.param_device.NumberPixels * param.param_device.NumberPixels);
localproj = lCC[omp_get_thread_num()];
memset(localproj, 0, param.param_device.NumberPixels * param.param_device.NumberPixels * sizeof(*localproj));
alpha = param.angles[iMap].pos[0];
......@@ -492,8 +478,6 @@ int bioem::createProjection(int iMap, mycomplex_t* mapFFT)
// ********** Omp Critical is necessary with FFTW*******
myfftw_execute_dft_r2c(param.fft_plan_r2c_forward, localproj, mapFFT);
myfftw_free(localproj);
return(0);
}
......@@ -505,8 +489,7 @@ int bioem::createConvolutedProjectionMap(int iMap, int iConv, mycomplex_t* lproj
// *************** and Backtransforming it to real Space ********************************
// **************************************************************************************
mycomplex_t* tmp;
tmp = (mycomplex_t*) myfftw_malloc(sizeof(mycomplex_t) * param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D);
mycomplex_t* tmp = localCCT[omp_get_thread_num()];
// **** Multiplying FFTmap with corresponding kernel ****
const mycomplex_t* refCTF = &param.refCTF[iConv * param.FFTMapSize];
......@@ -538,9 +521,6 @@ int bioem::createConvolutedProjectionMap(int iMap, int iConv, mycomplex_t* lproj
sumC = sumC / norm2;
sumsquareC = sumsquareC / norm4;
// **** Freeing fftw_complex created (dont know if omp critical is necessary) ****
myfftw_free(tmp);
return(0);
}
......@@ -570,10 +550,32 @@ int bioem::deviceInit()
int bioem::deviceStartRun()
{
if (FFTAlgo)
{
const int count = omp_get_max_threads();
localCCT = new mycomplex_t*[count];
lCC = new myfloat_t*[count];
for (int i = 0;i < count;i++)
{
localCCT[i] = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D);
lCC[i] = (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param.param_device.NumberPixels * param.param_device.NumberPixels);
}
}
return(0);
}
int bioem::deviceFinishRun()
{
if (FFTAlgo)
{
const int count = omp_get_max_threads();
for (int i = 0;i < count;i++)
{
myfftw_free(localCCT[i]);
myfftw_free(lCC[i]);
}
delete[] localCCT;
delete[] lCC;
}
return(0);
}
......@@ -47,6 +47,9 @@ protected:
int nProjectionMapsTotal; //Maps in total
int FFTAlgo;
mycomplex_t** localCCT;
myfloat_t** lCC;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment