Skip to content

perf(solver): Parallelize Matrix Construction and Optimize SCF Loop#14

Merged
TKanX merged 5 commits intomainfrom
feature/13-refactor-cheq-core-for-lossless-performance-gains
Dec 10, 2025
Merged

perf(solver): Parallelize Matrix Construction and Optimize SCF Loop#14
TKanX merged 5 commits intomainfrom
feature/13-refactor-cheq-core-for-lossless-performance-gains

Conversation

@TKanX
Copy link
Member

@TKanX TKanX commented Dec 10, 2025

Summary:

Significantly enhances the performance of the cheq solver through parallelization and algorithmic refinements. The computationally intensive construction of the off-diagonal matrix elements (shielded Coulomb integrals) is now parallelized using rayon, dramatically reducing setup time for large molecular systems. Additionally, the core SCF loop has been refactored to separate geometry-invariant computations from the iterative charge updates, minimizing redundant calculations and improving overall efficiency.

Changes:

  • Parallelized Off-Diagonal Matrix Construction:

    • Introduced the rayon crate to enable data parallelism.
    • The calculation of the J_ij shielded Coulomb integrals, which constitutes the majority of the matrix build time, is now performed in parallel across all atom pairs.
    • This change provides a substantial speedup, especially for systems with hundreds or thousands of atoms, by leveraging multi-core processors.
  • Optimized the Self-Consistent Field (SCF) Loop:

    • Refactored the solver to pre-compute all geometry-invariant parts of the linear system before entering the iterative loop.
    • A new InvariantSystem struct now stores the base matrix, the right-hand-side vector, and metadata about hydrogen atoms.
    • The per-iteration workload is now reduced to only updating the diagonal hardness terms for hydrogen atoms, avoiding the re-computation of the entire matrix.
  • Improved Numerical Efficiency:

    • Optimized the distance calculation within the tight loop to use (pi - pj).powi(2) instead of (pi - pj) * (pi - pj), which can offer minor performance gains in some compiler versions.
    • Refined the max_charge_delta calculation to use a more direct and potentially faster fold operation over the charge differences.
  • Dependency Updates:

    • Added rayon as a new core dependency.
    • Updated various development and CLI dependencies to their latest versions for improved stability and features.

@TKanX TKanX self-assigned this Dec 10, 2025
Copilot AI review requested due to automatic review settings December 10, 2025 01:42
@TKanX TKanX added enhancement ✨ New feature or request performance ⚡ Performance improvements and code optimizations labels Dec 10, 2025
@TKanX TKanX linked an issue Dec 10, 2025 that may be closed by this pull request
10 tasks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces significant performance optimizations to the charge equilibration (QEq) solver by parallelizing the computationally expensive matrix construction phase and refactoring the SCF loop to minimize redundant calculations. The changes leverage the rayon crate for data parallelism and separate geometry-invariant computations from charge-dependent iterations.

Key Changes:

  • Parallelized off-diagonal matrix element calculations using rayon's parallel iterators
  • Refactored SCF loop to pre-compute geometry-invariant system components before iteration
  • Updated development and CLI dependencies to more recent versions

Reviewed changes

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

File Description
Cargo.toml Added rayon dependency for parallelization; updated clap, prettytable-rs, indicatif, tempfile, and approx to newer versions
src/solver/implementation.rs Introduced InvariantSystem struct to cache geometry-invariant components; refactored solve() to separate pre-computation from iteration; added parallel compute_off_diagonal_rows() function; improved max_charge_delta calculation using iterators

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TKanX TKanX merged commit 05fce03 into main Dec 10, 2025
8 checks passed
@TKanX TKanX deleted the feature/13-refactor-cheq-core-for-lossless-performance-gains branch December 10, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement ✨ New feature or request performance ⚡ Performance improvements and code optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor cheq Core for Lossless Performance Gains

2 participants