Repository navigation
Stokes refuses, on every rank, a mesh that leaves a rank without cells (#962, interim) - #1137
Conversation
#962) A Stokes solve registers a Jacobian preconditioner, so SNES assembles two matrices. PETSc's DMPlexComputeJacobianByKey (3.25.3 and main) leaves early on a rank with no cells, before it has looked for the second matrix, and skips the assembly of the Jacobian that every other rank makes. The ranks are then out of step and the run stops in MPI or hangs. Until the assembly is fixed, the set-up gathers the local cell counts of the solver's DM once and raises the same error on every rank when some rank holds none. The count is the one PETSc tests: the rank's own top stratum, ghost cells included. Scalar and vector solvers have one matrix, are not affected and do not make the check. Three meshes reach this, none decided by cells against ranks: a coarse mesh (14 cells on 8 ranks), a refined mesh whose base left a rank empty (every level keeps the base's partition), and a region extracted from a mesh whose other ranks hold none of it. Tests: the decision and the text on one rank against a stand-in communicator (tests/test_0786); the refusal on two fixtures that leave a rank empty at every rank count from 2, and a scalar solve on the same region that is not refused (tests/parallel/test_0786). Two existing Stokes tests skip when a rank holds no cells (test_1140, test_0770's region solve). This does not fix #962: the solve still cannot be made on such a mesh. Underworld development team with AI support from Claude Code
Adversarial review record (before the PR opened)Made by a separate reviewing agent on the branch before its first commit, then answered in the commit that is here. Everything was run on macOS, 12-core Apple M4 (serial runs only). No finding was against the decision to refuse. The reviewer re-read
Not closed by this review
Issue state. #962: still live. This branch turns a stop in MPI or a hang into an error; the solve on such a mesh is still not possible. #888 is closed and its work is on the roadmap; its item 3 (a faulted annulus stopping at 8 ranks) was shown there to be #962, so that item stays open with #962. Until then the way round is a base fine enough to give every rank a cell. Underworld development team with AI support from Claude Code |
|
READY at 1fd2f1d. On development the new file's Stokes cases stop in MPI at every rank count. On the branch they are refused on every rank with one message, the process returns, and the scalar solve on the same region passes. The refusal is what stands between the user and the stop: with it taken out, the file stops again. Nothing hangs, and no skip fires where it should not. Parallel review by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)).
a. Development 70b240c: the stop the refusal replaces
None of the eight passes, so the premise holds at every rank count tried. Under b. The branch: the new parallel file at np 2 to 8
The test asserts that the outcome string is identical on all ranks, that it carries the counts and "#962", and that the ranks are in step for the gather afterwards. Each run returns in 4 to 10 s, and the scalar solve on the region converges to the prescribed linear field at every np. Beyond the file, the same refusal at three other places this defect was reproduced:
Each returns instead of stopping in MPI. The rotated and fault paths are covered because the refusal sits in c. test_1140 and test_0770 on the branch, np 2 to 8test_1140. Nothing hangs at any np.
The skip fires exactly where a fixture leaves a rank empty, and never at np 2. test_0770. 6 passed at every np from 2 to 8, with no skip: this region reaches every rank at these counts, so d. The mutant: the refusal made a no-op
So the file cannot pass without the refusal. Reading
Checks
Not done
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
…all (underworldcode#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 (underworldcode#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
What this does
A Stokes solve on a mesh where some rank holds no cells now stops at set-up with the same error on every rank. Before, it stopped inside MPI on the ranks without cells, or hung (#962).
This is an interim refusal. It does not make the solve work. The fix is a change to how the two matrices are assembled, and it is a separate piece of work that needs its own measurements.
Cause
The Stokes solver registers a Jacobian preconditioner, so SNES assembles two matrices. PETSc's
DMPlexComputeJacobianByKeyleaves early on a rank with no cells, before it has looked at whether there is a second matrix, and so skips theMatAssemblyBegin/Endof the Jacobian that every other rank makes. The ranks are then out of step in the next collective call. This is in PETSc 3.25.3 (the conda-forge build we ship against) and in PETScmain.A solver whose Jacobian and preconditioner are one matrix is not affected: PETSc assembles once on every rank. That is every scalar and vector solver here. Only
SNES_Stokes_SaddlePt(and its multiplier fields) registers a Jacobian preconditioner.Three cases reach it, and the cell count against the rank count does not decide any of them:
Annulus(cellSize=0.8, refinement=2)on 8 ranks has [48, 48, 0, 64, 0, 64, 64, 64];extract_regionfrom a mesh whose other ranks hold none of that region. An extracted region keeps its parent's partition, so this is the ordinary case for a small region on many ranks.Every such run stops in MPI or hangs today, so the refusal refuses nothing that runs.
The check
SNES_Stokes_SaddlePt._refuse_a_rank_without_cells, called from_setup_solver:dm.getHeightStratum(0)size once on the DM's communicator, and raises the sameRuntimeErroron every rank if some count is zero and some is not. The message names the number of ranks without cells, the rank count, the total cell count, the PETSc routine and Rotated free-slip solve aborts when a rank has no cells (mismatched Allreduce on cell-less ranks; test_1140 at np 8) #962, and says that the base of a refined mesh, or the region, must reach every rank.DMPlexGetAllCells_Internal, which is the rank's own top stratum of thedepthlabel, ghost cells included;getHeightStratum(0)is that range. A rank that owns no cells but holds ghost cells is not refused, and PETSc does not leave early there either.set_active_region, used by one example script and by no default path) can meet the same early exit on a rank whose first cell is in the inactive part. That is not tested for here.There is no tolerance and no coordinate comparison in the change: the decision is an integer count.
Tests
tests/test_0786_stokes_refuses_a_rank_without_cells.py(level 1, tier B, one rank): the method is run against a stand-in DM whose communicator reports several ranks. It asserts no refusal and no gather on one rank, no refusal where every rank holds cells or none does, the same text on every rank for three sets of counts, and that a full set-up of a real solver calls it. With the refusal removed from the set-up, or with the decision or the text changed, this file fails by assertion.tests/parallel/test_0786_stokes_refuses_a_rank_without_cells_parallel.py(level 2, tier B, two ranks or more). Here a regression shows as a stopped or hung run, ended by the supervisor's silence limit:Both fixtures leave a rank without cells at every rank count from 2 up, and each test asserts that premise. At 2 ranks the triangle fixture is a single cell; the region fixture has the shape of the reported cases at every count. CI runs this file at 2 ranks.
Two existing Stokes tests now skip, with the cell counts in the reason, when a rank holds no cells:
tests/parallel/test_1140_rotated_analytic_normal_wall_nodes_parallel.py(meshes of 14 and 18 cells) andtest_stokes_on_submesh_parallelintests/parallel/test_0770_submesh_extract_mpi.py(a region of an annulus, on its parent's partition).docs/developer/design/submesh-solver-architecture.mdsays that a Stokes solve needs cells of the region on every rank, anddocs/developer/guides/fault-multigrid.mdthat the base of a hierarchy must give every rank a cell.What was run
Serial only, on macOS (12-core Apple M4). Nothing in this PR has been run on more than one rank by us: the refusal itself, the parallel test file and the two skips need the parallel desk (a 96-thread Linux workstation), which is asked to show the hang or stop on
developmentfirst and then runtests/parallel/test_0786_*,test_1140_*andtest_0770_submesh_extract_mpi.pyat 2 to 8 ranks.tests/test_0786_stokes_refuses_a_rank_without_cells.pytests/test_0052_collective_guard_scan.pyand the serial Stokes files (test_1010*,test_1012*,test_1013*,test_1014*,test_1017*,test_1018*,test_0771*,test_1058*)developmentat 70b240c. After it, on a fresh build:test_0786, the guard scan,test_1010_stokesCart.pyandtest_0771_extract_region.py, 23 passedscripts/check_test_coverage.pydevelopmenthas already (submesh-solver-architecture.mdis in no toctree)Not shown by a run: that the test "a full set-up reaches the refusal" fails when the call is taken out of
_setup_solver. The call site is compiled, so it cannot be changed in memory; the test replaces the method on the instance and expects its error fromsolve().test_stokes_on_submesh_parallel(test_0770) passes in CI today at 2 ranks, so the region reaches both ranks there, the skip does not fire, and CI keeps running it. The skip is conditional on the premise (some rank holds none of the region). Where it fires, it is one of the tests the assembly fix will turn back on, with test_1140's.An adversarial review was made before this PR opened; its record is in the first comment.
Issue state
#962 stays open and is not labelled as fixed: the refusal replaces a hang with an error, and the solve still cannot be made. The refusal is removed when the assembly is fixed.
Solver register: row 16, "a Stokes or constrained solve on a mesh where some rank has no local cells: refuse at setup, collectively, naming the rank count, the cell count and the PETSc defect; no numerics; removed when the shipped PETSc is fixed".
Underworld development team with AI support from Claude Code