Skip to content

perf(mpi): token protocol for the neighbour mesh exchanges - #477

Draft
gouarin wants to merge 1 commit into
hpc-maths:mainfrom
gouarin:mpi-comm-reduction
Draft

gouarin wants to merge 1 commit into
hpc-maths:mainfrom
gouarin:mpi-comm-reduction

Conversation

@gouarin

@gouarin gouarin commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
  • I have installed pre-commit locally and use it to validate my commits.
  • The PR title follows the conventional commits convention.
    Available tags: 'build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'
  • This new PR is documented.
  • This new PR is tested.

Description

Rebased on main after #490/#491.

The graduation half of this PR is dropped on rebase. #482 replaced the graduation fixed point by the single-pass algorithm, which exchanges one level array per level (exchange_level_mpi) and has no repeated identical send to elide - update_subdomains_mpi and the fixed-point loop the token protocol hooked into no longer exist. What remains here is the mesh-exchange half.

Every mesh construction serialized and sent the full mesh state to each neighbour three times (subdomain, cells, then the whole mesh with every derived mesh id) - even when the receivers already held identical data from the previous construction.

This PR replaces those exchanges by a token protocol: a one-int header announces whether the serialized payload follows; when it does not, the receiver keeps its cached copy of the neighbour's data. A sender only skips the payload when the receivers provably hold identical data:

  • mesh exchanges (update_neighbour_subdomain, update_meshid_neighbour, update_mesh_neighbour): cells geometrically identical to the reference mesh (same_cells, from perf(mesh): detect the adaptation fixed point before constructing the new mesh #476), same neighbour set and - for the whole-mesh exchange, whose derived ids depend on the neighbours' cells - a token received from every neighbour in the cells exchange. find_neighbourhood now carries the previously exchanged neighbour meshes over to the rebuilt neighbourhood; they are the receive-side cache.

The exchanges stay collective over the (symmetric) neighbourhood, so the communication pattern remains matched.

Measurements on advection_2d (Tf 0.1, Apple M, MPICH + libfabric, interleaved A/B vs #476), taken before the rebase, i.e. on the pre-#482 graduation and with both halves of the original change in place. They are kept for reference; the mesh-exchange half alone on today's main has not been re-measured:

Config before after
8 ranks, libfabric sockets provider 167 s 120 s (-28%)
8 ranks, FI_PROVIDER=tcp 7.6-7.7 s 7.4-7.5 s (-3%)
4 ranks 3.09-3.14 s 3.03-3.10 s (-2%)
serial parity parity

Tokens cut the payload volume, which pays hugely on expensive transports and grows with rank count and mesh size. On a sane transport at low rank counts, the remaining MPI cost of the adaptation loop is the number of synchronous exchange rounds - addressed in #478.

Related issue

None.

How has this been tested?

Outputs are unchanged by construction: a token replaces the payload only when the receiver already holds an identical copy.

Before the rebase (on the pre-#482 base):

After the rebase, the rebased branch is verified by CI.

Code of Conduct

By submitting this PR, you agree to follow our Code of Conduct

  • I agree to follow this project's Code of Conduct

@codacy-production

codacy-production Bot commented Jul 22, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -8 duplication

Metric Results
Duplication -8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@gouarin
gouarin force-pushed the mpi-comm-reduction branch 4 times, most recently from 14877b2 to c8be3ff Compare July 22, 2026 18:29
@gouarin gouarin changed the title perf(mpi): token protocol for the neighbour mesh and graduation exchanges perf(mpi): token protocol for the neighbour mesh exchanges Sep 1, 2026
Every mesh construction serialized and sent the full mesh state to each
neighbour three times - the subdomain, the cells, then the whole mesh
with every derived mesh id - even when the receivers already held
identical data from the previous construction.

Replace these exchanges by a token protocol: a one-int header announces
whether the serialized payload follows; when it does not, the receiver
keeps its cached copy of the neighbour's data. A sender only skips the
payload when the receivers provably hold identical data:

- cells geometrically identical to the reference mesh (the CellArray
  equality already used for the adaptation fixed point);
- the same neighbour set; and
- for the whole-mesh exchange, whose derived ids depend on the
  neighbours' cells, a token received from every neighbour in the cells
  exchange.

find_neighbourhood now carries the previously exchanged neighbour meshes
over to the rebuilt neighbourhood, which is the receive-side cache. The
empty-neighbourhood fast path moves into the shared helper, so it still
covers all three exchanges.

Outputs are unchanged by construction: a token replaces the payload only
when the receiver already holds an identical copy.

The graduation half of the original change is dropped on rebase: hpc-maths#482
replaced the graduation fixed point by the single-pass algorithm, which
exchanges one level array per level and has no repeated identical send
to elide.
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