Skip to content

Commit

Permalink
Merge pull request dftbplus#1460 from aradi/arpackfinders
Browse files Browse the repository at this point in the history
* Add consistent finders for arpack and parpack

* Drop installation step with Intel in CI to (hopefully) prevent lockup in GitHub CI
  • Loading branch information
aradi authored May 15, 2024
2 parents c07f9fa + 0571ac8 commit 1ab3e50
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 78 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,6 @@ jobs:
ctest -j 2 --output-on-failure
popd
- name: Install project
run: |
cmake --install ${BUILD_DIR}
# - name: Install project
# run: |
# cmake --install ${BUILD_DIR}
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ list(APPEND PKG_CONFIG_LIBS_PRIVATE ${BLAS_LIBRARY} ${LAPACK_LIBRARY})

if(WITH_ARPACK)
find_package(CustomArpack REQUIRED)
list(APPEND PKG_CONFIG_LIBS_PRIVATE ${ARPACK_LIBRARY})
list(APPEND PKG_CONFIG_REQUIRES arpack)
if (WITH_MPI)
find_package(CustomParpack REQUIRED)
list(APPEND PKG_CONFIG_REQUIRES parpack)
endif()
endif()

if(WITH_MAGMA)
Expand Down
4 changes: 0 additions & 4 deletions cmake/DftbPlusUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ function (dftbp_ensure_config_consistency)
message(FATAL_ERROR "Building with PEXSI requires MPI-parallel build and ELSI enabled")
endif()

if(WITH_ARPACK AND WITH_MPI)
message(FATAL_ERROR "Building with ARPACK requires MPI-parallel build disabled")
endif()

if(WITH_GPU AND WITH_MPI AND NOT WITH_ELSI)
message(FATAL_ERROR "GPU support in MPI-parallelized applications requires the ELSI library (built with GPU support)")
endif()
Expand Down
183 changes: 124 additions & 59 deletions cmake/Modules/FindCustomArpack.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Distributed under the OSI-approved BSD 3-Clause License.
#
# Copyright (C) 2023 DFTB+ developers group
# Copyright (C) 2024 DFTB+ developers group
#

#[=======================================================================[.rst:
Expand All @@ -15,14 +15,17 @@ Imported Targets
This module provides the following imported target, if found:
``Arpack::Arpack``
``ARPACK::ARPACK``
The ARPACK library
Result Variables
^^^^^^^^^^^^^^^^
This module will define the following variable:
This module will define the following variables:
``CustomArpack_FOUND``
True, if ARPACK had been found.
``ARPACK_FOUND``
True if the system has the ARPACK library
Expand All @@ -33,67 +36,129 @@ Cache variables
The following cache variables may be set to influence the library detection:
``ARPACK_DETECTION``
Whether ARPACK libraries should be detected (default: True). If set to False,
the settings in ``ARPACK_LIBRARY`` will be used without any further checks.
``ARPACK_LIBRARY``
Customized ARPACK library/libraries to use (instead of autodetected one). If
not set or empty, the default library (arpack) will be tried. The listed
libraries will be checked for existence (unless disabled in
``ARPACK_DETECTION``) and the variable is overwritten to contain the libraries
with their with full path.
not set or empty, the default library (arpack) will be tried.
``ARPACK_LIBRARY_DIR``
Directories which should be looked up in order to find the customized libraries.
``ARPACK_INCLUDE_DIRECTORY``
Customized ARPACK include library to check for include files.
#]=======================================================================]

include(FindPackageHandleStandardArgs)
include(CustomLibraryFinder)

if(TARGET Arpack::Arpack)

set(CUSTOMARPACK_FOUND True)
set(CustomArpack_FOUND True)
set(ARPACK_FOUND True)
set(Arpack_FOUND True)

else()

option(ARPACK_DETECTION "Whether ARPACK library should be detected" TRUE)

if(ARPACK_DETECTION)

if("${ARPACK_LIBRARY}" STREQUAL "")
# Very simple ARPACK auto-detection
find_library(ARPACK_LIBRARY arpack HINTS ${ARPACK_LIBRARY_DIR})
set(_arpack_found_method)
set(_arpack_found_msg)

if (TARGET ARPACK::ARPACK)

set(ARPACK_FOUND TRUE)
set(_arpack_found_method "target")
set(_arpack_found_msg "target ARPACK::ARPACK already defined")

elseif ("${CustomArpack_FOUND}" STREQUAL "")

set(_quiet)
if (CustomArpack_FIND_QUIETLY)
set(_quiet QUIET)
endif ()

set(_required)
if (CustomArpack_FIND_REQUIRED)
set(_required REQUIRED)
endif ()

