|
peclet-dem 1.1.0
Performance-portable XPBD Discrete Element Method (Kokkos + ArborX)
|
Target: dem-momentum worktree, architecture for conserving momentum across rank boundaries when solving distributed contacts.
The shared contact solver runs the same modern sequence on both single-GPU and MPI paths.
Hertz–Mindlin driver hooks; halo topology rebuild at every pair-list rebuild (band = 2 R_max_global + skin), state-forward between rebuilds. Allreduce gates the collective rebuild schedule.
Band = (2.0 + skinFrac) * R_max_global (Allreduce MAX over ranks). Calls demStepForce with MpiForceHooks.
Kernel: solveVelocity, one thread per manifold.
Averaged apply (applyVelocityDeltasAveraged, l.233–253):
Cross-rank write behavior: Kernel atomically writes both bodies' deltas to their respective real indices (whether owner or ghost). Ghost slots' deltas are discarded at the next forward refresh; only owned rows are kept and integrated.
Kernel: solvePosition, one thread per contact (not manifold).
Ghost bodies: Position kernel writes to BOTH owned AND ghost slots (identified by raw body index idA, idB). Ghost deltas are discarded by applyUpdates after the colour sweep (only owned rows ∈ [0, numReal) are kept).
Graph: Vertices = body slots (owned + ghosts); edges = manifolds (bodyA, bodyB pairs).
Colour assignment: Greedy round-based max-index arbitration. No two manifolds sharing a body get the same colour. Colour class $C_i$ is an independent set → within a colour, RMW on sweeps is race-free.
Incremental carry (single-GPU only, gravity-gated): Surviving pairs carry colour across substeps; new manifolds arbitrate against them. Full recolour on MPI or first substep.
Leftover contacts (colour-mask saturation, degree > 62): Applied via Jacobi fallback with count-averaging.
Ghost participation: Ghosts participate in the colouring symmetrically. Their manifolds are coloured and swept; their deltas are atomically accumulated; deltas are then DISCARDED by selfMapReals (ghost slots map to themselves in realIndices, so updates land in ghost rows which are re-overwritten at the next gather/forward).
Message pattern: Uses core's ParticleHalo<3>::dev_.forward() — NBX (Neighborhood Collective MPI) on topology rebuild, persistent neighbourhood collective on state forwards. One forward per field type (F3 vs F4).
NO REVERSE (ghost→owner accumulate) operations in dem. Core's ParticleMigrator::migrate and ParticleHalo::gather are one-way (owner→ghost). Force/velocity deltas computed on ghost slots are DISCARDED; only owned rows are integrated.
Signature: hertzPairForces(pairs, np, pos, vel, angVel, rad, invMass, matId, pairMaterials, …, hertzE, hertzNu, dt, hertzXi, deltaVel, deltaAngVel)
Per-pair: Load positions, velocities, radii from the pairs array (both bodies by slot index). Compute Hertz contact stiffness (elastic moduli, contact radius). Apply normal spring force + Mindlin tangential history xi. Scatter forces (sign opposite) to both bodies' slots.
Hertz history: Keyed by gid-pair (pairKeyFromGids(gid_i, gid_j), l.76). Each owner tracks its half of paired history. On migration, MigratePack carries each particle's slice of the ledger (up to 14 pairs per particle in hertzPairEntry[kWarmCarryMax]).
Single-rank behaviour: Local slot indices ≡ gids (identity mapping) → history carries transparently. Under MPI, gid carries across halo rebuilds and ownership changes.
Ghost participation: Pair kernels atomically write forces to both bodies' deltaVel/deltaAngVel (owned or ghost slots). Ghost forces are cleared by zeroForceScratch (l.180–192) after integration; only owned rows are kept.
Scene:
The issue:
Validation: Run 4 substeps distributed vs MPI_COMM_SELF (global particle set, no halo). Compare per-particle positions by global id; tolerance 1e-4.
CMakeLists pinning (tests/kokkos_mpi/CMakeLists.txt:83):
"and the <tt>MPI_Allreduce(MAX)</tt> on every adaptive-stop residual (a rank-local break would desynchronise the collective refreshes and deadlock). Persistent-contact pair keys are built from <strong>global ids</strong>, so the ledger survives halo rebuilds and ownership migration, and <tt>MigratePack</tt> carries each particle's slice of it across a rebalance. The force-based engine has the same shape in <tt>src/solve_driver_force.hpp</tt> (<tt>SoloForceHooks</tt> / <tt>MpiForceHooks</tt>, Mindlin history keyed by gid). - <strong>Periodicity:</strong> cross-rank ghosts supply the wrap on <em>decomposed</em> axes; local periodic self-ghosts (the halo built with <tt>includePeriodicSelf</tt>) supply it on <em>undecomposed</em> periodic axes. @subsection autotoc_md360 The EXACT scheme + the <tt>sync_every</tt> (M) knob <tt>sync_every=1</tt> is <strong>EXACT</strong>: every owned particle has all its neighbours refreshed every iteration, so it reproduces the serial XPBD delta at np=1; at np=2/4 the rank-local sweep order of the colored PGS differs from single-rank, so agreement is statistical rather than bit-exact (numbers under <em>What is validated</em> below). <tt>sync_every=M\>1</tt> is an approximation — boundary error grows with M in exchange for fewer halo exchanges per step. <tt>forward_rotation=False</tt> skips the ghost quaternion forward and is <strong>exact for spheres</strong>. @subsection autotoc_md361 What is validated - <tt>tests/kokkos_mpi/</tt> — the distributed Kokkos <tt>demStep</tt>/<tt>rebalance</tt> ctests, run under <tt>mpirun</tt> at <strong>np=1,2,4</strong>, in both a closed (non-periodic) box and a fully-periodic lattice (the periodic case exercises the local periodic self-ghosts on undecomposed axes). Build/run (from the root tree): @icode{bash} cmake -S . -B build_dev -DCMAKE_PREFIX_PATH="<suite>/extern/install/<backend>" \ -DPECLET_DEM_MPI=ON -DPECLET_DEM_BUILD_TESTS=ON -DMPIEXEC_EXECUTABLE=/usr/bin/mpirun cmake --build build_dev -j && OMP_NUM_THREADS=1 ctest --test-dir build_dev -L mpi --output-on-failure @endicode (<tt>tests/kokkos_mpi</tt> also still configures standalone.) - <tt>tests/python/mpi/</tt> — the Python drivers on core's <tt>peclet.core.mpi</tt> + mpi4py, registered as the <tt>python_mpi_*_np{1,2,4}</tt> ctests (exit 77 = SKIP when that stack is missing): <tt>test_validate_exact</tt> (per-particle vs serial), <tt>test_validate_periodic</tt> (wrap through the split axes: 2-body, corner, N-body with resting straddlers), <tt>test_verify_distributed</tt> (elastic energy + settling-pack observables) and <tt>test_verify_rotating_drum_mpi</tt> (moving SDF wall + rebalancing). - np=1 agrees with the single-rank step to float noise (max 1e-4 over 15 steps). At np=2/4 the modern stack (processor-block Gauss–Seidel with rank-local colouring) sweeps the finite-iteration PGS in a different order than single-rank, so per-particle agreement on a stiff, randomly overlapping IC is <em>statistical</em> (measured 2026-09-08, N=200, 15 steps: mean 5e-3, 95 % quantile 4e-2, max 0.11 = a quarter diameter); resting wrap contacts agree exactly and the aggregate observables (energy, overlap, pile geometry) match to their tolerances. The C++ <tt>demstep_*</tt> ctests are the tolerance-based statement of the same thing."
Reach: Narrow phase reports pair at gap < margin, i.e. centre distance < r_i + r_j + margin. A body across the face can be ≤ 2 R_max + 0.1 R_max from the other. Both owners must see it.
Band: max(caller's rcut, 2.1 R_max_global) — if rcut < 2.1 R_max, it is widened.
Visibility: A cross-rank pair is visible to BOTH owners by design: the halo gathers ghosts in a band wide enough that both the owned and its cross-face partner sit within it. Each owner computes its body's delta locally; ghost updates are discarded.
Rebuild trigger: Ghost lists are rebuilt whenever the band changes (e.g., growth updates radius, or caller sets a larger rcut). tests/kokkos_mpi/test_ghost_band_mpi.cpp:band_change exercises this.
| File | Lines | Role |
|---|---|---|
| src/solve_driver.hpp | 923 | Main velocity + position solve driver; all phase hooks |
| src/step_solve_mpi.hpp | 207 | MPI substep choreography; MpiSolveHooks, MpiForceHooks |
| src/mpi_halo.hpp | 1009 | ParticleHalo gather, forward, topology, MPI schedule |
| src/solver_velocity.hpp | 1733 | Manifold velocity solves (Jacobi, coloured GS, PGS); impulse apply |
| src/solver_position.hpp | 562 | Contact position solve (overlap projection); impulse apply |
| src/contact_preprocessing.hpp | 611 | Contact→manifold reduction; pair key, persistent detect |
| src/solve_driver_force.hpp | 317 | Force-based DEM driver (Hertz–Mindlin); gid-keyed history |
| src/particles.hpp | 547 | Particle SoA structure; manifold/contact arrays |
| tests/kokkos_mpi/test_ghost_band_mpi.cpp | (see file) | Ghost band validation: 4 modes (np=1,2,4,8) |
| docs/mpi.md | (see file) | Distributed step specification & validation summary |
Total production: ~5909 lines C++; tests + docs additional.