25#ifndef PECLET_CORE_DECOMP_STAGE_TARGET_HPP
26#define PECLET_CORE_DECOMP_STAGE_TARGET_HPP
70 Index m = std::numeric_limits<Index>::max();
71 for (
const auto& s :
d.sizes())
72 for (
int k = 0;
k <
Dim; ++
k)
73 m = s[
k] <
m ? s[
k] :
m;
81 for (
const auto& s :
d.sizes()) {
83 for (
int k = 0;
k <
Dim; ++
k)
114template <
int Dim,
class Liftable>
117 for (
int d =
cur.treeDepth() - 1;
d >= 0; --
d) {
120 m.dec =
cur.agglomerated(
d, &
m.groupOf, &
m.ownerOf);
124 if (ok &&
minExtent > 0 &&
m.dec.numBlocks() > 1 &&
127 if (ok &&
m.dec.numBlocks() <
cur.numBlocks())
152template <
int Dim,
class Liftable>
158 throw std::invalid_argument(
"repartitionTarget: maxBlockCells must be positive");
161 for (
int k = 0;
k <
Dim; ++
k)
167 for (
int k = 0;
k <
Dim; ++
k) {
186 while (2 *
p2 <=
npL)
188 std::vector<Index>
tries;
191 for (
Index n =
p2; n >= 1; n /= 2)
198 t.dec = std::move(r);
199 t.ownerOf.resize(
static_cast<std::size_t
>(n));
200 for (
Index b = 0; b < n; ++b)
201 t.ownerOf[
static_cast<std::size_t
>(b)] =
static_cast<int>(b);
245template <
int Dim,
class Liftable>
250 throw std::invalid_argument(
251 "chooseStageTarget: levelGrid differs from the current decomposition's global size");
253 throw std::invalid_argument(
"chooseStageTarget: maxBlockCells must be >= 0 (0 disables)");
255 const std::size_t
nb =
cur.numBlocks();
262 t.ownerOf.resize(
nb);
263 for (std::size_t b = 0; b <
nb; ++b)
264 t.ownerOf[b] =
static_cast<int>(b);
271 t.dec = std::move(
m->dec);
272 t.ownerOf = std::move(
m->ownerOf);
273 t.groupOf = std::move(
m->groupOf);
281 return std::move(*r);
Index largestBlockCells(const BlockDecomposer< Dim > &d)
Cell count of the largest block — replicated, like the decomposition.
StageKind
How a multigrid level moves when it can no longer coarsen in place (see chooseStageTarget and the fil...
@ Repartition
a fresh proportional ORB of the level grid on the first np_L parent ranks
@ InPlace
no stage: the level coarsens on its current decomposition
@ SiblingMerge
ORB tree truncated: contiguous runs of blocks merge onto their lowest rank.
@ Replicated
the whole level as one block, held identically on every rank
std::optional< StageTarget< Dim > > repartitionTarget(const BlockDecomposer< Dim > &cur, const std::type_identity_t< IVec< Dim > > &levelGrid, Liftable &&liftable, int minExtent, Index maxBlockCells)
The Repartition candidate (design §11.2): a fresh proportional, unweighted, unaligned ORB of the leve...
std::optional< SiblingMergeChoice< Dim > > shallowestLiftableMerge(const BlockDecomposer< Dim > &cur, Liftable &&liftable, int minExtent)
The sibling-merge SEARCH on its own, with no trigger: the shallowest merge — fewest merges,...
Index minBlockExtent(const BlockDecomposer< Dim > &d)
Smallest block extent over every block and axis — replicated, like the decomposition.
StageTarget< Dim > chooseStageTarget(const BlockDecomposer< Dim > &cur, const std::type_identity_t< IVec< Dim > > &levelGrid, Liftable &&liftable, int minExtent, Index maxBlockCells=0)
Choose the stage target of a level whose current decomposition is cur over the level grid levelGrid (...
Kokkos::View< T *, MemSpace > View
1D device array.
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
A sibling merge the search chose: the tree depth it truncates at, the merged decomposition,...
std::vector< int > groupOf
current block -> merged block
std::vector< int > ownerOf
merged block -> lowest parent rank of its group
BlockDecomposer< Dim > dec
the merged decomposition
int depth
ORB tree depth the merge truncates at (agglomerated(depth))
Where a level goes: the result of chooseStageTarget / repartitionTarget.
BlockDecomposer< Dim > dec
The target decomposition, of the SAME level grid as the current one.
std::vector< int > groupOf
Current block -> target block. SiblingMerge only (agglomerated's groupOf); empty otherwise.
std::vector< int > ownerOf
Target block -> the rank that owns it, in the PARENT communicator (whose rank r owns block r of the c...
StageKind kind
which movement reaches dec