-
-
Notifications
You must be signed in to change notification settings - Fork 423
/
new_2848.cpp
167 lines (137 loc) · 4.94 KB
/
new_2848.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2015-2017 Hartmut Kaiser
// Copyright (c) 2017 Igor Krivenko
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <hpx/hpx_main.hpp>
#include <hpx/include/components.hpp>
#include <hpx/include/actions.hpp>
#include <hpx/util/lightweight_test.hpp>
#include <cstddef>
#include <utility>
#include <vector>
///////////////////////////////////////////////////////////////////////////////
struct test_server : hpx::components::simple_component_base<test_server>
{
test_server() = delete;
test_server(int i) : i_(i) {}
hpx::id_type call() const { return hpx::find_here(); }
HPX_DEFINE_COMPONENT_ACTION(test_server, call);
int i_;
};
typedef hpx::components::simple_component<test_server> server_type;
HPX_REGISTER_COMPONENT(server_type, test_server);
typedef test_server::call_action call_action;
HPX_REGISTER_ACTION(call_action);
struct test_client : hpx::components::client_base<test_client, test_server>
{
typedef hpx::components::client_base<test_client, test_server> base_type;
test_client(hpx::id_type const& id)
: base_type(id)
{}
test_client(hpx::future<hpx::id_type> && id)
: base_type(std::move(id))
{}
hpx::id_type call() const
{
return hpx::async<call_action>(this->get_id()).get();
}
};
///////////////////////////////////////////////////////////////////////////////
void test_create_single_instance()
{
// make sure created objects live on locality they are supposed to be
for (hpx::id_type const& loc: hpx::find_all_localities())
{
hpx::id_type id = hpx::new_<test_server>(loc, 42).get();
HPX_TEST(hpx::async<call_action>(id).get() == loc);
}
for (hpx::id_type const& loc: hpx::find_all_localities())
{
test_client t1 = hpx::new_<test_client>(loc, 42);
HPX_TEST(t1.call() == loc);
}
// make sure distribution policy is properly used
hpx::id_type id = hpx::new_<test_server>(hpx::default_layout, 42).get();
HPX_TEST(hpx::async<call_action>(id).get() == hpx::find_here());
test_client t2 = hpx::new_<test_client>(hpx::default_layout, 42);
HPX_TEST(t2.call() == hpx::find_here());
for (hpx::id_type const& loc: hpx::find_all_localities())
{
hpx::id_type id =
hpx::new_<test_server>(hpx::default_layout(loc), 42).get();
HPX_TEST(hpx::async<call_action>(id).get() == loc);
}
for (hpx::id_type const& loc: hpx::find_all_localities())
{
test_client t3 = hpx::new_<test_client>(hpx::default_layout(loc), 42);
HPX_TEST(t3.call() == loc);
}
}
///////////////////////////////////////////////////////////////////////////////
void test_create_multiple_instances()
{
// make sure created objects live on locality they are supposed to be
for (hpx::id_type const& loc: hpx::find_all_localities())
{
std::vector<hpx::id_type> ids =
hpx::new_<test_server[]>(loc, 10, 42).get();
HPX_TEST_EQ(ids.size(), std::size_t(10));
for (hpx::id_type const& id: ids)
{
HPX_TEST(hpx::async<call_action>(id).get() == loc);
}
}
for (hpx::id_type const& loc: hpx::find_all_localities())
{
std::vector<test_client> ids =
hpx::new_<test_client[]>(loc, 10, 42).get();
HPX_TEST_EQ(ids.size(), std::size_t(10));
for (test_client const& c: ids)
{
HPX_TEST(c.call() == loc);
}
}
// make sure distribution policy is properly used
std::vector<hpx::id_type> ids =
hpx::new_<test_server[]>(hpx::default_layout, 10, 42).get();
HPX_TEST_EQ(ids.size(), std::size_t(10));
for (hpx::id_type const& id: ids)
{
HPX_TEST(hpx::async<call_action>(id).get() == hpx::find_here());
}
std::vector<test_client> clients =
hpx::new_<test_client[]>(hpx::default_layout, 10, 42).get();
HPX_TEST_EQ(clients.size(), std::size_t(10));
for (test_client const& c: clients)
{
HPX_TEST(c.call() == hpx::find_here());
}
for (hpx::id_type const& loc: hpx::find_all_localities())
{
std::vector<hpx::id_type> ids =
hpx::new_<test_server[]>(hpx::default_layout(loc), 10, 42).get();
HPX_TEST_EQ(ids.size(), std::size_t(10));
for (hpx::id_type const& id: ids)
{
HPX_TEST(hpx::async<call_action>(id).get() == loc);
}
}
for (hpx::id_type const& loc: hpx::find_all_localities())
{
std::vector<test_client> ids =
hpx::new_<test_client[]>(hpx::default_layout(loc), 10, 42).get();
HPX_TEST_EQ(ids.size(), std::size_t(10));
for (test_client const& c: ids)
{
HPX_TEST(c.call() == loc);
}
}
}
///////////////////////////////////////////////////////////////////////////////
int main()
{
test_create_single_instance();
test_create_multiple_instances();
return 0;
}