Commit beebec5d authored by David Rohr's avatar David Rohr

fix segfault if rotated model point out of map, improve debug message and options, fix memory leaks

parent 05e7d589
...@@ -68,6 +68,7 @@ ostream& operator<<(ostream& os, const vector<T>& v) ...@@ -68,6 +68,7 @@ ostream& operator<<(ostream& os, const vector<T>& v)
bioem::bioem() bioem::bioem()
{ {
FFTAlgo = getenv("FFTALGO") == NULL ? 0 : atoi(getenv("FFTALGO")); FFTAlgo = getenv("FFTALGO") == NULL ? 0 : atoi(getenv("FFTALGO"));
DebugOutput = getenv("BIOEM_DEBUG_OUTPUT") == NULL ? 2 : atoi(getenv("BIOEM_DEBUG_OUTPUT"));
} }
bioem::~bioem() bioem::~bioem()
...@@ -219,8 +220,9 @@ int bioem::configure(int ac, char* av[]) ...@@ -219,8 +220,9 @@ int bioem::configure(int ac, char* av[])
if (getenv("BIOEM_DEBUG_BREAK")) if (getenv("BIOEM_DEBUG_BREAK"))
{ {
param.nTotGridAngles = atoi(getenv("BIOEM_DEBUG_BREAK")); const int cut = atoi(getenv("BIOEM_DEBUG_BREAK"));
param.nTotCTFs = atoi(getenv("BIOEM_DEBUG_BREAK")); if (param.nTotGridAngles > cut) param.nTotGridAngles = cut;
if (param.nTotCTFs > cut) param.nTotCTFs = cut;
} }
pProb.init(RefMap.ntotRefMap, param.nTotGridAngles, *this); pProb.init(RefMap.ntotRefMap, param.nTotGridAngles, *this);
...@@ -308,32 +310,34 @@ int bioem::run() ...@@ -308,32 +310,34 @@ int bioem::run()
HighResTimer timer; HighResTimer timer;
printf("\tMain Loop (GridAngles %d, CTFs %d, RefMaps %d, Shifts (%d/%d)²), Pixels %d²\n", param.nTotGridAngles, param.nTotCTFs, RefMap.ntotRefMap, 2 * param.param_device.maxDisplaceCenter + param.param_device.GridSpaceCenter, param.param_device.GridSpaceCenter, param.param_device.NumberPixels); if (DebugOutput >= 1) printf("\tMain Loop (GridAngles %d, CTFs %d, RefMaps %d, Shifts (%d/%d)²), Pixels %d²\n", param.nTotGridAngles, param.nTotCTFs, RefMap.ntotRefMap, 2 * param.param_device.maxDisplaceCenter + param.param_device.GridSpaceCenter, param.param_device.GridSpaceCenter, param.param_device.NumberPixels);
// printf("\tInner Loop Count (%d %d %d) %lld\n", param.param_device.maxDisplaceCenter, param.param_device.GridSpaceCenter, param.param_device.NumberPixels, (long long int) (param.param_device.NumberPixels * param.param_device.NumberPixels * (2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1) * (2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1))); // printf("\tInner Loop Count (%d %d %d) %lld\n", param.param_device.maxDisplaceCenter, param.param_device.GridSpaceCenter, param.param_device.NumberPixels, (long long int) (param.param_device.NumberPixels * param.param_device.NumberPixels * (2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1) * (2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1)));
for (int iOrient = 0; iOrient < param.nTotGridAngles; iOrient++) for (int iOrient = 0; iOrient < param.nTotGridAngles; iOrient++)
{ {
// *************************************************************************************** // ***************************************************************************************
// ***** Creating Projection for given orientation and transforming to Fourier space ***** // ***** Creating Projection for given orientation and transforming to Fourier space *****
timer.ResetStart(); if (DebugOutput >= 1) timer.ResetStart();
createProjection(iOrient, proj_mapFFT); createProjection(iOrient, proj_mapFFT);
printf("Time Projection %d: %f\n", iOrient, timer.GetCurrentElapsedTime()); if (DebugOutput >= 1) printf("Time Projection %d: %f\n", iOrient, timer.GetCurrentElapsedTime());
// *************************************************************************************** // ***************************************************************************************
// ***** **** Internal Loop over convolutions **** ***** // ***** **** Internal Loop over convolutions **** *****
for (int iConv = 0; iConv < param.nTotCTFs; iConv++) for (int iConv = 0; iConv < param.nTotCTFs; iConv++)
{ {
printf("\t\tConvolution %d %d\n", iOrient, iConv); if (DebugOutput >= 2) printf("\t\tConvolution %d %d\n", iOrient, iConv);
// *** Calculating convolutions of projection map and crosscorrelations *** // *** Calculating convolutions of projection map and crosscorrelations ***
timer.ResetStart(); if (DebugOutput >= 2) timer.ResetStart();
createConvolutedProjectionMap(iOrient, iConv, proj_mapFFT, conv_map, conv_mapFFT, sumCONV, sumsquareCONV); createConvolutedProjectionMap(iOrient, iConv, proj_mapFFT, conv_map, conv_mapFFT, sumCONV, sumsquareCONV);
printf("Time Convolution %d %d: %f\n", iOrient, iConv, timer.GetCurrentElapsedTime()); if (DebugOutput >= 2) printf("Time Convolution %d %d: %f\n", iOrient, iConv, timer.GetCurrentElapsedTime());
// *************************************************************************************** // ***************************************************************************************
// *** Comparing each calculated convoluted map with all experimental maps *** // *** Comparing each calculated convoluted map with all experimental maps ***
timer.ResetStart(); if (DebugOutput >= 2) timer.ResetStart();
compareRefMaps(iOrient, iConv, conv_map, conv_mapFFT, sumCONV, sumsquareCONV); compareRefMaps(iOrient, iConv, conv_map, conv_mapFFT, sumCONV, sumsquareCONV);
if (DebugOutput >= 2)
{
const double compTime = timer.GetCurrentElapsedTime(); const double compTime = timer.GetCurrentElapsedTime();
const int nShifts = 2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1; const int nShifts = 2 * param.param_device.maxDisplaceCenter / param.param_device.GridSpaceCenter + 1;
const double nFlops = (double) RefMap.ntotRefMap * (double) nShifts * (double) nShifts * const double nFlops = (double) RefMap.ntotRefMap * (double) nShifts * (double) nShifts *
...@@ -345,6 +349,7 @@ int bioem::run() ...@@ -345,6 +349,7 @@ int bioem::run()
printf("Time Comparison %d %d: %f sec (%f GFlops, %f GB/s (cached), %f GB/s)\n", iOrient, iConv, compTime, nFlops / 1000000000., nGBs / 1000000000., nGBs2 / 1000000000.); printf("Time Comparison %d %d: %f sec (%f GFlops, %f GB/s (cached), %f GB/s)\n", iOrient, iConv, compTime, nFlops / 1000000000., nGBs / 1000000000., nGBs2 / 1000000000.);
} }
} }
}
//deallocating fftw_complex vector //deallocating fftw_complex vector
myfftw_free(proj_mapFFT); myfftw_free(proj_mapFFT);
myfftw_free(conv_mapFFT); myfftw_free(conv_mapFFT);
...@@ -516,6 +521,12 @@ int bioem::createProjection(int iMap, mycomplex_t* mapFFT) ...@@ -516,6 +521,12 @@ int bioem::createProjection(int iMap, mycomplex_t* mapFFT)
i = floor(RotatedPointsModel[n].pos[0] / param.pixelSize + (myfloat_t) param.param_device.NumberPixels / 2.0f + 0.5f); i = floor(RotatedPointsModel[n].pos[0] / param.pixelSize + (myfloat_t) param.param_device.NumberPixels / 2.0f + 0.5f);
j = floor(RotatedPointsModel[n].pos[1] / param.pixelSize + (myfloat_t) param.param_device.NumberPixels / 2.0f + 0.5f); j = floor(RotatedPointsModel[n].pos[1] / param.pixelSize + (myfloat_t) param.param_device.NumberPixels / 2.0f + 0.5f);
if (i < 0 || j < 0 || i >= param.param_device.NumberPixels || j >= param.param_device.NumberPixels)
{
if (DebugOutput >= 3) cout << "Model Point out of map: " << i << ", " << j << "\n";
continue;
}
localproj[i * param.param_device.NumberPixels + j] += Model.densityPointsModel[n] / Model.NormDen; localproj[i * param.param_device.NumberPixels + j] += Model.densityPointsModel[n] / Model.NormDen;
} }
......
...@@ -450,6 +450,7 @@ int bioem_cuda::deviceFinishRun() ...@@ -450,6 +450,7 @@ int bioem_cuda::deviceFinishRun()
if (GPUWorkload < 100) if (GPUWorkload < 100)
{ {
pProb.copyFrom(pProb_host, *this); pProb.copyFrom(pProb_host, *this);
free_device_host(pProb_host->ptr);
delete[] pProb_host; delete[] pProb_host;
} }
......
...@@ -55,6 +55,7 @@ protected: ...@@ -55,6 +55,7 @@ protected:
int nProjectionMapsTotal; //Maps in total int nProjectionMapsTotal; //Maps in total
int FFTAlgo; int FFTAlgo;
int DebugOutput;
mycomplex_t** localCCT; mycomplex_t** localCCT;
myfloat_t** lCC; myfloat_t** lCC;
......
...@@ -16,6 +16,7 @@ typedef float myfloat_t; ...@@ -16,6 +16,7 @@ typedef float myfloat_t;
#define myfftw_plan_dft_r2c_2d fftwf_plan_dft_r2c_2d #define myfftw_plan_dft_r2c_2d fftwf_plan_dft_r2c_2d
#define myfftw_plan_dft_c2r_2d fftwf_plan_dft_c2r_2d #define myfftw_plan_dft_c2r_2d fftwf_plan_dft_c2r_2d
#define myfftw_plan fftwf_plan #define myfftw_plan fftwf_plan
#define myfftw_cleanup fftwf_cleanup
#define MY_CUFFT_C2R CUFFT_C2R #define MY_CUFFT_C2R CUFFT_C2R
#define mycufftExecC2R cufftExecC2R #define mycufftExecC2R cufftExecC2R
#define mycuComplex_t cuComplex #define mycuComplex_t cuComplex
...@@ -32,6 +33,7 @@ typedef double myfloat_t; ...@@ -32,6 +33,7 @@ typedef double myfloat_t;
#define myfftw_plan_dft_r2c_2d fftw_plan_dft_r2c_2d #define myfftw_plan_dft_r2c_2d fftw_plan_dft_r2c_2d
#define myfftw_plan_dft_c2r_2d fftw_plan_dft_c2r_2d #define myfftw_plan_dft_c2r_2d fftw_plan_dft_c2r_2d
#define myfftw_plan fftw_plan #define myfftw_plan fftw_plan
#define myfftw_cleanup fftw_cleanup
#define mycufftExecC2R cufftExecZ2D #define mycufftExecC2R cufftExecZ2D
#define mycuComplex_t cuDoubleComplex #define mycuComplex_t cuDoubleComplex
#define MY_CUFFT_C2R CUFFT_Z2D #define MY_CUFFT_C2R CUFFT_Z2D
......
...@@ -150,6 +150,7 @@ int bioem_model::readModel() ...@@ -150,6 +150,7 @@ int bioem_model::readModel()
NormDen += densityPointsModel[numres]; NormDen += densityPointsModel[numres];
numres++; numres++;
} }
fclose(file);
nPointsModel = numres; nPointsModel = numres;
cout << "Protein structure read from Standard File\n"; cout << "Protein structure read from Standard File\n";
} }
......
...@@ -241,7 +241,7 @@ int bioem_param::readParameters() ...@@ -241,7 +241,7 @@ int bioem_param::readParameters()
//More checks with input parameters //More checks with input parameters
// Envelope should not have a standard deviation greater than Npix/2 // Envelope should not have a standard deviation greater than Npix/2
if(sqrt(1./( (myfloat_t) numberGridPointsDisplaceCenter * gridEnvelop + startGridEnvelop))> float(param_device.NumberPixels)/2.0) { if(sqrt(1./( (myfloat_t) numberGridPointsDisplaceCenter * gridEnvelop + startGridEnvelop))> float(param_device.NumberPixels)/2.0) {
cout << "MAX Standar deviation of envelope is larger than Allowed KERNEL Length"; cout << "MAX Standard deviation of envelope is larger than Allowed KERNEL Length\n";
exit(1); exit(1);
} }
// Envelop param should be positive // Envelop param should be positive
...@@ -303,6 +303,7 @@ void bioem_param::releaseFFTPlans() ...@@ -303,6 +303,7 @@ void bioem_param::releaseFFTPlans()
myfftw_destroy_plan(fft_plan_c2c_backward); myfftw_destroy_plan(fft_plan_c2c_backward);
myfftw_destroy_plan(fft_plan_r2c_forward); myfftw_destroy_plan(fft_plan_r2c_forward);
myfftw_destroy_plan(fft_plan_c2r_backward); myfftw_destroy_plan(fft_plan_c2r_backward);
myfftw_cleanup();
} }
fft_plans_created = 0; fft_plans_created = 0;
} }
......
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