Skip to content

Let PCASM refresh its own submatrices - #5403

Open
pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/fix-pcasm-getsubksp-before-setup
Open

Let PCASM refresh its own submatrices#5403
pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/fix-pcasm-getsubksp-before-setup

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Depends on PETSc petsc/petsc!9536, branch pbrubeck/fix-pcasm-getsubksp-before-setup. CI picks up the identically named PETSc branch automatically.

ASMStarPC hands its patches to PETSc's PCASM, which keeps one small matrix per patch. If the patch solver is told to factor in place, it overwrites that little matrix with its own factors. So the next time the operator changes and PETSc goes to refill the patch matrices, it refuses: as far as it can tell, that matrix is a factorization, not a matrix.

Firedrake worked around this by reaching into PCASM, walking its sub-solvers, and clearing the "this is factored" flag itself. That is what update was for.

The trouble is that Firedrake only tells PCASM which patches it wants. PCASM does not create the sub-solvers until it is set up, and nothing here sets it up. Usually the first time the preconditioner is applied forces that, and by the time update runs the sub-solvers exist. But if the preconditioner is set up twice before it is ever applied, update asks for sub-solvers that were never created and gets a null pointer back, which segfaults. A multigrid smoother does exactly that from three levels up, where the level's operator is swapped out after the initial setup.

The companion PETSc MR makes PCASM clear the flag itself when it refills the patch matrices, which is where the job belonged. That leaves nothing for update to do.

Changes

  • ASMPatchPC.update is now empty. It cannot be deleted outright, because PCBase.update is an abc.abstractmethod.
  • Adds test_star_inplace_factorization_reused, covering a patch solver that factors in place across a change of coefficient.

AI was used to draft this change (Claude Code, Opus 5).

@pbrubeck
pbrubeck marked this pull request as ready for review August 28, 2026 00:51
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix-pcasm-getsubksp-before-setup branch from bee0dce to 1159780 Compare August 28, 2026 07:43
@pbrubeck pbrubeck changed the title Set up the inner PCASM before querying its sub-KSPs Let PCASM refresh its own submatrices Aug 28, 2026
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix-pcasm-getsubksp-before-setup branch 2 times, most recently from 8546465 to 7fd7b8d Compare August 28, 2026 07:48
ASMPatchPC.update cleared the factored flag a subsolver's in-place
factorization leaves on its submatrix, by iterating the sub-KSPs of the
inner PCASM. That is PCASM's own business, and doing it here crashed:
for the petscasm backend initialize only specifies the subdomains, so
on a setup that precedes any apply the sub-KSPs do not exist yet and
PCASMGetSubKSP hands back a null array.

PCSetUp_ASM now calls MatSetUnfactored on the submatrices it reuses, so
update has nothing left to do.

Add a regression test: a star patch whose subsolver factors in place,
solved twice with a changed coefficient, at 1 and 2 processes.
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix-pcasm-getsubksp-before-setup branch from 7fd7b8d to 70336ba Compare August 28, 2026 08:10
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