Skip to content

global_evaluate answers each point from a rank whose cell contains it (#1178) - #1258

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/global-evaluate-exact-ownership-1178
Nov 20, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/global-evaluate-exact-ownership-1178

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

global_evaluate now answers each point from a rank whose cell contains it. This is the core evaluation path; the change is confined to which rank answers a point (the ownership claim). The interpolation itself, and the refusals before the migration, are unchanged. Fixes #1178.

The defect. The evaluation swarm's migration lets a rank keep a point that none of its cells contains, when the point is within the evaluation face tolerance (Mesh._EVAL_FACE_TOL, a slab of about 1e-5) of one of its cells. Near a partition seam the neighbour rank's cell contains that point. The keeping rank evaluated it in its own cell with the reference coordinates clamped onto the face, an error of about |grad f| times the point's distance from that cell. The parallel review desk measured, on #1123's sheared box with points 1e-8 to 1e-4 off interior edges: up to 2.1e-4, 1.0e-4 and 4.1e-4 at np 2, 3 and 4, where serial is 1.8e-15.

The fix (_hand_points_to_containing_rank in function/_function.pyx, called by global_evaluate_nd straight after its migration):

  • each rank finds the points it holds that no local cell contains, by exact containment (Mesh._contained_in_local_cells: the exact walk of Exact point location on simplex meshes: barycentric coordinates and a face-crossing walk (#1123, register row 14) #1175 on a simplex mesh, containment to rounding, _EVAL_CONTAIN_TOL, on other meshes);
  • those points are gathered, every rank tests them, and each goes to the lowest rank that contains it (a reduction, so the choice is the same on every rank and does not depend on which rank asked);
  • a point no rank contains (on or just outside the domain boundary) stays where the migration put it, under the face tolerance, as before;
  • every gather, reduction and the migration are reached by every rank, guarded only by reduced counts.

Mesh._robust_owning_cells and points_in_domain are not changed, so a swarm's own claims and the other callers of the face-tolerance claim are as before. (The parallel review desk's probe counts claims by _robust_owning_cells; that count is unchanged. What changes is which rank evaluates.)

What a user's run does now. In parallel, global_evaluate of a field at points near a partition seam returns the value from the containing cell, the same as serial to round-off, on every asking rank. Development returned a value from a neighbouring cell for some of them. This was not limited to sheared meshes: on a plain 3-D box (cell 1/20) with 1e6 uniform points at np 4, development's largest error for a linear P1 field is 1.5e-5; this branch gives 8.9e-16.

Test

tests/parallel/test_1178_global_evaluate_seam_ownership_parallel.py (level 2, tier B): the sheared box of sheared_box_fixture.py, a P1 field linear in x, y, z, one point on each of the 604 interior edges, moved 1e-8, 1e-6, 1e-5 or 1e-4 in a random direction. Every rank asks for every point. The baseline is exact: the element represents the field, so every value must equal it to round-off; the bound is 1e-12 (serial gives about 1e-15; a point evaluated in a non-containing cell is off by 1e-8 to 4e-4).

development (c58aaef) this branch
np 1 passes 4 passed
np 2 4 failed: 30 to 31 points per asking rank off, worst 3.3e-4 4 passed on both ranks
np 3 4 failed: 44 to 47 per rank, worst 3.0e-4 4 passed on every rank
np 4 4 failed: 48 to 57 per rank, worst 2.6e-4 4 passed on every rank

The file runs in the MPI phase of scripts/test.sh through the tests/parallel glob (coverage check: all 492 files reachable).

Cost

global_evaluate of a P1 field, N points in total spread over the ranks, uniform in a box; median of three calls, slowest rank (cost.py):

mesh N np 1 before → after np 4 before → after
2-D box, cell 1/96 1e4 0.100 → 0.083 s 0.049 → 0.053 s
2-D box, cell 1/96 1e6 8.21 → 6.91 s 3.53 → 3.50 s
3-D box, cell 1/20 1e4 0.132 → 0.140 s 0.097 → 0.096 s
3-D box, cell 1/20 1e6 12.81 → 11.78 s 7.12 → 6.61 s

At one rank the new step returns at once, so the np 1 differences are run-to-run noise. At np 4 the cost is not unchanged: the parallel review desk's measurements (best of three, repeated in interleaved sets; slowest rank) put the overhead at:

case, np 4 overhead
2-D, 1e6 random points +10 to 13 %
3-D, 1e6 random points +7 to 16 %
1e5 points 1e-9 off the partition seams +25 % (2-D), +33 % (3-D)
1e5 points 1e-6 outside the boundary +53 % (2-D), +69 % (3-D)
1e4 random points noise (2-D), +5 % (3-D)

My own np 4 table above does not show it; theirs, with more repeats, does, and theirs is the one to rely on. The extra work is one exact containment test of the points a rank already holds and a gather of the uncontained ones. Points just outside the domain are in that gathered set on every call, because no rank contains them, which is why they cost most. The gathered set goes to every rank, so it grows with the rank count; replacing it with a neighbour-only exchange is a follow-up. In return, the worst error at 1e6 points on 4 ranks drops from 2.2e-5 (2-D) and 3.6e-5 (3-D) to 1.3e-15 and 2.7e-15.

A second bug this fixes: the parallel MMPDE mover

The MMPDE mover evaluates through global_evaluate, so on development it read wrong values at partition seams too, and moved the mesh differently in parallel than in serial. On test_1152's split-level fixture at np 2, against a serial run (nodes matched to their nearest serial node):

after move development, np 2 this branch, np 2
1 nodes up to 3.4e-3 off serial; 16 zone cells differ 8.3e-8 off; 0 differ
2 3.2e-3; 16 differ 1.5e-4; 0 differ
3 4.9e-3; 35 differ 3.1e-3; 7 differ

(The growth over moves on this branch is the iterative mover's own drift.)

test_1152's split-level bound

test_1152_fac_zone_survives_a_mover_parallel.py::test_a_kept_zone_patch_matches_a_fresh_registration[zone_on_a_split_level] failed on this branch at np 2 on CI, (2, {'fresh': 17, 'kept': 19}). Velocity iterations, kept / fresh (zone recomputed), moves 1 to 3:

move 1 move 2 move 3
serial (this branch's new step does nothing on one rank) 18 / 17 17 / 17 18 / 18
np 2, development 19 / 19 19 / 19 20 / 19
np 2, this branch 19 / 18 19 / 17 20 / 19
np 2, this branch, a registration after the move with the kept solver's own mask 19 19 20

The kept count is the same on both builds; the fresh one moved to the serial value, because the zone it is recomputed from is now right. A registration with the kept solver's own mask takes exactly the kept count, so the kept solver carries nothing partition-dependent from before the move: the gap is the zone drift the patch is kept despite (the lead's ruling of 2026-11-10), which on development the inflated fresh count hid. The bound is now one iteration on one rank (unchanged) and two on several, with these counts in the test (03f2263). Whether the kept patch should cost one or two iterations more in parallel than in serial is a separate question for the custom multigrid.

What was run

On a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH):

What Result
the new test, np 1 to 4 as in the table above
12 parallel evaluate, locator and migration files (0785, 0786 far outside, 0795, 0960, 0999, 1075, 1076, 1093, 1123, 1183, 1213, 1249 non-finite), np 2 and np 4 all pass on every rank
16 serial evaluate and function files, with the collective guard scan and test_1123 177 passed, 1 skipped
scripts/check_test_coverage.py OK

#1249's non-finite refusal and the far-outside refusal run before the migration and are untouched; their tests (1249, 0786) pass at np 2 and 4.

Not run

Above np 4; a mesh with an empty rank in the new test (test_1076 covers global_evaluate with an empty rank and passes); the full suite; macOS.

For the parallel review desk (H1).

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9)
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4)
  • Every exception swallow states its sanctioned failure mode in a comment (S4) — none added
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7)
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • No mesh entity or rank identified by coordinates; any remaining tolerance is named, relative and says what it bounds (S12): ownership is by exact containment; the face tolerance now decides only points no rank contains
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Underworld development team with AI support from Claude Code

