| 80 | |
| 81 | template <typename T, int N, bool C> |
| 82 | void test (ArrayND<T,N,C>& a) |
| 83 | { |
| 84 | auto sz = a.size(); |
| 85 | auto* p = a.dataPtr(); |
| 86 | amrex::ParallelForRNG(sz, [=] AMREX_GPU_DEVICE (std::size_t i, |
| 87 | RandomEngine const& eng) |
| 88 | { |
| 89 | p[i] = amrex::Random_int(1000000, eng); |
| 90 | }); |
| 91 | T tot = Reduce::Sum<T>(sz, p, 0); |
| 92 | |
| 93 | if constexpr (std::remove_reference_t<decltype(a)>::IsArray4_v) { |
| 94 | test_array4(a, tot); |
| 95 | } |
| 96 | |
| 97 | if constexpr (std::remove_reference_t<decltype(a)>::IsLastDimComponent_v) { |
| 98 | test_comp(a, tot); |
| 99 | } |
| 100 | |
| 101 | { |
| 102 | ReduceOps<ReduceOpSum> reduce_op; |
| 103 | ReduceData<T> reduce_data(reduce_op); |
| 104 | using ReduceTuple = typename decltype(reduce_data)::Type; |
| 105 | BoxND<N> box(a.begin, a.end-1); |
| 106 | reduce_op.eval(box, reduce_data, |
| 107 | [=] AMREX_GPU_DEVICE (IntVectND<N> const& iv) -> ReduceTuple |
| 108 | { |
| 109 | auto v0 = a(iv); |
| 110 | auto* p0 = a.ptr(iv); |
| 111 | auto v1 = amrex::Apply([&] (auto&&... i) { |
| 112 | return a(i...); |
| 113 | }, iv); |
| 114 | auto* p1 = amrex::Apply([&] (auto&&... i) { |
| 115 | return a.ptr(i...); |
| 116 | }, iv); |
| 117 | return (v0+v1+*p0+*p1)/4; |
| 118 | }); |
| 119 | ReduceTuple hv = reduce_data.value(reduce_op); |
| 120 | AMREX_ALWAYS_ASSERT(tot == amrex::get<0>(hv)); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | int main (int argc, char* argv[]) |
| 125 | { |
no test coverage detected