52int main(
int argc,
char** argv) {
53 MPI_Init(&argc, &argv);
54 Kokkos::initialize(argc, argv);
55 int fail = 0, size = 1, rank = 0;
57 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
58 MPI_Comm_size(MPI_COMM_WORLD, &size);
59 IVec<3> gs{32, 32, 32};
62 const std::size_t n = (std::size_t)ext.x * ext.y * ext.z;
63 CCField ox(
"ox", n), oy(
"oy", n), oz(
"oz", n);
64 Kokkos::deep_copy(ox, 1.0);
65 Kokkos::deep_copy(oy, 1.0);
66 Kokkos::deep_copy(oz, 1.0);
67 mg.
setOpenness(CCConst(ox), CCConst(oy), CCConst(oz), 1.0, 1.0, 1.0);
68 CCField b(
"b", n), x(
"x", n), r(
"r", n), p(
"p", n), z(
"z", n), Ap(
"Ap", n);
70 mg.
solvePCG(b, x, r, p, z, Ap, 200, 1e-10, 2, 2, 8);
71 auto hx = Kokkos::create_mirror_view(x);
72 Kokkos::deep_copy(hx, x);
78 mg.initMpi(gs[0], gs[1], gs[2],
NLEV, MPI_COMM_WORLD);
79 CutcellMG::Level& l0 = mg.
level(0);
80 auto hx = setupAndSolve(mg, l0.ext, l0.og);
85 ref.init(gs[0], gs[1], gs[2],
NLEV);
86 const C3 re{(int)gs[0] + 2 *
G, (
int)gs[1] + 2 *
G, (int)gs[2] + 2 *
G}, ro{0, 0, 0};
87 auto hr = setupAndSolve(ref, re, ro);
90 for (
int z =
G; z < l0.ext.z -
G; ++z)
91 for (
int y =
G; y < l0.ext.y -
G; ++y)
92 for (
int x =
G; x < l0.ext.x -
G; ++x) {
93 const int gx = x -
G + l0.og.x, gy = y -
G + l0.og.y, gz = z -
G + l0.og.z;
94 const double a = hx((
long)x + (
long)y * l0.ext.x + (
long)z * (
long)l0.ext.x * l0.ext.y);
96 hr((
long)(gx +
G) + (
long)(gy +
G) * re.x + (
long)(gz +
G) * (
long)re.x * re.y);
97 const double d = std::fabs(a - rr);
103 const double tol = (size == 1) ? 1e-13 : 1e-8;
106 std::fprintf(stderr,
"[rank %d] max|distributed - single-rank CutcellMG| = %.3e (tol %.0e)\n",
108 }
else if (rank == 0)
109 std::printf(
" max|distributed - single-rank| = %.3e (np=%d, tol %.0e)\n", maxdiff, size,
113 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
116 std::printf(
"OK (np=%d): production CutcellMG MG-PCG distributed == single-rank\n", size);
118 std::fprintf(stderr,
"FAILED (np=%d): %d ranks differ\n", size, totalFail);
122 return totalFail == 0 ? 0 : 1;
int solvePCG(CCField b, CCField x, CCField r, CCField p, CCField z, CCField Ap, int maxit, double rtol, int pre, int post, int bottom)