Skip to content

Commit 3c4c6b1

Browse files
committed
Adding channel-based ping-pong example
1 parent e32a3cc commit 3c4c6b1

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

libs/full/collectives/examples/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021 The STE||AR-Group
1+
# Copyright (c) 2021-2025 The STE||AR-Group
22
#
33
# SPDX-License-Identifier: BSL-1.0
44
# Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -17,14 +17,17 @@ else()
1717
return()
1818
endif()
1919

20-
set(example_programs channel_communicator distributed_pi)
20+
set(example_programs channel_communicator channel_pingpong distributed_pi)
2121

2222
set(channel_communicator_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 2)
2323
set(channel_communicator_FLAGS DEPENDENCIES iostreams_component)
2424

2525
set(distributed_pi_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 2)
2626
set(distributed_pi_FLAGS COMPILE_FLAGS -DHPX_HAVE_RUN_MAIN_EVERYWHERE)
2727

28+
set(channel_pingpong_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 2)
29+
set(channel_pingpong_FLAGS COMPILE_FLAGS -DHPX_HAVE_RUN_MAIN_EVERYWHERE)
30+
2831
foreach(example_program ${example_programs})
2932

3033
set(sources ${example_program}.cpp)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2025 Hartmut Kaiser
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <hpx/hpx_main.hpp>
8+
9+
#if !defined(HPX_COMPUTE_DEVICE_CODE)
10+
#include <hpx/hpx.hpp>
11+
12+
#include <iostream>
13+
14+
int main()
15+
{
16+
using namespace hpx::collectives;
17+
18+
std::uint32_t const locality_id = hpx::get_locality_id();
19+
auto const comm = get_world_channel_communicator();
20+
21+
if (locality_id == 0)
22+
{
23+
set(hpx::launch::sync, comm, that_site_arg(1), 42, tag_arg(123));
24+
int const received =
25+
get<int>(hpx::launch::sync, comm, that_site_arg(1), tag_arg(123));
26+
std::cout << "Received: " << received << "\n";
27+
}
28+
if (locality_id == 1)
29+
{
30+
int const received =
31+
get<int>(hpx::launch::sync, comm, that_site_arg(0), tag_arg(123));
32+
set(hpx::launch::sync, comm, that_site_arg(0), received, tag_arg(123));
33+
}
34+
return 0;
35+
}
36+
37+
#else
38+
39+
int main()
40+
{
41+
return 0;
42+
}
43+
44+
#endif

0 commit comments

Comments
 (0)