From a476152e40cccf0cf46c43ecf20b45214d555626 Mon Sep 17 00:00:00 2001 From: David Rohr <drohr@jwdt.org> Date: Sat, 19 Apr 2014 19:00:41 +0200 Subject: [PATCH] remove unnecessary copies --- bioem.cpp | 19 +++---------------- param.cpp | 7 +++---- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/bioem.cpp b/bioem.cpp index a0f3d27..e0f97ea 100644 --- a/bioem.cpp +++ b/bioem.cpp @@ -505,13 +505,10 @@ int bioem::createConvolutedProjectionMap(int iMap, int iConv, mycomplex_t* lproj // *************** and Backtransforming it to real Space ******************************** // ************************************************************************************** - myfloat_t* localconvFFT; - localconvFFT = (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param.param_device.NumberPixels * param.param_device.NumberPixels); mycomplex_t* tmp; tmp = (mycomplex_t*) myfftw_malloc(sizeof(mycomplex_t) * param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D); // **** Multiplying FFTmap with corresponding kernel **** - const mycomplex_t* refCTF = ¶m.refCTF[iConv * param.FFTMapSize]; for(int i = 0; i < param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D; i++) { @@ -524,24 +521,15 @@ int bioem::createConvolutedProjectionMap(int iMap, int iConv, mycomplex_t* lproj memcpy(tmp, localmultFFT, sizeof(mycomplex_t) * param.param_device.NumberPixels * param.param_device.NumberFFTPixels1D); // **** Bringing convoluted Map to real Space **** - myfftw_execute_dft_c2r(param.fft_plan_c2r_backward, tmp, localconvFFT); - - // ****Asigning convolution fftw_complex to bioem_map **** - for(int i = 0; i < param.param_device.NumberPixels ; i++ ) - { - for(int j = 0; j < param.param_device.NumberPixels ; j++ ) - { - Mapconv[i * param.param_device.NumberPixels + j] = localconvFFT[i * param.param_device.NumberPixels + j]; - } - } + myfftw_execute_dft_c2r(param.fft_plan_c2r_backward, tmp, Mapconv); // *** Calculating Cross-correlations of cal-convoluted map with its self ***** sumC = 0; sumsquareC = 0; for(int i = 0; i < param.param_device.NumberPixels * param.param_device.NumberPixels; i++) { - sumC += localconvFFT[i]; - sumsquareC += localconvFFT[i] * localconvFFT[i]; + sumC += Mapconv[i]; + sumsquareC += Mapconv[i] * Mapconv[i]; } // *** The DTF gives an unnormalized value so have to divded by the total number of pixels in Fourier *** // Normalizing @@ -551,7 +539,6 @@ int bioem::createConvolutedProjectionMap(int iMap, int iConv, mycomplex_t* lproj sumsquareC = sumsquareC / norm4; // **** Freeing fftw_complex created (dont know if omp critical is necessary) **** - myfftw_free(localconvFFT); myfftw_free(tmp); return(0); diff --git a/param.cpp b/param.cpp index c92a5bd..cad4ae0 100644 --- a/param.cpp +++ b/param.cpp @@ -275,10 +275,12 @@ int bioem_param::CalculateRefCTF() myfloat_t amp, env, phase, ctf, radsq; myfloat_t* localCTF; + mycomplex_t* localout; int nctfmax = param_device.NumberPixels / 2; int n = 0; localCTF = (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param_device.NumberPixels * param_device.NumberPixels); + localout = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param_device.NumberPixels * param_device.NumberFFTPixels1D); nTotCTFs = numberGridPointsCTF_amp * numberGridPointsCTF_phase * numberGridPointsEnvelop; delete[] refCTF; @@ -314,9 +316,6 @@ int bioem_param::CalculateRefCTF() localCTF[(param_device.NumberPixels - i - 1)*param_device.NumberPixels + param_device.NumberPixels - j - 1] = (myfloat_t) ctf; } } - //Creatting FFT_Forward of Kernel to store - mycomplex_t* localout; - localout = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param_device.NumberPixels * param_device.NumberFFTPixels1D); //Calling FFT_Forward myfftw_execute_dft_r2c(fft_plan_r2c_forward, localCTF, localout); @@ -331,12 +330,12 @@ int bioem_param::CalculateRefCTF() CtfParam[n].pos[1] = phase; CtfParam[n].pos[2] = env; n++; - myfftw_free(localout); } } } myfftw_free(localCTF); + myfftw_free(localout); if (nTotCTFs != n) { cout << "Internal error during CTF preparation\n"; -- GitLab