49int main(
int argc,
char** argv) {
50 MPI_Init(&argc, &argv);
51 Kokkos::initialize(argc, argv);
52 int fail = 0, size = 1, rank = 0;
54 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55 MPI_Comm_size(MPI_COMM_WORLD, &size);
56 IVec<3> gs{32, 32, 32};
59 const std::size_t n = (std::size_t)ext.x * ext.y * ext.z;
61 FPV
AC(
"AC", n), AW(
"AW", n), AE(
"AE", n), AS(
"AS", n), AN(
"AN", n), AB(
"AB", n), AT(
"AT", n);
63 for (FPV* p : {&AW, &AE, &AS, &AN, &AB, &AT})
64 Kokkos::deep_copy(*p, (
float)(-
BETA));
65 vmg.
setFineStencil(FPC(
AC), FPC(AW), FPC(AE), FPC(AS), FPC(AN), FPC(AB), FPC(AT));
67 CCField th(
"th", n), solid(
"solid", n), clean(
"clean", n);
68 Kokkos::deep_copy(th, 1.0);
69 Kokkos::deep_copy(solid, 0.0);
70 Kokkos::deep_copy(clean, 1.0);
72 CCField b(
"b", n), x(
"x", n);
74 Kokkos::deep_copy(x, 0.0);
76 auto hx = Kokkos::create_mirror_view(x);
77 Kokkos::deep_copy(hx, x);
82 vmg.initMpi(gs[0], gs[1], gs[2],
NLEV, MPI_COMM_WORLD);
83 VelocityMG::Level& l0 = vmg.
level(0);
84 auto hx = setupAndSolve(vmg, l0.ext, l0.og);
87 ref.init(gs[0], gs[1], gs[2],
NLEV);
88 const C3 re{(int)gs[0] + 2 *
G, (
int)gs[1] + 2 *
G, (int)gs[2] + 2 *
G}, ro{0, 0, 0};
89 auto hr = setupAndSolve(ref, re, ro);
92 for (
int z =
G; z < l0.ext.z -
G; ++z)
93 for (
int y =
G; y < l0.ext.y -
G; ++y)
94 for (
int x =
G; x < l0.ext.x -
G; ++x) {
95 const int gx = x -
G + l0.og.x, gy = y -
G + l0.og.y, gz = z -
G + l0.og.z;
96 const double a = hx((
long)x + (
long)y * l0.ext.x + (
long)z * (
long)l0.ext.x * l0.ext.y);
98 hr((
long)(gx +
G) + (
long)(gy +
G) * re.x + (
long)(gz +
G) * (
long)re.x * re.y);
99 const double d = std::fabs(a - rr);
103 if (maxdiff > 1e-11) {
105 std::fprintf(stderr,
"[rank %d] max|distributed - single-rank VelocityMG| = %.3e\n", rank,
107 }
else if (rank == 0)
108 std::printf(
" max|distributed - single-rank| = %.3e (np=%d)\n", maxdiff, size);
111 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
114 std::printf(
"OK (np=%d): production VelocityMG V-cycle distributed == single-rank\n", size);
116 std::fprintf(stderr,
"FAILED (np=%d): %d ranks differ\n", size, totalFail);
120 return totalFail == 0 ? 0 : 1;