include/pops/mesh/boundary/fill_boundary.hpp Source FileΒΆ
|
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
|
fill_boundary.hpp
Go to the documentation of this file.
44// NAMED FUNCTORS (not POPS_HD lambdas) for the halo-exchange kernels. Same reasons as the rest of the
45// elliptic/mesh path (#93, recipe #64): fill_boundary is first instantiated from the MG V-cycle pulled
46// from an external TU; an extended lambda there stalls device kernel emission under nvcc (-O Release
64// Pack of a send job: sb[b0 + c*rsz + off] = s(i - sx, jc - sy, c), off = (jc-lo1)*rnx + (i-lo0).
90// Enumerates the halo schedule for (mf layout, per, domain): the BoxHash build + the local (dst AND
91// src local) and, under MPI with n_ranks()>1, the global (cross-rank send/recv) job lists. This is
93// (layout, Periodicity, domain) and is then replayed from the cache. Jobs are produced in the SAME
179// Returns the cached schedule for (mf layout, per, domain), building and memoizing it on first use.
206 // writes/reads directly into them since pinned host is device-accessible; BUT the pointer passed to
207 // MPI is seen as HOST (cuPointerGetAttribute = HOST), so a CUDA-aware MPI (BTL smcuda) does NOT
208 // attempt CUDA IPC on it. A managed/UVM pointer, on the other hand, triggered IPC, which DEADLOCKS
209 // between two GPUs isolated by cgroup (srun --gpus-per-task=1: each rank sees only its GPU as device
220inline HaloExchange fill_boundary_begin(MultiFab& mf, const Box2D& domain, Periodicity per = {}) {
252 // c-major then (jj, ii), IDENTICAL to the old k++ order -> buffer bit-identical to the host path
253 // (the CPU MPI ctests stay bit-identical at np=1/2/4). The peer rank enumerates in the same order,
302 // device UNPACK (for_each) from the received PINNED HOST buffers. Waitall guarantees the transfer is
303 // complete; the kernel launched next reads the pinned host (device-accessible, coherent). Replayed
304 // from the SAME cached recv list begin used (h.sched), so base offsets match the sender's layout.
321 // The unpack kernels above are ASYNC (device) and read h.rbuf; comm_allocator (pinned host) frees
Box2D: the integer index space of a 2D cell-centered Cartesian grid.
BoxHash: spatial hash for fast lookup of boxes intersecting a query.
Single-grid data on a Box2D: VALID box + ng ghost layers, ncomp components, component-slow layout.
Definition fab2d.hpp:59
ConstArray4 const_array() const
READ handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:96
Array4 array()
WRITE handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:91
Small per-MultiFab cache of halo schedules, one entry per distinct (Periodicity, domain).
Definition halo_schedule.hpp:57
std::shared_ptr< HaloSchedule > add()
Appends a fresh, empty schedule and returns it for the caller to populate.
Definition halo_schedule.hpp:70
std::shared_ptr< const HaloSchedule > find(bool px, bool py, const Box2D &dom) const
Existing schedule for (px, py, dom), or nullptr if none is cached yet.
Definition halo_schedule.hpp:60
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
Fab2D & fab(int li)
Local fab at index li (0 <= li < local_size()), for writing.
Definition multifab.hpp:67
int local_index_of(int global) const
LOCAL index of the global box global, or -1 if it is not owned by this rank.
Definition multifab.hpp:75
HaloScheduleCache & halo_cache() const
Internal (ADC-260): memoized halo-exchange schedule used by fill_boundary.
Definition multifab.hpp:100
const BoxArray & box_array() const
GLOBAL decomposition of the level (all boxes, all ranks).
Definition multifab.hpp:56
Parallel seam: minimal MPI abstraction (rank/size + collectives) with serial fallback.
Fab2D: single-grid data on a Box2D (in-house equivalent of AMReX's FArrayBox); Array4 / ConstArray4: ...
for_each_cell and reductions: the parallelism SEAM over the cells of a Box2D; sync_host / sync_device...
HaloSchedule: memoized intra-level halo-exchange plan for fill_boundary (ADC-260).
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
void copy_shifted(Fab2D &dst, const Fab2D &src, const Box2D ®ion, int sx, int sy, int ncomp)
Definition fill_boundary.hpp:56
std::shared_ptr< const HaloSchedule > get_halo_schedule(const MultiFab &mf, const Box2D &domain, Periodicity per)
Definition fill_boundary.hpp:180
void build_halo_schedule(const MultiFab &mf, const Box2D &domain, Periodicity per, HaloSchedule &sched)
Definition fill_boundary.hpp:97
Definition amr_hierarchy.hpp:29
void for_each_cell(const Box2D &b, F f)
Applies f to EACH cell (i, j) of box b (bounds inclusive), via Kokkos::parallel_for (Serial / OpenMP ...
Definition for_each.hpp:138
void device_fence()
Device barrier: waits for in-flight kernels to finish before a HOST access to unified memory.
Definition kokkos_env.hpp:43
void fill_boundary(MultiFab &mf, const Box2D &domain, Periodicity per={})
BLOCKING halo exchange: begin then end immediately (no overlap).
Definition fill_boundary.hpp:333
void fill_boundary_end(MultiFab &mf, HaloExchange &h)
Phase 2 (blocking): MPI_Waitall on the transfers posted by begin, then unpacks the received buffers i...
Definition fill_boundary.hpp:297
HaloExchange fill_boundary_begin(MultiFab &mf, const Box2D &domain, Periodicity per={})
Phase 1 (non-blocking): does the LOCAL halo copies and posts the Isend/Irecv of the distant halos.
Definition fill_boundary.hpp:220
int suggest_bin(const BoxArray &ba)
Recommended bin size for a BoxArray: the largest box extent (at least 1), so that neighboring boxes f...
Definition box_hash.hpp:72
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
bool empty() const
true if the box contains no cell (hi < lo in one direction).
Definition box2d.hpp:58
Box2D grow(int n) const
Grows the box by n cells in ALL directions (uniform ghost layer).
Definition box2d.hpp:69
POPS_HD int nx() const
Width (direction 0). POPS_HD (called from Geometry::dx() in a device kernel).
Definition box2d.hpp:50
POPS_HD int ny() const
Height (direction 1). POPS_HD (called from Geometry::dy() in a device kernel).
Definition box2d.hpp:52
Box2D shift(int d, int s) const
Translates the box by s cells in direction d (lo and hi shifted by the same s).
Definition box2d.hpp:78
Box2D intersect(const Box2D &o) const
Intersection of the two boxes (possibly empty: hi < lo if they do not overlap).
Definition box2d.hpp:95
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Opaque state of an in-flight halo exchange, returned by fill_boundary_begin and consumed by fill_boun...
Definition fill_boundary.hpp:201
std::shared_ptr< const HaloSchedule > sched
Definition fill_boundary.hpp:202
Memoized schedule for ONE (Periodicity, domain) over a fixed layout.
Definition halo_schedule.hpp:40
Per-direction periodicity: halo wrapping in x and/or y during the exchange (false = open edge,...
Definition fill_boundary.hpp:37
Definition fill_boundary.hpp:48
POPS_HD void operator()(int i, int j) const
Definition fill_boundary.hpp:52
Definition fill_boundary.hpp:65
POPS_HD void operator()(int i, int jc) const
Definition fill_boundary.hpp:70
Definition fill_boundary.hpp:78
POPS_HD void operator()(int i, int jc) const
Definition fill_boundary.hpp:83
Generated by