Commit 6765875d authored by David Rohr's avatar David Rohr

improve build system, some related fixes

parent beebec5d
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT( BioEM )
cmake_minimum_required(VERSION 2.6)
project(BioEM)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
###Set up options
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)
FIND_PACKAGE(CUDA)
###Set up general variables
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
FIND_PACKAGE(PkgConfig REQUIRED)
include_directories(include)
PKG_CHECK_MODULES(FFTW fftw3 REQUIRED)
INCLUDE_DIRECTORIES(${FFTW_INCLUDE_DIRS})
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")
FIND_PACKAGE(Boost 1.43 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_ICC_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BIOEM_GCC_FLAGS}")
endif()
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET( CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS})
ADD_DEFINITIONS(-DWITH_OPENMP)
ENDIF()
set (BIOEM_SOURCE_FILES "bioem.cpp" "main.cpp" "map.cpp" "model.cpp" "param.cpp" "cmodules/timer.cpp")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -fopenmp -fweb -mfpmath=sse -frename-registers -minline-all-stringops -ftracer -funroll-loops -fpeel-loops -fprefetch-loop-arrays -ffast-math -ggdb" )
SET( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};--use_fast_math;-ftz=true;-O4;-Xptxas -O4" )
###Find Required Packages
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFTW fftw3 REQUIRED)
include_directories(${FFTW_INCLUDE_DIRS})
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")
find_package(Boost 1.43 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES( include $HOME/usr/include )
###Find Optional Packages
IF(CUDA_FOUND)
ADD_DEFINITIONS(-DWITH_CUDA)
CUDA_ADD_EXECUTABLE( bioEM bioem.cpp main.cpp map.cpp model.cpp param.cpp cmodules/timer.cpp bioem_cuda.cu )
CUDA_ADD_CUFFT_TO_TARGET(bioEM)
ELSE()
ADD_EXECUTABLE( bioEM bioem.cpp main.cpp map.cpp model.cpp param.cpp cmodules/timer.cpp )
ENDIF()
TARGET_LINK_LIBRARIES(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f)
TARGET_LINK_LIBRARIES(bioEM -L${Boost_LIBRARY_DIRS} -lboost_program_options)
###Find CUDA
set (BIOEM_CUDA_STATUS "Disabled")
if (INCLUDE_CUDA)
set (BIOEM_CUDA_STATUS "Not Found")
find_package(CUDA)
endif()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wno-vla -Wno-unused-result -pedantic" )
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")
endif()
###Find OpenMP
set (BIOEM_OPENMP_STATUS "Disabled")
if (INCLUDE_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")
endif()
###Find MPI
set (BIOEM_MPI_STATUS "Disabled")
if (INCLUDE_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")
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})
else()
add_executable(bioEM ${BIOEM_SOURCE_FILES})
endif()
#Additional CXX Flags not used by CUDA compiler
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wno-vla -Wno-unused-result -pedantic")
endif()
if (NOT OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif()
###Add Libraries
if (CUDA_FOUND)
cuda_add_cufft_to_target(bioEM)
endif()
target_link_libraries(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f)
target_link_libraries(bioEM -L${Boost_LIBRARY_DIRS} -lboost_program_options)
if (MPI_FOUND)
target_link_libraries(bioEM ${MPI_LIBRARIES})
endif()
###Show Status
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: ${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()
endif()
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
......@@ -16,7 +16,9 @@
#include <stdlib.h>
#include <string>
#include <cmath>
#ifdef WITH_OPENMP
#include <omp.h>
#endif
#include <fftw3.h>
#include <math.h>
......
......@@ -95,4 +95,9 @@ static inline void* reallocchk(void* oldptr, size_t size)
return(ptr);
}
#ifndef WITH_OPENMP
#define omp_get_max_threads() 1
#define omp_get_thread_num() 0
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
#include <time.h>
#include <fenv.h>
......@@ -15,7 +14,10 @@
#include <iterator>
#include "bioem.h"
#include "bioem_cuda.h"
#ifdef WITH_OPENMP
#include <omp.h>
#endif
#include "cmodules/timer.h"
......@@ -25,10 +27,12 @@ int main(int argc, char* argv[])
// ********************************* Main BioEM code **********************************
// ************************************************************************************
#ifdef _MM_DENORMALS_ZERO_ON
#pragma omp parallel
{
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); //Flush denormals to zero in all OpenMP threads
}
#endif
HighResTimer timer;
bioem* bio;
......
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