From 8b108ff162cc12efc2cb6dee0071c1ba22637552 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 15 Aug 2023 10:48:05 -0400 Subject: [PATCH] Use ScopeGuard --- .../triangle_intersection.cpp | 103 +++++++++--------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/examples/triangle_intersection/triangle_intersection.cpp b/examples/triangle_intersection/triangle_intersection.cpp index f3bbe7ee6..670880e17 100644 --- a/examples/triangle_intersection/triangle_intersection.cpp +++ b/examples/triangle_intersection/triangle_intersection.cpp @@ -330,60 +330,57 @@ class TriangleIntersectionCallback // Triangles class, we can continue with performing the actual search. int main() { - Kokkos::initialize(); - { - using ExecutionSpace = Kokkos::DefaultExecutionSpace; - using MemorySpace = typename ExecutionSpace::memory_space; - ExecutionSpace execution_space; - - std::cout << "Create grid with triangles.\n"; - Triangles triangles(execution_space); - std::cout << "Triangles set up.\n"; - - std::cout << "Creating BVH tree.\n"; - ArborX::BasicBoundingVolumeHierarchy< - MemorySpace, ArborX::Details::PairIndexVolume< - ArborX::ExperimentalHyperGeometry::Box<2>>> const - tree(execution_space, triangles); - std::cout << "BVH tree set up.\n"; - - std::cout << "Create the points used for queries.\n"; - Points points(execution_space); - std::cout << "Points for queries set up.\n"; - - std::cout << "Starting the queries.\n"; - int const n = points.size(); - Kokkos::View offsets("offsets", n); - Kokkos::View coefficients("coefficients", n); - - tree.query(execution_space, points, - TriangleIntersectionCallback{triangles, offsets, - coefficients}); - std::cout << "Queries done.\n"; + Kokkos::ScopeGuard guard; -#ifndef NDEBUG - std::cout << "Starting checking results.\n"; - Kokkos::parallel_for( - Kokkos::RangePolicy(execution_space, 0, n), - KOKKOS_LAMBDA(int i) { - constexpr float eps = 1.e-3; + using ExecutionSpace = Kokkos::DefaultExecutionSpace; + using MemorySpace = typename ExecutionSpace::memory_space; + ExecutionSpace execution_space; - if (offsets(i) != i) - Kokkos::abort("Offsets are wrong"); - auto const &c = coefficients(i); - auto const &t = triangles(offsets(i)); - auto const &p_h = points(i); - auto const p = ArborX::ExperimentalHyperGeometry::Point<2>{ - c[0] * t.a[0] + c[1] * t.b[0] + c[2] * t.c[0], - c[0] * t.a[1] + c[1] * t.b[1] + c[2] * t.c[1]}; - if ((Kokkos::abs(p[0] - p_h[0]) > eps) || - Kokkos::abs(p[1] - p_h[1]) > eps) - Kokkos::abort("Coefficients are wrong"); - }); - std::cout << "Checking results successful.\n"; -#endif - execution_space.fence(); - } + std::cout << "Create grid with triangles.\n"; + Triangles triangles(execution_space); + std::cout << "Triangles set up.\n"; - Kokkos::finalize(); + std::cout << "Creating BVH tree.\n"; + ArborX::BasicBoundingVolumeHierarchy< + MemorySpace, ArborX::Details::PairIndexVolume< + ArborX::ExperimentalHyperGeometry::Box<2>>> const + tree(execution_space, triangles); + std::cout << "BVH tree set up.\n"; + + std::cout << "Create the points used for queries.\n"; + Points points(execution_space); + std::cout << "Points for queries set up.\n"; + + std::cout << "Starting the queries.\n"; + int const n = points.size(); + Kokkos::View offsets("offsets", n); + Kokkos::View coefficients("coefficients", n); + + tree.query(execution_space, points, + TriangleIntersectionCallback{triangles, offsets, + coefficients}); + std::cout << "Queries done.\n"; + +#ifndef NDEBUG + std::cout << "Starting checking results.\n"; + Kokkos::parallel_for( + Kokkos::RangePolicy(execution_space, 0, n), + KOKKOS_LAMBDA(int i) { + constexpr float eps = 1.e-3; + + if (offsets(i) != i) + Kokkos::abort("Offsets are wrong"); + auto const &c = coefficients(i); + auto const &t = triangles(offsets(i)); + auto const &p_h = points(i); + auto const p = ArborX::ExperimentalHyperGeometry::Point<2>{ + c[0] * t.a[0] + c[1] * t.b[0] + c[2] * t.c[0], + c[0] * t.a[1] + c[1] * t.b[1] + c[2] * t.c[1]}; + if ((Kokkos::abs(p[0] - p_h[0]) > eps) || + Kokkos::abs(p[1] - p_h[1]) > eps) + Kokkos::abort("Coefficients are wrong"); + }); + std::cout << "Checking results successful.\n"; +#endif + execution_space.fence(); }