Skip to content

Commit 60ea82d

Browse files
authored
refactor: find scalapack automatically (#7235)
* refactor: find scalapack automatically * robust FindScaLAPACK.cmake
1 parent f13e1c5 commit 60ea82d

2 files changed

Lines changed: 23 additions & 55 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -555,56 +555,8 @@ elseif(NOT USE_SW)
555555
find_package(Lapack REQUIRED)
556556
include_directories(${FFTW3_INCLUDE_DIRS})
557557
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS)
558-
if(SCALAPACK_LIBRARY_DIR)
559-
if(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}")
560-
find_library(
561-
USER_SCALAPACK_LIBRARY
562-
NAMES scalapack scalapack-openmpi scalapack-mpi scalapack-mpich
563-
HINTS ${SCALAPACK_LIBRARY_DIR}
564-
PATH_SUFFIXES lib lib64
565-
NO_DEFAULT_PATH
566-
)
567-
if(USER_SCALAPACK_LIBRARY)
568-
list(APPEND math_libs ${USER_SCALAPACK_LIBRARY})
569-
else()
570-
find_package(ScaLAPACK QUIET)
571-
if(ScaLAPACK_FOUND)
572-
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
573-
else()
574-
message(
575-
FATAL_ERROR
576-
"SCALAPACK_LIBRARY_DIR is set to '${SCALAPACK_LIBRARY_DIR}', but no compatible ScaLAPACK library was found there and find_package(ScaLAPACK) also failed."
577-
)
578-
endif()
579-
endif()
580-
else()
581-
if(NOT IS_ABSOLUTE "${SCALAPACK_LIBRARY_DIR}")
582-
message(
583-
FATAL_ERROR
584-
"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."
585-
)
586-
elseif(NOT EXISTS "${SCALAPACK_LIBRARY_DIR}")
587-
message(
588-
FATAL_ERROR
589-
"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."
590-
)
591-
elseif(IS_DIRECTORY "${SCALAPACK_LIBRARY_DIR}")
592-
message(
593-
FATAL_ERROR
594-
"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."
595-
)
596-
endif()
597-
list(APPEND math_libs ${SCALAPACK_LIBRARY_DIR})
598-
endif()
599-
elseif(USE_DSP)
600-
message(
601-
FATAL_ERROR
602-
"USE_DSP is enabled, but SCALAPACK_LIBRARY_DIR is not set. Please provide -DSCALAPACK_LIBRARY_DIR=<scalapack dir or full library path>."
603-
)
604-
else()
605-
find_package(ScaLAPACK REQUIRED)
606-
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
607-
endif()
558+
find_package(ScaLAPACK REQUIRED)
559+
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
608560
if(USE_OPENMP)
609561
list(APPEND math_libs FFTW3::FFTW3_OMP)
610562
endif()

cmake/FindScaLAPACK.cmake

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
# ScaLAPACK_FOUND - True if ScaLAPACK is found.
66
#
77

8+
# Accept common root hints from cache vars and environment.
9+
set(_scalapack_hints
10+
${SCALAPACK_DIR}
11+
${SCALAPACK_ROOT}
12+
$ENV{SCALAPACK_DIR}
13+
$ENV{SCALAPACK_ROOT}
14+
)
15+
816
find_library(ScaLAPACK_LIBRARY
9-
NAMES scalapack scalapack-openmpi
10-
HINTS ${SCALAPACK_DIR}
11-
PATH_SUFFIXES "lib"
17+
NAMES
18+
scalapack
19+
scalapack-openmpi
20+
scalapack-mpi
21+
scalapack-mpich
22+
HINTS ${_scalapack_hints}
23+
PATH_SUFFIXES lib lib64
1224
)
1325

26+
unset(_scalapack_hints)
27+
1428
# Handle the QUIET and REQUIRED arguments and
1529
# set ScaLAPACK_FOUND to TRUE if all variables are non-zero.
1630
include(FindPackageHandleStandardArgs)
17-
find_package_handle_standard_args(ScaLAPACK DEFAULT_MSG ScaLAPACK_LIBRARY)
31+
find_package_handle_standard_args(
32+
ScaLAPACK
33+
REQUIRED_VARS ScaLAPACK_LIBRARY
34+
)
1835

1936
# Copy the results to the output variables and target.
2037
if(ScaLAPACK_FOUND)
@@ -23,7 +40,6 @@ if(ScaLAPACK_FOUND)
2340
if(NOT TARGET ScaLAPACK::ScaLAPACK)
2441
add_library(ScaLAPACK::ScaLAPACK UNKNOWN IMPORTED)
2542
set_target_properties(ScaLAPACK::ScaLAPACK PROPERTIES
26-
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
2743
IMPORTED_LOCATION "${ScaLAPACK_LIBRARY}")
2844
endif()
2945
endif()

0 commit comments

Comments
 (0)