Skip to content

Refactor HSolver to remove global runtime dependencies - #7887

Open
Critsium-xy wants to merge 3 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hsolver-remove-global-dependencies
Open

Refactor HSolver to remove global runtime dependencies#7887
Critsium-xy wants to merge 3 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hsolver-remove-global-dependencies

Conversation

@Critsium-xy

@Critsium-xy Critsium-xy commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • remove all GlobalC, GlobalV, and PARAM references from source/source_hsolver
  • pass communicator/rank, process-count, and logging dependencies explicitly from ESolver and other orchestration boundaries
  • update HSolver unit and MPI tests to use local configuration and explicit communication contexts
  • remove the unused cuSolverMP outputParameters() helper

The baseline scan contained 103 matching lines in source/source_hsolver (50 GlobalV occurrences, 56 PARAM occurrences, and no GlobalC occurrences; three lines contained both symbols). The same scan now returns zero matches.

Design

HSolver is treated as a numerical solver layer. Runtime ownership remains at workflow/orchestration boundaries, while solver APIs receive only the context they need:

  • DiagoIterAssist receives diag_comm_info for subspace reductions
  • BPCG uses the rank already owned by its parallel linear-transform context
  • HSolverLCAO and PEXSI receive world rank/process count explicitly
  • PW, SDFT, and LCAO-in-PW solvers receive an output stream explicitly
  • dense solver implementations no longer write through the global log stream

The governance checker reports migration warnings where existing globals are read at ESolver/LCAO/PSI/PW call boundaries. Those are deliberate boundary reads: this PR removes solver-layer coupling without broadening the refactor into the workflow/configuration layers. The PR-level global dependency budget is non-increasing (added=31, removed=117, net_delta=-86).

Verification

Passed:

cmake -S . -B build -G Ninja \
  -DBUILD_TESTING=ON -DENABLE_MPI=OFF -DENABLE_ELPA=OFF \
  -DMKLROOT=/tmp/abacus-mkl
cmake --build build -j2

Full serial build: 855/855 build steps passed before final formatting. After the final include cleanup, the same build was reconfigured with -DFETCHCONTENT_FULLY_DISCONNECTED=ON and its 29 affected targets rebuilt successfully.

cmake -S . -B /tmp/abacus-build-mpi-openblas -G Ninja \
  -DBUILD_TESTING=ON -DENABLE_MPI=ON -DENABLE_ELPA=OFF \
  -DBLA_VENDOR=OpenBLAS \
  -DCMAKE_CXX_COMPILER=/usr/bin/mpicxx \
  -DCMAKE_C_COMPILER=/usr/bin/mpicc \
  -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=/tmp/abacus-build-mpi/_deps/googletest-src

cmake --build /tmp/abacus-build-mpi-openblas \
  --target hsolver esolver \
  MODULE_HSOLVER_bpcg MODULE_HSOLVER_cg MODULE_HSOLVER_cg_float \
  MODULE_HSOLVER_cg_real MODULE_HSOLVER_dav MODULE_HSOLVER_dav_float \
  MODULE_HSOLVER_dav_real MODULE_HSOLVER_pw MODULE_HSOLVER_sdft \
  MODULE_HSOLVER_LCAO MODULE_HSOLVER_linear_trans -j2

Focused MPI/OpenBLAS targets built successfully.

OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 \
ctest --test-dir /tmp/abacus-build-mpi-openblas --output-on-failure \
  -R '^MODULE_HSOLVER_(bpcg|cg|cg_float|dav|dav_float|cg_real|dav_real|pw|sdft|LCAO|linear_trans)$'

Result: 11/11 passed.

OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 \
ctest --test-dir /tmp/abacus-build-mpi-openblas --output-on-failure \
  -R '^MODULE_HSOLVER_(para_linear_trans|cg_parallel|parak2d_test_parallel|dav_parallel|LCAO_parallel)$'

Result: 5/5 passed outside the restricted sandbox.

python3 tools/03_code_analysis/agent_governance_check.py \
  --base upstream/develop --head HEAD --format text

Result: passed with review warnings described above.

Also passed: git diff --check and the zero-hit global dependency scan.

CI follow-up

The first CI run exposed a missing direct include in the ELPA-only build path: diago_elpa.cpp still calls ModuleBase::TITLE after dropping the transitive global_variable.h include. Commit 89a0d509c adds the required source_base/tool_title.h include.

The CI failure was reproduced and the fix was verified with:

cmake -S . -B /tmp/abacus-hsolver-elpa-build -G Ninja \
  -DBUILD_TESTING=ON -DENABLE_MPI=ON -DENABLE_ELPA=ON \
  -DBLA_VENDOR=OpenBLAS \
  -DCMAKE_CXX_COMPILER=/usr/bin/mpicxx \
  -DCMAKE_C_COMPILER=/usr/bin/mpicc \
  -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=/tmp/abacus-build-mpi/_deps/googletest-src \
  -DFETCHCONTENT_FULLY_DISCONNECTED=ON
cmake --build /tmp/abacus-hsolver-elpa-build --target hsolver -j2
cmake --build /tmp/abacus-hsolver-elpa-build \
  --target MODULE_HSOLVER_LCAO MODULE_HSOLVER_dav_real MODULE_HSOLVER_cg_real -j2

Results: ELPA-enabled hsolver build 20/20 passed; MODULE_HSOLVER_LCAO passed; MODULE_HSOLVER_LCAO_parallel passed outside the restricted sandbox. diago_elpa.cpp scores 93/100 in code_quality_score.py.

Notes

  • INPUT behavior is unchanged, so no parameter documentation update or regeneration is required.
  • CUDA/cuSolverMP and PEXSI interface paths were updated, but those optional backends were not enabled in the local build environment. ELPA was enabled separately for the CI follow-up verification above.
  • Sandboxed MPI-linked compilation emitted the documented OpenMPI opal_ifinit: socket() failed errno=1 warning; runtime/MPI tests were rerun outside the sandbox and passed.

@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants