2

I want to use the Intel MKL libraries (including the Pardiso solver) with Eigen3. When I manually specify the compiler options in CMake I get it to work (for that I've followed the Intel Link Line Advisor). But I know there is a pre-difined way through FindBLAS.cmake together with the BLA_VENDOR environment variable, in particular using the FindBLAS.cmake modified by Eigen. Only I'm stuck with this. How should I write my CMakeLists.txt?

I should emphesize that use the latests Eigen3 version on a cluster, so have 'installed' it in a non-trivial location in my home-folder. Also after simply using

cmake /path/to/eigen3 -DCMAKE_INSTALL_PREFIX:PATH=$HOME/opt
make install

I did not get the third-party CMake files.


Edit

I have found a solution that seems to work properly:

cmake_minimum_required(VERSION 2.8.12)

project(main)

set(PROJECT_LIBS "")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# find Eigen3, use an environment variable that specifies the root of the Eigen download:
#   export EIGENPATH="/path/to/clone/of/eigen3/"
list(APPEND CMAKE_MODULE_PATH "$ENV{EIGENPATH}/cmake/")
find_package(Eigen3 3.3.0)
include_directories(${EIGEN3_INCLUDE_DIRS})

# enable Intel-MKL (only for Intel compilers)
# NB requires correct specification of BLA_VENDOR, e.g.
#   export BLA_VENDOR=Intel10_64lp_seq
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  find_package(BLAS)
  include_directories(${BLAS_INCLUDE_DIRS})
  set(PROJECT_LIBS ${BLAS_LIBRARIES})
  add_definitions(-DEIGEN_USE_MKL_ALL)
endif()

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS})

Note that it is important to remark that the 'installation' of Eigen does not work for this solution, as piggy-bagging on pkg-config is not sufficient here. I.e. one should just download/clone Eigen and point CMake to the download location.

5
  • So, when you try to simply use find_package(NAME) it doesn't work? Which variables are not set exactly? Which compiler flags are missing?
    – pptaszni
    Nov 23, 2017 at 8:32
  • @Ptaq666 I added everything I have tried so far (except my own version of FindMKL.cmake, which is irrelevant to this discussion). Nov 23, 2017 at 13:09
  • Try to print all of your include directories from CMake. Here is some example how to do it: stackoverflow.com/questions/6902149/…. It seems that some of the findXXX.cmake scripts is not setting all the appropriate include dirs. A brutal way to fix it is just to add target_include_directories(appropriate_target PUBLIC DIR_WITH_mkl.h).
    – pptaszni
    Nov 23, 2017 at 15:37
  • @Ptaq666 Thanks for pointing me in the right direction. I have posted my solution as an edit of my question. Please comment (or change) if you find improvements. Nov 24, 2017 at 8:46
  • I'm having a similar problem. So it isn't possible at all to cmake install Eigen configured with MKL? If this is the case, what would be a nice CMake setup? Like, putting the entire Eigen folder within an "Extern" directory, maybe? And then setup CMakeLists.txt within the Eigen folder explicitly to use MKL.... Cheers.
    – Breno
    Dec 6, 2023 at 13:27

1 Answer 1

2

It might be a tad bit late to answer this, but with the recent CMake Versions, you could use the following. This might be a cleaner solution.

cmake_minimum_required(VERSION 2.8.3)

project(main)

set(CMAKE_CXX_STANDARD 14)

find_package(Eigen3 REQUIRED)
include_directories(
    ${EIGEN3_INCLUDE_DIRS}
)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
    set(BLA_VENDOR Intel10_64lp)
    add_definitions(-DEIGEN_USE_MKL_ALL)
endif()

find_pacakge(BLAS REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Eigen3::Eigen ${BLAS_LIBRARIES})

Make sure you have run the oneAPI/MKL setup vars script.

source /opt/intel/oneapi/setvars.sh for oneAPI(it is probably best to add it to .bashrc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.