跳到主要内容

Compile

Here, we assume that you have installed all required packages as described in the Prerequisites.

Next, the build process is straightforward after you have correctly configured your CMakeLists.txt

configure

CMakeLists.txt

In the CMakeLists.txt, the Prerequisites packages should be specified.

For instance, with Intel MKL, you should specify the following:

find_package(MKL REQUIRED)

target_link_libraries(your_target_name ${MKL_LIBRARIES})

and with MPI, you should specify the following:

find_package(MPI REQUIRED)

target_link_libraries(your_target_name ${MPI_LIBRARIES})
提示

Alternatively, you can follow the template:

cmake_minimum_required(VERSION 3.15.3)
project(iSLIPs)
set(CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0074 NEW)

set(Armadillo_ROOT "$ENV{HOME}/.local/packages/armadillo/")
set(HDF5_ROOT "$ENV{HOME}/.local/packages/hdf5/")
#set(MPI_ROOT "$ENV{HOME}/.local/packages/openmpi/")
# choose the build type, either for debugging or for production
set(CMAKE_BUILD_TYPE "Debug")
#set(CMAKE_BUILD_TYPE "Release")
#set(BLA_VENDOR Intel10_64lp)
#find_package(BLAS REQUIRED)
#find_package(LAPACK REQUIRED)
# do not modify
set(CMAKE_EXPORT_COMPILE_COMMANDS, ON)


find_package(Armadillo REQUIRED)
find_package(HDF5 REQUIRED)
find_package(MPI REQUIRED)

if (MPI_FOUND)
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
SET(CMAKE_C_COMPILER ${MPI_C_COMPILER})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ffast-math")
endif(MPI_FOUND)

if (HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIRS})
link_libraries(${HDF5_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DARMA_USE_HDF5")
endif(HDF5_FOUND)

#set(MKL_LIB "/opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/libmkl_rt.so")
#set(MKL_INC "/opt/intel/compilers_and_libraries/linux/mkl/include")
#
#include_directories(${MKL_INC})

if (LAPACK_FOUND)
link_libraries(${LAPACK_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DARMA_DONT_USE_WRAPPER -llapack")
endif(LAPACK_FOUND)

build

once you have done with the CMakeLists.txt, the build process is straightforward:

  • mkdir a build directory with the src in the same folder
  • excuate cmake ../
  • make && make install

Finally, the compiled binary code should be found in $codehome/bin/