20int main(
int argc,
char** argv) {
21 Kokkos::initialize(argc, argv);
26 I3 e{inner.x + 2 * g, inner.y + 2 * g, inner.z + 2 * g};
28 const std::size_t n = (std::size_t)e.x * e.y * e.z;
31 std::uniform_real_distribution<double> uf(-1.0, 1.0);
32 std::vector<double> hphi(n), hd(n), hu(n), hv(n), hw(n);
33 for (std::size_t i = 0; i < n; ++i) {
41 auto up = [&](
const char* nm, std::vector<double>& h) {
43 auto m = Kokkos::create_mirror_view(v);
44 for (std::size_t i = 0; i < n; ++i)
46 Kokkos::deep_copy(v, m);
49 SField phi = up(
"phi", hphi), d = up(
"d", hd), u = up(
"u", hu), v = up(
"v", hv),
56 auto hp = Kokkos::create_mirror_view(phi);
57 Kokkos::deep_copy(hp, phi);
58 auto hdo = Kokkos::create_mirror_view(dout);
59 Kokkos::deep_copy(hdo, dout);
62 std::vector<double> rphi = hphi;
63 for (
int color = 0; color < 2; ++color)
64 for (
int z = g; z < e.z - g; ++z)
65 for (
int y = g; y < e.y - g; ++y)
66 for (
int x = g; x < e.x - g; ++x) {
67 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) != color)
69 long i =
l3(x, y, z, e), sx = 1, sy = e.x, sz = (long)e.x * e.y;
70 double s = rphi[i + sx] + rphi[i - sx] + rphi[i + sy] + rphi[i - sy] + rphi[i + sz] +
72 rphi[i] = (s - hd[i]) / 6.0;
74 auto close = [](
double a,
double b) {
75 return std::fabs(a - b) <= 1e-10 * (1.0 + std::fabs(b));
78 for (std::size_t i = 0; i < n; ++i)
79 if (!close(hp(i), rphi[i]))
81 for (
int z = g; z < e.z - g; ++z)
82 for (
int y = g; y < e.y - g; ++y)
83 for (
int x = g; x < e.x - g; ++x) {
84 long i =
l3(x, y, z, e), sx = 1, sy = e.x, sz = (long)e.x * e.y;
85 double rd = (hu[i + sx] - hu[i]) + (hv[i + sy] - hv[i]) + (hw[i + sz] - hw[i]);
86 if (!close(hdo(i), rd))
90 std::fprintf(stderr,
"FAIL: %d cells differ (sweep/divergence)\n", bad);
96 SField phi2 = up(
"phi2", hphi);
98 auto m = Kokkos::create_mirror_view(phi2);
99 Kokkos::deep_copy(m, phi2);
101 for (
int z = g; z < e.z - g; ++z)
102 for (
int y = g; y < e.y - g; ++y)
103 for (
int x = g; x < e.x - g; ++x) {
104 long i =
l3(x, y, z, e), sx = 1, sy = e.x, sz = (long)e.x * e.y;
105 double s = m(i + sx) + m(i - sx) + m(i + sy) + m(i - sy) + m(i + sz) + m(i - sz);
106 double res = (s - 6.0 * m(i)) - hd[i];
112 for (
int it = 0; it < 100; ++it)
115 if (!(r1 < 0.2 * r0)) {
116 std::fprintf(stderr,
"FAIL: smoother did not reduce residual (%.3e -> %.3e)\n", r0, r1);
122 "[mac_stencils] PASS: RB-GS sweep + divergence match host; residual %.2e -> %.2e (exec: "
124 r0, r1, SExec::name());