43static void printRows(
const char* tag,
const std::vector<Row>& rows) {
44 for (std::size_t L = 0; L < rows.size(); ++L) {
45 const Row& r = rows[L];
47 " %s L%zu global %3dx%3dx%3d ranks %2d block0 %3dx%3dx%3d ratio(%d,%d,%d)%s\n", tag,
48 L, r.global.x, r.global.y, r.global.z, r.ranks, r.block.x, r.block.y, r.block.z, r.ratio.x,
50 r.tele ? (r.repartition ?
" -> REPARTITION" :
" -> TELESCOPE") :
"");
55static bool compare(
const char* what,
const std::vector<Row>& built,
56 const std::vector<Row>& predicted,
int rank) {
59 ok = built.size() == predicted.size();
60 for (std::size_t L = 0; ok && L < built.size(); ++L)
61 ok =
sameRow(built[L], predicted[L]);
62 std::printf(
" %s: %zu levels built, %zu predicted -> %s\n", what, built.size(),
63 predicted.size(), ok ?
"match" :
"MISMATCH");
69 MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD);
83 std::vector<peclet::core::Real> w((std::size_t)g.x * g.y * g.z, 1.0);
84 for (
int z = 0; z < g.z; ++z)
85 for (
int y = 0; y < g.y; ++y)
86 for (
int x = 0; x < g.x; ++x) {
89 v = z < g.z / 2 ? 4.0 : 1.0;
91 const double dx = (x + 0.5) / g.x - 0.3, dy = (y + 0.5) / g.y - 0.6,
92 dz = (z + 0.5) / g.z - 0.35;
93 v = 1.0 + 6.0 * std::exp(-(dx * dx + dy * dy + dz * dz) / 0.02);
95 v = x < 13 ? g.x - 13 : 13;
96 w[(std::size_t)x + (std::size_t)y * g.x + (std::size_t)z * g.x * g.y] = v;
101int main(
int argc,
char** argv) {
102 MPI_Init(&argc, &argv);
103 Kokkos::initialize(argc, argv);
104 int fail = 0, size = 1, rank = 0;
106 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
107 MPI_Comm_size(MPI_COMM_WORLD, &size);
108 int teleCases = 0, repartCases = 0, alignedCases = 0;
109 const Grid3 grids[] = {{32, 32, 32}, {48, 32, 40}};
110 const char* names[] = {
"half-z x4",
"bump",
"uniform",
"odd step x=13"};
111 for (
const Grid3 g : grids) {
112 for (
int kind = 0; kind < 4; ++kind) {
114 std::printf(
"grid %dx%dx%d, weights '%s', np=%d\n", g.x, g.y, g.z, names[kind], size);
116 CutcellMG::decomposition((std::size_t)size, g.x, g.y, g.z);
117 const auto blk = dec.block((std::size_t)rank);
118 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
120 s.setAdvection(
false);
121 s.initMpi(g.x, g.y, g.z, MPI_COMM_WORLD);
125 s.setPressureLevels(
LEVELS);
126 s.setPressurePcg(
true, 200, 1e-6);
127 s.setSolid(std::vector<double>((std::size_t)lnx * lny * lnz, 1e30),
true);
130 const auto predA = CutcellMG::predict(g.x, g.y, g.z, size,
LEVELS,
true,
MIN_EXTENT);
131 if (!
compare(
"A default partition", s.pressureMgPlan(), predA, rank))
135 const auto w =
weights(kind, g);
137 const auto predB = CutcellMG::predict(g.x, g.y, g.z, size,
LEVELS,
true,
MIN_EXTENT, 0,
138 1.05, &w, &alignPred);
139 const int alignGot = s.rebalanceByWeights(w);
140 const auto built = s.pressureMgPlan();
141 if (!
compare(
"B after rebalanceByWeights", built, predB, rank))
144 std::printf(
" alignment: rebalanceByWeights %d, predict %d -> %s\n", alignGot, alignPred,
145 alignGot == alignPred ?
"match" :
"MISMATCH");
146 if (alignGot != alignPred)
149 bool tele =
false, rep =
false;
150 for (
const Row& r : built) {
151 tele = tele || r.tele;
152 rep = rep || r.repartition;
156 alignedCases += alignGot > 1;
162 std::printf(
"coverage: %d weighted case(s) telescope, %d repartition, %d align > 1\n",
163 teleCases, repartCases, alignedCases);
164 if (alignedCases == 0 || (size > 1 && (teleCases == 0 || repartCases == 0))) {
165 std::printf(
"FAIL: the cases no longer exercise what this test gates\n");
169 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
171 std::printf(
"%s\n", fail ?
"FAIL" :
"PASS");