…ng rank (#1178)

On development at np 2, 3 and 4, 30 to 57 of 604 points per asking rank on
the sheared box are off the exact P1 field, by up to 3.3e-4.

Underworld development team with AI support from Claude Code
)

After the evaluation swarm's migration, the points a rank holds without any
local cell containing them are gathered, every rank tests them for exact
containment, and each goes to the lowest rank that contains it. A point no
rank contains keeps the face-tolerance claim. The interpolation is unchanged.

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

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.)

6ac2ff5: ready to merge on green from this review. The fix does what it says at every rank count and layout tried. Finding 1 (cost) does not block, but the PR text should be corrected.

How it was run

  • The PR was built fresh at 6ac2ff5. All compiled modules were newer than the build start, and the new function is in the built _function module.
  • "Development" means the merge base c58aaef. It used a build whose compiled sources match c58aaef exactly, with c58aaef's Python laid over it. Every run printed underworld3.__file__ to confirm which build it used.
  • Ranks were pinned to 4 cores, at most 4 processes at a time, under the MPI supervisor.
  • Layouts: the default partition, plus a shell partition hook on gmsh meshes. "band" puts cells in horizontal bands by rank. "rand7" assigns cells at random (seed 7). "emptyband" uses bands over np-1 ranks, so the last rank has no cells.
  • The PR's own test builds its mesh from a DM, not gmsh, so the hook does not reach it. It ran on the default partition only.

