Skip to content

Lazy coordinate fields: an np 2 empty-rank case and the notes from #1271's review - #1297

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/lazy-coordinate-field-sites
Nov 24, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/lazy-coordinate-field-sites

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

The follow-ups from the review of #1271 (and the lows on #1287), with no issue. Review: H1, the session that reviews pull requests and runs the parallel tests on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

The other clone and sub-DM sites: probed, no drift found

#1271 fixed the lazy coordinate field on the solver's clones. The review listed other sites that clone a DM or make a sub-DM, and so could create the field lazily too. Each was reached through the public operation that uses it, at np 3 and at np 2, on development with #1271. Every gmsh mesh was given a test-only shell partition that leaves the last rank with no cells. The next tag on COMM_WORLD was read on every rank before and after each operation:

operation (sites reached) tags used per rank, np 3 np 2
Clement gradient (gradient_evaluation) 11, 11, 11 11, 11
gradient interpolant (gradient_evaluation) 11, 11, 11 11, 11
project_to_degree (field_projection: clone and sub-DM) 61, 61, 61 59, 59
variable write and read_timestep (mesh-variable sub-DMs and clones) 277, 277, 277 275, 275
Stokes solve and boundary_flux (boundary_flux) 1903, 1903, 1903 1913, 1913
refined-base Stokes solve (custom_mg levels) 1926, 1926, 1926 1922, 1922
add_fault (fault_split, line_cut, edge_split) 932, 932, 932 1062, 1062
node_redistribution (the mover's frozen DM) 1104, 1104, 1104 1210, 1210
faulted refined Stokes solve (custom_mg with fault levels) 3077, 3077, 3077 see the finding below
a gmsh load after all of these 295, 295, 295 295, 295
  • No drift: the counts are equal across ranks in every case, so none of these sites drifts through these operations. No speculative forcing is added.
  • Empty ranks confirmed: the meshes built inside the operations do have an empty rank, for example cells 80 / 88 / 0 for the refined base and 162 / 0 at np 2.
  • Not exercised: the adjoint's sub-DMs were not probed.

Changes

  • An np 2 case for Solver DM clones create their coordinate field on every rank #1271's test. test_1107_mesh_load_after_a_solve_on_an_empty_rank_parallel gains a case that runs from np 2, as CI does: a gmsh box whose cells all go to rank 0 (a shell partition set on the loaded DM, through a fixture that patches _from_plexh5), a viscoelastic solve, the ranks' next tag compared, and a second gmsh load.
  • dm_force_coordinate_field docstring. It now states both effects: the coordinate field is made on every rank that calls it, and every label of the coordinate DM except depth and celltype is removed. dm's own labels are untouched. clone_dm_hierarchy says why the strip loses nothing there: the clone's coordinate DM is a clone of the level's own, whose labels were stripped when the level was built (Parallel bug - Calculating a boundary integral causes the next Stokes solve to hang #96).
  • _rebuild_level_coordinate_field docstring. It said a solver's clone inherits the field. It does not (DMClone copies the coordinates, not the DMField); the docstring now says so and points to clone_dm_hierarchy.
  • Mesh.remesh region-label branch. It is rank-local above the metric: a rank with no cells neither creates _CellRegions_ nor sets rgLabel_name, while the others pass rgLabel="_CellRegions_" to adaptMetric. A TODO(BUG) says so. It matters only once a parallel remesher is in the build.

Finding, not fixed here

At np 2 with every cell of a refined base on one rank (cells 168 / 0), add_fault raises the same CollectiveBuildError on both ranks: "84 fine cell(s) have no local parent cell on the level below; the add-on levels are not co-partitioned". So it is agreed, not a hang. At np 3 with one empty rank (80 / 88 / 0), and at np 2 with cells on both ranks, the same call works. A DM with every point on one rank reads as not distributed, which addon_partition already notes for the case where the partition would put everything on one rank. This looks like the same edge, met earlier. It is reported separately.

Underworld development team with AI support from Claude Code

's review

- test_1107_mesh_load_after_a_solve_on_an_empty_rank_parallel gains a case
  that runs from np 2, as CI does: a gmsh box whose cells all go to rank 0
  (a shell partition set on the loaded DM), a viscoelastic solve, the ranks'
  next tag compared, and a second gmsh load. It fails at np 2 without
  #1271. The right-triangle cases keep their np >= 3 skip.
- dm_force_coordinate_field's docstring states both effects: the field made
  on every rank, and every coordinate-DM label but depth and celltype
  removed. clone_dm_hierarchy says why the strip loses nothing there.
- _rebuild_level_coordinate_field's docstring no longer says a clone
  inherits the field.
- Mesh.remesh's region-label branch is rank-local above the metric; a
  TODO(BUG) says so (it matters once a parallel remesher is in the build).

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

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 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Review of #1297 at 831147e

Verdict at 831147e: ready to merge on green from this review.

We confirm the author's main result. None of the other clone and sub-DM sites listed in the #1271 review drifts the tag counter. We checked each one we could reach at np 3 and at np 2, with a rank that holds no cells, on the branch and on development. The tag spread was 0 after every operation and after the gmsh load that followed. Branch and development matched in every count. The new np 2 case fails without #1271 and passes on the branch at np 2, 3 and 4. The .pyx change is a docstring only. Every test outcome and probe answer we compared is the same on both. One low finding: the new comment in clone_dm_hierarchy gives the wrong reason. On a refined mesh the levels' coordinate DMs do carry the boundary labels. A one-sentence fix is worth making in this PR. Three problems that existed before this PR turned up in passing; they are listed at the end.

Method

  • Head: built fresh from 831147e. The compiled .so files are dated the day of the review, and dm_force_coordinate_field.__doc__ carries the new text.
  • Development: the merge base 1e10c63. We copied the installed package of an existing build whose compiled sources match 1e10c63 exactly (no differences in .pyx, .pxd, .h, .c, setup.py or the pixi files), and laid 1e10c63's .py files over it.
  • Without Solver DM clones create their coordinate field on every rank #1271: development at 9564201 (the merge base of Solver DM clones create their coordinate field on every rank #1271), from the Solver DM clones create their coordinate field on every rank #1271 review's install.
  • Every run prints underworld3.__file__, and every run used the intended install.
  • MPICH, cores 0-3 only, with other jobs on the machine. Every parallel run went through the repository's MPI supervisor (silence 60-300 s) inside an outer timeout. A hang shows as exit 124, with the stacks of every rank.
  • Empty rank: a test-only shell partition on every gmsh load. It bands the cells over np - 1 ranks and gives the last rank none. At np 2 this puts every cell on rank 0, as the new test does.
  • Tag probe: the same method as the test. PetscCommDuplicate on COMM_WORLD gives each rank's next tag, and the values are gathered.
  • Site coverage: sys.monitoring counted, on each rank and without any communication, every execution of each .clone() and createSubDM( line in the listed modules. So a site counts as reached only when that line actually ran. Each operation ran in its own process.

1. Tags at each site

Tags used = the tags each rank took during the operation (the same on every rank in every row). Spread = the largest minus the smallest next tag over the ranks: first after the operation, then after a following gmsh load. Branch and development gave identical numbers in every cell. Cells per rank: plain box 175 / 171 / 0 (np 3) and 346 / 0 (np 2); refined box 348 / 300 / 0 and 648 / 0; faulted base 700 / 684 / 0 and 1384 / 0.

operation sites reached (line ran on every rank) np 3: tags used, spread after op / after load np 2
evaluate_gradient, interpolant gradient_evaluation scratch clone (l. 190) 89, 0 / 0 87, 0 / 0
Clement gradient gradient_evaluation scratch clone (l. 646) 89, 0 / 0 87, 0 / 0
project_to_degree field_projection clone and sub-DM 139, 0 / 0 135, 0 / 0
Stokes (velocity degree 3) and boundary_flux boundary_flux coordinate-DM clone (_trace_interior_coords), mesh-variable sub-DMs 2383, 0 / 0 2387, 0 / 0
T.write, write_timestep, read_timestep, read_checkpoint MeshVariable.write coordinate-DM clone, read_checkpoint sub-DM and section clone, mesh-variable sub-DMs 650, 0 / 0 646, 0 / 0
Stokes on a refined box mesh-variable sub-DMs only (no custom_mg clone line ran) 1582, 0 / 0 1578, 0 / 0
_mmpde_mover, frozen metric mmpde frozen DM (l. 341) 465, 0 / 0 571, 0 / 0
Stokes gradient (a parameter and a field in a datum) adjoint._owned_to_ghosts sub-DM 6316, 0 / 0 6334, 0 / 0
add_fault on a refined box fault_split (add_fault, redistribute_by_assignment), line_cut (three clones) 841, 0 / 0 raises CollectiveBuildError on both ranks; 454, 0 / 0
faulted_2d(2) and a shear solve with the fault the fault sites above, custom_mg reduced map sub-DM (l. 400) and coarse clone with the solver's discretisation (l. 435) 5586, 0 / 0; slip 0.159581, custom FMG not reached: add_fault raises as above; 1824, 0 / 0
  • No drift found. The author's result holds at every site we reached.

  • np 2: with every cell of a refined base on one rank, add_fault raises CollectiveBuildError on both ranks ("fine cell(s) have no local parent cell on the level below"). The failure is agreed, so there is no hang. This is the case the PR body reports separately. Because of it, the faulted solve is not reached at np 2.

  • Answers: where the operation returns a value, the branch matches development exactly: the gradient values, the mover's energies, dJ/dα = 7.3644103763e-03 and the fault slip.

  • Not reached by any operation above:

    • the custom_mg level wrap (_DMLevelView)
    • the SBR adapt clone (_sbr_apply)
    • _colocate_level
    • adjoint.inner's sub-DM
    • edge_split.bisect_longest_edges
    • four fault_split clones (_label_embedded_edges, _redistribute_fault_interior, _track_fault_records, split_fault)

    These lines never ran on any rank. So they are not cleared, but they are not implicated either.

2. The new test

build np 2 np 3 np 4
branch (831147e) 1 passed, 2 skipped 3 passed 3 passed
without #1271 (9564201, test file from the branch) the gmsh case fails: tags [536865878, 536865879] the run hangs in a gmsh load's _from_plexh5 (every rank in PetscSFSetUp under PetscCommBuildTwoSided), exit 124 not run

So the np 2 case catches the bug the way CI runs the file. It fails on the tag check before the second load, so it fails rather than hangs. The fixture shell-partitions each rank's local cells to rank 0 and checks that rank 0 holds every cell. It is function-scoped, so the patch is undone after the test. Its rank-local reads are symmetric.

3. The .pyx change

petsc_maths.pyx changes only the docstring of dm_force_coordinate_field. The PR body's "Changes" list says so. The function body and UW_DMForceCoordinateField are untouched. The docstring is compiled into the module, which is why a rebuild is needed to see it. It cannot change an answer. The tests that exercise it (test_0501_integrals, test_0502_boundary_integrals, test_1019_boundary_flux) are in the serial set below and give the same outcome on both builds.

4. Neighbours

  • Parallel: the Solver DM clones create their coordinate field on every rank #1271 review's 17 files (VE and stress history, SUPG and SLCN, empty-rank Stokes and free surface, custom MG, fault-split MG, coarse GAMG, rotated free slip, rebuild memory, natural BCs on unowned boundaries) at np 2 and np 3, head and development.
    • Outcomes are identical in 34 of 34 (file, np) pairs, skips included.
    • test_1114 [rotated] fails at np 3 on both, with iterations (4, 10) against a bound of (4, 9). The Solver DM clones create their coordinate field on every rank #1271 review saw the same failure, so it is not caused by this PR.
    • test_0780 needs np 4. It passes at np 4 on both.
  • Serial: 10 files that touch the mesh hierarchy, coordinate fields, remesh, integrals or boundary flux, run with 4 workers:
    • test_0834, test_0830, test_1172, test_0810, test_1240, test_0501, test_0502, test_1019, test_0690, test_1012
    • 81 passed, 8 skipped, 1 xfailed on both.

5. Docstrings and the TODO

  • dm_force_coordinate_field: accurate. It states both effects, and that dm's own labels are untouched. This matches UW_DMForceCoordinateField: it calls DMGetCoordinateField on dm, then removes every label of the coordinate DM except depth and celltype.
  • _rebuild_level_coordinate_field: accurate now. A clone does not inherit the field. The Solver DM clones create their coordinate field on every rank #1271 review checked this: forcing it on a fresh clone takes one tag.
  • remesh TODO(BUG): accurate. On a rank with no cells, depth_label.getStratumIS(dim) returns a null IS. That rank skips the block, so it neither creates _CellRegions_ nor sets rgLabel_name. The same rgLabel_name also gates the region rebuild after adaptMetric. The TODO's remedy, making the label and the name on every rank, covers that too.
  • clone_dm_hierarchy comment: see finding 1.

Reading the diff

The diff changes no executable library code. It adds comments, two docstrings, a TODO and one test. The test's fixture and assertions run the same calls on every rank, so the diff adds no rank-local branch.

Findings

  1. Low: the new comment in clone_dm_hierarchy gives the wrong reason. It says the clone's coordinate DM is "a clone of the level's own, whose labels were stripped when the level was built". That holds for an unrefined mesh, but not for the levels of a refined one. Measured serially on a refined box:

    labels on the coordinate DM
    mesh.dm celltype, depth
    level 0 depth
    levels 1 to n All_Boundaries, Bottom, Elements, Left, Right, Top, UW_Boundaries, celltype, depth
    their solver clones celltype, depth

    The same holds on head and on development. So the strip does remove the boundary labels from the solver clones of every refined level, the finest included. This is the observation in finding 2 of the Solver DM clones create their coordinate field on every rank #1271 review. The comment's conclusion, that nothing a solver reads is lost, is supported by the outcomes: no test changed with Solver DM clones create their coordinate field on every rank #1271, and the 17 files and 10 serial files above agree. Only the reason is wrong. Suggested wording: "...also strips every label but depth and celltype from the clone's coordinate DM. On a refined mesh the levels' coordinate DMs carry the boundary labels, so the clones lose them; the solver reads its labels from the clone itself, not from its coordinate DM (Parallel bug - Calculating a boundary integral causes the next Stokes solve to hang #96)."

Seen in passing, not this PR

These behave the same on head and on development. We list them so they can be filed if wanted.

  • evaluate_gradient(T, pts) with points on a rank that holds no cells raises "An error was encountered attempting to find the closest cells to the provided coordinates" on that rank only, at np 2 and np 3. The other ranks return. In a script, that is a rank-local exception. With no points on the empty rank, the call works.

  • read_timestep on a file written by write_timestep(..., create_xdmf=False, petsc_reload=True), read into a variable with a different name: rank 0 alone reads fields/T with h5py. The file has no fields group, so rank 0 raises KeyError. The other ranks wait in the following bcast, and the run hangs (exit 124 at np 2 and np 3, with or without an empty rank). With create_xdmf=True the same read works.

  • read_checkpoint(file, data_name="T") into a second variable on the mesh that wrote it gives the wrong field at np 3. Against ∫T² = 0.203:

    run ∫(T_read - T)²
    np 3, cells 175 / 171 / 0 0.248
    np 3, every rank holding cells 0.198
    np 1 0
    np 2 0

    read_timestep from the same file is exact at every np. This may be a use the reader does not support. It needs a look.

Run and not run

Run:

  • the site probe above at np 3 and np 2 with an empty rank, head and development
  • the new test at np 2, 3 and 4 on head, and at np 2 and 3 without Solver DM clones create their coordinate field on every rank #1271
  • the 17 parallel files at np 2 and 3 on both (test_0780 at np 4)
  • 10 serial files on both
  • the coordinate-DM label check on both

Not run:

  • the sites listed as not reached in section 1
  • a 3-D mesh
  • a mesh from a source other than gmsh (the partition hook acts on gmsh loads only)
  • the full serial suite
  • CI

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

lmoresi and others added 2 commits November 21, 2026 05:13
…ver keeps its own

From the review of 831147e: on a refined mesh the levels' coordinate DMs
carry the boundary labels, so the strip removes them from the clones' coordinate
DMs; the solver reads its labels from the clone itself (#96). The wording is
the reviewer's.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit 2784f8c into development Nov 24, 2026
10 checks passed
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.

3 participants