diff --git a/.github/workflows/ase_plugin_test.yml b/.github/workflows/ase_plugin_test.yml index 3b5dd93a69..be902b7f59 100644 --- a/.github/workflows/ase_plugin_test.yml +++ b/.github/workflows/ase_plugin_test.yml @@ -48,11 +48,8 @@ jobs: - name: Configure & Build ABACUS (GNU) run: | git config --global --add safe.directory `pwd` - export LD_LIBRARY_PATH=${GKLIB_ROOT}/lib:${METIS32_ROOT}/lib:${PARMETIS32_ROOT}/lib:${SUPERLU_DIST32_ROOT}/lib:${PEXSI32_ROOT}/lib:${LD_LIBRARY_PATH} - export PKG_CONFIG_PATH=${GKLIB_ROOT}/lib/pkgconfig:${METIS32_ROOT}/lib/pkgconfig:${PARMETIS32_ROOT}/lib/pkgconfig:${SUPERLU_DIST32_ROOT}/lib/pkgconfig:${PEXSI32_ROOT}/lib/pkgconfig:${PKG_CONFIG_PATH} - export CPATH=${GKLIB_ROOT}/include:${METIS32_ROOT}/include:${PARMETIS32_ROOT}/include:${SUPERLU_DIST32_ROOT}/include:${PEXSI32_ROOT}/include:${CPATH} - export CMAKE_PREFIX_PATH=${PEXSI32_ROOT}:${SUPERLU_DIST32_ROOT}:${PARMETIS32_ROOT}:${METIS32_ROOT}:${GKLIB_ROOT}:${CMAKE_PREFIX_PATH} source toolchain/install/setup + prepend_path CMAKE_PREFIX_PATH ${PEXSI32_ROOT}:${SUPERLU_DIST32_ROOT}:${PARMETIS32_ROOT}:${METIS32_ROOT}:${GKLIB_ROOT} rm -rf build cmake -B build -G Ninja cmake --build build -j2 diff --git a/.github/workflows/build_test_cmake.yml b/.github/workflows/build_test_cmake.yml index e9d9b1ab4f..56e324993d 100644 --- a/.github/workflows/build_test_cmake.yml +++ b/.github/workflows/build_test_cmake.yml @@ -70,11 +70,8 @@ jobs: - name: Build run: | git config --global --add safe.directory `pwd` - export LD_LIBRARY_PATH=${GKLIB_ROOT}/lib:${METIS32_ROOT}/lib:${PARMETIS32_ROOT}/lib:${SUPERLU_DIST32_ROOT}/lib:${PEXSI32_ROOT}/lib:${LD_LIBRARY_PATH} - export PKG_CONFIG_PATH=${GKLIB_ROOT}/lib/pkgconfig:${METIS32_ROOT}/lib/pkgconfig:${PARMETIS32_ROOT}/lib/pkgconfig:${SUPERLU_DIST32_ROOT}/lib/pkgconfig:${PEXSI32_ROOT}/lib/pkgconfig:${PKG_CONFIG_PATH} - export CPATH=${GKLIB_ROOT}/include:${METIS32_ROOT}/include:${PARMETIS32_ROOT}/include:${SUPERLU_DIST32_ROOT}/include:${PEXSI32_ROOT}/include:${CPATH} - export CMAKE_PREFIX_PATH=${PEXSI32_ROOT}:${SUPERLU_DIST32_ROOT}:${PARMETIS32_ROOT}:${METIS32_ROOT}:${GKLIB_ROOT}:${CMAKE_PREFIX_PATH} source toolchain/install/setup + prepend_path CMAKE_PREFIX_PATH ${PEXSI32_ROOT}:${SUPERLU_DIST32_ROOT}:${PARMETIS32_ROOT}:${METIS32_ROOT}:${GKLIB_ROOT} rm -rf build cmake -B build -G Ninja ${{ matrix.build_args }} cmake --build build -j $(nproc) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3fa065011..c0d4a8a52c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,8 +244,8 @@ if(NOT DEFINED CMAKE_CXX_STANDARD) endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) -# Enable DFT-D4 languages before finding OpenMP. -if(ENABLE_DFTD4) +# Enable languages required by optional dependencies +if(ENABLE_DFTD4 OR ENABLE_PEXSI) enable_language(C) enable_language(Fortran) endif() @@ -323,7 +323,10 @@ if(ENABLE_LCAO) endif() if(ENABLE_PEXSI) - find_package(PEXSI REQUIRED) + find_package(PEXSI REQUIRED CONFIG) + if(PEXSI_VERSION VERSION_LESS "2.0.0") + message(FATAL_ERROR "PEXSI >= 2.0.0 is required") + endif() abacus_add_feature_definitions(__PEXSI) set(CMAKE_CXX_STANDARD 14) endif() diff --git a/cmake/CollectBuildInfoVars.cmake b/cmake/CollectBuildInfoVars.cmake index 5cf5f85248..962054a3f8 100644 --- a/cmake/CollectBuildInfoVars.cmake +++ b/cmake/CollectBuildInfoVars.cmake @@ -370,12 +370,7 @@ else() endif() if(ENABLE_PEXSI) - set(ABACUS_PEXSI_VERSION "yes (version unknown)") - if(PEXSI_VERSION) set(ABACUS_PEXSI_VERSION "yes (v${PEXSI_VERSION})") - elseif(PEXSI_DIR) - set(ABACUS_PEXSI_VERSION "yes (path: ${PEXSI_DIR})") - endif() else() set(ABACUS_PEXSI_VERSION "no") endif() diff --git a/cmake/modules/FindPEXSI.cmake b/cmake/modules/FindPEXSI.cmake deleted file mode 100644 index 5adc4c8a6d..0000000000 --- a/cmake/modules/FindPEXSI.cmake +++ /dev/null @@ -1,57 +0,0 @@ -############################################################################### -# - Find PEXSI -# Find PEXSI and its dependencies. -# -# PEXSI_FOUND - True if pexsi is found. -# PEXSI_INCLUDE_DIR - Where to find pexsi headers. -# PEXSI_LIBRARY - pexsi library. -# ParMETIS_INCLUDE_DIR - Where to find pexsi headers. -# ParMETIS_LIBRARY - parmetis library. -# METIS_LIBRARY - metis library. -# SuperLU_DIST_LIBRARY - superlu_dist library. - -find_path(PEXSI_INCLUDE_DIR - NAMES c_pexsi_interface.h - HINTS ${PEXSI_DIR} - PATH_SUFFIXES "include" -) - -find_library(PEXSI_LIBRARY - NAMES pexsi - HINTS ${PEXSI_DIR} - PATH_SUFFIXES "lib" -) - -find_path(ParMETIS_INCLUDE_DIR - NAMES metis.h parmetis.h - HINTS ${ParMETIS_DIR} - PATH_SUFFIXES "include" -) - -find_library(METIS_LIBRARY - NAMES metis - HINTS ${ParMETIS_DIR} - PATH_SUFFIXES "lib" -) - -find_library(ParMETIS_LIBRARY - NAMES parmetis - HINTS ${ParMETIS_DIR} - PATH_SUFFIXES "lib" -) - -find_library(SuperLU_DIST_LIBRARY - NAMES superlu_dist - HINTS ${SuperLU_DIST_DIR} - PATH_SUFFIXES "lib" -) - -# Handle the QUIET and REQUIRED arguments and -# set PEXSI_FOUND to TRUE if all variables are non-zero. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PEXSI DEFAULT_MSG PEXSI_LIBRARY PEXSI_INCLUDE_DIR ParMETIS_LIBRARY METIS_LIBRARY SuperLU_DIST_LIBRARY) - - -# Copy the results to the output variables and target. -mark_as_advanced(PEXSI_LIBRARY PEXSI_INCLUDE_DIR ParMETIS_LIBRARY SuperLU_DIST_LIBRARY) - diff --git a/docs/advanced/install.md b/docs/advanced/install.md index 2097b851a4..798e38fd3a 100644 --- a/docs/advanced/install.md +++ b/docs/advanced/install.md @@ -145,15 +145,11 @@ cmake -B build -DUSE_ABACUS_LIBM=1 ## Build with PEXSI support -ABACUS supports the PEXSI library for gamma only LCAO calculations. PEXSI version 2.0.0 is tested to work with ABACUS, please always use the latest version of PEXSI. +ABACUS supports the PEXSI library for gamma only LCAO calculations. PEXSI version >=2.0.0 is required. -To build ABACUS with PEXSI support, you need to compile PEXSI (and its dependencies) first. Please refer to the [PEXSI Installation Guide](https://pexsi.readthedocs.io/en/latest/install.html) for more details. Note that PEXSI requires ParMETIS and SuperLU_DIST. +To build ABACUS with PEXSI support, you need to compile PEXSI and its dependencies first. Please refer to the [PEXSI Installation Guide](https://pexsi.readthedocs.io/en/latest/install.html) for more details. You can also use [Spack](https://github.com/spack/spack) to install the required packages more easily. Note that PEXSI requires ParMETIS and SuperLU_DIST. -After compiling PEXSI, you can set `ENABLE_PEXSI` to `ON`. If the libraries are not installed in standard paths, you can set `PEXSI_DIR`, `ParMETIS_DIR` and `SuperLU_DIST_DIR` to the corresponding directories. - -```bash -cmake -B build -DENABLE_PEXSI=ON -DPEXSI_DIR=${path to PEXSI installation directory} -DParMETIS_DIR=${path to ParMETIS installation directory} -DSuperLU_DIST_DIR=${path to SuperLU_DIST installation directory} -``` +After compiling PEXSI, pass `-DENABLE_PEXSI=ON` to CMake. ABACUS uses the CMake config package provided by PEXSI; if PEXSI or its dependencies are not installed in standard paths, add their installation prefixes to `CMAKE_PREFIX_PATH`. ## Build ABACUS with make diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6106f52fdf..d43888feeb 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -201,16 +201,7 @@ if(ENABLE_LCAO) endif() if(ENABLE_PEXSI) - # Temporary adapter for the legacy FindPEXSI.cmake result. Replace this with - # PEXSI::PEXSI when config-package discovery is adopted. - list(APPEND _abacus_feature_libs - ${PEXSI_LIBRARY} - ${SuperLU_DIST_LIBRARY} - ${ParMETIS_LIBRARY} - ${METIS_LIBRARY}) - list(APPEND _abacus_feature_include_dirs - ${PEXSI_INCLUDE_DIR} - ${ParMETIS_INCLUDE_DIR}) + list(APPEND _abacus_feature_libs PEXSI::PEXSI) endif() endif() @@ -337,6 +328,7 @@ foreach(_abacus_feature_target IN ITEMS NEP::nep TensorFlow::tensorflow_cc ZLIB::ZLIB + PEXSI::PEXSI NCCL::NCCL CAL::CAL cusolverMp::cusolverMp diff --git a/source/source_hsolver/test/CMakeLists.txt b/source/source_hsolver/test/CMakeLists.txt index 771bce4c0d..1b0b38e2c3 100644 --- a/source/source_hsolver/test/CMakeLists.txt +++ b/source/source_hsolver/test/CMakeLists.txt @@ -102,10 +102,10 @@ if (ENABLE_MPI) ) endif() - if (ENABLE_PEXSI) + if (TARGET PEXSI::PEXSI) AddTest( TARGET MODULE_HSOLVER_LCAO_PEXSI - LIBS parameter ${PEXSI_LIBRARY} ${SuperLU_DIST_LIBRARY} ${ParMETIS_LIBRARY} ${METIS_LIBRARY} MPI::MPI_CXX base psi device pexsi + LIBS parameter PEXSI::PEXSI base psi device pexsi SOURCES diago_pexsi_test.cpp ../diago_pexsi.cpp ../../source_basis/module_ao/parallel_orbitals.cpp ) endif()