From d7b76a62968265b40f2c355e117011aafb30866a Mon Sep 17 00:00:00 2001 From: Chen Nuo <49788094+Cstandardlib@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:38:07 +0800 Subject: [PATCH 1/2] Fix SCALAPACK LIBRARY find logic --- CMakeLists.txt | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e185000d90..c1946c23da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -555,8 +555,29 @@ elseif(NOT USE_SW) find_package(Lapack REQUIRED) include_directories(${FFTW3_INCLUDE_DIRS}) list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS) - if(USE_DSP) - target_link_libraries(${ABACUS_BIN_NAME} ${SCALAPACK_LIBRARY_DIR}) + if(SCALAPACK_LIBRARY_DIR) + if(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}") + find_library( + USER_SCALAPACK_LIBRARY + NAMES scalapack + HINTS ${SCALAPACK_LIBRARY_DIR} + NO_DEFAULT_PATH + ) + if(NOT USER_SCALAPACK_LIBRARY) + message( + FATAL_ERROR + "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but libscalapack was not found in this directory." + ) + endif() + list(APPEND math_libs ${USER_SCALAPACK_LIBRARY}) + else() + list(APPEND math_libs ${SCALAPACK_LIBRARY_DIR}) + endif() + elseif(USE_DSP) + message( + FATAL_ERROR + "USE_DSP is enabled, but SCALAPACK_LIBRARY_DIR is not set. Please provide -DSCALAPACK_LIBRARY_DIR=." + ) else() find_package(ScaLAPACK REQUIRED) list(APPEND math_libs ScaLAPACK::ScaLAPACK) From 4d11ca5f44a00031bd37c61b9c2e9b35129cdee9 Mon Sep 17 00:00:00 2001 From: Chen Nuo <49788094+Cstandardlib@users.noreply.github.com> Date: Tue, 7 Apr 2026 19:25:07 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1946c23da..f4675a964a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -559,18 +559,41 @@ elseif(NOT USE_SW) if(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}") find_library( USER_SCALAPACK_LIBRARY - NAMES scalapack + NAMES scalapack scalapack-openmpi scalapack-mpi scalapack-mpich HINTS ${SCALAPACK_LIBRARY_DIR} + PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH ) - if(NOT USER_SCALAPACK_LIBRARY) + if(USER_SCALAPACK_LIBRARY) + list(APPEND math_libs ${USER_SCALAPACK_LIBRARY}) + else() + find_package(ScaLAPACK QUIET) + if(ScaLAPACK_FOUND) + list(APPEND math_libs ScaLAPACK::ScaLAPACK) + else() + message( + FATAL_ERROR + "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but no compatible ScaLAPACK library was found there and find_package(ScaLAPACK) also failed." + ) + endif() + endif() + else() + if(NOT IS_ABSOLUTE "${SCALAPACK_LIBRARY_DIR}") + message( + FATAL_ERROR + "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this is not an absolute library path. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file." + ) + elseif(NOT EXISTS "${SCALAPACK_LIBRARY_DIR}") message( FATAL_ERROR - "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but libscalapack was not found in this directory." + "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this path does not exist. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file." + ) + elseif(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}") + message( + FATAL_ERROR + "SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but this value resolved to a directory in the full-library-path branch. Please provide either a directory containing libscalapack or a full absolute path to the ScaLAPACK library file." ) endif() - list(APPEND math_libs ${USER_SCALAPACK_LIBRARY}) - else() list(APPEND math_libs ${SCALAPACK_LIBRARY_DIR}) endif() elseif(USE_DSP)