Skip to content

Fix O(m^2) assembly in HypreSolver::factorize#111

Open
Chenyang-Joe wants to merge 1 commit into
polyfem:mainfrom
Chenyang-Joe:fix/hypre-remove-loop
Open

Fix O(m^2) assembly in HypreSolver::factorize#111
Chenyang-Joe wants to merge 1 commit into
polyfem:mainfrom
Chenyang-Joe:fix/hypre-remove-loop

Conversation

@Chenyang-Joe

Copy link
Copy Markdown

Problem

HypreSolver::factorize builds the HYPRE matrix with a nested loop: for each nonzero
in a column it rebuilds and re-sets the entire column, so every column is handed to
HYPRE_IJMatrixSetValues nnz(col) times. Assembly is therefore O(m^2) in the number
of nonzeros and dominates solve setup on large matrices.

Fix

Build each column's index/value arrays once and set it in a single HYPRE_IJMatrixSetValues
call -> O(nnz) total. The assembled matrix (and the
solution) is unchanged.

Testing

  • Builds clean.
  • Full ctest suite passes 27/27, including hypre and hypre_initial_guess.

@maxpaik16 PTAL, thanks!

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.73%. Comparing base (a7727e3) to head (8582129).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   80.76%   80.73%   -0.03%     
==========================================
  Files          51       51              
  Lines        2121     2118       -3     
  Branches      281      280       -1     
==========================================
- Hits         1713     1710       -3     
  Misses        408      408              
Flag Coverage Δ
polysolve 80.73% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants