|
peclet-dem 1.1.0
Performance-portable XPBD Discrete Element Method (Kokkos + ArborX)
|
The MPI-aware XPBD step (Simulation::step_mpi, see mpi.md) is correctness-complete and validated (tests/kokkos_mpi, np=1,2,4, closed + periodic) but at-scale multi-GPU tuning is the remaining roadmap work. On a single GPU, np>1 ranks share one device (the GPU contexts serialise and the wall-clock is contention-bound). This document is the plan for running and profiling on real multi-GPU hardware (one rank per GPU, single- or multi-node), where the design is meant to scale. It captures the prerequisites, launch recipes, what to measure, the profiling toolchain, and the optimisation backlog ranked by expected payoff.
The engine is header-only Kokkos + ArborX (CUDA retired); the backend (CUDA/HIP/OpenMP) is chosen by the extern/install/<backend> prefix the build is pointed at, not hard-coded. The profiling tools below assume the CUDA backend (nvidia-cuda prefix); for HIP use the ROCm equivalents (rocprof/omnitrace).
Read alongside: ../../core/docs/archive/cuda-aware-mpi.md (the CUDA-aware-MPI diagnosis & sysadmin ask), the "MPI / flow" section of ../../flow/CLAUDE.md (the Eulerian precedent), and ../../docs/ROADMAP.md Phase 4 / Phase 7.
The dem module calls Kokkos::initialize() (no args) at import, so each rank takes whatever device Kokkos selects by default — device 0 unless the environment restricts it. There is no set_cuda_device helper in the Kokkos module (that was a CUDA-era API). Bind each MPI rank to its own GPU by restricting visibility to the node-local rank before from peclet import dem:
Equivalent launcher binding: mpirun --map-by ppr:1:gpu (sets CUDA_VISIBLE_DEVICES per rank), or a wrapper script. Verify the mapping at startup — a silent fallback to a shared device 0 looks like a correctness pass but with zero speedup. (For HIP, use ROCR_VISIBLE_DEVICES.)
Use the system MPI, not ParaView's bundled one (it launches OpenMPI binaries as singletons): -DMPIEXEC_EXECUTABLE=/usr/bin/mpirun. Build the peclet.dem module with -DPECLET_DEM_MPI=ON against the bootstrapped backend prefix:
mpi4py must live in the same Python (the one suite ../.venv) as the peclet.dem module.
The stock /usr/bin OpenMPI is built without CUDA (device-pointer MPI segfaults). A user-space CUDA-aware stack (OpenMPI + UCX, both --with-cuda) is required for device→device transfers; see ../../core/docs/archive/cuda-aware-mpi.md for the build/runtime recipe. core's GridHalo device-pointer branch is runtime-gated on PECLET_CORE_GPU_AWARE_MPI (not MPIX_Query_cuda_support(), which mis-reports here). Bringing the peclet.dem particle halo's gather/scatter onto the device-pointer path (§5.1) is the remaining piece.
The mpi4py drivers in this directory each construct a dem.Simulation per rank and drive step_mpi:
tests/python/mpi/test_validate_exact.py and examples/bench_step.py read their own environment: M=sync_every (1=EXACT), R=forward_rotation (0 for spheres), PI/VI=the set_solver_iterations(pos, vel) counts. These are script arguments, not library knobs. The Kokkos tests/kokkos_mpi ctests are the primary correctness gate; the Python drivers are for at-scale throughput/observable checks.
| Experiment | Setup | Metric | Expectation |
|---|---|---|---|
| Strong scaling | fixed global N (e.g. 1e6), np = 1,2,4,8 | ms/step, speedup, parallel efficiency | near-linear until comm/halo dominates |
| Weak scaling | fixed N per rank (e.g. 2e5), grow np | ms/step ~ flat | flat = comm not growing with np |
| Comm fraction | per-step time split | gather + per-iter forward vs solve | shrinks with N/rank; sets the device-pack payoff |
| Ghost fraction | sim.num_ghost / owned | surface/volume ratio | drops as N/rank grows; drives redundant compute |
| M-knob sweep | M=1,2,4,8 | ms/step and mean‖dist−serial‖ | trade boundary error for fewer exchanges |
| Load balance | per-rank owned count + ms/step | max/mean | weighted-ORB split quality; imbalance caps speedup. Try rebalance_every=N |
Record alongside each run: np, N, N/rank, ghost fraction, cells (ORB cell grid), rcut, sync_every, forward_rotation, rebalance_every, GPU model, MPI build (CUDA-aware?), interconnect (NVLink/PCIe/IB).
A clean scaling story needs the comm fraction: instrument step_mpi (Kokkos::Profiling regions or MPI_Wtime) around (a) gather, (b) the per-iteration forwards, (c) the solver kernels, and reduce-max across ranks. That single breakdown tells you whether to spend effort on the device pack (§5.1), load balance, or larger blocks.
Keep the owner→ghost forward fully on-device: a gather kernel packs the owned records into a contiguous device buffer, MPI transfers it device→device (CUDA-aware), and received ghosts land directly in the contiguous ghost slab [num_real, num_real+num_ghost) (positions get a per-ghost shift kernel). This is the Kokkos counterpart of core's device GridHalo path; it is groundwork for real multi-GPU/multi-node — on a single shared GPU the per-transfer overhead beats the tiny host bounce, but across NVLink / GPUDirect RDMA it eliminates the D2H + network + H2D round trip. Build against the CUDA-aware MPI (§1.3) and gate on PECLET_CORE_GPU_AWARE_MPI.
Post the ghost forward asynchronously and compute the interior (owned particles with no ghost neighbour) while the halo is in flight, then apply the boundary. Needs an interior/boundary partition of the owned set (particles within rcut of the block edge). core's GridHalo already has the overlap-capable start()/wait() split to mirror.
step_mpi rebuilds the halo each substep. When the neighbour list is stable (small motion per step), skip the ParticleHalo::build() and reuse the correspondence for several substeps (rebuild on a skin-distance trigger). Saves the build round and the topology recompute.
For evolving packings, sweep enable_mpi_step(rcut, rebalance_every=N) (weighted-ORB SoA ownership migration via Sim.rebalance()): too-frequent rebalancing pays migration cost, too-rare lets imbalance cap speedup. Track per-rank owned-count max/mean alongside ms/step.
Ghost (surface) cost scales as $N^{2/3}$; larger blocks amortise comm. One fat rank per GPU beats many thin ones. Tune cells (init_mpi) so the ORB blocks are compact (low surface/volume).