Skip to content

feat: reuse the halo geometry of kept patches, and Morton cuts weighted by cost - #73

Merged
max-models merged 10 commits into
develfrom
claude/tree-d3d-poison-maxwell-atyjic
Nov 25, 2026
Merged

max-models merged 10 commits into
develfrom
claude/tree-d3d-poison-maxwell-atyjic

Conversation

@max-models

@max-models max-models commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Halo geometry reused across regrids. HaloExchange keeps each patch's geometry on the hierarchy as a record: its copies and interpolation weights, with its fields named by patch key (level, box, ranks). Records are kept per centering, halo width, dtype and split, and regrid hands them to the new hierarchy. A patch reuses its record when it has the same box and ranks and the same patches within reach of its halo (same level) and of its interpolation (level below). Otherwise the geometry is found again as before. The halos are bit-identical to a fresh build; a test checks this for node and cell fields, serially and under MPI.
  • Morton cuts weighted by cost. regrid(..., placement="morton", cost=...) takes a per-cell cost per level, in units of one cell. A patch's weight is its cells plus the cost of its leaf cells (box_costs), and the base level's cost counts as each rank's starting load. morton_ranks(..., weights=...) cuts the curve by these weights. marker_counts gives the markers per cell of every level, summed over the ranks; marker_tags now uses it.
  • rebalance(cost). It places the patches of a hierarchy again along the weighted Morton curve and moves the fields. The base level stays where it is; the markers follow with migrate.
  • benchmarks/quadtree compares morton, markers under MPI and reports the marker imbalance. RESULTS.md has the new runs. The "Quadtree patches" tutorial shows the cuts with and without the markers.

Findings (RESULTS.md)

  • Reusing the halo geometry saves 7–34% of the halo time with quadtree blocks: block 8 296 → 274 ms, block 16 95 → 78 ms, block 32 43 → 28 ms. About a third of the patches still rebuild their geometry. Building the mpiarray.CopyPlan of each exchange is now the largest part, about 100 of 250 ms at 386 patches.
  • Weighting by markers lowers the marker imbalance on 4 ranks: block 8 1.26 → 1.16, block 16 1.35 → 1.24. The cell imbalance rises to 1.09–1.18. The step time doesn't change measurably at this marker count. In the tutorial's example the weighted cuts bring the cost per rank to 4742–4904, against 4113–5515 when cutting by cells.

Checklist

  • pre-commit run and pytest pass (728 passed locally; the quadtree tests also under mpirun -n 2/3/4)
  • New code has docstrings and tests
  • The docs (docs/, tutorials or README.qmd) are updated where the behaviour changed
  • The commit messages follow Conventional Commits (feat:, fix:, docs:, ...)

@max-models
max-models merged commit 326c79d into devel Nov 25, 2026
27 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.

1 participant