• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #868

16 Jan 2023 08:21PM UTC coverage: 86.487%. Remained the same
#868

push

StellarBot
Merge #6137

6137: Adding example of a simple master/slave distributed application r=hkaiser a=hkaiser

The purpose of this example is to demonstrate how HPX actions can be used to build a simple master-slave application. The master (locality 0) assigns work to the slaves (all other localities). Note that if this application is run on one locality only it uses the same locality for the master and the slave functionalities.

The slaves receive a message that encodes how many sub-tasks of a certain type they should spawn locally.


Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

72 of 72 new or added lines in 1 file covered. (100.0%)

174663 of 201952 relevant lines covered (86.49%)

1849169.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.9
/libs/full/async_colocated/tests/unit/new_colocated.cpp
1
//  Copyright (c) 2015 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/config.hpp>
8
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx_main.hpp>
10
#include <hpx/include/actions.hpp>
11
#include <hpx/include/components.hpp>
12
#include <hpx/include/runtime.hpp>
13
#include <hpx/modules/testing.hpp>
14

15
#include <utility>
16

17
///////////////////////////////////////////////////////////////////////////////
18
struct test_server : hpx::components::component_base<test_server>
16✔
19
{
20
    hpx::id_type call() const
4✔
21
    {
22
        return hpx::find_here();
4✔
23
    }
24

25
    HPX_DEFINE_COMPONENT_ACTION(test_server, call)
26
};
27

28
typedef hpx::components::component<test_server> server_type;
29
HPX_REGISTER_COMPONENT(server_type, test_server)
74✔
30

31
typedef test_server::call_action call_action;
32
HPX_REGISTER_ACTION(call_action)
7✔
33

34
struct test_client : hpx::components::client_base<test_client, test_server>
×
35
{
36
    typedef hpx::components::client_base<test_client, test_server> base_type;
37

38
    test_client(hpx::future<hpx::id_type>&& id)
×
39
      : base_type(std::move(id))
×
40
    {
×
41
    }
×
42
    test_client(hpx::id_type&& id)
×
43
      : base_type(std::move(id))
×
44
    {
×
45
    }
×
46

47
    hpx::id_type call()
×
48
    {
49
        return hpx::async<call_action>(this->get_id()).get();
×
50
    }
×
51
};
52

53
///////////////////////////////////////////////////////////////////////////////
54
void test_create_single_instance()
×
55
{
56
    // make sure created objects live on locality they are supposed to be
57
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
58
    {
59
        hpx::id_type target = hpx::new_<test_server>(loc).get();
×
60
        hpx::id_type id = hpx::new_<test_server>(hpx::colocated(target)).get();
×
61

62
        HPX_TEST_EQ(hpx::async<call_action>(id).get(), loc);
×
63
    }
×
64

65
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
66
    {
67
        test_client target = hpx::new_<test_client>(loc);
×
68
        hpx::id_type id = hpx::new_<test_server>(hpx::colocated(target)).get();
×
69

70
        HPX_TEST_EQ(hpx::async<call_action>(id).get(), loc);
×
71
    }
×
72

73
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
74
    {
75
        test_client target = hpx::new_<test_client>(loc);
×
76
        test_client t1 = hpx::new_<test_client>(hpx::colocated(target));
×
77

78
        HPX_TEST_EQ(t1.call(), loc);
×
79
    }
×
80

81
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
82
    {
83
        test_client target = hpx::new_<test_client>(loc);
×
84
        test_client t2 = hpx::new_<test_client>(hpx::colocated(target));
×
85

86
        HPX_TEST_EQ(t2.call(), loc);
×
87
    }
×
88
}
×
89

90
int main()
×
91
{
92
    test_create_single_instance();
×
93
    return 0;
×
94
}
95
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc