Commit 9768552f authored by Pilar Cossio's avatar Pilar Cossio

Correcting bug accessing ilegal memory in CC mat & tidying up

parent 19bc6d4d
......@@ -6,7 +6,7 @@ option (INCLUDE_CUDA "Build BioEM with CUDA support" ON)
option (INCLUDE_OPENMP "Build BioEM with OpenMP support" ON)
option (INCLUDE_MPI "Build BioEM with MPI support" ON)
option (PRINT_CMAKE_VARIABLES "List all CMAKE Variables" OFF)
option (CUDA_FORCE_GCC "Force GCC as host compiler for CUDA part (If standard host compiler is incompatible with CUDA)" OFF)
option (CUDA_FORCE_GCC "Force GCC as host compiler for CUDA part (If standard host compiler is incompatible with CUDA)" ON)
###Set up general variables
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
......@@ -18,9 +18,9 @@ set (BIOEM_ICC_FLAGS "-xHost -O3 -fno-alias -fno-fnalias -unroll -g0 -ipo")
set (BIOEM_GCC_FLAGS "-O3 -march=native -fweb -mfpmath=sse -frename-registers -minline-all-stringops -ftracer -funroll-loops -fpeel-loops -fprefetch-loop-arrays -ffast-math -ggdb")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_ICC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_ICC_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_GCC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_GCC_FLAGS}")
endif()
set (BIOEM_SOURCE_FILES "bioem.cpp" "main.cpp" "map.cpp" "model.cpp" "param.cpp" "cmodules/timer.cpp")
......@@ -43,93 +43,94 @@ include_directories(${Boost_INCLUDE_DIRS})
###Find CUDA
set (BIOEM_CUDA_STATUS "Disabled")
if (INCLUDE_CUDA)
set (BIOEM_CUDA_STATUS "Not Found")
find_package(CUDA)
set (BIOEM_CUDA_STATUS "Not Found")
find_package(CUDA)
endif()
if (CUDA_FOUND)
if (CUDA_FORCE_GCC)
cmake_minimum_required(VERSION 2.8.10.1)
#Use GCC as host compiler for CUDA even though host compiler for other files is not GCC
set (CUDA_HOST_COMPILER gcc)
endif()
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};--use_fast_math;-ftz=true;-O4;-Xptxas -O4")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_13,code=sm_13")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_20,code=sm_20")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_20,code=sm_21")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_30,code=sm_30")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_35,code=sm_35")
add_definitions(-DWITH_CUDA)
set (BIOEM_CUDA_STATUS "Found")
if (CUDA_FORCE_GCC)
cmake_minimum_required(VERSION 2.8.10.1)
#Use GCC as host compiler for CUDA even though host compiler for other files is not GCC
set (CUDA_HOST_COMPILER gcc)
endif()
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};--use_fast_math;-ftz=true;-O4;-Xptxas -O4")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_13,code=sm_13")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_20,code=sm_20")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_20,code=sm_21")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_30,code=sm_30")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_35,code=sm_35")
list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_52,code=sm_52")
add_definitions(-DWITH_CUDA)
set (BIOEM_CUDA_STATUS "Found")
endif()
###Find OpenMP
set (BIOEM_OPENMP_STATUS "Disabled")
if (INCLUDE_OPENMP)
set (BIOEM_OPENMP_STATUS "Not Found")
find_package(OpenMP)
set (BIOEM_OPENMP_STATUS "Not Found")
find_package(OpenMP)
endif()
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DWITH_OPENMP)
set (BIOEM_OPENMP_STATUS "Found")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DWITH_OPENMP)
set (BIOEM_OPENMP_STATUS "Found")
endif()
###Find MPI
set (BIOEM_MPI_STATUS "Disabled")
if (INCLUDE_MPI)
set (BIOEM_MPI_STATUS "Not Found")
find_package(MPI)
set (BIOEM_MPI_STATUS "Not Found")
find_package(MPI)
endif()
if (MPI_FOUND)
include_directories(${MPI_INCLUDE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${MPI_LINK_FLAGS}")
add_definitions(-DWITH_MPI)
set (BIOEM_MPI_STATUS "Found")
include_directories(${MPI_INCLUDE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${MPI_LINK_FLAGS}")
add_definitions(-DWITH_MPI)
set (BIOEM_MPI_STATUS "Found")
endif()
###Build Executable
if (CUDA_FOUND)
set(BIOEM_TMP_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if (CUDA_FORCE_GCC)
#Hack to use GCC flags for GCC host compiler during NVCC compilation, although host compiler is in fact not GCC for other files
set(CMAKE_CXX_FLAGS ${BIOEM_GCC_FLAGS})
endif()
cuda_add_executable(bioEM ${BIOEM_SOURCE_FILES} bioem_cuda.cu)
set(CMAKE_CXX_FLAGS ${BIOEM_TMP_CMAKE_CXX_FLAGS})
set(BIOEM_TMP_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if (CUDA_FORCE_GCC)
#Hack to use GCC flags for GCC host compiler during NVCC compilation, although host compiler is in fact not GCC for other files
set(CMAKE_CXX_FLAGS ${BIOEM_GCC_FLAGS})
endif()
cuda_add_executable(bioEM ${BIOEM_SOURCE_FILES} bioem_cuda.cu)
set(CMAKE_CXX_FLAGS ${BIOEM_TMP_CMAKE_CXX_FLAGS})
else()
add_executable(bioEM ${BIOEM_SOURCE_FILES})
add_executable(bioEM ${BIOEM_SOURCE_FILES})
endif()
#Additional CXX Flags not used by CUDA compiler
#Additional CXX Flags not used by CUDA compiler
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-vla -Wno-unused-result -Wno-unused-local-typedefs -pedantic")
endif()
if (NOT OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla -Wno-long-long -Wall -pedantic")
endif()
###Add Libraries
if (CUDA_FOUND)
cuda_add_cufft_to_target(bioEM)
target_link_libraries(bioEM ${CUDA_CUDA_LIBRARY})
cuda_add_cufft_to_target(bioEM)
#set(CUDA_LIBRARIES "/afs/ipp/.cs/cuda/6.5-gtx9/amd64_sles11/lib64/stubs/libcuda.so")
#cuda_add_library()
target_link_libraries(bioEM ${CUDA_CUDA_LIBRARY})
# target_link_libraries(bioEM ${CUDA_LIBRARIES})
endif()
if (FFTWF_LIBRARIES)
target_link_libraries(bioEM ${FFTWF_LIBRARIES})
target_link_libraries(bioEM ${FFTWF_LIBRARIES})
else()
target_link_libraries(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f)
target_link_libraries(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f)
endif()
target_link_libraries(bioEM -L${Boost_LIBRARY_DIRS} -lboost_program_options)
if (MPI_FOUND)
target_link_libraries(bioEM ${MPI_LIBRARIES})
target_link_libraries(bioEM ${MPI_LIBRARIES})
endif()
###Show Status
......@@ -137,14 +138,16 @@ message(STATUS "Build Status")
message(STATUS "FFTW library: ${FFTW_LIBDIR}")
message(STATUS "Boost directory: ${Boost_LIBRARY_DIRS}")
message(STATUS "FFTW includedir: ${FFTW_INCLUDEDIR}")
message(STATUS "CUDA libraries: ${CUDA_CUDA_LIBRARY}")
message(STATUS "CUDA libraries: ${CUDA_LIBRARIES}")
message(STATUS "CUDA: ${BIOEM_CUDA_STATUS}")
message(STATUS "OpenMP: ${BIOEM_OPENMP_STATUS}")
message(STATUS "MPI: ${BIOEM_MPI_STATUS}")
if (PRINT_CMAKE_VARIABLES)
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endif()
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,12 @@
See license statement for terms of distribution.
Note: This program contains subroutine "read_MRC" of the Situs 2.7.2 program.
Ref: Willy Wriggers. Using Situs for the Integration of Multi-Resolution Structures.
Biophysical Reviews, 2010, Vol. 2, pp. 21-27.
with a GPL lisences version XX.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <fstream>
......@@ -35,6 +41,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
int allocsize = 0;
if (param.loadMap)
{
//************** Loading Map from Binary file *******
FILE* fp = fopen("maps.dump", "rb");
if (fp == NULL)
{
......@@ -50,12 +57,14 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
}
else if(readMRC)
{
//************** Reading MRC file *******
ntotRefMap=0;
if(readMultMRC)
{
cout << "Opening File with MRC list names: " << filemap << "\n";
//************** Reading Multiple MRC files *************
cout << "Opening File with MRC list names: " << filemap << "\n";
ifstream input(filemap);
if (!input.good())
......@@ -74,9 +83,9 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
input.getline(line,511);
char tmpVals[100] = {0};
string strline(line);
string strline(line);
// cout << "MRC File name:" << strline << "\n";
// cout << "MRC File name:" << strline << "\n";
strncpy (tmpVals,line,99);
......@@ -87,10 +96,10 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
if(strcmp(tmpm,"XXX")!=0)
{
indifile=strline.c_str();
indifile=strline.c_str();
size_t foundpos= strline.find("mrc");
size_t endpos = strline.find_last_not_of(" \t");
// size_t foundpos= strline.find("mrc");
// size_t endpos = strline.find_last_not_of(" \t");
//Reading Multiple MRC
......@@ -106,15 +115,15 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
else
{
string strfilename(filemap);
string strfilename(filemap);
size_t foundpos= strfilename.find("mrc");
size_t endpos = strfilename.find_last_not_of(" \t");
size_t foundpos= strfilename.find("mrc");
size_t endpos = strfilename.find_last_not_of(" \t");
if(foundpos > endpos){
cout << "Warining:::: mrc extension NOT dectected in file name::" << filemap <<" \n";
cout << "Warining:::: Are you sure you want to read an MRC? \n";
}
if(foundpos > endpos){
cout << "Warining:::: mrc extension NOT dectected in file name::" << filemap <<" \n";
cout << "Warining:::: Are you sure you want to read an MRC? \n";
}
read_MRC(filemap,param);
cout << "\n++++++++++++++++++++++++++++++++++++++++++ \n";
......@@ -123,6 +132,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
}
else
{
//************** Reading Text file *************
int nummap = -1;
int lasti = 0;
int lastj = 0;
......@@ -201,7 +211,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
maps[nummap * refMapSize + i * numPixels + j] = (myfloat_t) z;
lasti = i;
lastj = j;
// cout << countpix << " " << param.param_device.NumberPixels*param.param_device.NumberPixels << "\n";
// cout << countpix << " " << param.param_device.NumberPixels*param.param_device.NumberPixels << "\n";
}
else
{
......@@ -221,20 +231,21 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
cout << "Particle Maps read from Standard File: " << ntotRefMap << "\n";
}
//Dumping Maps
//************* If Dumping Maps *********************
if (param.dumpMap)
{
FILE* fp = fopen("maps.dump", "w+b");
if (fp == NULL)
{
cout << "Error opening dump file\n";
exit(1);
}
fwrite(&ntotRefMap, sizeof(ntotRefMap), 1, fp);
fwrite(maps, sizeof(myfloat_t) * refMapSize, ntotRefMap, fp);
fclose(fp);
}
{
FILE* fp = fopen("maps.dump", "w+b");
if (fp == NULL)
{
cout << "Error opening dump file\n";
exit(1);
}
fwrite(&ntotRefMap, sizeof(ntotRefMap), 1, fp);
fwrite(maps, sizeof(myfloat_t) * refMapSize, ntotRefMap, fp);
fclose(fp);
}
//*********** To Debug with few Maps ********************
if (getenv("BIOEM_DEBUG_NMAPS"))
{
......@@ -250,7 +261,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
int bioem_RefMap::PreCalculateMapsFFT(bioem_param& param)
{
// **************************************************************************************
// ********** Routine that pre-calculates Kernels for Convolution **********************
// ********** Routine that pre-calculates Reference maps FFT for Convolution/ Comparison **********************
// ************************************************************************************
RefMapsFFT = new mycomplex_t[ntotRefMap * param.FFTMapSize];
......@@ -320,17 +331,19 @@ int bioem_RefMap::precalculate(bioem_param& param, bioem& bio)
void bioem_Probability::init(size_t maps, size_t angles, size_t cc, bioem& bio)
{
//********** Initializing pointers *******************
nMaps = maps;
nAngles = angles;
nCC = cc;
ptr = bio.malloc_device_host(get_size(maps, angles, cc, bio.param.param_device.writeAngles, bio.param.param_device.writeCC));
cout << "Allocation #Maps " << maps << " #Angles " << angles << " #cross.cor " << cc << "\n";
//<< " == " << get_size(maps, angles, cc, bio.param.param_device.writeAngles, bio.param.param_device.writeCC)<< "\n";
//<< " == " << get_size(maps, angles, cc, bio.param.param_device.writeAngles, bio.param.param_device.writeCC)<< "\n";
set_pointers();
}
void bioem_Probability::copyFrom(bioem_Probability* from, bioem& bio)
{
bioem_Probability_map& pProbMap = getProbMap(0);
bioem_Probability_map& pProbMapFrom = from->getProbMap(0);
memcpy(&pProbMap, &pProbMapFrom, from->nMaps * sizeof(bioem_Probability_map));
......@@ -358,6 +371,12 @@ void bioem_Probability::copyFrom(bioem_Probability* from, bioem& bio)
int bioem_RefMap::read_MRC(const char* filename,bioem_param& param)
{
/* subroutine "read_MRC" of the Situs 2.7.2 program.
Ref: Willy Wriggers. Using Situs for the Integration of Multi-Resolution Structures.
Biophysical Reviews, 2010, Vol. 2, pp. 21-27.*/
myfloat_t st,st2;
unsigned long count;
FILE *fin;
......@@ -453,7 +472,7 @@ int bioem_RefMap::read_MRC(const char* filename,bioem_param& param)
if(nr!=param.param_device.NumberPixels || nc!=param.param_device.NumberPixels )
{
cout << "PROBLEM INCONSISTENT NUMBER OF PIXELS IN MAPS AND INPUTFILE ( " << param.param_device.NumberPixels << ", i " << nc << ", j " << nr << ")" << "\n";
if(!param.notsqure) exit(1);
if(!param.notsqure) exit(1);
}
if (ntotRefMap == 0)
......@@ -498,25 +517,25 @@ int bioem_RefMap::read_MRC(const char* filename,bioem_param& param)
}
else
{
if(!param.notsqure){
maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] = (myfloat_t) currfloat;
st += currfloat;
st2 += currfloat*currfloat;
} else {
if( i > 595 && i < 675 && j > 1250 && j< 1330 && nmap >230 && nmap <310)cout << "map1: " << i << " "<< j << " " << nmap << " " << currfloat <<"\n";
}
if(!param.notsqure){
maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] = (myfloat_t) currfloat;
st += currfloat;
st2 += currfloat*currfloat;
} else {
if( i > 595 && i < 675 && j > 1250 && j< 1330 && nmap >230 && nmap <310)cout << "map1: " << i << " "<< j << " " << nmap << " " << currfloat <<"\n";
}
}
}
if(param.notsqure)exit(1);
if(param.notsqure)exit(1);
//Normaling maps to zero mean and unit standard deviation
if(!param.notnormmap){
st /= float(nr*nc);
st2 = sqrt(st2 / float(nr * nc) - st * st);
for ( int j = 0 ; j < nr ; j ++ ) for ( int i = 0 ; i < nc ; i ++ ){
maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] = maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] / st2 - st/st2;
//cout <<"MAP:: " << i << " " << j << " " << maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] << "\n";
}
}
st /= float(nr*nc);
st2 = sqrt(st2 / float(nr * nc) - st * st);
for ( int j = 0 ; j < nr ; j ++ ) for ( int i = 0 ; i < nc ; i ++ ){
maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] = maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] / st2 - st/st2;
//cout <<"MAP:: " << i << " " << j << " " << maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] << "\n";
}
}
}
ntotRefMap += ns ;
// cout << ntotRefMap << "\n";
......
This diff is collapsed.
This diff is collapsed.
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