23#ifndef PECLET_CORE_DECOMP_STAGE_COMM_HPP
24#define PECLET_CORE_DECOMP_STAGE_COMM_HPP
73 std::swap(
sub,
o.sub);
74 std::swap(
kind,
o.kind);
107 throw std::invalid_argument(
"makeStageComm: an InPlace target has no stage");
108 int rank = 0, size = 1;
116 if (
t.groupOf.size() !=
static_cast<std::size_t
>(size))
117 throw std::invalid_argument(
118 "makeStageComm: groupOf must map every block of the current decomposition, one per rank");
119 const int myGroup =
t.groupOf[
static_cast<std::size_t
>(rank)];
120 const bool owner = (rank ==
t.ownerOf[
static_cast<std::size_t
>(myGroup)]);
126 for (
int b = 0; b < size; ++b)
127 if (
t.groupOf[
static_cast<std::size_t
>(b)] == myGroup)
129 if (c.
members.front() !=
t.ownerOf[
static_cast<std::size_t
>(myGroup)])
130 throw std::logic_error(
"makeStageComm: a group's owner must be its lowest rank");
132 const std::size_t
npL =
t.dec.numBlocks();
133 if (!
t.groupOf.empty() ||
t.ownerOf.size() !=
npL ||
npL < 1 ||
134 npL >
static_cast<std::size_t
>(size))
135 throw std::invalid_argument(
136 "makeStageComm: a Repartition target needs 1..size blocks, ownerOf per block, no "
138 for (std::size_t b = 0; b <
npL; ++b)
139 if (
t.ownerOf[b] !=
static_cast<int>(b))
140 throw std::invalid_argument(
141 "makeStageComm: a Repartition target's owners must be the identity on [0, np_L)");
142 const bool owner =
static_cast<std::size_t
>(rank) <
npL;
154 c.
members.resize(
static_cast<std::size_t
>(size));
155 for (
int r = 0; r < size; ++r)
156 c.
members[
static_cast<std::size_t
>(r)] = r;
int MPI_Comm_size(MPI_Comm, int *s)
int MPI_Comm_free(MPI_Comm *)
int MPI_Finalized(int *f)
int MPI_Comm_rank(MPI_Comm, int *r)
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.
StageComm makeStageComm(MPI_Comm parent, const StageTarget< Dim > &t)
Build the stage communicators for t on parent.
Kokkos::View< T *, MemSpace > View
1D device array.
The communicators of one coarse-level multigrid stage, made by makeStageComm (the file comment spells...
StageComm(const StageComm &)=delete
MPI_Comm sub
owners only, key = target block; MPI_COMM_NULL elsewhere
StageComm & operator=(const StageComm &)=delete
int myTargetBlock
the target block this rank owns, or -1
std::vector< int > members
Parent ranks of this rank's group, in group-comm order (owner first); empty for Repartition.
bool active
this rank owns a target block
StageKind kind
the kind of the StageTarget this was made for
StageComm & operator=(StageComm &&o) noexcept
Frees this object's own communicators first, then takes over o's.
StageComm(StageComm &&o) noexcept
Takes over o's communicators; o is left empty (all MPI_COMM_NULL, nothing to free).
MPI_Comm group
this rank's target block's members; owner = group rank 0
int myGroup
the target block this rank's current block moves into (-1: Repartition)