File: TestHPX_IndependentInstancesRefCounting.cpp

package info (click to toggle)
kokkos 5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,148 kB
  • sloc: cpp: 225,388; sh: 1,250; python: 78; makefile: 16; fortran: 4; ansic: 2
file content (48 lines) | stat: -rw-r--r-- 1,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project

#include <Kokkos_Macros.hpp>
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
import kokkos.core;
#else
#include <Kokkos_Core.hpp>
#endif
#include <TestHPX_Category.hpp>

namespace {
std::atomic<int> dummy_count;

struct dummy {
  dummy() { ++dummy_count; }
  dummy(dummy &&) { ++dummy_count; }
  dummy(dummy const &) { ++dummy_count; }
  ~dummy() { --dummy_count; }
  void f() const {}
};

// This test makes sure the independent HPX instances don't hold on to captured
// data after destruction.
TEST(hpx, independent_instances_reference_counting) {
  ASSERT_EQ(0, dummy_count);

  {
    dummy d;
    ASSERT_EQ(1, dummy_count);
    Kokkos::Experimental::HPX hpx(
        Kokkos::Experimental::HPX::instance_mode::independent);
    Kokkos::parallel_for(
        "Test::hpx::reference_counting::dummy",
        Kokkos::RangePolicy<Kokkos::Experimental::HPX>(hpx, 0, 1),
        KOKKOS_LAMBDA(int) {
          // Make sure dummy struct is captured.
          d.f();
        });

    hpx.fence();
    ASSERT_EQ(1, dummy_count);
  }

  ASSERT_EQ(0, dummy_count);
}

}  // namespace