Skip to content

Stokes assembles the Jacobian and the preconditioner's matrix one to a call, so a rank without cells assembles like the rest (works around #962) - #1156

Merged
lmoresi merged 11 commits into
developmentfrom
bugfix/jacobian-and-preconditioner-in-two-calls-962
Nov 13, 2026
Merged

lmoresi merged 11 commits into
developmentfrom
bugfix/jacobian-and-preconditioner-in-two-calls-962

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

A Stokes solve now completes on a mesh where some rank holds no cells. A constrained solve reached a second defect once the refusal was gone (its set-up hung); that is fixed at 7f1c201 and has been run on one rank only so far. This works around #962, which stays open until PETSc assembles alike on every rank; the refusal that #1137 put in front of the defect is removed.

The defect, and why it is PETSc's

The Stokes solvers register kernels for the Jacobian and for the matrix the preconditioner is built from, so SNES assembles two matrices. PETSc's DMPlexComputeJacobianByKey assembles both in one pass. On a rank with no cells it leaves before it has read that there are two, and skips a MatAssemblyBegin/End of the Jacobian that every other rank makes. The Jacobian comes back zero, and the run then stops in MPI or hangs. The defect is in PETSc 3.25.0, 3.25.3, 3.26.1 and main. A solver with one matrix (Poisson, a vector solve) never meets it.

A report for PETSc is drafted, with a stand-alone C reproducer and a suggested fix, and has not been sent yet: upstream/petsc-962-jacobian-assembly.md.

The workaround

UW_DMPlexSNESComputeJacobianFEM (src/underworld3/cython/petsc_compat.h) is registered as the DM's local Jacobian routine in place of PETSc's. Handed one matrix, every rank assembles alike. PETSc's cell loop then reads the Jacobian's kernels only, while its boundary loop still adds both sets, so the routine calls PETSc twice and leaves it one set to find each time:

  1. (J, J) with the preconditioner's kernel tables set aside;
  2. (P, P) with the preconditioner's tables in the Jacobian's place.

The tables are put back on every path, including an error from either call. When the caller hands one matrix for both, or no discrete system has both sets of kernels, the routine hands the call straight to PETSc's, so those calls are assembled exactly as before.

Two things make this a workaround and not a fix:

  • it reads PETSc's private kernel tables (PetscWeakForm's form[]), which no release promises to keep;
  • it relies on what PETSc does when handed one matrix twice.

So it is guarded twice. The header stops the build on any PETSc outside 3.25.x, with a message listing what to re-verify before a release is added. And tests/test_0786_stokes_jacobian_and_preconditioner_one_call_each.py compares both matrices with PETSc's one-pass matrices, bit for bit, on every CI run.

A constrained solve's set-up. With the refusal gone, a constrained solve with a rank without cells reached a second defect, found by the parallel review: _constrain_interior_multipliers_in_section removes the multipliers' interior unknowns and rebuilds the DM's global section, which is collective, behind a test each rank made for itself ("have I anything to remove?"). A rank with nothing to remove returned early and the solve hung at set-up. The ranks now decide together (one allreduce), so every rank rebuilds or none does. On one rank nothing changes.

Removing it. When the PETSc we ship assembles alike on every rank, the routine, the guard and the test go, and #962 closes. The roadmap carries that as "Drop the two-call Jacobian when PETSc's DMPlexComputeJacobianByKey assembles alike on every rank (#962)".

The stated PETSc requirement

The guard makes 3.25.x a build requirement, so every place that states one now says the same: pixi.toml (the three conda PETSc features), pyproject.toml, setup.cfg, conda/meta.yaml, the version check of uw doctor, and the install page (which said 3.21 or higher). The custom PETSc build script cloned PETSc's release branch, which is now 3.26; it clones the v3.25.3 tag instead. pixi.lock does not change: it holds 3.25.3, and 3.25.1 for the two Open MPI environments. The HPC container recipe's default (3.25.0) passes; a different petsc_version input now needs the re-verification the guard lists.

What "3.25.x" rests on: PETSc's source read at 3.25.0, every run at 3.25.3. Nothing was read or run at 3.25.1, 3.25.2 or 3.25.4 to 3.25.6, which the guard also accepts.

Evidence

Ours is from macOS, 12-core Apple M4, one rank, conda-forge PETSc 3.25.3. The table, the cost and the mutants are from f1ff675; the Jacobian routine's code has not changed since. The runs on more than one rank are the parallel review's (H1, the review and parallel-test session on a 96-thread Linux workstation), at baf1159, np 2 to 8; its record is in the comments below and its results are quoted here where they change a statement.

