Debian Codegraph @

packages/kokkos/core/unit_test/hpx/TestHPX_IndependentInstancesDelayedExecution.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 #include <hpx/execution.hpp>
21
22 namespace {
23
24 TEST(hpx, independent_instances_delayed_execution) {
25 Kokkos::View<bool, Kokkos::Experimental::HPX> ran("ran");
26
27 // Create a sender that will call set_value on a receiver after a delay.
28 hpx::execution::experimental::unique_any_sender<> s{
29 hpx::execution::experimental::schedule(
30 hpx::execution::experimental::thread_pool_scheduler{}) |
31 hpx::execution::experimental::then(
32 [] { hpx::this_thread::sleep_for(std::chrono::milliseconds(500)); })};
33 Kokkos::Experimental::HPX hpx(std::move(s));
34 Kokkos::parallel_for(
35 "Test::hpx::independent_instances::delay_execution",
36 Kokkos::Experimental::require(
37 Kokkos::RangePolicy<Kokkos::Experimental::HPX>(hpx, 0, 1),
38 Kokkos::Experimental::WorkItemProperty::HintLightWeight),
39 KOKKOS_LAMBDA(int) { ran() = true; });
40
41 #if defined(KOKKOS_ENABLE_IMPL_HPX_ASYNC_DISPATCH)
42 ASSERT_FALSE(ran());
43 #else
44 ASSERT_TRUE(ran());
45 #endif
46 hpx.fence();
47 ASSERT_TRUE(ran());
48 }
49
50 } // namespace