# Use user specified value, if present
if (ARPACK_LIBRARY)
add_library(ARPACK::ARPACK UNKNOWN IMPORTED)
set_target_properties(
ARPACK::ARPACK PROPERTIES
IMPORTED_LOCATION ${ARPACK_LIBRARY}
)
set(_arpack_found_msg "as user defined library ${ARPACK_LIBRARY}")
set(_arpack_found_method "user")
if (ARPACK_INCLUDE_DIRECTORY)
set_target_properties(
ARPACK::ARPACK PROPERTIES
INCLUDE_DIRECTORIES ${ARPACK_INCLUDE_DIRECTORY}
)
set(_arpack_found_msg "${_arpack_found_msg} with user defined include dir ${ARPACK_INCLUDE_DIRECTORY}")
endif ()
endif ()

# NOTE: Disabled as many ARPACK-NG installations contain broken CMake export files.
# # Try to find it via CMake export file if had not been tried yet
# if (NOT (arpackng_FOUND OR arpack-ng_FOUND))
# foreach (_package_name IN ITEMS arpackng arpack-ng)
# if (NOT TARGET ARPACK::ARPACK)
# find_package(${_package_name} QUIET)
# if (TARGET ARPACK::ARPACK)
# set(_arpack_found_method "cmake")
# set(_arpack_found_msg "as CMake package ${_package_name}")
# endif ()
# endif ()
# unset(_package_name)
# endforeach ()
# endif ()

# Try to find it via PkgConfig
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
if (NOT TARGET ARPACK::ARPACK)
pkg_check_modules(arpack IMPORTED_TARGET arpack ${_quiet})
if (TARGET PkgConfig::arpack)
add_library(ARPACK::ARPACK INTERFACE IMPORTED)
target_link_libraries(ARPACK::ARPACK INTERFACE PkgConfig::arpack)
if (TARGET ARPACK::ARPACK)
set(_arpack_found_method "pkgconfig")
set(_arpack_found_msg "via package-config")
endif ()
endif ()
endif ()
endif ()

# Try to find it by name
if (NOT TARGET ARPACK::ARPACK)
find_library(ARPACK_LIBRARIES arpack ${_quiet})
find_path(ARPACK_INCLUDE_DIRECTORIES arpack.h HINTS ARPACK_INCLUDE_DIRECTORY ${_quiet})
if (ARPACK_LIBRARIES)
add_library(ARPACK::ARPACK INTERFACE IMPORTED)
target_link_libraries(ARPACK::ARPACK INTERFACE ${ARPACK_LIBRARIES})
set(_arpack_found_method "library")
set(_arpack_found_msg "as library ${ARPACK_LIBRARIES}")
if (ARPACK_INCLUDE_DIRECTORIES)
set_target_properties(
ARPACK::ARPACK PROPERTIES
INCLUDE_DIRECTORIES ${ARPACK_INCLUDE_DIRECTORIES}
)
set(
_arpack_found_msg
"${_arpack_found_msg} with include directory ${ARPACK_INCLUDE_DIRECTORIES}"
)
endif ()
endif ()
endif ()

if (TARGET ARPACK::ARPACK)
set(ARPACK_FOUND TRUE)

# Find and link dependency if not found via CMake export file
if (NOT _arpack_found_method STREQUAL "cmake")
if (NOT TARGET BLAS::BLAS)
find_package(BLAS REQUIRED ${_quiet})
endif ()
if (NOT TARGET LAPACK::LAPACK)
find_package(LAPACK REQUIRED ${_quiet})
endif ()
target_link_libraries(ARPACK::ARPACK INTERFACE LAPACK::LAPACK BLAS::BLAS)
endif ()
endif ()

unset(_quiet)
unset(_required)

endif ()

else()

# Library explicitely set by the user, search for those libraries
find_custom_libraries("${ARPACK_LIBRARY}" "${ARPACK_LIBRARY_DIR}"
"${CustomArpack_FIND_QUIETLY}" _libs)
set(ARPACK_LIBRARY "${_libs}" CACHE STRING "List of ARPACK libraries to link" FORCE)
unset(_libs)

endif()

set(ARPACK_DETECTION False CACHE BOOL "Whether ARPACK libraries should be detected" FORCE)

endif()

find_package_handle_standard_args(CustomArpack REQUIRED_VARS ARPACK_LIBRARY)

set(ARPACK_FOUND ${CUSTOMARPACK_FOUND})
set(Arpack_FOUND ${CUSTOMARPACK_FOUND})

if(ARPACK_FOUND AND NOT TARGET Arpack::Arpack)
add_library(Arpack::Arpack INTERFACE IMPORTED)
target_link_libraries(Arpack::Arpack INTERFACE "${ARPACK_LIBRARY}")
endif()

mark_as_advanced(ARPACK_DETECTION ARPACK_LIBRARY ARPACK_LIBRARY_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CustomArpack DEFAULT_MSG _arpack_found_msg)

endif()
unset(_arpack_found_method)
unset(_arpack_found_msg)
Loading

0 comments on commit 1ab3e50

Please sign in to comment.