Skip to content

Optimize GintAtom::set_phi() in module_gint#7530

Open
chaomianpkp wants to merge 2 commits into
deepmodeling:developfrom
chaomianpkp:perf/gint-set-phi-micro-opt
Open

Optimize GintAtom::set_phi() in module_gint#7530
chaomianpkp wants to merge 2 commits into
deepmodeling:developfrom
chaomianpkp:perf/gint-set-phi-micro-opt

Conversation

@chaomianpkp

Copy link
Copy Markdown

Summary

Optimize GintAtom::set_phi() in module_gint, which is a hotspot on the
cal_gint_rho / cal_gint_vl path in LCAO grid integration.

Changes:

  • Refactor single-meshgrid logic into set_phi_at_meshgrid()
  • Micro-optimizations (enabled by default): compute coord.norm() once,
    use inv_dist instead of repeated divisions, cache rcut/nw/nwl/dr_uniform
  • Optional CMake flags: GINT_SET_PHI_SIMD, GINT_SET_PHI_OPENMP
    (nested OpenMP in SCF is intentionally disabled when already inside a parallel region)

Motivation

set_phi() is called for every atom on every fine meshgrid inside each BigGrid.
The original implementation repeated norm/division and loop-invariant lookups.

Test plan

  • Build with ENABLE_MPI=OFF, USE_OPENMP=ON, ENABLE_LCAO=ON
  • Build with -DGINT_SET_PHI_SIMD=ON
  • ctest -R gint (if BUILD_TESTING=ON)
  • SCF on tests/performance/P110_C2H6O_lcao (ethanol + vacuum box)
    • Correctness: etot / stress unchanged within floating-point tolerance (~1e-10)
    • Performance (8 OpenMP threads, serial binary):
      • cal_gint_vl: 5.70s → 1.86s (~3.1×)
      • cal_gint_rho: 5.29s → 1.53s (~3.5×)
    • #pragma omp simd on the iw loop shows no measurable gain on tested platform

Notes

  • Does not change numerical formulas; only code structure and local efficiency.
  • GINT_SET_PHI_OPENMP is for non-nested contexts only; normal SCF uses micro-opts only.

chaomian and others added 2 commits June 26, 2026 23:32
…ional SIMD

- Extract set_phi_at_meshgrid() for single meshgrid computation
- Cache norm once, use inv_dist, hoist rcut/nw/nwl out of the loop
- Add optional GINT_SET_PHI_SIMD and GINT_SET_PHI_OPENMP CMake options
- Use SIMD-compatible for-loop form (no comma increment in omp simd)
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.

1 participant