Debian Codegraph @

packages/kokkos/core/unit_test/hpx/TestHPX_IndependentInstancesRefCounting.cpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16
17 #include <Kokkos_Core.hpp>
18 #include <TestHPX_Category.hpp>
19
20 namespace {
21 std::atomic<int> dummy_count;
22
23 struct dummy {
24 dummy() { ++dummy_count; }
25 dummy(dummy &&) { ++dummy_count; }
26 dummy(dummy const &) { ++dummy_count; }
27 ~dummy() { --dummy_count; }
28 void f() const {}
29 };
30
31 // This test makes sure the independent HPX instances don't hold on to captured
32 // data after destruction.
33 TEST(hpx, independent_instances_reference_counting) {
34 ASSERT_EQ(0, dummy_count);
35
36 {
37 dummy d;
38 ASSERT_EQ(1, dummy_count);
39 Kokkos::Experimental::HPX hpx(
40 Kokkos::Experimental::HPX::instance_mode::independent);
41 Kokkos::parallel_for(
42 "Test::hpx::reference_counting::dummy",
43 Kokkos::RangePolicy<Kokkos::Experimental::HPX>(hpx, 0, 1),
44 KOKKOS_LAMBDA(int) {
45 // Make sure dummy struct is captured.
46 d.f();
47 });
48
49 hpx.fence();
50 ASSERT_EQ(1, dummy_count);
51 }
52
53 ASSERT_EQ(0, dummy_count);
54 }
55
56 } // namespace