Skip to content

CMake: Rewrite FindMKL.cmake#7595

Open
Growl1234 wants to merge 3 commits into
deepmodeling:developfrom
Growl1234:cmake-mkl
Open

CMake: Rewrite FindMKL.cmake#7595
Growl1234 wants to merge 3 commits into
deepmodeling:developfrom
Growl1234:cmake-mkl

Conversation

@Growl1234

@Growl1234 Growl1234 commented Jul 6, 2026

Copy link
Copy Markdown

This reworks FindMKL.cmake to model the oneMKL link closure required by ABACUS rather than exposing individual MKL libraries to callers.

ABACUS directly uses LP64 Fortran-style BLAS/LAPACK symbols and, in MPI builds, BLACS/ScaLAPACK routines. The finder now provides:

  • abacus::mkl for the BLAS/LAPACK and FFTW compatibility interfaces;
  • abacus::mkl_scalapack for the MPI closure, including ScaLAPACK, the matching BLACS library, base MKL libraries, and MPI::MPI_CXX.

The configuration handles the relevant oneMKL choices explicitly:

  • LP64 only, since ABACUS integer arguments are not ILP64-compatible;
  • mkl_gf_lp64 for GCC and mkl_intel_lp64 otherwise, preserving the established ABACUS interface-library selection;
  • Sequential, GNU-threaded, or Intel-threaded MKL;
  • Static or shared oneMKL libraries, with a local linker group for static archive closures on Linux;
  • Open MPI through mkl_blacs_openmpi_lp64, while MPICH and Intel MPI use mkl_blacs_intelmpi_lp64, as required by oneMKL.

Note about visible affects

  1. For MKL_MPI=AUTO, MPI library-version probing is enabled before find_package(MPI) when the build is not cross-compiled. This allows Open MPI to be detected reliably, but does not work for cross builds. People who process cross builds should know what they are doing, and select the BLACS interface explicitly through MKL_MPI when using MKL.
  2. Only GCC and Intel compilers are tested. Further validation on other type of compilers like LLVM-Clang might be needed.
  3. This PR targets tested Linux configurations only (including Windows WSL2) as ABACUS is a Linux-based program anyways.

Closes #7568.

Details

Linked Issue

Fix #7568

Unit Tests and/or Case Tests for my changes

  • Tested two GCC-MKL toolchain builds, one with MPICH and one with OpenMPI.

Exact Verification Performed

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • See above.

Governance Checklist

  • Global dependencies: no net increase in GlobalV, GlobalC, or PARAM code references, or exception requested below with reason, scope, risk, and cleanup plan.
  • Default parameters: no new default arguments added to existing interfaces, or exception requested below.
  • Headers: no unnecessary header dependencies or .hpp propagation, or rationale provided below.
  • Line endings: text files use LF; only .bat and .cmd use CRLF.
  • Build linkage: new source files are listed in the relevant CMakeLists.txt, or rationale provided below.
  • Documentation: no documentation update is required
  • CodeRabbit: what's this?

INPUT Parameter Changes

  • Parameters added/removed/changed: none
  • docs/parameters.yaml updated: no
  • docs/advanced/input_files/input-main.md updated: no
  • If not updated, explain why no INPUT documentation update is required: not affected.

Core Module Impact

  • Affected core modules: CMake Find package
  • Risk summary:
  • Compatibility or performance impact:

Governance Exception

  • Rule:
  • Reason:
  • Scope:
  • User or maintenance risk:
  • Why the normal rule cannot be followed now:
  • Follow-up cleanup plan:
  • Requested approver:

Copilot AI review requested due to automatic review settings July 6, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request rewrites cmake/modules/FindMKL.cmake to expose ABACUS-oriented oneMKL link closures (BLAS/LAPACK/FFTW, plus BLACS/ScaLAPACK+MPI for MPI builds) instead of exposing individual MKL libraries, and adjusts the build to support MPI-flavor auto-detection for the BLACS interface.

Changes:

  • Replace FindMKL.cmake with a closure-based design that provides MKL::MKL and MKL::MKL_SCALAPACK, plus cache axes for link mode/threading/MPI ABI.
  • Enable MPI library-version probing (when not cross-compiling) so MKL can auto-select the correct BLACS interface.
  • Switch the core linalg link closure to consume ${MKL_LIBRARIES} and key off MKL_FOUND.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
cmake/modules/FindMKL.cmake Reworked MKL discovery to build ABACUS-specific imported-target closures with explicit threading/link-mode/MPI-ABI handling.
CMakeLists.txt Enables MPI_DETERMINE_LIBRARY_VERSION pre-probing for improved Open MPI detection used by the MKL finder.
source/CMakeLists.txt Updates the linalg closure to link via ${MKL_LIBRARIES} and key off MKL_FOUND.

Comment thread cmake/modules/FindMKL.cmake Outdated
Comment thread cmake/modules/FindMKL.cmake
Comment thread cmake/modules/FindMKL.cmake
Comment thread cmake/modules/FindMKL.cmake Outdated
Comment thread source/CMakeLists.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Require MKL interface library in non-MPI detection

2 participants