Skip to content

global_evaluate: send an uncontained point only to the ranks whose cell box holds it - #1290

Merged
lmoresi merged 5 commits into
developmentfrom
perf/global-evaluate-neighbour-exchange
Nov 24, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
perf/global-evaluate-neighbour-exchange

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What changed and why

UNFILED 25, from the parallel review desk's review of #1258 (its low finding 2, and the optional finding 3).

#1258 made global_evaluate answer each point from a rank whose cell contains it: after the evaluation swarm's migration, each rank's points that none of its own cells contains were gathered to every rank (allgather), every rank tested all of them for exact containment, and each point went to the lowest rank that contains it. So each rank's work followed the global count of such points and grew with the rank count, and points just outside the domain (contained by no rank) were in that set on every call.

Now, in _hand_points_to_containing_rank (function/_function.pyx):

  • each rank's cell bounding box is gathered (two corners per rank, from the vertex coordinates of its cells; an empty rank's box is inverted and holds nothing);
  • each uncontained point is sent only to the other ranks whose box holds it (one all-to-all of points, one of the answers back);
  • the point goes to the lowest rank that contains it, as before; a point no rank contains stays where the migration put it, as before.

Why this is exact. Mesh coordinates are of degree 1 (#978), so a cell lies inside the box of its vertices, and a rank whose cell contains a point has the point inside its box. The boxes are widened by 1e-8 of the domain's extent, more than the containment test's rounding allowance (a barycentric coordinate down to -1e-12, or 1e-10 of a cell on non-simplex meshes), so a point that a cell accepts to rounding is asked about too. The widening only adds ranks to ask; the decision is still each rank's own exact containment test, and the tie-break (lowest containing rank) is unchanged.

Collectives. Every rank, including one with no cells or no points, reaches the box gather, both all-to-all exchanges, the reductions and the migration; they are guarded only by reduced counts. The previous count allgather is now one allreduce.

What a user's run sees: the same answers, bit for bit, at less cost where many points are not contained by the rank holding them.

Answers unchanged

A probe asks global_evaluate for eight point sets on each rank and saves each rank's answers: random and near-vertex points (1e-8 off) on #1123's sheared 3-D box; random, near-vertex (1e-9 off), just-outside (1e-6) and per-rank-different points on a 2-D box; points on the triangle with a rank that holds no cells; and zero points on every rank. Against development at np 2, 3 and 4: 72 of 72 rank-by-rank answer arrays are bit-identical.

Tests

Three cases added to tests/parallel/test_1178_global_evaluate_seam_ownership_parallel.py (level 2, tier B), as the review asked:

  • test_a_rank_with_no_cells_takes_part_and_every_point_is_exact (the empty-rank triangle fixture; exact linear field to 1e-12);
  • test_every_rank_asking_for_no_points_returns_nothing;
  • test_points_just_outside_keep_the_face_tolerance_answer_on_every_rank (1e-6 outside; the clamped answer within a few times |grad f| times the distance, 3.0e-6 measured, and every rank's answer identical).

They pass on development too: this change is not meant to alter any answer, so they pin behaviour rather than fail first.

Cost

global_evaluate of a P1 field, slowest rank, best of three; 2-D box cell 1/64, 3-D box cell 1/12 (the review's meshes); "tested" is the number of points a rank tests for containment in the hand-over (before: every rank tests the whole gathered set). Before = #1258's code; after = this branch. np 4:

case before after tested per rank, before → after (max)
2-D, 1e4 random 0.050 s 0.047 s 0 → 0
2-D, 1e6 random 3.085 s 3.050 s 22 → 8
2-D, 1e5 near vertices (1e-9) 0.322 s 0.317 s 3,050 → 961
2-D, 1e5 just outside (1e-6) 0.874 s 0.691 s (−21 %) 100,000 → 0
3-D, 1e4 random 0.098 s 0.090 s 0 → 0
3-D, 1e6 random 6.413 s 6.567 s 26 → 16
3-D, 1e5 near vertices (1e-9) 0.676 s 0.621 s 13,420 → 5,507
3-D, 1e5 just outside (1e-6) 1.898 s 1.597 s (−16 %) 100,000 → 0

Points just outside lie in no rank's box, so they are no longer sent anywhere. Random points differ within run-to-run noise. The rest of #1258's overhead is the first containment walk of every held point (the review's finding 1), which this does not change.

Not measured: np 8 and np 12. Those runs were not made within this session's core allowance on a shared machine. Before, the tested set per rank was the global count, so it grew with the rank count; after, it is the points within a rank's box, which does not. The table's "tested" column is where that shows, and it would be the thing to confirm at np 8 and 12.

Review fold-in

The parallel review desk found the 1e-8 × extent widening narrower than the cell-wall containment test's absolute rounding slab (a few times 1e-14) on domains under about 5e-6 across: on a quad box 1e-6 across, points a cell contained to rounding were not routed to that cell's rank, and came back up to 0.12 off. The widening now has a floor of 1e-12, ten times the largest distance that test accepts. New test test_points_just_outside_a_tiny_box_are_answered_by_the_cell_that_contains_them: fails at np 2 and 4 before the floor, passes on development and on this head (np 1 to 4). The docstring also says what the box holds on a 2-manifold.

What was run

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

What Result
the probe, np 2, 3, 4, against development 72 of 72 rank answer arrays bit-identical
test_1178 file, serial and np 2, 3, 4 7 passed on every rank
10 parallel evaluate, locator and points-in-domain files (0682, 0785, 0786 outside-domain, 0795, 0960, 1075, 1076, 1123, 1213, 1249), np 2 and np 4 all pass
16 serial evaluate and locator files 192 passed, 3 skipped
collective guard scan 20 passed
scripts/check_test_coverage.py OK, 505 files reachable

Not run

np 5 and above; the full suite; macOS; manifold or curved-coordinate meshes (the box argument rests on degree-1 coordinates, which every mesh has today, #978).

Underworld development team with AI support from Claude Code

…nts just outside

Coverage asked for in the parallel review desk's review of #1258. These pass
on development too: the change that follows is not meant to alter any answer.

Underworld development team with AI support from Claude Code
…ll box holds it

The hand-over of #1258 gathered every rank's uncontained points to every rank,
so each rank's work followed the global count of such points and grew with the
rank count; points just outside the domain were in that set on every call.
Now each rank's cell bounding box is gathered (2 x cdim numbers per rank), each
point goes only to the ranks whose box (widened by 1e-8 of the domain extent)
holds it, and the claims come back by a second all-to-all. A rank whose cell
contains a point has it inside its box, so the lowest containing rank is the
same as before.

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

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

120aff9, np 1 to 4: ready to merge on green from this review. Every answer I compared matches development bit for bit, except in one constructed case on a domain 1e-6 model units across (finding 1). The hand-over now tests far fewer points, and the cost falls as the PR says. np 8 and 12 will follow in a separate comment.

How it was run

  • The PR was built fresh at 120aff9. All 12 compiled modules are newer than the build start, and _local_cell_box is in the built _function module.
  • "Development" means the merge base 8bdc52f. I used an existing build whose compiled sources (.pyx, .pxd, .pxi, .h, .c, setup.py) match 8bdc52f exactly, and laid 8bdc52f's Python over it. Every run printed underworld3.__file__ to confirm which build it used.
  • Ranks were pinned to 4 cores, with at most 4 processes at a time, under the MPI supervisor. Other jobs on the machine were using other cores, so timings have some noise; I repeated the np 4 timings.
  • 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 meshes from a DM or with UnstructuredSimplexBox, so I ran it on the default partition. Its new empty-rank case makes its own rank with no cells.

Results

Answers: PR against development

Each rank asks its own permutation of the same point sets, saves its answers in the set's order, and the saved arrays are compared bit for bit between the two builds.

probe meshes runs per build rank arrays identical
case probe from the #1258 review: interior vertices, edges and faces, those moved off by 1e-9 to 1e-4, boundary vertices and edges, points pushed 1e-8 to 5e-2 in and out, 1,000 duplicates, random points; P1 and P2 fields tri, quad, tet and sheared-tet boxes 13 per mesh: np 1; np 2, 3, 4 on default, band and rand7; np 3 emptyband; np 3 with one rank asking for no points (with and without emptyband) 3,180 of 3,180
#1178 seam probe: sheared 3-D box, 292 points 1e-8 to 1e-4 off interior edges sheared tet np 1; np 2, 3, 4 on default, band and rand7; np 3 emptyband 124 of 124 (worst error 1.8e-15 on both builds)
curved boundaries: points in cells and on cell edges (moved 1e-9, 1e-6 and 1e-4 off), and points on the true circle or sphere and up to 1e-3 either side of it; P1 and P2 Annulus (r 0.5 to 1), SphericalShell (r 0.5 to 1), SphericalManifold (r 1) 12 per mesh: as above, plus np 3 with one rank asking for no points 1,292 of 1,292
points pushed outward by 0 to 1,000 w from boundary vertices where two ranks meet (w = 1e-8 × extent, the PR's widening) tri, quad and tet boxes of size 1; quad and tri boxes of size 1e-6 np 1; np 2, 3, 4 on default and band 1,276 of 1,330; the 54 that differ are all on the quad box of size 1e-6 (finding 1)
  • On the curved meshes the rank boxes overlap heavily. At np 4 on the default partition, each rank's box covers 25 to 28% of the annulus's bounding square, 37 to 44% of the shell's bounding cube, and 35 to 52% of the manifold's. With rand7, every box covers 99 to 100% of the domain's box, so every uncontained point goes to every rank, as on development.
  • The partition hook does not reach SphericalManifold: its band and rand7 runs used the default partition.
  • Points between the polygonal boundary and the true circle (or sphere) are in no cell. Both builds give them the same face-tolerance answer, bit for bit.
  • No point was evaluated on a rank whose cells do not contain it while another rank's cells do. On the PR this count is 0 in every case-probe run, as it was for global_evaluate answers each point from a rank whose cell contains it (#1178) #1258.
  • The PR's test file: 7 passed on every rank at np 1, 2, 3 and 4. The three new cases also pass on development, which is expected because the PR is not meant to change any answer.

Hand-over load: points each rank tests

I wrapped _hand_points_to_containing_rank and the mesh's _contained_in_local_cells, and counted the points each rank receives to test inside the hand-over. The mesh is a 2-D box with cellSize 1/64, or a 3-D box with cellSize 1/12. N = 1e5 points in total, split over ranks. The sets are:

  • seam: points on faces shared by two ranks' cells, moved 1e-9 off;
  • out: points 1e-6 outside the boundary;
  • far: points 5e-3 outside the boundary, past the face tolerance but within one cell size.

Each cell gives the largest per-rank count, with the sum over ranks in brackets.

dim np layout set development PR
2-D 2 default seam 49,877 (99,754) 25,010 (49,877)
2-D 4 default seam 49,914 (199,656) 15,534 (53,907)
2-D 4 band seam 50,324 (201,296) 21,331 (50,324)
2-D 2, 3, 4 both out, far 100,000 (np × 100,000) 0 (0)
3-D 2 default seam 49,839 (99,678) 24,952 (49,839)
3-D 4 default seam 49,811 (199,244) 21,417 (72,214)
3-D 4 band seam 50,134 (200,536) 15,415 (50,134)
3-D 2, 3, 4 both out, far 100,000 (np × 100,000) 0 (0)
  • On development every rank tests every uncontained point, so the per-rank count is the global count, and the sum grows as np × N.
  • On the PR, a seam point goes to the ranks whose box holds it. On band layouts that is exactly one other rank, so the sum equals the number of held points. On the default (graph) partition the boxes overlap more, so the sum is 1.0 to 1.45 times that (most in 3-D at np 4).
  • Points just or far outside go to no rank: the 1e-8 widening does not reach 1e-6. This matches the PR's "100,000 -> 0".
  • Random interior points: 0 to 4 per rank on both builds.
  • np 3 rows are in the logs and fall between the np 2 and np 4 rows. This is the figure to watch at np 8 and 12.

Cost

Each figure is the time for global_evaluate of a P1 field, on the slowest rank, taking the best of three calls. The meshes are as above, on the default partition. The np 4 rows are the range over several sets of three, interleaved between builds: three sets at 1e6, and four sets at 1e4.

dim N np set development (s) PR (s) change
2-D 1e4 1 rand / seam / out 0.063 / 0.069 / 0.187 0.062 / 0.063 / 0.186 noise
2-D 1e4 2 rand / seam / out 0.061 / 0.080 / 0.149 0.062 / 0.069 / 0.123 noise / -14% / -17%
2-D 1e4 4 rand / seam / out 0.043 / 0.064 / 0.100 0.044 / 0.057 / 0.082 noise / -11% / -18%
2-D 1e6 1 rand / seam / out 6.04 / 6.01 / 20.4 6.15 / 5.86 / 19.0 noise (within ±7%)
2-D 1e6 2 rand / seam / out 5.11 / 7.24 / 14.2 5.21 / 6.22 / 12.1 +2% / -14% / -15%
2-D 1e6 4 rand / seam / out 3.05-3.06 / 5.06-5.14 / 8.77-8.92 3.06-3.09 / 4.25-4.29 / 6.81-6.99 0% / -16% / -22%
3-D 1e4 1 rand / seam / out 0.112 / 0.109 / 0.510 0.118 / 0.112 / 0.495 noise
3-D 1e4 2 rand / seam / out 0.126 / 0.158 / 0.315 0.124 / 0.132 / 0.255 noise / -16% / -19%
3-D 1e4 4 rand / seam / out 0.090 / 0.127 / 0.212 0.091 / 0.110 / 0.167 noise / -13% / -21%
3-D 1e6 1 rand / seam / out 10.3 / 10.4 / 55.0 10.5 / 9.6 / 51.8 noise (within ±7%)
3-D 1e6 2 rand / seam / out 10.5 / 15.4 / 30.7 10.6 / 14.1 / 24.9 +1% / -8% / -19%
3-D 1e6 4 rand / seam / out 6.26-6.32 / 10.4-11.0 / 18.8-19.3 6.29-6.39 / 8.73-8.83 / 14.4-14.6 +1% / -16% / -23%
  • np 1 does not reach the new code (it returns on comm.size == 1). Its spread, up to ±7%, is the noise level.
  • Far-outside points: -8 to -15% at np 2 and 4.
  • Errors against the exact field are the same on both builds, from 8.9e-16 to 2.7e-13.
  • I agree with the PR's figures: about -21% (2-D) and -16% (3-D) for just-outside points, I measure -22 and -23%. Random points are unchanged.
  • The overhead on random points measured on global_evaluate answers each point from a rank whose cell contains it (#1178) #1258 (+10 to 16% at 1e6 on 4 ranks) is in both builds, so it does not show here. That overhead came from the extra exact walk, which this PR does not touch.

Collective safety

From the code:

  • Every rank reaches each collective: the reduced count of uncontained points, the box Allgather, the count Alltoall, the two Alltoallv calls, the reduced count of moving points, and the migration.
  • The only early returns depend on comm.size or on reduced counts.
  • An empty rank gets an inverted box, so it is sent nothing, and _contained_in_local_cells returns at once on a rank with no cells.
  • Counts and displacements are consistent. The coordinate exchange counts send_counts * cdim doubles, and the claim exchange counts recv_counts ints back the other way. The send buffer is grouped by destination: np.nonzero(inside.T) orders the pairs by rank. Displacements are left to mpi4py, which makes them contiguous. Empty arrays keep the shape (0, cdim).
  • The claim is that of the lowest rank, via np.minimum.at over the claiming pairs, as before.

Tested with no hang, on all four boxes and the three curved meshes:

  • one rank with no cells (np 3 emptyband);
  • one rank asking for no points (np 3);
  • both of these together on one rank (np 3, boxes);
  • all ranks asking for no points (np 2 and 4, and np 3 emptyband, boxes);
  • the PR's three new cases at np 1 to 4.

Neighbouring tests (PR build)

  • Parallel, at np 2 and np 4, all pass. These are the same 27 evaluate, global_evaluate, points_in_domain, swarm, advection and remap files as in the global_evaluate answers each point from a rank whose cell contains it (#1178) #1258 review, plus ptest_003, which exits 0. test_0780 needs 4 ranks, so at np 2 it skips.
  • Serial, 27 evaluate, function, remap and history files with 4 xdist workers: 283 passed, 1 skipped.
  • test_1086 starts its own mpirun, so I ran it alone at its 2- and 3-rank cases: 12 passed.

Findings

  1. Low: on a very small domain, the box widening is narrower than the cell-wall test's rounding allowance.
    • On a simplex mesh the containment test's allowance scales with the cell (1e-12 in barycentric coordinates), so it is always well inside the 1e-8 × extent widening.
    • The cell-wall path is used for quads, hexes and 2-manifolds. There, the allowance is an absolute slab of a few times 1e-14 model units. Measured: points 3e-14 outside are contained, points 1e-13 outside are not.
    • The widening falls below that slab when the domain is less than about 5e-6 model units across.
    • Constructed case: a 12 × 12 quad box 1e-6 across, so w = 1e-14. I placed points 1.1 w, 3 w and 3e-14 outside the boundary, at and near boundary vertices where two ranks meet, with a non-polynomial P1 field.
    • The cell that contains them to rounding is on a rank whose widened box does not hold them, so that rank is no longer asked. On development they take that cell's boundary value (within 2e-16 of the points exactly on the boundary). On the PR they fall to the face-tolerance path and are up to 0.12 off, at np 2, 3 and 4, on default and band layouts.
    • The same box at size 1, and the simplex boxes at both sizes, are bit-identical to development.
    • Suggested fix: give the widening a floor above that slab, for example max(1e-8 * extent, 1e-12). The docstring's "more than the containment test's rounding allowance" would then hold at every scale.
    • Not blocking: model domains this small are unusual.
    • Separately, and on both builds: at this size the face-tolerance answer is already 0.1 off for points 1e-13 outside, on quads and on simplices. That is not this PR's doing. I mention it because the same absolute control-point offset is behind both.
  2. Low: the box test uses temporary arrays of size (uncontained points × np × cdim).
    • inside is built from three boolean temporaries of that size.
    • At np 12 this is small. At np 1,000, with 1e5 just-outside points per rank, it is about 0.9 GB per rank.
    • A loop over ranks, testing all points against one box at a time, keeps memory at O(points), at the same cost.
    • Not needed for this PR. Worth a note if global_evaluate is expected at that scale.
  3. Low: the docstring says "a rank whose cell contains a point has the point inside that cell's box, so inside the rank's box". That is true for the cells the box is built from.
    • On a 2-manifold, _contained_in_local_cells also tests the one-cell overlap of the navigation DM, while _local_cell_box reads mesh.dm, which has no overlap.
    • The rank that owns such a cell is still asked, so the answer can only differ in which rank claims a point. On the sphere manifold the answers are bit-identical to development at np 2, 3 and 4, on the default partition (the partition hook does not reach this mesh).
    • A word in the docstring ("its own cells; on a manifold the owning rank's box") would keep the reasoning exact.

What was run and not run

  • Run, at np 1 to 4:
  • Not run:
    • np 8 and 12 (to follow);
    • the full suite;
    • the 4- and 5-rank cases of test_1086;
    • meshes with curved (degree 2) cells;
    • hex meshes, which take the same cell-wall path as the quads tested here.
  • The hand-over count probe works at any np. It is the same probe that will give the np 8 and 12 figures.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

…takes that cell's value

Fails at np 2 and 4 on 120aff9 (up to 0.14 off); passes on development.

Underworld development team with AI support from Claude Code
…-wall slab

1e-8 of the extent fell below the cell-wall containment test's absolute
rounding slab (a few times 1e-14) on domains under about 5e-6 across, so a
point a quad cell contained was not routed to its rank. The widening is now
max(1e-8 * extent, 1e-12). The docstring says what the box holds on a
2-manifold.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

The parallel review desk's two points, at ee9e711 (fix e9b4366, test 0eafbe0, then development merged):

  1. Widening floor. The widening is now max(1e-8 * extent, 1e-12) (_CELL_WALL_SLAB_FLOOR). The containment tolerance itself is not a usable floor: on simplices it is relative to the cell (well inside 1e-8 of the extent), and the cell-wall test's acceptance slab is set by rounding, a few times 1e-14 absolute (your measurement: 3e-14 accepted, 1e-13 rejected), so 1e-12 is ten times the largest distance it accepts. Test: test_points_just_outside_a_tiny_box_are_answered_by_the_cell_that_contains_them in tests/parallel/test_1178_global_evaluate_seam_ownership_parallel.py: a 12 x 12 quad box 1e-6 across, boundary vertices pushed 1.1e-14 and 3e-14 out, a non-polynomial P1 field; only the points some rank's cell contains are checked (selected by the containment test itself, reduced over ranks), against the field at the vertex to 1e-6. On 120aff9 it fails at np 2 and 4 (up to 0.14 off); on development (with global_evaluate answers each point from a rank whose cell contains it (#1178) #1258) it passes at np 1, 2 and 4; on this head it passes at np 1 to 4. Points contained by no cell are not checked: at this scale their face-tolerance answer is already about 0.1 off on development, as you noted, and is not this PR's. A simplex box is not in the test, since its containment allowance is relative and always inside the widening.
  2. Manifold word. The docstring now says the box is the rank's own cells, and on a 2-manifold, whose containment test also takes the navigation overlap, the owning rank's box.

Runs on the rebuilt head: the #1178 file 8 passed on every rank at np 1, 2, 3 and 4; 12 parallel files that call global_evaluate at np 2, 64 passed and 2 skipped on both ranks; coverage OK (517 files).

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit a72603b 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