At the head (7f1c201). The serial comparison test, the collective guard scan and the 13 serial test files that use the constrained solver: 143 passed, 1 expected failure (test_1064's known one). The new parallel case's solve on one rank gives the recorded speed, 1.2158645452e-03, with 104 of each multiplier's 109 unknowns removed. scripts/check_test_coverage.py: all 458 test files reachable. The docs build was last run at baf1159 (exit 0); nothing under docs/ has changed since.

On one rank the matrices are PETSc's, bit for bit; on more than one, to round-off. A pytest plugin wrapped every Stokes-family solve of the serial suite, assembled J and P with our routine and with PETSc's one pass at the solution, and compared with MatEqual.

Test files run under the plugin 164
Files with at least one comparison 108
Solves compared 2,522
Solves where J or P differs 0
Solves not compared (no solution vector at the call) 313
By solver class Stokes 2,062; composed Navier-Stokes 388; Navier-Stokes 48; constrained Stokes 24
System sizes 66 to 62,013 rows

Five of the 164 files did not exit 0 under the plugin. test_0019_mcp_server skips its one test. test_1160, test_1161 and test_1174 each assert the file a warning is attributed to, and the plugin's wrapper becomes that file; all three pass without the plugin. test_0006_memory_leak measured 44.8 MiB of growth against its 30 MiB limit with the plugin, which copies four matrices per solve; it passes without the plugin, and once with it when run alone. PETSc's own list of unfreed memory (-malloc_debug -malloc_dump) has the same 14,649 blocks after 5 and after 50 Jacobian evaluations, and none of them is from the routine.

The parallel review ran the same plugin at np 2 to 8. From np 3 up PETSc's own routine does not assemble the same matrix twice bit for bit (the order in which contributions from other ranks are summed varies), and our matrices differ from PETSc's by at most 1.1e-17 relative, which is what PETSc's differ from themselves by. So MatEqual is a one-rank test only.

Cost on one rank. A 3-D Stokes solve, 5,592 cells and 19,130 rows, three solves, each routine run twice:

this branch PETSc's one pass
SNES / KSP iterations per solve 1 / 1 1 / 1
Largest speed 1.434149959586e-03 1.434149959586e-03
Flops in the Jacobian assembly 3.745228e+09 3.745228e+09
MatAssemblyEnd calls 39 39
Passes over the cells per Jacobian 2 1
Time in the Jacobian assembly (two runs each) 24.64 s, 21.91 s 24.66 s, 21.95 s

The two routines do the same arithmetic. The times are from a loaded laptop and differ by less than the spread between runs.

Mutants of the routine, each built into the library and run against the serial comparison test:

Mutant Result
the first call sees the preconditioner's kernels too killed (Nitsche and constrained cases)
the second call keeps the Jacobian's kernels killed (all three cases)
the Jacobian's tables are not put back killed (the process crashes)
the preconditioner's tables are not put back killed (the process crashes)
the boundary tables are left alone killed (Nitsche and constrained cases)
the routine is not registered killed (all three cases)

The plain case cannot see the first and fifth mutants: it has no boundary kernels. That is why the Nitsche and constrained cases are in the test. After these runs the constrained case was given multiplier_schur_pc = True, so that its multiplier blocks differ between the two matrices as well; the plain and Nitsche cases, which between them kill every mutant, are unchanged.

One mutant no case could kill, by reading (it was not built): a second call that swaps the volume tables and leaves the boundary tables alone. Every solver registers the same boundary kernels for the Jacobian and for the preconditioner, so the result is the same matrix. The test's docstring says so.

Tests

  • tests/test_0786_stokes_jacobian_and_preconditioner_one_call_each.py (tier B, one rank): the registered routine is ours; J and P equal PETSc's one-pass matrices for a plain solve, for Nitsche walls and for a constrained solve with the multiplier preconditioner block switched on.
  • tests/parallel/test_0786_stokes_rank_without_cells_parallel.py (tier B, np 2 and up): a Stokes solve converges, and its largest nodal speed equals the one-rank value, on three meshes that leave a rank without cells: a structured box of two quadrilaterals, a triangle of cells, and a region extracted from a parent with all of it on rank 0. A scalar solve on the region converges to the linear field its walls prescribe. A constrained solve on the region (multipliers on its side walls, no slip on its base) converges to its one-rank speed, and asserts that one rank removes multiplier unknowns beside a rank that has none. The box's premise (both cells on one rank) is the partitioner's choice; tests/parallel/test_0766_mover_refreshes_mesh_vector_parallel.py on development asserts the same of the same mesh.
  • What CI runs. CI runs the parallel suite at np 2, where the triangle is skipped (it would be one cell), so scripts/test.sh now also runs this file at np 3 on every run. The #962 skips in tests/parallel/test_0770 and tests/parallel/test_1140 are removed. test_1140 meets ranks without cells at np 8, which CI does not reach. test_0770's region has cells on every rank at every np from 2 to 8, so its skip never fired and removing it tests nothing; the test of a rank without cells is test_0786.
  • The two tests of Stokes refuses, on every rank, a mesh that leaves a rank without cells (#962, interim) #1137's refusal are removed with the refusal.

Tolerances and coordinate matches

The library change has none: the routine decides by which discrete systems have which kernels, which is the same on every rank. In the tests: the parallel test compares the largest nodal speed with its one-rank value to a relative 1e-6, and the scalar test asks for 1e-8 against a field the elements hold exactly. All three one-rank values were recorded on macOS. The box and the region are gmsh meshes (the box a transfinite one), so their values may need a second baseline on Linux; this PR's CI run is the first measurement of that.

Not run, and not tested

  • Run by the parallel review at baf1159, on Linux (np 2 to 8): the parallel test file at np 2, 3, 4 and 8 (the macOS-recorded speeds hold to 1e-8); the same file with PETSc's routine put back (every run stops in MPI within seconds, so the test has power); test_1140 at np 8 with two ranks without cells; a refined faulted annulus at np 8 with ranks without cells on every level of the fault multigrid, which matches one rank to 3.6e-11 in the integral of |v|^2; the 3-D cost at np 4 (19.33 s against 19.34 s in the Jacobian, the same flops).
  • Not yet run on more than one rank: the collective decision in the constrained solve's set-up and its new test. The hang was measured by the parallel review at np 8 (it completes with the multiplier reduction switched off). The change after it has been run on one rank only, where it changes nothing; the new test's first parallel run is this PR's CI (np 2 and np 3).
  • No test runs a multigrid hierarchy with a rank without cells. The faulted annulus above is a probe, not a test. The routine is registered on the solver's DM; a coarse level that is rediscretised assembles with whatever routine its own DM carries.
  • A solve on a DM with more than one discrete system (set_active_region). The routine's loop over systems, and its refusal of a system that has Jacobian kernels only beside one that has both, are reached by no test: that route stops in the first residual (Stokes: set_active_region ends in a segmentation fault inside PETSc, and its region value is never used #1154).
  • One matrix handed for both. That call goes to PETSc unchanged, and PETSc's boundary loop then adds the boundary preconditioner kernels to the Jacobian (the behaviour behind Scalar and vector solvers: a natural BC that reads the unknown enters the Jacobian twice (Newton 17-23 its on a linear Robin problem) #1065, which was fixed for the scalar and vector solvers). On the Stokes solvers the one caller is the linearity probe, which compares two such matrices with each other. Measured by the review on one rank, as the relative difference from the true Jacobian: 0 for the plain case, 0.26 with Nitsche walls, 1.0 for the constrained case, the same with either routine. Not changed here.

Issues

Solver register row 16.

Underworld development team with AI support from Claude Code

…all (#962)

A solver with kernels for both the Jacobian and the matrix its preconditioner
is built from is handed two matrices, and PETSc assembles them in one pass. On
a rank without cells that pass leaves before it has read that there are two
and skips an assembly of the Jacobian that the other ranks make
(DMPlexComputeJacobianByKey, PETSc 3.25.3 and main): the run stops in MPI or
hangs.

The local Jacobian routine registered by UW_DMPlexSetSNESLocalFEM now hands
PETSc one matrix and one set of kernels at a time: the Jacobian with the
preconditioner's kernel tables set aside, then the preconditioner's matrix
with its tables in the Jacobian's place. Both are decided by the discrete
systems, which every rank has alike. A solver with one matrix, or with no
preconditioner kernels, makes the one call it made before.

The preconditioner's tables are set aside for the first call because PETSc's
boundary assembly adds both boundary sets to one matrix when it is handed the
same matrix twice, and the Nitsche and multiplier terms are in both sets.

The Stokes refusal on a mesh with a rank without cells (#1137) is removed.

On one rank both matrices equal PETSc's one-pass matrices in structure and bit
for bit in value: plain, Nitsche and constrained solves
(tests/test_0786_stokes_jacobian_and_preconditioner_one_call_each.py).

Underworld development team with AI support from Claude Code
… skips go

The parallel file of the refusal becomes
tests/parallel/test_0786_stokes_rank_without_cells_parallel.py: the triangle
with a shell partition and the region held by rank 0 are solved, and the
largest nodal speed is compared with the same solve on one rank. At np 2 the
triangle is one cell with no free velocity node and is skipped; the region
carries that count.

test_0770 and test_1140 no longer skip their Stokes solves when a rank holds
no cells. The submesh design page and the fault multigrid guide say that such
a solve runs, and what it costs.

Underworld development team with AI support from Claude Code
…c 3.25.x and reports its errors (#962)

UW_DMPlexSNESComputeJacobianFEM is a workaround for a PETSc defect: it reads
PETSc's private kernel tables and relies on what DMPlexSNESComputeJacobianFEM
does when handed one matrix twice. The header now stops the build on a PETSc
release that was not verified, with a message that says what to re-verify.

An error in either assembly call no longer leaves the preconditioner's kernels
in the Jacobian's place: the tables are restored on every path, and the first
error is the one reported. The four call sites that register the routine check
its return value. A DM in which one discrete system has Jacobian kernels only
beside one with both is refused, because PETSc's one pass and two calls would
assemble it differently; no solver here builds one.

The branch for PETSc 3.20.5 and older is removed with the guard: it cannot be
compiled any more.

Underworld development team with AI support from Claude Code
…cells needs no mesh generator

The one-rank comparison now asserts which local Jacobian routine the DM carries
before and after PETSc's own is put back, so it fails if the solver stops
registering its routine.

The parallel test gains a structured box of two cells, which leaves a rank
without cells at every np >= 2 on any host. Its walls let the flow slide: with
no slip the box's three interior velocity nodes do not move for any body force,
and the comparison would assert nothing.

Underworld development team with AI support from Claude Code
…hat #962's workaround covers

pixi.toml (the three conda-petsc features), pyproject.toml, setup.cfg,
conda/meta.yaml and the version check of `uw doctor` named ranges that the
build guard in petsc_compat.h now refuses. They name the range it accepts, so
that a lock refresh or an install solves to a PETSc the code builds against.
pixi.lock is unchanged (3.25.3).

The submesh design note and the fault multigrid guide say that a Stokes solve
is no longer refused with a rank that holds no cells, that this is a
workaround to be removed, and which cases have no test.

Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
The header stops the build on any PETSc outside 3.25.x (#962). The custom
build script cloned PETSc's release branch, which is 3.26 now, so a fresh
custom build ended at that stop; it clones the v3.25.3 tag, and its version
fallback is 325. The install page asked for 3.21 or higher.

Underworld development team with AI support from Claude Code
…, np 3 runs always

The serial comparison's constrained case said its multiplier block has a
preconditioner kernel of its own; at the defaults it has not, so the case
sets multiplier_schur_pc. Its docstring says what no case can tell: which
boundary tables the second call reads, since every solver registers the same
boundary kernels for both matrices.

The parallel file's triangle is skipped at np 2, the only rank count CI runs
the suite at, so scripts/test.sh runs the file at np 3 on every run. The box
is a gmsh (transfinite) mesh, not a mesh made without a generator; its premise
is the one test_0766's parallel test already asserts.

The header comment said PETSc reads one set of kernels when handed one matrix.
That is its cell loop; its boundary loop adds both sets, which is why the first
call sets the preconditioner's tables aside.

Underworld development team with AI support from Claude Code
…no cells (#962)

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 13, 2026 19:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Adversarial review, round 2: bugfix/jacobian-and-preconditioner-in-two-calls-962 at f1ff675

Diff read: 116fc454..f1ff675c (commits 58524d8, d3ad12c, d59d216, 3785b76, 91ca557 and the merge). Runs: macOS, 12-core Apple M4 (serial runs only), conda-forge PETSc 3.25.3, one process at a time. PETSc source read at 3.25.0. No MPI run of any kind was made for this review, so every statement below about a rank without cells is by reading, not by measurement. No tool call was denied. The reviewed checkout is unchanged (git status --short is empty after the runs).

Findings

1. Two install routes now end at the #error, and nothing on those routes says so (medium).
Commit 91ca557 is titled "The stated PETSc requirement is 3.25.x everywhere". Two places were missed.

  • petsc-custom/build-petsc.sh:339 is git clone -b release https://gitlab.com/petsc/petsc.git. Upstream now carries tags v3.26.0 and v3.26.1 (git ls-remote --tags ... 'v3.26*'), and release follows the newest release. A fresh custom build therefore gets 3.26.x, and the Underworld3 build then stops in petsc_compat.h:266. This is the route behind petsc-local-build in pixi.toml (lines 207, 232, 253), the cluster builds (pixi.toml:290, :398) and ./uw (line 144). An existing 3.25 clone keeps working, because clone_petsc skips a directory that already has configure. Before this branch a 3.26 clone would have compiled.
  • The same script falls back to 324 when it cannot detect a version (line 59), and its help text offers checkout v3.24.2 # switch back (line 643), which the guard refuses.
  • docs/beginner/installation.md:116 says "PETSc 3.21 or higher", and line 121 shows module load petsc/3.21. A user who follows that page gets the #error.

Smallest change: clone a 3.25 tag (or check one out after the clone), make the fallback 325, drop the 3.24 line from the help, and make the install page say 3.25.x.

The header is included by five extension modules (nm -g shows UW_DMPlexSNESComputeJacobianFEM exported from generic_solvers, petsc_discretisation, petsc_maths, _dmfield_wrapper, _function), so the stop is at the first of them, not only at the solvers.

2. In CI the new parallel test runs at np 2 only, and its np 2 baselines have not been shown to hold on Linux (medium).
.github/workflows/build_uw3_and_test.yaml runs ./scripts/test.sh --p 2 --shard K/N. The np 3 and np 4 passes are behind --full-parallel, which CI does not pass (scripts/test.sh:7, :597). Only test_1084 (np 3) and test_1184 (np 4) have always-on lines (:581, :588). So:

  • The triangle fixture is skipped at np 2 by design, so it and both SPEED_TRIANGLE values never run in CI.
  • The skips removed from tests/parallel/test_0770_submesh_extract_mpi.py and tests/parallel/test_1140_rotated_analytic_normal_wall_nodes_parallel.py matter at np 4 (cells [27, 0, 41, 0]) and np 8 ([0, 3, 2, 2, 0, 3, 2, 2]) according to Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962. CI reaches neither.
  • The third reproduction recorded on Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962 (faulted annulus at np 8, with ranks 2 and 4 empty on the child and on every coarse level) has no test. The docs do say that a multigrid hierarchy with such a rank is untested.
  • What gates in CI is the box and the region at np 2, both tier B, against constants recorded on "macOS, PETSc 3.25.3" at 1e-6 relative. Both meshes come from gmsh. The region is an unstructured simplex mesh (BoxInternalBoundary), and this repository has a recorded case of a gmsh mesh differing between the laptop and the CI host (test_1106, 4780 against 4772 cells). No CI run and no PR exist for the branch (gh run list --branch ... and gh pr list --head ... are empty), and Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962 carries no run record of this file.
  • The box docstring claims "Cells per rank [0, 2] at np 2 and [0, 0, 0, 2] at np 4", and commit 3785b76 says "at every np >= 2 on any host". The partitioner decides that, and Mesh distributes with PETSc's default (self.dm.distribute()). empty_rank_fixtures.py itself says of a one-cell mesh that "which rank it lands on is not ours to say". If the premise is false on Linux, the test fails loudly at assert counts.count(0) >= 1, in a gating tier.

Smallest change: run the file at np 2, 3, 4 and 8 on the Linux workstation with the CI environment, put the table (cells per rank, speeds) in the PR body, and add an always-on np 3 line for this file in scripts/test.sh beside test_1084's, so the triangle fixture has a CI run.

3. "The box needs no mesh generator" is false (low, documentation of a test).
The module docstring of tests/parallel/test_0786_stokes_rank_without_cells_parallel.py says "The box needs no mesh generator, so its value is the same on every host", and the commit title repeats it. uw.meshing.StructuredQuadBox (src/underworld3/meshing/cartesian.py, from about line 1283) imports gmsh, builds a transfinite recombined mesh on rank 0 and reads it back from a .msh file. A transfinite 1 x 2 mesh very likely is the same on every host, but the reason given is wrong and the conclusion is unmeasured. Smallest change: say "a structured (transfinite) gmsh mesh" and drop "the same on every host" until a Linux run confirms it.

4. Handed one matrix for both, the routine does not return the Jacobian when boundary kernels are in both sets; the header comment says otherwise (low to medium, not a regression).
petsc_compat.h says "Handed one matrix, PETSc reads one set of kernels and every rank assembles alike." That is true of the cell loop only (plexfem.c:6255, if (hasJac && Jac == JacP) hasPrec = PETSC_FALSE;). The boundary routine has no such test: DMPlexComputeBdJacobianSingleByLabel adds elemMat to Jac and elemMatP to JacP (plexfem.c:6086-6092), so with one matrix both boundary sets land in it. Commit 58524d8 says exactly this, and the #error text is worded correctly ("in its cell loop"). The comment is not.

The early return if (J == P || !two) passes that case straight to PETSc. Measured with snes.computeJacobian(x, J1, J1) on the three fixtures of the serial test, as |J_one - J_two| / |J_two|:

fixture branch routine PETSc's routine
plain 0 same matrix
Nitsche 2.640406e-01 same matrix
constrained 9.964998e-01 same matrix

The one-matrix result is bit for bit the same under both routines, so the branch does not introduce it. One caller in the library does hand one matrix: _residual_is_nonlinear (petsc_generic_snes_solvers.pyx:6441-6442, snes.computeJacobian(U1, J1)). It compares two such matrices, so a linear problem still reads as linear. This is the Stokes counterpart of #1065, which was fixed for the scalar and vector solvers by dropping their boundary preconditioner registration.

Smallest change in this branch: correct the sentence in the comment. The routine already has what is needed to make the one-matrix case right (make only the first of its two calls when J == P and two), but that changes what _residual_is_nonlinear sees, so it is a decision with a solver check behind it, not a tidy-up. If it is not done here it is one issue, tied to #1065.

5. The serial test's constrained case does not test what its docstring says (low).
The docstring of tests/test_0786_stokes_jacobian_and_preconditioner_one_call_each.py says the constrained solve has "a multiplier block whose preconditioner kernel is not its Jacobian kernel". At the defaults it is the same kernel: hh_pc = self._pp_G0 if self._multiplier_schur_pc else self._hh_G0[k] (pyx 12007), and _multiplier_schur_pc is False (pyx 9402). Measured: in all three fixtures the only field block where P differs from J is (1,1), the pressure block (norm 0.0945434). With stokes.multiplier_schur_pc = True, blocks (2,2) and (3,3) differ as well (8.51e-03, 8.06e-03), and both matrices still equal PETSc's one pass bit for bit. Smallest change: set multiplier_schur_pc = True in _constrained (a warning about selfp is printed; assembly is unaffected), or correct the sentence.

6. No fixture can tell whether the second call reads the right boundary tables (low).
Every solver registers the same kernel pointers for the boundary Jacobian and the boundary preconditioner (pyx 12109-12200, "Preconditioner: mirror the Jacobian structure"), and the multiplier (h,h) kernel is a volume kernel. A routine whose second call swapped the volume tables only would assemble the same P and pass every test. This cannot be closed with today's solvers; the test docstring should say it, so that a solver with a distinct boundary preconditioner kernel brings its own fixture.

7. The refusal and the multi-system loop are unreached by any test (low).
PetscCheck(!jacobianOnly, ...) and the Nds > 1 path need a DM with more than one discrete system. Nothing in tests/ calls set_active_region, and that route stops in the first residual evaluation before any Jacobian (#1154). By reading, no solver builds a DM the check refuses: the scalar, vector and multi-component solvers register no preconditioner kernels (pyx 7223, 8323, 9081), so they take the early return. One difference from the one pass exists on that path, in the branch's favour: PETSc zeroes the Jacobian only if the first discrete system has both kernel sets (dmplexsnes.c, if (!s) { ... if (hasJac && hasPrec) MatZeroEntries(Jac); ...}), while the two calls zero each matrix whatever the first system holds. "Equal to the one pass" is therefore unverified, and possibly untrue, for a region solve.

8. Housekeeping (low).

  • Commit d59d216 removes the branch for PETSc 3.20.5 and older "because it cannot be compiled any more". Three more #else branches in petsc_compat.h are in the same state (lines 10-15, 412-416, 461-465).
  • Commit 91ca557 says "pixi.lock is unchanged (3.25.3)". The lock also holds PETSc 3.25.1 with petsc4py 3.25.2 for the openmpi and openmpi-dev environments on linux-64 and osx-arm64. The guard accepts it; nothing was run or read at 3.25.1.
  • UW_DMPlexSetSNESLocalFEM(dm, flag, ctx) ignores ctx and passes NULL to both registrations. All four callers pass NULL, so nothing breaks today.
  • The triangle fixture creates the All_Boundaries label by hand, with a comment that describes Essential condition on All_Boundaries segfaults on a mesh wrapped around a bare DMPlex: the name is listed, the DM has no such label #1138 without citing it.
  • The warning branch of check_petsc_version cannot be reached in an installed build any more, since the extensions do not compile against another minor release. It is harmless.

What holds

  • Restore on every path, no leak, first error kept (by reading). UW_WeakFormTablesGet only reads, and reads every table before any swap, so a weak form reached twice is saved twice with its originals. A failure before the swap leaves the tables untouched. Both sets are put back whenever the swap happened. PetscHMapFormDestroy(&none) with none == NULL returns success (hashmap.h:92, if (!*ht) PetscFunctionReturn(PETSC_SUCCESS);). tables is freed on every path after the allocation, and PetscCall(ierr) on the kept code is valid.
  • Shared weak forms. DMCopyDS copies weak forms (dtds.c:3570, :3807, PetscWeakFormCopy), and the swap exchanges table pointers in the solver DM's own weak forms only, freeing nothing, so a coarse DM's copy is not disturbed.
  • Equal to PETSc's one pass on one rank (measured). tests/test_0786_stokes_jacobian_and_preconditioner_one_call_each.py: 3 passed in 5.13 s. Independently: J and P are bit for bit equal between the two routines in the plain, Nitsche and constrained fixtures, and in the constrained fixture with multiplier_schur_pc = True.
  • The serial test fails if the solver stops registering its routine (measured, in-memory mutant). With PETSc's routine left on the DM after solve, all three cases fail at line 110, assert not _has_the_one_pass_assembly_of_petsc(stokes.dm). stokes.dm is the DM the SNES assembles on (handles equal).
  • The routine does make two calls (measured). DMPlexJacobianFE events per computeJacobian: 2 under the branch's routine, 1 under PETSc's.
  • "Costs a second sweep over the cells for each Jacobian" (docs) is true and small. 2744 cells, 12415 unknowns, Nitsche Stokes, minimum of 5, three alternating blocks: 0.2623 / 0.2621 / 0.2620 s against 0.2600 / 0.2576 / 0.2590 s, a ratio of 1.009 to 1.018.
  • The parallel test's constants are the one-rank values on this host, and every fixture has real flow (measured at np 1).
fixture cells speed relative difference from the constant velocity nodes that move
box 2 3.5798925e-02 1.40e-09 10 of 15
triangle, n = 4 16 2.4923109e-03 1.00e-08 21 of 45
triangle, n = 8 64 2.5355659e-03 2.89e-09 105 of 153
region 42 8.1535981e-05 3.85e-09 61 of 109

All converge (SNES 1 iteration, KSP 1). The sliding walls on the box do what the comment says.

  • cells_per_rank counts local cells with ghosts included, which is the quantity PETSc's early exit tests (cStart >= cEnd).
  • Reach and markers. scripts/check_test_coverage.py: "OK: all 457 test files are reachable from scripts/test.sh". The serial file is level_1 with a tier_b test. The parallel file is mpi(min_size=2), level_2, timeout 300, both tests tier_b.
  • Pins agree where a pin exists. pixi.toml (three features), pyproject.toml, setup.cfg, conda/meta.yaml (twice) and uw doctor all say 3.25.x. environment.yaml and the devcontainer file say petsc=3.25. The lock satisfies the new range without a re-solve, and CI installs the dev environment frozen at 3.25.3.
  • The four CHKERRQ(UW_DMPlexSetSNESLocalFEM(...)) sites (pyx 7255, 8361, 9115, 12254) use the repository's own Python-raising cdef inside def methods, like their neighbours. A failure now raises RuntimeError with the numeric code, where it was dropped before.
  • Docs. The new text in docs/developer/design/submesh-solver-architecture.md and docs/developer/guides/fault-multigrid.md matches the code and the tests, including what has no test. No other mention of the Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962 refusal remains in docs/, src/, tests/ or scripts/.

Not checked

  • Anything in parallel: the parallel test at any np; the box partition claim; test_0770 at np 4; test_1140 at np 8; the faulted annulus at np 8; the Linux values of the three constants.
  • C mutants. We would want these run:
  1. First call without emptying the preconditioner tables (expected: Nitsche and constrained fail, plain passes).
  2. Second call assembled from the Jacobian tables (all fail).
  3. Second call swapping the volume tables only (expected to pass everything; see finding 6).
  4. Second call swapping the boundary tables only (fail).
  5. Restore of one set skipped (fail).
  6. The PetscCheck removed, and the J == P return removed (expected to pass everything; see findings 4 and 7).
  7. PETSc's routine registered, with the parallel file at np 2 on Linux (expected MPI abort or hang).
  • PETSc 3.25.1 and 3.25.2 (source read at 3.25.0, runs at 3.25.3; petscdsimpl.h is byte-identical between 3.25.0 and the installed 3.25.3).
  • A region solve (set_active_region), because of Stokes: set_active_region ends in a segmentation fault inside PETSc, and its region value is never used #1154.
  • A constrained solve or a multigrid hierarchy with an empty rank. The routine is registered on the solver's DM only; whichever routine a coarse DM carries assembles any rediscretised coarse operator.
  • A matrix-free Jacobian (-snes_mf_operator) with the Stokes solvers.
  • PETSc's HPDDM overlap path (MatComputeNeumannOverlap_Plex), which also hands one matrix.

Issue verdicts (open issues in the territory)

No open issue other than #962 is fixed by this branch.


What the branch does with these (79b0b9d, 4e9e55f, baf1159)

The review read f1ff675. Since then the branch merged development (bc3d536) and made three commits. None changes the routine's code, so we have not asked for a third round.

  1. Fixed (79b0b9d). The custom build script clones the v3.25.3 tag, its version fallback is 325, and the 3.24 line is gone from its help. The install page says 3.25.x.
  2. Partly. scripts/test.sh now runs the parallel file at np 3 on every run, so the triangle has a CI run (4e9e55f). The box's premise is not new to CI: tests/parallel/test_0766_mover_refreshes_mesh_vector_parallel.py on development asserts a rank without cells on the same mesh at np 2. Still owed, and listed in the PR body under "Not run": the file at np 2, 3, 4 and 8 on Linux with the cells per rank and the speeds, test_0770 at np 4, test_1140 at np 8, and the faulted annulus at np 8.
  3. Fixed (4e9e55f). The docstring says a structured mesh of two quadrilaterals and no longer claims the value is the same on every host.
  4. Comment corrected (4e9e55f). The one-matrix call is not changed here; the PR body records the measurement and that the Stokes solvers' linearity probe is the one caller.
  5. Fixed (4e9e55f). The constrained case sets multiplier_schur_pc = True; the test passes.
  6. Recorded in the test's docstring (4e9e55f).
  7. Recorded in the PR body under "Not run, and not tested".
  8. The triangle fixture's comment cites Essential condition on All_Boundaries segfaults on a mesh wrapped around a bare DMPlex: the name is listed, the DM has no such label #1138. The PR body gives what pixi.lock holds (3.25.3, and 3.25.1 for the two Open MPI environments) and which 3.25 releases nothing was read or run at. Left as they are: the three other #else branches for old PETSc in the header, the unused ctx argument, and the warning in check_petsc_version that an installed build cannot reach.

At baf1159 on macOS, 12-core Apple M4 (serial runs only): the serial comparison test, the collective guard scan and the two nested-transfer files from development, 35 passed; all 458 test files reachable from scripts/test.sh.

Of the C mutants the review lists under "Not checked", the first, the second and both halves of the fifth were built and run at f1ff675, and each is killed (table in the PR body, with two more: the boundary tables left alone in both calls, and the routine not registered). The third, fourth and sixth were not built; that the third and sixth would pass every test is by reading. The seventh needs more than one rank.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

NOT READY at baf1159, parallel. The two-call Jacobian does what it says on every mesh I ran, at every rank count, and costs nothing measurable. But a constrained solve with a rank that holds no cells now hangs at set-up, where development refused it cleanly. The cause is not the Jacobian. It is a local early return in _constrain_interior_multipliers_in_section, which #1137's refusal used to hide and this branch exposes. The fix is small (one collective decision); with it and a test, this is ready.

Parallel review by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), at head baf1159 against base development bc3d536. PETSc 3.25.3 (conda-forge, dev environment). Every MPI job ran through scripts/mpi_supervisor.py --silence 300, pinned to 8 logical CPUs, one job at a time. Tests were run from the head's own tests/ tree. Probes were loaded as pytest plugins or as scripts; no library file was changed. Logs are kept by the reviewer.

1. The new parallel test at np 2, 3, 4 and 8

tests/parallel/test_0786_stokes_rank_without_cells_parallel.py on the head. Cells per rank were counted on the solver's DM after each solve, ghost cells included, which is the quantity PETSc's early exit tests.

np box triangle region scalar on region result
2 [0, 2] skipped (one cell) [42, 0] [42, 0] 3 passed, 1 skipped
3 [0, 2, 0] [8, 8, 0] (16) [42, 0, 0] [42, 0, 0] 4 passed
4 [0, 0, 0, 2] [6, 5, 5, 0] (16) [42, 0, 0, 0] same 4 passed
8 [0, 0, 0, 2, 0, 0, 0, 0] [10, 9, 9, 9, 9, 9, 9, 0] (64) [42, 0, …, 0] same 4 passed

Every solve converged (SNES reason 2). Here is the largest nodal speed against the file's constants, which were recorded on macOS:

fixture Linux value (every np) relative difference from the constant W1's macOS np 1 difference
box (2 cells) 3.5798925050e-02 1.40e-09 1.40e-09
triangle, n = 4 (16 cells) 2.4923109250e-03 1.00e-08 1.00e-08
triangle, n = 8 (64 cells) 2.5355659073e-03 2.89e-09 2.89e-09
region (42 cells) 8.15359813e-05 3.80e-09 to 3.85e-09 3.85e-09

Partitioning on Linux. The two gmsh meshes come out the same on Linux as on macOS: the box has 2 cells and the region has 42. Linux partitions them the same way the docstring says (box: every cell on one rank; region: every cell on rank 0). The values differ from the macOS constants exactly as the macOS one-rank values do, so the 1e-6 tolerance has about three orders of margin. No second Linux baseline is needed.

Time per test (pytest call, the slowest rank):

np box triangle region scalar whole run (wall)
2 0.75 s (skip) 2.97 s 2.80 s 12 s
3 0.72 s 2.45 s 0.84 s 0.68 s 10 s
4 0.71 s 0.30 s 0.84 s 0.66 s 8 s
8 0.84 s 0.58 s 0.92 s 0.73 s 9 s

The 2 to 3 s entries are the first solver of a new form in the process, which includes compiling it.

2. The same file with PETSc's routine put back

The branch installs its routine in UW_DMPlexSetSNESLocalFEM (petsc_compat.h): it calls DMPlexSetSNESLocalFEM(dm, flag, NULL), then DMSNESSetJacobianLocal(dm, UW_DMPlexSNESComputeJacobianFEM, NULL). A pytest plugin wrapped every Stokes-family _setup_solver and, after it returned, called DMPlexSetSNESLocalFEM(solver.dm, False, NULL) through ctypes. That is exactly the registration on development. The plugin then confirmed with DMSNESGetJacobianLocal that the DM's routine was DMPlexSNESComputeJacobianFEM again. I did not use the base build for this, because the base refuses at set-up and so never reaches the assembly.

run stopped in exit wall
np 2, whole file box: MPI_Allreduce "Message truncated; 4 bytes received but buffer size is 8" 142 5 s
np 3, box only the same truncation (1 byte against 8) 142 5 s
np 3, triangle only the same truncation 142 5 s
np 3, region only "stack smashing detected", Python fatal abort inside solve 134 6 s
np 4, whole file box: truncation 142 5 s
np 8, whole file box: truncation 142 5 s

Every run stopped in MPI at the first solve with a rank without cells; none needed the supervisor's silence kill. The test has power: each of the three Stokes fixtures fails on its own with PETSc's routine.

3. test_0770 at np 4 and test_1140 at np 8 (skips removed)

file np result cells per rank in its Stokes solves rank without cells?
test_0770_submesh_extract_mpi.py 4 6 passed [110, 95, 97, 104] (406) no
test_1140_rotated_analytic_normal_wall_nodes_parallel.py 8 10 passed, 2 skipped ("not measured to hold the case at np 8", unchanged) (False, 0.5): [0, 3, 2, 2, 0, 3, 2, 2]; (True, 0.4): [3, 0, 3, 3, 3, 0, 3, 3] yes, in all four solve cases
  • test_1140 is a real check. All four test_no_normal_flow_at_any_wall_node cases solve with two empty ranks. The same head test file against the base build fails those four cases with the Stokes refuses, on every rank, a mesh that leaves a rank without cells (#962, interim) #1137 RuntimeError.
  • test_0770 never has a rank without cells. Its region (AnnulusInternalBoundary(cellSize=1/8), extract_region("Inner"), 406 cells) reaches every rank at every np from 2 to 8:
np 2 3 4 5 6 7 8
min cells 192 125 95 64 60 48 24

The base build passes test_stokes_on_submesh_parallel at np 4 too, so its skip never fired here. The [27, 0, 41, 0] in W1's record and in the PR body come from the #962 probe mesh (BoxInternalBoundary, cellSize 0.1), not from this test. Removing the skip is harmless. But the PR body's "those tests meet an empty rank at np 4 and np 8" holds for test_1140 only.

4. MatEqual: the branch's J and P against PETSc's one pass, every rank with cells

I ran W1's matequal_plugin.py unchanged, at np 2 to 8, over ten parallel test files: 0770, 0768, 1063, 1062 (constrained stratum guard), 1078, 0780, 1017, 1071, 1088 and 1089. Each run compared 16 to 17 solves (Stokes 5 to 6, Stokes_Constrained 5, composed Navier-Stokes 6; 1,095 to 4,122 rows). The 13 rotated solves are recorded "no solution vector" and not compared.

np 2 3 4 5 6 7 8
solves where J or P is not bit-equal 0 1 4 6 5 6 6

That looked like a defect, so I added two controls to a copy of the plugin. Each routine was assembled a second time on fresh matrices, and every comparison now also records the relative Frobenius norm of the difference. Seven of the files, np 2, 3, 4, 5 and 8:

np compared branch ≠ PETSc (J / P) PETSc ≠ PETSc (J / P) branch ≠ branch (J / P) largest relative difference, branch vs PETSc (J / P) the same, PETSc vs PETSc
2 16 0 / 0 0 / 0 0 / 0 0 / 0 0 / 0
3 16 0 / 1 0 / 2 0 / 0 0 / 1.4e-19 0 / 1.4e-19
4 17 2 / 4 2 / 6 3 / 2 2.3e-18 / 4.9e-18 2.3e-18 / 3.8e-18
5 17 7 / 5 2 / 4 2 / 3 3.2e-18 / 2.7e-18 5.6e-19 / 2.7e-18
8 17 9 / 9 7 / 7 7 / 9 4.4e-18 / 1.1e-17 3.2e-18 / 1.1e-17

From np 3 up, PETSc's own routine does not assemble the same matrix twice bit for bit. The order in which off-rank contributions are summed varies between assemblies. The branch's differences from PETSc are the same size as PETSc's differences from itself, at most 1.1e-17 relative. So in parallel the branch's matrices are PETSc's to round-off, and "bit for bit" is a one-rank property only. The serial test claims it on one rank, which is correct. No parallel test should be written with MatEqual.

Separately, test_1062_constrained_stratum_guard_parallel.py::test_constrained_parallel_no_segfault fails at np 6 and 7 (|u|_inf 2.484378e-02 against a golden value of 2.533050e-02, rtol 1e-3, on one or two ranks). It fails the same way without the plugin and on the base build. It is not this PR's, and CI does not run those rank counts.

5. The faulted annulus, and a constrained solve, with a rank without cells

Faulted refined annulus, np 8 (#962's third reproduction). Annulus(radiusOuter=1, radiusInner=0.5, cellSize=0.8, refinement=2), then add_fault([("Flt", [[0.62, 0.10], [0.85, 0.30]])]), viscous Stokes, rotated free slip on Lower and Upper, add_fault_bc(0, "Flt"), tolerance 1e-8. The child owns its multigrid tail (2 coarse levels). The solve reports velocity_pc: custom-FMG, velocity_pc_type: mg, coarse_solve: redundant.

np 1 np 8 relative difference
cells per rank: base, finest level [352] [48, 48, 0, 64, 0, 64, 64, 64]
cells per rank: child [356] [58, 58, 0, 60, 0, 56, 55, 69]
cells per rank: tail levels [22]; [88] [3, 3, 0, 4, 0, 4, 4, 4]; [12, 12, 0, 16, 0, 16, 16, 16]
converged, rnorm / rnorm0 yes, 1.80e-12 / 5.79e-02 yes, 2.79e-12 / 5.79e-02
∫|v|² 5.5045688038e-05 5.5045688036e-05 3.6e-11
∫(x v_y − y v_x) −2.1244666754e-05 −2.1244666894e-05 6.6e-09
∫p² 7.3878647260e-03 7.3878889085e-03 3.3e-06
max |v| 8.8209361319e-03 8.8209361395e-03 8.6e-10

It completes and matches serial, with ranks 2 and 4 empty on the child and on every coarse level of the hierarchy. That answers the "no test runs a multigrid hierarchy with an empty rank" gap for this one case; it is not a test. development aborted this run with the #962 truncation before #1137 and refused it after #1137.

Stokes_Constrained with a rank without cells, np 8: it hangs. I used the test_1140 box (UnstructuredSimplexBox(cellSize=0.5, regular=False), cells per rank [0, 3, 2, 2, 0, 3, 2, 2]), no slip on Bottom, and add_constraint_bc(0, "Left"/"Right", normal=…). The defaults are the same as in the serial test's _constrained case, but without multiplier_schur_pc.

build np 1 np 8
base bc3d536 solves RuntimeError from the #1137 refusal on every rank, exit 1
head baf1159 solves hangs; the supervisor kills it after 300 s of silence (exit 124)
head, _reduce_interior_multiplier = False (probe only) solves solves, and matches np 1 to 10 digits (∫|v|² 1.4763760685e-03, max |v| 6.5943240317e-02 at both)

The supervisor's native stacks show the cause:

  • the two ranks without cells (0 and 4) are in MPI_Allreduce < DMClone < DMCreateSubDM < DMCreateFieldDecomposition < _withdraw_block_size_if_not_node_blocked;
  • the six ranks with cells are in MPI_Scan < PetscSectionCreateGlobalSection < DMGetGlobalSection < _constrain_interior_multipliers_in_section.

That routine (petsc_generic_snes_solvers.pyx, from #224) returns early on a local test, if not any(interior_pts.values()): return. A rank with no cells has no interior multiplier points, so it returns and skips the collective section rebuild that every other rank makes.

So the two-call Jacobian handles the constrained case. With the reduction off, the solve completes and is right. What hangs is a set-up path the branch newly exposes. The PR body's first sentence ("A Stokes or constrained solve now completes on a mesh where some rank holds no cells") is false for a default Stokes_Constrained.

Smallest fix: decide "nothing to constrain" collectively, so that a rank with nothing to add still goes through the section rebuild with empty sets:

if not self.dm.comm.tompi4py().allreduce(any(interior_pts.values()), op=MPI.LOR):
    return

Alternatively, keep #1137's refusal for Stokes_Constrained with block constraints until this is fixed. Either way, add this probe as a test (np 8, the box above, Stokes_Constrained, compare with np 1), or as an np 3 case of the new file, which CI reaches. The same local return may also affect a rank that has cells but no interior multiplier points [read]; I did not construct that case.

6. The 3-D cost at np 4

W1's cost_one_rank.py, with times reduced to the slowest rank: UnstructuredSimplexBox 3-D, cellSize 0.2, refinement 1, 5,592 cells as [1400, 1464, 1384, 1344], 19,130 rows. Each run makes three timed solves after a first untimed one. Every run took 1 SNES and 1 KSP iteration per solve, reached max speed 1.434162965727e-03 (all builds, all repeats), and recorded the same flops: Jacobian 3.752499e+09, solve 5.433342e+10.

build / routine DMPlexJacobianFE calls Jacobian time, 3 solves (repeats 1, 2, 3) SNESSolve time (repeats 1, 2, 3)
head, branch routine 6 22.53, 19.33, 19.66 s 34.15, 30.40, 30.82 s
base, PETSc routine 3 19.34, 19.35, 22.36 s 30.46, 30.59, 36.01 s
head, PETSc routine put back 3 19.42, 19.33, 19.37 s 30.38, 30.53, 30.56 s

The best of three are 19.33, 19.34 and 19.33 s. The 22 s outliers (head repeat 1, base repeat 3) are load on a shared machine, and they fall on both builds. The second pass over the cells costs nothing measurable at np 4, consistent with W1's one-rank result.

Other checks

  • Attribution. All ten commits (58524d8 … baf1159) end with "Underworld development team with AI support from Claude Code". None carries a Co-Authored-By line or names a model. The PR body ends with the same line.
  • scripts/check_test_coverage.py at the head: "OK: all 458 test files are reachable from scripts/test.sh (0 deferred by decision); 18 of 40 ptest files run (22 deferred with a reason)."
  • The new np 3 line in scripts/test.sh is reached in CI [read]. CI runs ./scripts/test.sh --p 2 --shard K/N with N from --print-shards (6 at the head). The line sits in the PARALLEL_RANKS > 0 && shard_owns 4 block, beside test_1084's np 3 line and outside the --full-parallel loop, so shard 4 runs it on every pull request. The np 2 enumeration (tests/parallel/test_*.py in batches of 6) also runs the file at np 2 (box and region). Locally the np 3 run takes 4.8 s of pytest time.

Conditions to merge

  1. Make the early return in _constrain_interior_multipliers_in_section collective, or keep the refusal for Stokes_Constrained with block constraints. Then add a constrained solve with a rank without cells to the parallel tests, at an np that CI reaches.
  2. Correct the PR body: constrained solves (until 1 is done); test_0770 never meets an empty rank; and "bit for bit" holds on one rank only (in parallel, to round-off of 1e-17, the same as PETSc against itself).

Underworld development team with AI support from Claude Code

…ction (#962)

_constrain_interior_multipliers_in_section removes the multipliers'
interior unknowns and rebuilds the DM's global section, which is
collective. It returned early on a rank with nothing of its own to
remove. With a rank that holds no cells that rank went on to the field
decomposition while the others were inside the rebuild, and the solve
hung at set-up (found by the parallel review at np 8; #1137's refusal
had hidden it).

The ranks now decide with one allreduce, so every rank rebuilds or none
does. On one rank nothing changes.

Test: a constrained solve on the region that rank 0 holds entirely
(multipliers on its side walls, no slip on its base) converges to its
one-rank speed, and asserts that one rank removes multiplier unknowns
beside a rank that has none. Run on one rank only here; its first
parallel runs are CI's, at np 2 and np 3.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Response to the parallel review of baf1159 (the record above, from H1: the review and parallel-test session on a 96-thread Linux workstation). The head is now 7f1c201.

The blocker: fixed in 7f1c201. _constrain_interior_multipliers_in_section tested "have I anything to remove?" on each rank and returned before the global-section rebuild on a rank that had nothing. The ranks now decide with one allreduce (the largest of the per-rank answers), so every rank rebuilds or none does. We read the rest of the routine for a second rank-local branch in front of a collective call and found none: the one earlier return tests the solver's configuration, which is the same on every rank. #1137's refusal is not put back.

The test. tests/parallel/test_0786_stokes_rank_without_cells_parallel.py::test_a_constrained_solve_completes_with_a_rank_without_cells: the region that rank 0 holds entirely, multipliers on its side walls, no slip on its base. It asserts that a rank has no cells, that one rank removes multiplier unknowns beside a rank that removes none (the premise of the hang), a converged reason, and the one-rank speed 1.2158645e-03 to a relative 1e-6. CI runs the file at np 2 and np 3.

What we have and have not run. On one rank (macOS, 12-core Apple M4, PETSc 3.25.3): the new case's solve gives 1.2158645452e-03 with 104 of each multiplier's 109 unknowns removed; the serial comparison test, the collective guard scan and the 13 serial files that use the constrained solver give 143 passed and 1 expected failure. On more than one rank: nothing. The fix is one line whose effect exists only in parallel, so the evidence that it is enough is CI's np 2 and np 3 and the re-run of the np 8 case (test_1140's box with constraints on Left and Right and no slip on Bottom). If the np 8 case still hangs, the allreduce was not the whole of it and we look again before anything else.

The body, corrected:

  1. The first line no longer says a constrained solve completes without saying that the fix for it has been run on one rank only.
  2. "Bit for bit" is now a one-rank statement. From np 3 up the body gives the review's numbers: PETSc's routine does not reproduce its own matrix bit for bit, and ours differs from it by at most 1.1e-17 relative.
  3. test_0770: the body now says its region has cells on every rank from np 2 to 8, that its skip never fired, and that the test of a rank without cells is test_0786. We left test_0770 as it is.

Solver register row 16 now also covers the collective decision in the constrained solve's set-up.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Re-check of #1156 at 7f1c201: READY. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), following its review at baf1159. Head built from source.

The blocker is fixed.

  • _constrain_interior_multipliers_in_section now decides with allreduce(MAX) whether any rank has interior multiplier points to remove. If one has, every rank rebuilds the section.
  • The guard before it (_block_constraint_bcs and _reduce_interior_multiplier) is solver configuration, the same on every rank.
  • I found no other rank-local return before a collective in the routine.

The hang case from the first review is Stokes_Constrained on test_1140's box (UnstructuredSimplexBox, cellSize 0.5, 14 cells), with constraints on Left and Right and no slip on Bottom. All of these converge (SNES reason 2):

run cells per rank ∫|v|² ∫p² max |v|
np 1 [14] 1.4763760641e-03 3.8144904297e-02 6.5943239500e-02
np 8, default partition [0, 3, 2, 2, 0, 3, 2, 2] 1.4763760641e-03 3.8144904297e-02 6.5943239500e-02
np 8, random shell partition [3, 3, 1, 2, 2, 0, 3, 0] 1.4763760641e-03 3.8144904297e-02 6.5943239500e-02

At baf1159 the np 8 default case hung at set-up.

A finer mesh (cellSize 0.1, 242 cells), with shell partitions, matches np 1 to every printed digit (∫|v|² 1.5103225833e-03, ∫p² 3.8035760202e-02, max |v| 6.8728803692e-02). The layouts:

  • bands with the last rank empty: np 4 [81, 79, 82, 0] and np 8 [39, 37, 31, 32, 40, 29, 34, 0];
  • random: np 4 and np 8, no rank empty.

The new test. test_0786, run under the supervisor:

np result
2 4 passed, 1 skipped (the triangle case, which is one cell at np 2)
3 5 passed on every rank
4 5 passed on every rank
8 5 passed on every rank

The constrained case passes at every np.

The new test has power. I put the old rank-local early return back with a Python wrapper (the method lives on a Python class in generic_solvers). The wrapper returns before the collective on a rank with nothing of its own to remove. Under it, the constrained case at np 3 prints anything=True on rank 0 and False on ranks 1 and 2, then hangs: the supervisor ends it with exit 124.

"A rank holding cells but no multiplier unknowns" can't be constructed. The multiplier is a whole-mesh field, so every rank with cells holds multiplier unknowns. A simplex can't have its whole closure inside one wall's facet closure, so such a rank always has a point to remove. The empty rank is the only rank with nothing to remove, and the test asserts that case (min(removed) == 0, max(removed) > 0).

Also run: test_1140 at np 8, which has empty ranks: 10 passed and 2 skipped on every rank, the same as at baf1159.

Not re-run: the first review's other runs (test_0770, MatEqual, the faulted annulus, the 3-D cost). The fix is one line, in a routine that only constrained solves reach.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit c766bea into development Nov 13, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 13, 2026
Brings in the cap on the ranks the serial facet-slip driver launches
(#1155), whose five-rank case stalled this branch's CI on a 4-vCPU
runner, and the two-call Jacobian (#1156). The two sides change
different parts of the solver file; the merge is automatic.

Underworld development team with AI support from Claude Code
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.

2 participants