16int main(
int argc,
char** argv) {
17 Kokkos::initialize(argc, argv);
21 Ext3 inner{20, 16, 12};
22 Ext3 ext{inner.
x + 2 * ghost, inner.y + 2 * ghost, inner.z + 2 * ghost};
23 const std::size_t n =
static_cast<std::size_t
>(ext.x) * ext.y * ext.z;
26 std::uniform_real_distribution<float> uf(-1.f, 1.f);
27 std::vector<double> ha(n), hb(n);
28 for (std::size_t i = 0; i < n; ++i) {
33 DField a(
"a", n), b(
"b", n);
35 auto h = Kokkos::create_mirror_view(a);
36 for (std::size_t i = 0; i < n; ++i)
38 Kokkos::deep_copy(a, h);
41 auto h = Kokkos::create_mirror_view(b);
42 for (std::size_t i = 0; i < n; ++i)
44 Kokkos::deep_copy(b, h);
49 double dot =
localDot(a, b, ext, ghost, inner);
52 double rsum = 0.0, rmax = 0.0, rdot = 0.0;
54 for (
int iz = 0; iz < inner.z; ++iz)
55 for (
int iy = 0; iy < inner.y; ++iy)
56 for (
int ix = 0; ix < inner.x; ++ix) {
57 std::size_t idx = (std::size_t)(ix + ghost) + (std::size_t)(iy + ghost) * ext.x +
58 (std::size_t)(iz + ghost) * (std::size_t)ext.x * ext.y;
60 rmax = std::fmax(rmax, std::fabs(ha[idx]));
61 rdot += ha[idx] * hb[idx];
65 auto close = [](
double x,
double y) {
return std::fabs(x - y) <= 1e-9 * (1.0 + std::fabs(y)); };
66 if (!close(sm.
sum, rsum) || !close(sm.
maxabs, rmax) || !close(dot, rdot)) {
67 std::fprintf(stderr,
"FAIL: sum %.10g/%.10g max %.10g/%.10g dot %.10g/%.10g\n", sm.
sum,
68 rsum, sm.
maxabs, rmax, dot, rdot);
73 const double mean = rsum /
static_cast<double>(count);
76 const double expect2 = rsum - mean *
static_cast<double>(count);
77 if (!close(sm2.
sum, expect2)) {
78 std::fprintf(stderr,
"FAIL: post-subtract inner sum %.10g != %.10g\n", sm2.
sum, expect2);
84 "[mac_reductions] PASS: sum/max/dot + mean-subtract match host (%ld inner cells, exec: "
double localDot(DConst a, DConst b, Ext3 ext, int ghost, Ext3 inner)
Local inner product <a,b> over the inner cells.