131static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
132 int lnx,
int lny,
int lnz,
int rank,
int size) {
133 std::vector<double> global;
135 global.assign(
GCELLS, 0.0);
136 for (
int r = 0; r < size; ++r) {
137 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
140 for (
int z = 0; z < lnz; ++z)
141 for (
int y = 0; y < lny; ++y)
142 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
143 (std::size_t)(z + oz) *
NX *
NY],
144 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
145 (std::size_t)lnx *
sizeof(
double));
149 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
150 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
151 }
else if (rank == 0) {
152 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
153 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
154 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
156 for (
int z = 0; z < meta[5]; ++z)
157 for (
int y = 0; y < meta[4]; ++y)
158 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
159 (std::size_t)(z + meta[2]) *
NX *
NY],
160 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
161 (std::size_t)meta[3] *
sizeof(
double));
220int main(
int argc,
char** argv) {
221 MPI_Init(&argc, &argv);
222 Kokkos::initialize(argc, argv);
225 int rank = 0, size = 1;
226 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
227 MPI_Comm_size(MPI_COMM_WORLD, &size);
229 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
230 auto blk = dec.block(rank);
231 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
232 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
233 const int gn[3] = {
NX,
NY,
NZ};
234 bool cut[3] = {
false,
false,
false};
235 for (
const auto& sz : dec.sizes())
236 for (
int a = 0; a < 3; ++a)
237 if ((
int)sz[a] != gn[a])
240 std::printf(
"DRAGBETA-GHOST MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n",
241 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
244 const Config configs[] = {
245 {
"per-z", 2,
false,
true}, {
"per-x", 0,
false,
false}, {
"cons-z", 2,
true,
true}};
248 for (
const Config& c : configs) {
249 if (c.needCut && size > 1 && !cut[c.comp]) {
252 " [%-6s np=%d] FAIL — the decomposition does NOT cut the forced axis %d; "
253 "this test exists to gate the drag_beta ghost ACROSS a rank boundary (WO-I)\n",
254 c.name, size, c.comp);
259 sd.initMpi(dec, MPI_COMM_WORLD);
261 std::vector<double> diagLocal;
262 for (
int it = 0; it <
STEPS; ++it) {
271 std::vector<double> gu[3];
272 for (
int comp = 0; comp < 3; ++comp)
274 const std::vector<double> gp =
279 const std::vector<double> gd =
gatherGlobal(diagLocal, ox, oy, oz, lnx, lny, lnz, rank, size);
284 for (
int it = 0; it <
STEPS; ++it)
286 double du = 0, umag = 0;
287 for (
int comp = 0; comp < 3; ++comp) {
288 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
289 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
291 const double dp =
maxAbsDiff(gp, ref.getPressure());
292 const double pmag =
maxAbs(ref.getPressure());
293 const double utol = (size == 1) ? 0.0 : std::fmax(1e-15, 1e-11 * umag);
294 const double ptol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * pmag);
295 bool ok = du <= utol && dp <= ptol;
299 const std::vector<double>& uf = gu[c.comp];
300 double lo = uf[0], hi = uf[0];
301 for (
double v : uf) {
302 lo = std::fmin(lo, v);
303 hi = std::fmax(hi, v);
305 const double spread = hi - lo, verr = std::fabs(0.5 * (hi + lo) - want) / want;
309 for (
int comp = 0; comp < 3; ++comp)
311 cross = std::fmax(cross,
maxAbs(gu[comp]));
312 const double pabs =
maxAbs(gp);
315 double dlo = gd[0], dhi = gd[0];
316 for (
double v : gd) {
317 dlo = std::fmin(dlo, v);
318 dhi = std::fmax(dhi, v);
320 const double wantDiag = (double)(
float)(
RHO0 /
DT +
BETA);
321 const bool diagOk = (dlo == wantDiag) && (dhi == wantDiag);
322 ok = ok && diagOk && spread <= 1e-13 * want && verr <= 1e-13 && cross <= 1e-13 * want &&
325 " [%-6s np=%d] du=%.3e dp=%.3e (tol %.1e/%.1e) | diag [%.17g, %.17g] "
326 "(want %.17g, worst plane %d) | u spread=%.3e (want 0) value=%.17g "
327 "(want %.17g) cross=%.2e max|P|=%.2e %s\n",
328 c.name, size, du, dp, utol, ptol, dlo, dhi, wantDiag,
worstPlane(gd, c.comp), spread,
329 0.5 * (hi + lo), want, cross, pabs, ok ?
"OK" :
"FAIL");
333 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
336 std::printf(
"DRAGBETA-GHOST MPI (np=%d): %s\n", size, fail ?
"FAIL" :
"PASS");
static constexpr double FORCE