17#ifndef PECLET_CORE_DECOMP_GRID_REDISTRIBUTE_HPP
18#define PECLET_CORE_DECOMP_GRID_REDISTRIBUTE_HPP
35 for (
int d = 0; d < Dim; ++d) {
38 const Index hi = ahi < bhi ? ahi : bhi;
50 Index stride = 1, idx = 0;
51 for (
int d = 0; d < Dim; ++d) {
52 idx += (gcell[d] - blk.
origin[d] + g) * stride;
53 stride *= (blk.
size[d] + 2 * g);
59 return size[0] * size[1] * size[2];
66 for (
Index z = 0; z < size[2]; ++z)
67 for (
Index y = 0; y < size[1]; ++y)
68 for (
Index x = 0; x < size[0]; ++x, ++n)
69 f(n,
IVec<3>{origin[0] + x, origin[1] + y, origin[2] + z});
84 int rank,
int g,
const std::vector<const T*>& oldFields,
85 const std::vector<T*>& newFields,
MPI_Comm comm) {
86 const int nF =
static_cast<int>(oldFields.size());
90 nbSelf =
static_cast<std::size_t
>(rank) < newDec.
numBlocks() ? newDec.
block(rank)
97 std::vector<Task> sends;
98 for (std::size_t d = 0; d < newDec.
numBlocks(); ++d) {
101 sends.push_back({
static_cast<int>(d), o, s});
105 for (
const auto& t : sends)
108 const Index si = detail::localFlat<3>(c, ob, g), di = detail::localFlat<3>(c, nbSelf, g);
109 for (int f = 0; f < nF; ++f)
110 newFields[f][di] = oldFields[f][si];
117 [&](std::vector<char>& out) ->
int {
118 while (si < sends.size() && sends[si].dst == rank)
120 if (si >= sends.size())
122 const Task t = sends[si++];
124 out.resize(
sizeof(
Index) * 6 +
sizeof(T) * cells * nF);
125 char* p = out.data();
126 std::memcpy(p, t.origin.data(),
sizeof(
Index) * 3);
127 std::memcpy(p +
sizeof(
Index) * 3, t.size.data(),
sizeof(
Index) * 3);
128 T* fp =
reinterpret_cast<T*
>(p +
sizeof(
Index) * 6);
130 const Index sidx = detail::localFlat<3>(c, ob, g);
131 for (int f = 0; f < nF; ++f)
132 fp[f * cells + n] = oldFields[f][sidx];
136 [&](int, std::vector<char>& msg) {
137 const char* p = msg.data();
139 std::memcpy(o.data(), p,
sizeof(
Index) * 3);
140 std::memcpy(s.data(), p +
sizeof(
Index) * 3,
sizeof(
Index) * 3);
142 const T* fp =
reinterpret_cast<const T*
>(p +
sizeof(
Index) * 6);
145 for (
int f = 0; f < nF; ++f)
146 newFields[f][di] = fp[f * cells + n];
Orthogonal recursive bisection of a Dim-dimensional global cell grid into numBlocks axis-aligned bloc...
Block< Dim > block(std::size_t b) const
Block b as (origin, size). Precondition: b < numBlocks() (unchecked).
std::size_t numBlocks() const
Number of blocks.
void exchange(PackNext &&packNext, OnRecv &&onRecv, int baseTag=0)
Index boxCellCount(const IVec< 3 > &size)
Index localFlat(const IVec< Dim > &gcell, const Block< Dim > &blk, int g)
bool intersectBox(const Block< Dim > &a, const Block< Dim > &b, IVec< Dim > &origin, IVec< Dim > &size)
void forBox(const IVec< 3 > &origin, const IVec< 3 > &size, F &&f)
void redistributeGridFields(const BlockDecomposer< 3 > &oldDec, const BlockDecomposer< 3 > &newDec, int rank, int g, const std::vector< const T * > &oldFields, const std::vector< T * > &newFields, MPI_Comm comm)
Redistribute nFields grid fields from oldDec to newDec (this rank = rank).
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
std::array< Index, Dim > IVec
Multi-dimensional integer index / coordinate (x-fastest order by convention).
A rank-owned axis-aligned block of the global cell grid.
IVec< Dim > size
extent in cells along each axis
IVec< Dim > origin
inclusive lower corner in global cell coordinates