Repository navigation
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
Conversation
…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
Adversarial review, round 2:
|
| 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
#elsebranches inpetsc_compat.hare 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
openmpiandopenmpi-devenvironments on linux-64 and osx-arm64. The guard accepts it; nothing was run or read at 3.25.1. UW_DMPlexSetSNESLocalFEM(dm, flag, ctx)ignoresctxand passesNULLto both registrations. All four callers passNULL, so nothing breaks today.- The triangle fixture creates the
All_Boundarieslabel 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_versioncannot 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_WeakFormTablesGetonly 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)withnone == NULLreturns success (hashmap.h:92,if (!*ht) PetscFunctionReturn(PETSC_SUCCESS);).tablesis freed on every path after the allocation, andPetscCall(ierr)on the kept code is valid. - Shared weak forms.
DMCopyDScopies 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 withmultiplier_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.dmis the DM the SNES assembles on (handles equal). - The routine does make two calls (measured).
DMPlexJacobianFEevents percomputeJacobian: 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_rankcounts 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 ismpi(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) anduw doctorall say 3.25.x.environment.yamland the devcontainer file saypetsc=3.25. The lock satisfies the new range without a re-solve, and CI installs thedevenvironment frozen at 3.25.3. - The four
CHKERRQ(UW_DMPlexSetSNESLocalFEM(...))sites (pyx 7255, 8361, 9115, 12254) use the repository's own Python-raisingcdefinsidedefmethods, like their neighbours. A failure now raisesRuntimeErrorwith the numeric code, where it was dropped before. - Docs. The new text in
docs/developer/design/submesh-solver-architecture.mdanddocs/developer/guides/fault-multigrid.mdmatches 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 indocs/,src/,tests/orscripts/.
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:
- First call without emptying the preconditioner tables (expected: Nitsche and constrained fail, plain passes).
- Second call assembled from the Jacobian tables (all fail).
- Second call swapping the volume tables only (expected to pass everything; see finding 6).
- Second call swapping the boundary tables only (fail).
- Restore of one set skipped (fail).
- The
PetscCheckremoved, and theJ == Preturn removed (expected to pass everything; see findings 4 and 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.his 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)
- Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962: left open and unlabelled by decision; not judged here.
- Stokes: set_active_region ends in a segmentation fault inside PETSc, and its region value is never used #1154 (
set_active_regionsegmentation fault): still live. The crash is in the first residual evaluation, which the branch does not touch; it also keeps the multi-system path of the new routine untested. - Stokes_Constrained with preonly + LU returns a wrong solution reported converged: the factorised matrix is not the system matrix (#651 item 3) #1151 (
Stokes_Constrainedwithpreonly+ LU): still live. The branch assembles the same J and P bit for bit; P differs from J in the pressure block, as that issue describes. - Stokes_Constrained on a 3-D shell: np 8 differs from np 2 and 4 by 1.55e-5 (velocity L2), independent of solver tolerance (#651 item 1) #1150 (
Stokes_Constrained, np 8 differs by 1.55e-5): still live, not re-probed. One-rank matrices are unchanged, and no parallel run was made. - Automatic cold Picard warm-up diverges a LINEAR constrained Stokes solve (Stokes_Constrained + multiplier free-slip) #817 (cold Picard warm-up, constrained Stokes): still live. The warm-up path is not touched.
- Scalar/vector/multi-component solvers: each in-place rewire appends another set of natural-BC kernels (right only by call order) #1069 (scalar, vector, multi-component rewire appends natural-BC kernels): still live. Those solvers take the early return, so PETSc's routine runs as before.
- Scalar/vector/multi-component solvers: a separate preconditioner matrix gets no natural-BC term, and -snes_mf_operator with a natural BC fails (error 56) #1070 (labelled fixed-in-development): the label stands. Its latent part (a separate P gets no natural-BC term) is unchanged, because the early return hands two matrices straight to PETSc.
- 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 (essential condition on
All_Boundaries, bare DMPlex): still live. The triangle fixture works around it by creating the label. - metricCreateIsotropic on an empty rank leaves a later distribute hanging #975 (
metricCreateIsotropicon an empty rank): still live. It is a different mechanism (metric creation, then distribute) and no Jacobian is involved. - Fault pins ptest_0863, 0864, 0865 fail at np 4, back to at least 2026-10-29 #956 (fault pins at np 4): still live and outside the mechanism. Its failures are assertion and surgery errors, not the mismatched collective.
- 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 (labelled fixed-in-development): the label stands for the scalar and vector solvers. Finding 4 is the same PETSc behaviour on the Stokes solvers when one matrix is handed, and is not covered by that fix.
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.
- Fixed (79b0b9d). The custom build script clones the
v3.25.3tag, its version fallback is 325, and the 3.24 line is gone from its help. The install page says 3.25.x. - Partly.
scripts/test.shnow 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.pyondevelopmentasserts 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_0770at np 4,test_1140at np 8, and the faulted annulus at np 8. - Fixed (4e9e55f). The docstring says a structured mesh of two quadrilaterals and no longer claims the value is the same on every host.
- 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.
- Fixed (4e9e55f). The constrained case sets
multiplier_schur_pc = True; the test passes. - Recorded in the test's docstring (4e9e55f).
- Recorded in the PR body under "Not run, and not tested".
- 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.lockholds (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#elsebranches for old PETSc in the header, the unusedctxargument, and the warning incheck_petsc_versionthat 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
|
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 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 1. The new parallel test at np 2, 3, 4 and 8
Every solve converged (SNES reason 2). Here is the largest nodal speed against the file's constants, which were recorded on macOS:
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
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 backThe branch installs its routine in
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)
The base build passes 4. MatEqual: the branch's J and P against PETSc's one pass, every rank with cellsI ran W1's
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:
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 Separately, 5. The faulted annulus, and a constrained solve, with a rank without cellsFaulted refined annulus, np 8 (#962's third reproduction).
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. Stokes_Constrained with a rank without cells, np 8: it hangs. I used the test_1140 box (
The supervisor's native stacks show the cause:
That routine ( 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 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):
returnAlternatively, keep #1137's refusal for 6. The 3-D cost at np 4W1'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
Conditions to merge
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
|
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. The test. 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 ( The body, corrected:
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 |
|
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.
The hang case from the first review is
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:
The new test.
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 "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 ( 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 |
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
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
DMPlexComputeJacobianByKeyassembles both in one pass. On a rank with no cells it leaves before it has read that there are two, and skips aMatAssemblyBegin/Endof 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 andmain. 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:(J, J)with the preconditioner's kernel tables set aside;(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:
PetscWeakForm'sform[]), which no release promises to keep;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.pycompares 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_sectionremoves 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 (oneallreduce), 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 ofuw doctor, and the install page (which said 3.21 or higher). The custom PETSc build script cloned PETSc'sreleasebranch, which is now 3.26; it clones thev3.25.3tag instead.pixi.lockdoes 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 differentpetsc_versioninput 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 underdocs/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.Five of the 164 files did not exit 0 under the plugin.
test_0019_mcp_serverskips its one test.test_1160,test_1161andtest_1174each 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_leakmeasured 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
MatEqualis 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:
MatAssemblyEndcallsThe 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:
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.pyondevelopmentasserts the same of the same mesh.scripts/test.shnow also runs this file at np 3 on every run. The#962skips intests/parallel/test_0770andtests/parallel/test_1140are removed.test_1140meets 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 istest_0786.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
test_1140at 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).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).Issues
fixed-in-PRlabel: the defect is PETSc's and this is a workaround.set_active_regionon a Stokes solver stops in the first residual), Stokes_Constrained on a 3-D shell: np 8 differs from np 2 and 4 by 1.55e-5 (velocity L2), independent of solver tolerance (#651 item 1) #1150 and Stokes_Constrained with preonly + LU returns a wrong solution reported converged: the factorised matrix is not the system matrix (#651 item 3) #1151 (the constrained solve: a rank-count difference at np 8, andpreonly+ LU), Stokes pressure-nullspace guard reads the velocity's Dirichlet conditions as the pressure's when the pressure field was created first #1147 (the pressure-nullspace guard), 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 triangle fixture makes theAll_Boundarieslabel by hand).Solver register row 16.
Underworld development team with AI support from Claude Code