Skip to content

Build: Improving CMake performance for finding LibXC and ELPA #3478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,8 @@ if(DEFINED Libxc_DIR)
set(ENABLE_LIBXC ON)
endif()
if(ENABLE_LIBXC)
find_package(Libxc REQUIRED HINTS
${Libxc_DIR}/share/cmake/Libxc
${Libxc_DIR}/lib/cmake/Libxc
${Libxc_DIR}/lib64/cmake/Libxc
)
# use `cmake/FindLibxc.cmake` to detect Libxc installation with `pkg-config`
find_package(Libxc REQUIRED)
message(STATUS "Found Libxc: version " ${Libxc_VERSION})
if(${Libxc_VERSION} VERSION_LESS 5.1.7)
message(FATAL_ERROR "LibXC >= 5.1.7 is required.")
Expand Down
47 changes: 31 additions & 16 deletions cmake/FindELPA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,49 @@
# ELPA_INCLUDE_DIR - Where to find ELPA headers.
#

find_path(ELPA_INCLUDE_DIR
find_package(PkgConfig)

if(PKG_CONFIG_FOUND)
if(DEFINED ELPA_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${ELPA_DIR}")
endif()
if(USE_OPENMP)
pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa_openmp)
else()
pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa)
endif()
else()
find_path(ELPA_INCLUDE_DIRS
elpa/elpa.h
HINTS ${ELPA_DIR}
PATH_SUFFIXES "include" "include/elpa"
)
if(USE_OPENMP)
find_library(ELPA_LIBRARY
NAMES elpa_openmp elpa
HINTS ${ELPA_DIR}
PATH_SUFFIXES "lib"
)
else()
find_library(ELPA_LIBRARY
NAMES elpa
HINTS ${ELPA_DIR}
PATH_SUFFIXES "lib"
)
if(USE_OPENMP)
find_library(ELPA_LINK_LIBRARIES
NAMES elpa_openmp elpa
HINTS ${ELPA_DIR}
PATH_SUFFIXES "lib"
)
else()
find_library(ELPA_LINK_LIBRARIES
NAMES elpa
HINTS ${ELPA_DIR}
PATH_SUFFIXES "lib"
)
endif()
#message(
# "ELPA : We need pkg-config to get all information about the elpa library")
endif()

# Handle the QUIET and REQUIRED arguments and
# set ELPA_FOUND to TRUE if all variables are non-zero.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LIBRARY ELPA_INCLUDE_DIR)
find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCLUDE_DIRS)

# Copy the results to the output variables and target.
if(ELPA_FOUND)
set(ELPA_LIBRARIES ${ELPA_LIBRARY})
set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIR})
set(ELPA_LIBRARY ${ELPA_LINK_LIBRARIES})
set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS})

if(NOT TARGET ELPA::ELPA)
add_library(ELPA::ELPA UNKNOWN IMPORTED)
Expand Down
36 changes: 36 additions & 0 deletions cmake/FindLibxc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include(FindPackageHandleStandardArgs)

if(DEFINED Libxc_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${Libxc_DIR}")
endif()
# Using CMake interface as default.
# NO REQUIRED here, otherwhile it would throw error
# with no LibXC found.
find_package(Libxc HINTS
${Libxc_DIR}/share/cmake/Libxc
${Libxc_DIR}/lib/cmake/Libxc
${Libxc_DIR}/lib64/cmake/Libxc
)
if(NOT TARGET Libxc::xc)
find_package(PkgConfig REQUIRED)
pkg_search_module(Libxc REQUIRED IMPORTED_TARGET GLOBAL libxc)
find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS)
endif()


# Copy the results to the output variables and target.
# if find_package() above works, Libxc::xc would be present and
# below would be skipped.
if(Libxc_FOUND AND NOT TARGET Libxc::xc)
set(Libxc_LIBRARY ${Libxc_LINK_LIBRARIES})
set(Libxc_LIBRARIES ${Libxc_LIBRARY})
set(Libxc_INCLUDE_DIR ${Libxc_INCLUDE_DIRS})
add_library(Libxc::xc UNKNOWN IMPORTED)
set_target_properties(Libxc::xc PROPERTIES
IMPORTED_LOCATION "${Libxc_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Libxc_INCLUDE_DIR}")
endif()

set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Libxc_INCLUDE_DIR})

mark_as_advanced(Libxc_INCLUDE_DIR Libxc_LIBRARY)
6 changes: 3 additions & 3 deletions docs/quick_start/easy_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ These requirements support the calculation of plane-wave basis in ABACUS. For LC
Some of these packages can be installed with popular package management system, such as `apt` and `yum`:

```bash
sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git
sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git pkgconf
```

> Installing ELPA by apt only matches requirements on Ubuntu 22.04. For earlier linux distributions, you should build ELPA from source.
Expand Down Expand Up @@ -111,12 +111,12 @@ Here, 'build' is the path for building ABACUS; and '-D' is used for setting up s
- `LAPACK_DIR`: Path to OpenBLAS library `libopenblas.so`(including BLAS and LAPACK)
- `SCALAPACK_DIR`: Path to ScaLAPACK library `libscalapack.so`
- `ELPA_DIR`: Path to ELPA install directory; should be the folder containing 'include' and 'lib'.
> Note: If you install ELPA from source, please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa`. This is a known behavior of ELPA.
> Note: In ABACUS v3.5.1 or earlier, if you install ELPA from source , please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa` to help the build system find ELPA headers.

- `FFTW3_DIR`: Path to FFTW3.
- `CEREAL_INCLUDE_DIR`: Path to the parent folder of `cereal/cereal.hpp`. Will download from GitHub if absent.
- `Libxc_DIR`: (Optional) Path to Libxc.
> Note: Building Libxc from source with Makefile does NOT support using it in CMake here. Please compile Libxc with CMake instead.
> Note: In ABACUS v3.5.1 or earlier, Libxc built from source with Makefile is NOT supported; please compile Libxc with CMake instead.
- `LIBRI_DIR`: (Optional) Path to LibRI.
- `LIBCOMM_DIR`: (Optional) Path to LibComm.

Expand Down