Skip to content

A free surface builds on a rank that holds no cells - #1215

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/free-surface-empty-rank
Nov 16, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/free-surface-empty-rank

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

A free surface could not be built on a rank that holds no cells. No issue was filed: this PR is the report. H1 found it while reviewing #1209, at np 3 on a 96-thread Linux workstation (Intel Xeon Gold 6240R, MPICH).

The defect

FreeSurface._build_interior_diffuser chooses how the mesh displacement is read: directly, node for node, when the carrier field's nodes coincide with the mesh's, or by a fallback otherwise. It tested that with np.max of each rank's node distances.

  • On a rank with no nodes the array is empty, so np.max raised.
  • The other ranks had gone on into the collective solve, and waited there.
  • The choice was also made rank by rank, so two ranks could read the displacement differently.

The verbose report had the same np.max of a possibly empty array inside an f-string that every rank builds.

Fix

  • The ranks agree on the choice, with a logical-AND reduce. A rank with no nodes counts for the direct read, having nothing against it.
  • The verbose report's maxima are reduced over the ranks before printing.

Tolerances and coordinate matches

  • Library: the existing coincidence test (dist < 1e-12, the nodal read's own) is unchanged; it is now agreed over the ranks.
  • Test: the surface integral of h_inf² and the energy, against the default partition's in the same run:
    • before the step, at rel 1e-8. H1 measured agreement to 1.6e-10 at np 3 with an empty rank.
    • after one step, at rel 1e-4. H1 measured partition dependence, repeatable, of up to 1.3e-5 at np 3 with an empty rank. It comes from the carrier Poisson solve at its 1e-3 tolerance and the P1 velocity projection.

Test

tests/parallel/test_1074_free_surface_on_an_empty_rank_parallel.py.

  • A shell partition gives the box's cells to every rank but the last, in bands, so from np 3 one rank is empty.
  • The test asserts that the integral of |v|² of the free-surface solve equals that of the same model on the default partition, in the same run.
  • It is added to test.sh's np 3 runs, since at np 2 the partition would leave one rank holding every cell.

H1's parallel run (comment 6911617873): development hangs at np 3 with an empty rank. The branch completes 1 and 5 steps, and without an empty rank it is bit-identical to development.

Run here, serially only on macOS (12-core Apple M4): the new test passes (no rank is empty), and so do the free-surface tests (14). It has not been run under MPI here. Please run it at np 3, on development (where it should hang) and on this branch.

Underworld development team with AI support from Claude Code

FreeSurface._build_interior_diffuser chose between a direct nodal read of the
mesh displacement and a fallback by np.max of each rank's node distances. On a
rank with no nodes the array is empty and np.max raised, while the other
ranks went on into the collective solve and waited (H1, np 3). The choice was
also made rank by rank. The ranks now agree on it (a logical AND, a rank with
no nodes counting for the direct read). The verbose report's maxima, built on
every rank, are reduced over the ranks too.

Test: tests/parallel/test_1074_free_surface_on_an_empty_rank_parallel.py, on
a box whose cells a shell partition gives to every rank but the last; it
compares the free-surface velocity's energy with the default partition's in
the same run, and is added to test.sh's np 3 runs. Serially it passes, as do
the free-surface tests (14); it has not run under MPI here.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:02

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.

…hat it produces (review of #1215)

From the adversarial review of c831b08:
- The test only solved, so it never reached advance(), where the agreed
  displacement read is used and the mesh deforms on the empty rank. It now
  builds the free surface verbose, solves, advances one step and solves again.
- It compared the user's Stokes energy, which the free surface does not
  change. It now compares the integral of h_inf^2 over the surface as well.
- Below np 3 it compared two runs on one partition and could not fail; it now
  skips there.
- The bound (rel 1e-6) is named and is to be set from the measured np 3
  difference.
- The absolute 1e-12 coincidence test is marked TODO(BUG): the two P1 fields
  share a DM, so the match is topological.
- The empty-safe global maximum is one function, _global_abs_max, at the
  eight sites that wrote it out; the test docstring no longer says who
  measured what.

Serially the free-surface tests pass (14); the new test skips there.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Adversarial review record, and the answer in a421d1c

One round, by a fresh reviewer that read the code through git without running it.

Fixed:

  • The test never reached advance(). That is where the agreed displacement read is used, and where the empty rank deforms. The test now builds verbose, solves, advances one step and solves again.
  • The assertion was on the user's Stokes energy, which the free surface does not change. The test now also compares the integral of h_inf² over the surface with the default partition's.
  • Below np 3 the test compared two runs on one partition and could not fail. It now skips there.
  • The absolute 1e-12 node-coincidence test is marked TODO(BUG). The two P1 fields share a DM, so whether their nodes coincide is topological.
  • The empty-safe global maximum is now one function, used at its eight sites.
  • The test docstring no longer says who measured what.

Checked and safe on an empty rank, by reading:

  • the wall classification, the surface-node gather, _field_rows, the ring gather, the surface weights and the demean;
  • the topography recovery's allreduces and allgathers, all taken by every rank;
  • on advance(): estimate_dt, the CFL and _relaxation_rate.

Not checked: mesh.deform on an empty rank, outside this file. The new step in the test reaches it.

Not run: MPI. The test skips serially; the free-surface tests pass (14). The bound SAME = 1e-6 is a placeholder until the np 3 difference is measured.

Please run at np 3, on development (it should hang at the build) and on this branch, and report the measured relative differences of the two integrals. I'll set SAME from them with a stated margin.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 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.)

Verdict at a421d1c: changes requested. The fix is right: development hangs on an empty rank and the branch does not. But the new test fails on the branch as written. Its placeholder SAME = 1e-6 is ten times tighter than the measured h_inf² difference, so the new np 3 line in test.sh would fail CI. Set the bound (suggestion below) and this is ready to merge on green from this review.

Development and the branch at np 3 with an empty rank

The scenario is the new test's model: the same box and shell partition, so the cells per rank are [161, 161, 0].

  • Development (merge base eccae6d) hangs. The empty rank raises ValueError: zero-size array to reduction operation maximum at np.max(dist) in _build_interior_diffuser. Ranks 0 and 1 go on and wait in an allgather. The supervisor saw no output for 300 s, found rank 2 apart from the other two, and killed the job (exit 124).
  • The branch completes, both for the build and one step, and for the 5-step run. The run is bit-identical between repeats.
  • The ordinary partition is unchanged. At np 3 without an empty rank, development and the branch give bit-identical results over 5 steps. The branch change only alters the outcome where the ranks used to disagree.

The new test on the branch

np result
3 FAILED: 0.000984403263288379 == 0.000984414372212203 ± 9.8e-10
2 skipped, as designed

The failure is on ∫h_inf², with the empty layout against the default one in the same run: a relative difference of 1.13e-5, against a bound of 1e-6. The energy assertion is not reached. Its difference is 4.3e-7, so it would also be close to 1e-6.

Relative differences against serial

These are the test's two quantities after solve, one step and a second solve. The serial reference is np 1. Each layout was run twice, in separate jobs.

np layout run energy ∫|v|² rel diff ∫h_inf² rel diff
1 default 2 (vs 1) 2.6e-15 0
2 default 1 6.95e-7 2.95e-6
2 default 2 6.95e-7 2.95e-6
3 one rank empty 1 4.68e-7 1.26e-5
3 one rank empty 2 4.68e-7 1.26e-5
3 default (no empty rank) 1 4.08e-8 1.32e-6
3 default (no empty rank) 2 4.08e-8 1.32e-6
3 empty vs default, same run (what the test asserts) – 4.27e-7 1.13e-5

Run-to-run noise: at np 2 and 3, every repeat is bit-identical to its first run. Serial repeats differ at about 1e-15. The spread in the table is therefore partition dependence, not noise.

Before the step, after the first solve only, all layouts agree with serial to 6.8e-11 or better in energy and 1.6e-10 or better in ∫h_inf². That matches the Stokes tolerance of 1e-8.

The step opens the spread to about 1e-6 to 1e-5. The deformed geometry comes from two solves that are much looser than the Stokes solve:

  • the interior carrier Poisson solve, which runs at tolerance = 1e-3;
  • the P1 velocity projection, whose surface u_n already differs between partitions by 6e-4 to 1.3e-3 of its maximum at step 0.

The empty-rank layout sits within a factor of about 4 of the ordinary np 2 spread, which is the largest of the ordinary layouts in energy.

Suggested bound: SAME = 1e-4 for both quantities after the step. That is about 9 times the largest measured ∫h_inf² difference: 1.26e-5 against serial, and 1.13e-5 for the in-run comparison the test makes. It is more than 100 times the energy difference. A bound of 1e-5 would leave no margin on ∫h_inf².

If you want a tight check to remain, also assert the two quantities after the first fs.solve(), before advance, at about 1e-8. The measured differences there are 1.6e-10 or better.

More steps: 5 steps, the same quantities and the surface itself

These are the maxima over steps 1 to 5, relative to serial. The surface height and u_n are the gathered surface ring, given as the maximum nodal difference over the maximum magnitude.

np layout energy ∫h_inf² surface height surface u_n
2 default 4.65e-6 2.95e-6 1.96e-4 5.9e-4
3 one rank empty 2.40e-6 2.92e-5 1.32e-4 1.30e-3
3 default 7.83e-7 3.65e-6 2.26e-5 1.06e-3
  • The empty-rank run tracks serial within the ordinary spread. Its surface height is closer to serial than np 2 is. Its u_n is within about 20% of the np 3 default layout.
  • Nothing grows over the steps. The differences in height and ∫h_inf² are largest at steps 1 to 3 and shrink by step 5. The time step agrees to 2e-6.
  • Both repeats were bit-identical here too.

Collectives

The diff:

  • _build_interior_diffuser: the direct-read or fallback choice is now one LAND allreduce, and an empty rank votes for the direct read. On the fallback, every rank now takes the function.evaluate path together. This is correct.
  • estimate_dt and the verbose reports: these go through _global_abs_max. That matches the form estimate_dt already used, and the verbose maxima used to be rank-local.

Other rank-local decisions in the build and the step. I read them looking for a branch an empty rank could take alone, and found none:

  • estimate_dt: _velocity_cfl guards the empty array and allreduces. get_min_radius allreduces, and an empty rank contributes +inf. speed == 0.0 is tested on the reduced value.
  • _relaxation_rate: den > 1e-300 is tested after the allreduce.
  • _solve_consistent, the consistent solve: abs(scale) > 1e-30 comes from a collective BdIntegral.
  • solve, the held solve: no rank-local branch. _demean and _surface_mean reduce owned-facet weights, and the empty rank contributes 0.
  • _surface_weights_local: its early return is serial-only (uw.mpi.size == 1).
  • _field_rows: guards empty coordinates.
  • _build_ring_gather, _ring_gather and _ring_scatter: handle a zero-length local ring.
  • The _launch_interp and _apply_tangential_transport paths act on the gathered global ring.
  • _conserve_composition: the rate is a collective integral.

Nits, not blocking:

  • _global_abs_max is defined between two import lines in free_surface.py. Moving it below the import block would read better.
  • The absolute 1e-12 coincidence test has an honest TODO.
  • Outside this PR, an empty rank prints RuntimeWarning: Mean of empty slice from Mesh._build_kd_tree_index. It is harmless here.

FreeSurface tests

The files were test_1070_free_surface_plume, test_1071_slcn_moving_mesh, test_1072_free_surface_spherical and test_1074_free_surface_config_drift, plus the new parallel file. All runs were on the branch.

run result skips
serial 15 passed, 2 skipped the new file, which needs np 3, and one test marked to need --with-mpi
np 2 16 passed, 1 skipped the new file, as designed

scripts/test.sh: the new np 3 line follows the existing pattern for test_1189_adapt_nvb_rank_without_cells_parallel.py. It sits under the supervisor, with the oversubscribe variable for Open MPI, inside the same shard. The enumerated tests/parallel batch at the default np 2 also collects the file and skips it, as it should. The line is right. It will fail until SAME is raised.

What was run, and what was not

Run:

  • Builds: the branch head a421d1c and the merge base eccae6d, as Python overlays on an existing build. That build's compiled sources (.pyx, .pxi, .pxd, .h, .c) are identical to the merge base's. The PR touches only Python and the test script.
  • Driver: the new test's model, run as a script for 5 steps, at np 1, at np 2, at np 3 with an empty rank and at np 3 without one, each twice. Development was run at np 3 with and without the empty rank.
  • Tests: the new test file at np 3 and np 2, and the FreeSurface tests serially and at np 2.
  • Setup: all runs used MPICH on 4 cores, with every parallel job under scripts/mpi_supervisor.py --silence 300 and an outer timeout.
  • The logs, the driver and the gathered surface arrays are kept by the reviewer.

Not run:

  • the new test file on development, because the same scenario was run as a script and hangs as described;
  • np 4 or more;
  • Open MPI;
  • the full test.sh suite;
  • the annulus or spherical free surface on an empty rank. The empty-rank fixture is a box only.

Underworld development team with AI support from Claude Code

…efore the step checked too

H1 measured the free surface at np 2 and 3 against serial (repeatable, so
partition dependence): before the step everything agrees to 1.6e-10; after
it the surface integral differs by up to 1.3e-5 (np 3, an empty rank),
widened by the carrier Poisson solve at its 1e-3 tolerance and the P1
velocity projection. The test now checks the state before the step at 1e-8,
which shows the empty rank changes nothing there, and after it at 1e-4, with
a comment giving the measurements.

Underworld development team with AI support from Claude Code
# Conflicts:
#	src/underworld3/systems/free_surface.py
@lmoresi
lmoresi merged commit c9c300e into development Nov 16, 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.

2 participants