Commit 64b4cf5f authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Added FindMKL.cmake and Intel compiler / MKL / Intel MPI support.

parent 5ae0c9fc
......@@ -18,15 +18,17 @@ set(PACKAGE_AUTHOR_EMAIL "[email protected]")
project(STEMsalabim CXX)
cmake_minimum_required(VERSION 3.3)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set (CMAKE_CXX_STANDARD 11)
# determine the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RELEASE")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_CXX_STANDARD 11)
string(TIMESTAMP DATE "%Y-%m-%dT%H:%M:%S")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(default_build_type "Release")
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
endif()
# Some information output
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
......@@ -36,6 +38,27 @@ get_git_head_revision(GIT_REFSPEC GIT_SHA1)
# libraries #############################################
# check if MKL.
if((MKL_ROOT) OR (DEFINED ENV{MKLROOT}))
if(GCCDIR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -cxxlib=${GCCDIR}")
message(STATUS "Using the libstdc++ from ${GCCDIR}")
else(GCCDIR)
message( FATAL_ERROR "At the moment, when using MKL, you NEED to specify -DGCCDIR!" )
endif(GCCDIR)
find_package(MKL REQUIRED)
include_directories(${MKL_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MKL_LIBRARIES})
else()
# look for FFTW3
find_package(FFTW REQUIRED)
include_directories(${FFTW_INCLUDES})
set(LIBS ${LIBS} ${FFTW_LIBRARIES})
endif()
# enable pthread
find_package(Threads REQUIRED)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
......@@ -45,11 +68,6 @@ find_package(LibConfig REQUIRED)
include_directories(${LIBCONFIG_INCLUDE_DIR})
set(LIBS ${LIBS} ${LIBCONFIG_LIBRARIES})
# look for FFTW3
find_package(FFTW REQUIRED)
include_directories(${FFTW_INCLUDES})
set(LIBS ${LIBS} ${FFTW_LIBRARIES})
# look for NetCDF
find_package(NetCDF REQUIRED)
include_directories(${NETCDF_INCLUDE_DIR})
......@@ -68,31 +86,20 @@ find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
set(LIBS ${LIBS} ${MPI_LIBRARIES})
# compilation #############################################
# CFLAGS
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_PROFILE "-g")
add_compile_options(
"$<$<CONFIG:RELASE>:-ffast-math>"
)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
endif()
message(${LIBS})
if(CMAKE_BUILD_TYPE MATCHES PROFILE)
message("Building with GPerftools support")
find_package(Gperftools REQUIRED)
include_directories(${GPERFTOOLS_INCLUDE_DIR})
set(LIBS ${LIBS} ${GPERFTOOLS_LIBRARIES})
add_definitions(-DWITHGPERFTOOLS)
endif(CMAKE_BUILD_TYPE MATCHES PROFILE)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(src)
......
# - Find Intel MKL
# Find the MKL libraries
#
# Options:
#
# MKLROOT : root path of MKL.
#
# This module defines the following variables:
#
# MKL_FOUND : True if MKL_INCLUDE_DIR are found
# MKL_INCLUDE_DIR : where to find mkl.h, etc.
# MKL_INCLUDE_DIRS : set when MKL_INCLUDE_DIR found
# MKL_LIBRARIES : the library to link against.
include(FindPackageHandleStandardArgs)
if((NOT MKL_ROOT) AND (DEFINED ENV{MKLROOT}))
set(MKL_ROOT $ENV{MKLROOT} CACHE PATH "Folder contains MKL")
else()
message( FATAL_ERROR "MKL not found! Specify MKL_ROOT!" )
endif()
if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(MKL_ARCH_DIR "${MKL_ROOT}/lib/intel64")
set(MKL_INTERFACE_LIBNAME mkl_intel_lp64)
else()
set(MKL_ARCH_DIR "${MKL_ROOT}/lib/ia32")
set(MKL_INTERFACE_LIBNAME mkl_intel)
endif()
# Find include dir
find_path(MKL_INCLUDE_DIRS fftw3.h
PATHS ${MKL_ROOT}
PATH_SUFFIXES "include" "include/fftw"
NO_DEFAULT_PATH)
find_library(MKL_INTERFACE_LIBRARY ${MKL_INTERFACE_LIBNAME}
PATHS ${MKL_ARCH_DIR})
find_library(MKL_THREADING_LIBRARY mkl_sequential
PATHS ${MKL_ARCH_DIR})
find_library(MKL_CORE_LIBRARY mkl_core
PATHS ${MKL_ARCH_DIR})
set(MKL_LIBRARIES ${MKL_INTERFACE_LIBRARY} ${MKL_THREADING_LIBRARY} ${MKL_CORE_LIBRARY})
find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INCLUDE_DIRS MKL_LIBRARIES)
mark_as_advanced(
MKL_INCLUDE_DIRS
MKL_LIBRARIES
)
\ No newline at end of file
......@@ -96,4 +96,40 @@ install location with ``make install``:
$ make -j8 # use 8 cores for compilation
$ make install # move the binaries and libraries to the INSTALL_PREFIX path
You are now ready to execute your first simulation.
\ No newline at end of file
You are now ready to execute your first simulation.
Building with Intel MKL, Intel compiler (and Intel MPI)
-------------------------------------------------------
It is possible to use the `Intel® Parallel Studio <https://software.intel.com/en-us/parallel-studio-xe>`_
for compilation, which includes the `Intel® Math Kernel Library (MKL) <https://software.intel.com/en-us/mkl>`_
that *STEMsalabim* can use for discrete fourier transforms instead of FFTW3. If the
`Intel® MPI Library <https://software.intel.com/en-us/intel-mpi-library>`_ is also available, it can be used
as the MPI implementation in *STEMsalabim*.
.. note:: We have tested compiling and running *STEMsalabim* only with Parallel Studio 2017 so far.
*STEMsalabim*'s CMake files try to find the necessary libraries themselves, when the folling conditions are true:
1. Either the environment variable :code:`MKLROOT` is set to a valid install location of the MKL, or
the CMake variable :code:`MKL_ROOT` (pointing at the same location) is specified.
2. The CMake variable :code:`GCCDIR` points to the install directory of a C++11 compatible GCC compiler.
This is important, because the :code:`libstdc++` from a GCC install is required for the Intel compilers
to use modern C++ features.
For example, let's say the Intel suite is installed in :code:`/opt/intel` and we have GCC 6.3 installed in
:code:`/opt/gcc-6.3`, then CMake could be invoked like this: ::
$ export PATH=$PATH:/opt/intel/... # mpicxx and icpc should be in the path!
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gcc-6.3/lib64 \
cmake ../source -DMKL_ROOT=/opt/intel -DCMAKE_CXX_COMPILER=icpc -DGCCDIR=/opt/gcc-6.3
Depending on how your environment variables are set, you may be able to skip the :code:`LD_LIBRARY_PATH=..` part.
When *STEMsalabim* is executed, you may again need to specify the library path of the :code:`libstdc++`, using ::
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gcc-6.3/lib64 mpirun -np ... /path/to/stemsalabim -p ...
.. note:: Some fiddling with paths and environment variables is probably necessary. It may help to know
basic CMake syntax and have a look at :code:`/path/to/stemsalabim/cmake/FindMKL.cmake` if
CMake is unable to find something.
......@@ -34,10 +34,11 @@
#include <cstdlib>
#include <atomic>
#include "algorithms.hpp"
namespace stemsalabim {
template<typename T>
void ignore(T &&) {}
/*!
* We define our own allocator to use with the vector<> stdlib class so
* we use fftwf_malloc and fftw_malloc, which apparently helps with memory
......@@ -85,12 +86,12 @@ namespace stemsalabim {
}
void deallocate(pointer p, size_type count) {
algorithms::ignore(count);
ignore(count);
fftwf_free(static_cast<void *>(p));
}
bool operator==(fftwAllocator const &rhs) const {
algorithms::ignore(rhs);
ignore(rhs);
return true;
}
......
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