|
peclet-dem 1.1.0
Performance-portable XPBD Discrete Element Method (Kokkos + ArborX)
|
MPI block-parallelism for the DEM/XPBD solver on the shared core library (sibling repo ../../core), mirroring the approach validated for flow (the Eulerian precedent). The Lagrangian counterpart to the Eulerian grid halo is particle migration (reassign particles to their owning rank) + ghost particles (copies within one interaction radius of a block boundary, so each rank's ArborX broad-phase runs locally), plus periodic load rebalancing (weighted-ORB SoA ownership migration).
The distributed step ships inside the peclet.dem Kokkos module as step_mpi, gated behind the PECLET_DEM_MPI build option (the default module never defines it, so the single-rank module stays byte-identical). This document is the status + how-to-build/run + what-is-validated for that step. The Python validation scripts it refers to live in ../tests/python/mpi/ (pytest files launched through mpirun, registered as ctests by -DPECLET_DEM_BUILD_TESTS=ON); the driver skeleton and the microbenchmark in ../examples/.
Build the peclet.dem module with MPI exposed, against the bootstrapped Kokkos prefix:
Python surface (gated; present only when built with -DPECLET_DEM_MPI=ON):
Every contact is solved by exactly one rank: the only owner that sees it, or, when both owners see it, the owner of its lower-gid body (for a periodic self-image twin: the twin whose real body has the lower gid). Each rank sweeps only the contacts it owns, writing the partner's half of every impulse into the partner's ghost slot. At every sync, each ghost's accumulated change is added onto its owner (core ParticleHalo::reverse) and the owners then republish their state (forward). Every impulse and every overlap correction is therefore applied once, equal and opposite: linear momentum and the centre of mass are conserved to round-off at any np, thread count and sync_every, and the velocity phase conserves angular momentum wherever the serial model does. sync_every=M sets how many sweeps pass between reconciliations: conservation does not depend on it; larger M means more lag at rank faces and fewer messages. Interior contacts keep the serial Gauss–Seidel order; a contact across a rank face sees its far body as of the last reconciliation. The fixed point every projection-form phase converges to is the coupled (serial) solution for any consistent copy count k (docs/contact_solve_framework.md §1.3 P4): run to a forced, generous iteration count with every adaptive stop disabled, np 2/4/8 converge to np 1 to the float floor. At the default, finite adaptive-stop budget, trajectories agree with single-rank statistically, not bit-for-bit (numbers under What is validated). forward_rotation=False skips the ghost angular-velocity and quaternion forwards (spheres).
Under Poisson (event-level) restitution two ranks can draw from one body's orphan account within one reconciliation interval; each active copy holds its share B/k of the owner's balance under mass splitting (Bodies updated in several places, below), the owner reduces the shares back to a single balance at every sync, and the clamp at 0 still applies (docs/mpi_momentum_conservation.md, R5; docs/contact_solve_framework.md §13.3).
The legacy friction pass stays a raw, count-averaged Jacobi sync, unaffected by the copies framework below because it runs after the phase's own reconciliation, on settled state: each rank counts only the contacts it owns, the ghosts' partial counts are summed onto their owners and forwarded back (syncFrictionCounts), and every copy of a body divides by the serial count. The 'jacobi' diagnostic (set_velocity_solver('jacobi')) is mass-split, not count-averaged: every contact is its own copy, solved against masses m/count (velocity and position both), and the true-mass deltas are summed with factor 1 — conservative like every other projection-form phase, unlike the min(1, 2/count) / 1/count count-averaged forms it replaced. The colouring's old count-averaged "leftover" fallback is gone with it: a colouring with edges still uncoloured after every vertex above 32 active edges has been split into local mass-split copies (docs/contact_solve_framework.md §4) throws an invariant violation on every rank, never silent fallback work.
A body written from more than one place during a substep — several ranks holding it, or (locally, even at np 1) more than 32 contact edges landing on it in one colouring — is represented by copies, and every contact's impulse is owned once, by exactly one copy (docs/contact_solve_framework.md §0–§5). Every projection-form update — warm-started PGS with cone and Poisson release, the overlap projection, every stabilization mode, the multilevel cycle, and the mass-split 'jacobi' diagnostic — mass-splits its copies (m/k, I/k, the exact active count k) and reconciles them by the mean at every sync: conservative at every iterate, with the coupled (serial) solution as its fixed point for any consistent k. The event-form g = 0 one-shot restitution sweep gets the opposite treatment, exclusive holding: a greedy rank colouring (C <= 64) picks exactly one holder rank per shared body each sync interval, only the holder's contacts fire, and the run is then a legal serial Gauss–Seidel order that inherits every serial property exactly, including conservation and each firing's non-increasing energy — mass-splitting the one-shot instead compounds restitution (measured: 14–18 % kinetic energy lost per substep on a dense cluster at e = 0.9/1.0) and is rejected. The Gauss–Seidel colourings never exceed 64 colours: a vertex above 32 active edges gets local mass-split copies, round-robin over its edges, and the phase is recoloured — the palette lemma then guarantees every colouring completes, so the old count-averaged fallback for an uncolourable leftover is gone. Visibility — every pair within contact reach seen by both bodies' owners — needs a ghost band of reach + S + P (S = 0.25 R_max drift slack, P the Verlet skin or else the substep's predicted displacement), a migration to current blocks whenever a body drifts more than S from its owner's block (voted inside the existing radius Allreduce, so no extra message), and every periodic image within that band, not just one.
| phase | form | policy | notes |
|---|---|---|---|
| Warm start | known impulses | applied on true masses before copies are seeded | none |
| One-shot restitution, g = 0 (colored GS) | event | X — one holder rank per sync interval; local hub copies mass-split (M) | reproduces serial to 0.03 % |
| PGS normal + cone + Poisson release, g != 0 | projection | M, ω_vel = 1 | |
| Stabilization (one-sided, escalate, ordered) | projection | M | |
| Multilevel: fine sweep + coarse cycle | projection + coarse accelerator | M; a folded hub's copies are one coarse vertex of mass a·m/k | |
| Legacy friction (g = 0, no gravity, or Jacobi A/B) | explicit Jacobi pass, raw sync | count-averaged (unaffected by copies) | single application point (midpoint); world-frame inverse inertia |
| Overlap projection (position phase) | accumulated, retractable projection (projected SOR on each contact's net push, ω_pos = 1.5; unique fixed point) | M | multi-point pairs solved as one unit |
| Poisson bank / orphan scatter | bookkeeping | true masses; credit only by the pair's owner | |
| 'jacobi' diagnostic | projection, mass-split | every contact its own copy, k = global contact count | |
| Hertz–Mindlin | explicit, redundant on both owners | unchanged; needs symmetric visibility + canonical pair orientation |
Validated (docs/contact_evidence/IMPL_A.md; gates G1 conservation, G2 energy, G5 visibility oracle, G6 race-freedom):
With rebalance_every=N (or an explicit sim.rebalance()), the decomposition is recomputed by particle count (weighted ORB) and SoA ownership is migrated — keeping per-rank work balanced as the packing evolves. See core's BlockDecomposer::init(..., weights) / DistributedOctree::rebalanceByParticleCount and ../../core/CLAUDE.md.
Co-rebalancing with the flow solver (peclet.coupling's CfdDem.rebalance()) goes through migrate_to_weights(w, align) instead: both codes build the partition from the same replicated weight field w (fluid work + gamma · particle count per ORB cell), so nothing but the split positions is shared. flow's diagnostics.rebalance_by_weights(w) picks an alignment 2^a for its pressure multigrid — every split plane on a multiple of 2^a cells, the largest a whose weight imbalance stays within 1.05 — and returns it; align= makes dem build exactly that partition (core's coarse-first aligned weighted ORB). The default align=1 is the plain weighted ORB. tests/kokkos_mpi/test_align_mpi.cpp checks dem's partition against flow's call, cell for cell, at np = 1, 2, 4, 8.
The original host-C++ bring-up harness (particle migration + the three ghost-exchange schemes A/B/C matched cell-for-cell to a serial reference) validated this machinery before it was wired into the module; it was retired at 1.0.0 (it targeted core's pre-peclet::core headers) and lives in git history before dem b43040c. Since 2026-09 the shipped step_mpi uses reverse reduction: owner-exclusive contacts plus a ghost→owner accumulation at every sync. The earlier "EXACT" variant solved each cross-rank contact on both owners, which is exact only for Jacobi-type deltas and broke momentum conservation under the Gauss–Seidel stack.
See multi_gpu_testing.md for the multi-GPU profiling/scaling playbook, ../../docs/ROADMAP.md (Phase 4 / Phase 7) and the "MPI / flow" section of ../../flow/CLAUDE.md for the Eulerian precedent.