90int main(
int argc,
char** argv) {
91 MPI_Init(&argc, &argv);
92 Kokkos::initialize(argc, argv);
93 int fail = 0, size = 1, rank = 0;
95 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
96 MPI_Comm_size(MPI_COMM_WORLD, &size);
98 const double gcells = (double)
N *
N *
N;
103 const peclet::core::decomp::BlockDecomposer<3> dec =
104 peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
N,
N,
N);
105 auto blk = dec.block(rank);
106 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
107 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
108 std::vector<double> lsdf((std::size_t)lnx * lny * lnz);
109 for (
int z = 0; z < lnz; ++z)
110 for (
int y = 0; y < lny; ++y)
111 for (
int x = 0; x < lnx; ++x)
112 lsdf[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] =
113 gsdf[(std::size_t)(x + ox) + (std::size_t)(y + oy) *
N +
114 (std::size_t)(z + oz) *
N *
N];
121 } CONFIGS[] = {{0,
false}, {9,
false}, {9,
true}};
122 for (
const auto& cfg : CONFIGS) {
123 const int mode = cfg.mode;
124 Colo sd(lnx, lny, lnz);
125 sd.initMpi(
N,
N,
N, MPI_COMM_WORLD);
129 for (
int it = 0; it < steps; ++it)
132 MPI_Allreduce(&lsum, &gsum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
133 const double k_dist =
MU * (gsum / gcells) /
F;
141 ref.setSolid(gsdf,
true);
142 for (
int it = 0; it < steps; ++it)
146 auto u = ref.getVelocity(0);
150 k_ref =
MU * (rsum / gcells) /
F;
152 MPI_Bcast(&k_ref, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
154 const double reld = std::fabs(k_dist - k_ref) / (std::fabs(k_ref) + 1e-30);
156 (size == 1) ? 1e-12 : 2e-5;
159 " [mode %d%s] k_dist=%.8e k_ref=%.8e rel=%.2e div=%.2e (np=%d, tol %.0e)\n", mode,
160 cfg.advect ?
" advect" :
"", k_dist, k_ref, reld, div_dist, size, tol);
161 if (reld > tol || !(div_dist < 1e-5))
166 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
169 std::printf(
"OK (np=%d): distributed collocated <u> == single-rank, every config\n", size);
171 std::fprintf(stderr,
"FAILED (np=%d)\n", size);
175 return totalFail == 0 ? 0 : 1;