Results

The #1178 probe from the earlier sweep

The mesh is the sheared 3-D box (cellSize 1/6) with a P1 field linear in x, y and z. The probe uses 292 points at offsets 1e-8 to 1e-4 from interior edges. Every rank asks for every point. The table gives the worst error against the exact field.

np layout development PR
1 - 1.8e-15 1.8e-15
2 default / band / rand7 2.1e-4 / 8.7e-5 / 6.4e-4 1.8e-15 for all
3 default / band / rand7 1.0e-4 / 6.4e-4 / 4.7e-4 1.8e-15 for all
3 emptyband 8.7e-5 1.8e-15
4 default / band / rand7 4.1e-4 / 2.1e-4 / 6.4e-4 1.8e-15 for all
  • On development, 15 to 168 points per asking rank are wrong at each offset.
  • On the PR, no point is wrong, and the ranks agree exactly.
  • _robust_owning_cells still reports points claimed by two or more ranks (132 at np 4 band). That is expected: the PR changes who evaluates a point, not who claims it.

The PR's new test

np development PR
1 4 passed 4 passed
2 4 failed: 30-31 of 604 points per rank, worst 3.3e-4 4 passed
3 4 failed: 44-47 points, worst 3.0e-4 4 passed
4 4 failed: 48-57 points, worst 2.6e-4 4 passed

This matches the PR's description.

Seam, edge, vertex and boundary cases

I wrote a separate probe for these. Each rank asks for its own permutation of the same point sets, and the answers are put back in the original order before they are compared. The point sets are:

  • interior vertices, including those shared by 3 or more ranks (at np 4: 2 to 9 such vertices on the default partition, and 62 to 133 with rand7);
  • points on interior edges, and on interior faces in 3-D;
  • those points moved off by 1e-9, 1e-6, 1e-5 and 1e-4;
  • boundary vertices and boundary edges, including those at a seam;
  • boundary points moved inward and outward by 1e-8 to 5e-2;
  • 1,000 copies of 20 seam points, to test identical coordinates;
  • 3,000 random interior points.

The probe evaluates a P1 field (linear) and a P2 field (quadratic) on four meshes. Both fields are exact in the element:

  • tri2: 2-D simplex box, cellSize 1/12;
  • quad2: 2-D quad box, 12 x 12. This mesh takes the non-walk containment path;
  • tet3: 3-D simplex box, cellSize 1/6;
  • shear3: the tet3 box after the sheared map.

