70static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
71 int lnx,
int lny,
int lnz,
int rank,
int size) {
72 std::vector<double> global;
74 global.assign(
GCELLS, 0.0);
75 for (
int r = 0; r < size; ++r) {
76 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
79 for (
int z = 0; z < lnz; ++z)
80 for (
int y = 0; y < lny; ++y)
81 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
82 (std::size_t)(z + oz) *
NX *
NY],
83 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
84 (std::size_t)lnx *
sizeof(
double));
88 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
89 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
90 }
else if (rank == 0) {
91 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
92 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
93 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
95 for (
int z = 0; z < meta[5]; ++z)
96 for (
int y = 0; y < meta[4]; ++y)
97 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
98 (std::size_t)(z + meta[2]) *
NX *
NY],
99 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
100 (std::size_t)meta[3] *
sizeof(
double));
140int main(
int argc,
char** argv) {
141 MPI_Init(&argc, &argv);
142 Kokkos::initialize(argc, argv);
145 int rank = 0, size = 1;
146 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
147 MPI_Comm_size(MPI_COMM_WORLD, &size);
149 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
150 auto blk = dec.block(rank);
151 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
152 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
153 const int gn[3] = {
NX,
NY,
NZ};
154 bool cut[3] = {
false,
false,
false};
155 for (
const auto& sz : dec.sizes())
156 for (
int a = 0; a < 3; ++a)
157 if ((
int)sz[a] != gn[a])
162 "WALL-SLIP MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s "
163 "walls z = %.2f / %.2f z-blocks:",
164 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
165 cut[2] ?
"z" :
"",
Z0,
Z1);
166 for (
int r = 0; r < size; ++r)
168 " [%d,%d)", (
int)dec.block((std::size_t)r).origin[2],
169 (
int)(dec.block((std::size_t)r).origin[2] + dec.block((std::size_t)r).size[2]));
172 if (size > 1 && !cut[2]) {
175 " FAIL — the decomposition does NOT cut the walled z axis; this test exists "
176 "to gate the Navier closure across a rank boundary\n");
180 const double lambdas[] = {0.0, 0.1};
181 for (
double lam : lambdas) {
183 sd.initMpi(dec, MPI_COMM_WORLD);
185 for (
int it = 0; it <
STEPS; ++it)
187 std::vector<double> gu[3];
188 for (
int comp = 0; comp < 3; ++comp)
198 ref.setPressureBottomSolver(
199 std::is_same_v<peclet::flow::CCExec::memory_space, Kokkos::HostSpace> ? 0 : 2);
200 for (
int it = 0; it <
STEPS; ++it)
202 double du = 0, umag = 0;
203 for (
int comp = 0; comp < 3; ++comp) {
204 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
205 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
207 const double tol = (size == 1) ? 0.0 : std::fmax(1e-15, 1e-11 * umag);
212 const bool ok = du <= tol && aerr < 5e-6;
214 " [lambda=%.2f np=%d] du=%.3e (|u|=%.3e, tol %.1e) | analytic rel err "
215 "%.3e (tol 5.0e-06) %s\n",
216 lam, size, du, umag, tol, aerr, ok ?
"OK" :
"FAIL");
220 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
223 std::printf(
"WALL-SLIP MPI (np=%d): %s\n", size, fail ?
"FAIL" :
"PASS");
static std::vector< double > gatherGlobal(const std::vector< double > &local, int ox, int oy, int oz, int lnx, int lny, int lnz, int rank, int size)