MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / test

Function test

Tests/ArrayND/main.cpp:82–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81template <typename T, int N, bool C>
82void 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
124int main (int argc, char* argv[])
125{

Callers 4

mainFunction · 0.70
operator[]Method · 0.50
ixTypeMethod · 0.50
toIntVectMethod · 0.50

Calls 10

Random_intFunction · 0.85
test_array4Function · 0.85
test_compFunction · 0.85
ptrMethod · 0.80
ParallelForRNGFunction · 0.50
ApplyFunction · 0.50
sizeMethod · 0.45
dataPtrMethod · 0.45
evalMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected