Skip to content

Faster setup of the Hiptmair-Xu preconditioner (TAE example): exact stiffness diagonal, preconditioners built in the setup - #796

Merged
spossann merged 9 commits into
develfrom
profiling-tae
Oct 19, 2026
Merged

spossann merged 9 commits into
develfrom
profiling-tae

Conversation

@spossann

Copy link
Copy Markdown
Member

Shortens the setup of the ITPA TAE example with ShearAlfvenCurlCurl (Hiptmair-Xu preconditioner). Bottlenecks were found with scope-profiler regions in the HX setup (first two commits).

TAE --test-run, 2 ranks, one time step: profiled session per rank 7.6 s → 3.0 s; HX build 3.8 s → 0.5 s, same PCG iterations.

Changes

  • LocalProjectionMatrix / LocalRotationMatrix evaluate each component once (were 18× / 6×). Weight evaluation of M2para_Bn: 0.97 → 0.18 s/rank.
  • Exact diagonal of dᵀ M d (_stiffness_local_diagonal in feec/preconditioner.py), used for the diagonal scaling of StiffnessPreconditioner, instead of probing with colored unit vectors (about 160 colors per block, each a full operator application). It is read from the band of the mid mass matrix and the 1d factors of the derivative; rows owned by the neighbouring process come from ghost regions, and band entries wrapping around in short periodic directions are summed. Probing remains the fallback for matrix-free mass operators. Without diagonal scaling HX needs 10–25 % more iterations (6 vs 8 at dt = 0.1, 24 vs 26 at dt = 1), so the scaling is kept.
  • StiffnessPreconditioner resolves the default mid M{k+1} only if mid is not given (the HX smoother no longer assembles M2).
  • New hook Propagator.prepare_time_step(dt), called by Simulation.run after allocate (profiling region setup: prepare time step) with the dt each propagator gets from integrate (dt/2 for all but the last with Strang). ShearAlfvenCurlCurlPropagator builds HX there and ShearAlfvenPropagator its multigrid / Kronecker preconditioner, instead of in the first time step. __call__ still rebuilds when dt changes.
  • scope-profiler upper bound 0.7.3.

Tests

  • New test_stiffness_local_diagonal: exact vs probed diagonal for grad/curl/div on a HollowTorus, a sum of mass terms, Dirichlet bcs and short periodic directions with p = 3.
  • New test_prepare_time_step: HX is built ahead of time, reused for the same dt and rebuilt for a new one.
  • Locally on 1 and 2 ranks: stiffness preconditioner, Hiptmair-Xu, Kronecker block, preconditioner transpose, ShearAlfven, ShearAlfvenCurlCurl and curl-curl propagator tests pass. A separate review also checked the exact diagonal on 3 ranks (each decomposition direction, degrees 1 and 3, M2gyro / M1perp mids, identity and summed stabilizations).

Not included: assembling M2gyro in one pass instead of M2_Bn - M2para_Bn. Mass matrix assembly (about 1.2 s/rank) is now the largest remaining setup cost.

🤖 Generated with Claude Code

spossann and others added 9 commits October 19, 2026 09:53
…onMatrix

LocalProjectionMatrix called the component functions 18 times (twice per entry), LocalRotationMatrix
6 times; equilibrium callables are expensive (weights eval for M2para_Bn: 1 s/rank in the TAE test run).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The diagonal scaling of StiffnessPreconditioner probed the core operator with colored unit vectors
(about 160 colors per block, each a full operator application). _stiffness_local_diagonal computes
it from the band of the mid mass matrix and the 1d factors of the derivative (rows owned by the
neighbouring process via ghost regions); probing remains the fallback for matrix-free mass operators.
TAE --test-run (ShearAlfvenCurlCurl, 2 ranks): HX build 3.8 s -> 0.5 s, same PCG iterations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… if needed

mass_mid_default = M{k+1} was assembled even when mid is given (e.g. mid='M2gyro' in the Hiptmair-Xu
smoother assembled M2, 0.17 s/rank in the TAE test run); the domain check uses the coefficient space.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…epare_time_step)

New optional hook Propagator.prepare_time_step(dt), called by Simulation.run after allocate (profiling
region 'setup: prepare time step') with the dt each propagator receives in integrate (dt/2 for all but
the last one with Strang). ShearAlfvenCurlCurlPropagator builds Hiptmair-Xu there and
ShearAlfvenPropagator its multigrid / Kronecker preconditioner, instead of in the first time step;
__call__ still rebuilds them when dt changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_propagators

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@spossann
spossann enabled auto-merge (squash) October 19, 2026 15:11
@spossann
spossann disabled auto-merge October 19, 2026 15:12
@spossann
spossann merged commit 8df8896 into devel Oct 19, 2026
28 checks passed
@spossann
spossann deleted the profiling-tae branch October 19, 2026 15:12
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