Skip to content

Performance: optimize module HS matrix output - #7838

Open
goodchong wants to merge 2 commits into
deepmodeling:developfrom
goodchong:geths_refactor
Open

Performance: optimize module HS matrix output#7838
goodchong wants to merge 2 commits into
deepmodeling:developfrom
goodchong:geths_refactor

Conversation

@goodchong

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Fix #

Unit Tests and/or Case Tests for my changes

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

What's changed?

• This PR improves the performance of source_io/module_hs without changing the user-facing matrix formats.

  • Replaces row-by-row dense MPI reductions for sparse R-space matrices with sparse entry gathering. Communication
    changes from approximately O(N²) to O(nnz) per R block.

  • Builds CSR values, column indices, and row pointers directly in memory, eliminating temporary index files.

  • Merges duplicate distributed entries before applying the sparse threshold.

  • Iterates only over locally owned rows and columns when calculating r(R), avoiding global nlocal² traversal on every
    MPI rank.

  • Batches dense H(k)/S(k)/Vxc matrix reductions in groups of 64 rows and removes the redundant per-row MPI barrier.

  • Pre-indexes HContainer atom-pair R blocks, avoiding repeated scans of every atom pair for each lattice vector while
    keeping memory bounded to one materialized R block.

  • Adds an optional Google Benchmark for sparse single-R CSR output at different matrix sizes.

  • Preserves existing text and native binary output ordering and formats.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:


// The off-diagonal term in SOC calculaiton is zero, and the two diagonal terms are the same
int new_index
= iw1 - PARAM.globalv.npol * orb_index_row + (iw2 - PARAM.globalv.npol * orb_index_col) * PARAM.globalv.npol;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you avoid using PARAM?

@mohanchen

Copy link
Copy Markdown
Collaborator

Could you explain more about what this PR does?

@mohanchen mohanchen added Refactor Refactor ABACUS codes Input&Output Suitable for coders without knowing too many DFT details labels Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants