From c44eeb3a1afb202659ec29d55e11014353cd552a Mon Sep 17 00:00:00 2001 From: Chun Cai Date: Fri, 12 Jul 2024 16:14:43 +0800 Subject: [PATCH] Build: manually link MKL scalapack in absence (#4663) * Build: manually link MKL scalapack in absence * add message output * set message type for finding elpa * Add scalapack setup for standard MKL config --- CMakeLists.txt | 6 ++---- cmake/FindELPA.cmake | 4 ++-- cmake/FindMKL.cmake | 7 +++++++ source/module_base/test_parallel/CMakeLists.txt | 5 +---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11809a941a..facd0990d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,13 +396,11 @@ if(DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT) endif() if(MKLROOT) set(MKL_INTERFACE lp64) + set(ENABLE_SCALAPACK ON) find_package(MKL REQUIRED) add_definitions(-D__MKL) include_directories(${MKL_INCLUDE} ${MKL_INCLUDE}/fftw) - list(APPEND math_libs MKL::MKL) - if(TARGET MKL::MKL_SCALAPACK) - list(APPEND math_libs MKL::MKL_SCALAPACK) - endif() + list(APPEND math_libs MKL::MKL MKL::MKL_SCALAPACK) if(CMAKE_CXX_COMPILER_ID MATCHES Intel) list(APPEND math_libs ifcore) endif() diff --git a/cmake/FindELPA.cmake b/cmake/FindELPA.cmake index 904be208a5..75689a7364 100644 --- a/cmake/FindELPA.cmake +++ b/cmake/FindELPA.cmake @@ -45,7 +45,7 @@ else() endif() # Incompatible with ELPA earlier than 2021.11.001 -# Before ELPA 2021.11.001, its pkg-config file +# Before ELPA 2021.11.001, its pkg-config file # is named like "elpa-2021.05.002.pc". if(NOT ELPA_INCLUDE_DIRS AND PKG_CONFIG_FOUND) if(DEFINED ELPA_DIR) @@ -57,7 +57,7 @@ if(NOT ELPA_INCLUDE_DIRS AND PKG_CONFIG_FOUND) pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa) endif() elseif(NOT PKG_CONFIG_FOUND) - message( + message(STATUS "ELPA : We need pkg-config to get all information about the elpa library") endif() diff --git a/cmake/FindMKL.cmake b/cmake/FindMKL.cmake index 92e3bc44ad..38db391d29 100644 --- a/cmake/FindMKL.cmake +++ b/cmake/FindMKL.cmake @@ -86,3 +86,10 @@ endif() # MKL::MKL if(TARGET MKL::MKL) add_library(IntelMKL::MKL ALIAS MKL::MKL) endif() + +# In oneAPI 2022, MKL_SCALAPACK might not be linked properly +if(NOT TARGET MKL::MKL_SCALAPACK) + find_library(MKL_SCALAPACK NAMES mkl_scalapack_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64) + message(STATUS "Found MKL_SCALAPACK: ${MKL_SCALAPACK}") + add_library(MKL::MKL_SCALAPACK OBJECT IMPORTED MKL_SCALAPACK) +endif() diff --git a/source/module_base/test_parallel/CMakeLists.txt b/source/module_base/test_parallel/CMakeLists.txt index 0081812973..d2b6164d6c 100644 --- a/source/module_base/test_parallel/CMakeLists.txt +++ b/source/module_base/test_parallel/CMakeLists.txt @@ -37,10 +37,7 @@ add_test(NAME base_parallel_reduce_test if(ENABLE_LCAO) # figure out the lib that provides BLACS if(MKLROOT) - list(APPEND BLACS_LIB MKL::MKL) - if(TARGET MKL::MKL_SCALAPACK) - list(APPEND BLACS_LIB MKL::MKL_SCALAPACK) - endif() + list(APPEND BLACS_LIB MKL::MKL MKL::MKL_SCALAPACK) else() set(BLACS_LIB ScaLAPACK::ScaLAPACK) endif()