The table gives the worst difference from np 1 over the inside sets, taking the worst of the default, band and rand7 layouts. In brackets is the number of point answers off by more than 1e-12, summed over ranks.

mesh np development PR
tri2 2 / 3 / 4 3.4e-5 (1562 / 3418 / 5403) 8.6e-14 or less (0)
quad2 2 / 3 / 4 2.6e-5 (1313 / 2755 / 3538) 2.1e-13 or less (0)
tet3 2 / 3 / 4 6.6e-5 / 9.3e-5 / 8.0e-5 (9662 / 19645 / 30145) 9.5e-13 or less (0)
shear3 2 / 3 / 4 1.3e-3 (6297 / 13172 / 20292) 3.8e-13 or less (0)
all four 3 emptyband 2.0e-5 to 2.9e-4 4.4e-16 to 2.0e-13 (0)
  • The serial round-off on these sets is 8.5e-14 (tri2) to 9.5e-13 (tet3, boundary vertices, P2). The PR stays within it everywhere.
  • Development is wrong in 2-D as well, and on quads, not only on the sheared 3-D box.
  • On development, even points exactly on interior edges and vertices are off by about 1e-10 in 3-D.
  • The shear3 row leaves out three kinds of points. These are boundary points and face points moved 1e-4 off the face. My own map puts some of them a hair outside the mesh, so neither build gives the exact value there. Those points give the same answers on both builds to within 8e-4 (development's own spread).

Points no rank contains keep the face-tolerance claim. On tri2 and tet3, the outward sets (1e-8 to 5e-2 outside) give bit-identical answers on the PR and on development. This holds at np 2, 3 and 4 for every layout, emptyband included. Both differ from serial by up to 0.2 there. That is the existing extrapolation, and it is unchanged.

Every point is evaluated exactly once, and where it is contained. I wrapped evaluate_nd in the main pass to count points and to check each against an independent barycentric (or box) test on the gathered cells.

  • On both builds, the count of evaluated points equals the count of points asked, in every run.
  • On development, up to 61,358 point evaluations per run happen on a rank whose cells do not contain the point while another rank's cells do.
  • On the PR this count is 0 in every run, on all four meshes.

Result order. Each rank's answers, put back in its own order, match np 1. So the order returned to the caller is unchanged.

Collective safety

Reading the code:

  • _hand_points_to_containing_rank returns early only on comm.size == 1, or on reduced values (total, and the reduced count of moving points). These are the same on every rank.
  • _contained_in_local_cells returns early on a rank with no points or no cells, but it holds no collective. The kd-tree build and SimplexLocator are rank-local, so skipping them on one rank cannot desynchronise.
  • The ordering is allgather (counts), allgather (coordinates), Allreduce (MIN owner), allreduce (moving count), then migrate. Every rank reaches each of them.

Tested, on all four meshes, with no hang and correct answers:

  • one rank with zero query points (np 3);
  • one rank with no cells (np 3, emptyband);
  • a rank with no cells that also asks for no points (np 3);
  • all ranks asking for zero points (np 2, np 4, and np 3 emptyband).

Other checks

  • Far outside: test_0786 passes at np 2 and 4.
  • Non-finite points: test_1249 passes at np 2 and 4.

Cost

The probe times global_evaluate on a P1 field, taking the slowest rank. Meshes: 2-D cellSize 1/64, 3-D cellSize 1/12. Each figure is the best of three repeats. The 1e6 np 4 cases had two more sets of three, interleaved between builds. The ranges below cover all of them.

case development (s) PR (s) change
2-D, 1e4 random, np 1 0.074 0.071 noise
2-D, 1e4 random, np 4 0.044 0.048 noise
2-D, 1e6 random, np 1 6.40 6.46 noise
2-D, 1e6 random, np 4 2.71-2.80 3.05-3.09 +10 to 13%
3-D, 1e4 random, np 1 0.119 0.118 noise
3-D, 1e4 random, np 4 0.088 0.092 +5%
3-D, 1e6 random, np 1 10.51 10.61 noise
3-D, 1e6 random, np 4 5.92-6.01 6.40-6.90 +7 to 16%
2-D, 1e5 points 1e-9 off band seams, np 4 0.54 0.68 +25%
3-D, 1e5 points 1e-9 off band seams, np 4 1.00 1.33 +33%
2-D, 1e5 points 1e-6 outside the boundary, np 4 0.77 1.17 +53%
3-D, 1e5 points 1e-6 outside the boundary, np 4 1.44 2.44 +69%

The 1e6 np 4 runs also show the gain: the worst error drops from 2.2e-5 (2-D) and 3.6e-5 (3-D) on development to 1.3e-15 and 2.7e-15 on the PR.

Neighbouring tests (PR build)

  • Parallel, at np 2 and np 4, 27 files, all pass. These are the evaluate, global_evaluate, points_in_domain, swarm, advection and remap files:
    • 0682, 0700, 0756, 0760, 0765, 0766, 0768 (remap), 0775, 0780, 0783, 0785, 0786, 0795, 0796, 0873, 0960, 0999, 1062, 1075, 1076, 1077, 1093, 1123, 1178, 1213, 1243, 1249.
  • ptest_003 (swarm projection, a script) exits 0 at np 2 and 4 on both builds.
  • Serial, 28 evaluate, function, remap and history files, with 4 xdist workers: 295 passed, 1 skipped, 1 failed, 7 errors.
    • The failure and the errors are all in test_1086_mmpde_seam_matches_serial. That file launches its own mpirun, and under 4 workers on 4 cores it timed out at its 120 s supervisor limit.
    • Run alone, without xdist, at its 2-, 3- and 4-rank cases, it gives 18 passed on the PR and 18 passed on development. Its 5-rank cases were left out to keep to 4 cores.

Findings

  1. Medium: the cost is not unchanged at 1e6 points on 4 ranks.

    • The PR says cost is unchanged within noise at 1e4 and 1e6, np 1 and 4. I agree at 1e4 and at np 1.
    • At 1e6 on 4 ranks I measure +10 to 13% in 2-D and +7 to 16% in 3-D, across three interleaved sets of repeats.
    • Points near seams cost more (+25 to 33%). Points just outside the domain cost the most (+53 to 69%): no rank contains them, so they are gathered and tested on every call.
    • The likely cause: every held point gets an extra exact walk in _contained_in_local_cells, and then evaluate_nd locates it again. Every not-contained point is also sent to every rank and walked there.
    • Possible follow-ups:
      • Keep the cells from the first walk and hand them to the evaluation.
      • Skip the second walk for points whose holding rank found them contained.
    • This does not block. The correctness gain is large, and global_evaluate is not usually the dominant cost. But the PR text should give the measured overhead.
  2. Low: the gathered set grows with the rank count.

    • comm.allgather of the not-contained coordinates sends every such point to every rank, and each rank walks them all. So the work per rank is in the global count of such points, not the local count.
    • Points just outside the boundary are in this set on every call. The existing fallback block then gathers them again.
    • At np 4 this is the +53 to 69% above. I did not measure above np 4.
    • A targeted exchange (send each point only to ranks whose bounding box holds it) would bound this. A note in the docstring would do for now.
  3. Low: the new test covers only the default partition, with every rank asking for every point.

What was run and not run

  • Run:
  • Not run: above np 4; the full suite; manifold (surface) meshes; meshes with curved (degree 2) coordinates; the 5-rank cases of test_1086.
  • Manifold and curved meshes take the cell-wall containment path, as quads do, and that path was exercised only on the quad box.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

claude and others added 2 commits November 20, 2026 20:39
On one rank the kept patch stays within one velocity iteration of a fresh
registration. At np 2 it takes 19, 19, 20 against 18, 17, 19 for the
recomputed zone, and exactly the count of a registration made after the
move with its own mask, so the gap is zone drift, not state carried from
before the move. Before this branch the parallel mover moved the mesh up to
3.4e-3 off the serial one and inflated the fresh count, which hid the gap.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit 233d3c4 into development Nov 20, 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