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

STEllAR-GROUP / hpx / #844

02 Dec 2022 12:37AM UTC coverage: 85.8% (+0.2%) from 85.634%
#844

push

StellarBot
Merge #6084

6084: Renaming hpx::apply and friends to hpx::post r=hkaiser a=hkaiser

- this is needed to be able to rename invoke_fused to apply later

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497



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

468 of 468 new or added lines in 96 files covered. (100.0%)

171389 of 199753 relevant lines covered (85.8%)

1914550.97 hits per line

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

87.4
/libs/full/agas_base/src/primary_namespace.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//  Copyright (c) 2016 Thomas Heller
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
////////////////////////////////////////////////////////////////////////////////
8

9
#include <hpx/config.hpp>
10
#include <hpx/agas_base/primary_namespace.hpp>
11
#include <hpx/agas_base/server/primary_namespace.hpp>
12
#include <hpx/assert.hpp>
13
#include <hpx/async_distributed/base_lco_with_value.hpp>
14
#include <hpx/async_distributed/continuation.hpp>
15
#include <hpx/components_base/agas_interface.hpp>
16
#include <hpx/modules/async_distributed.hpp>
17
#include <hpx/modules/errors.hpp>
18
#include <hpx/parcelset_base/parcel_interface.hpp>
19
#include <hpx/serialization/vector.hpp>
20
#include <hpx/type_support/unused.hpp>
21

22
#include <cstdint>
23
#include <string>
24
#include <system_error>
25
#include <utility>
26
#include <vector>
27

28
using hpx::components::component_agas_primary_namespace;
29

30
using hpx::agas::server::primary_namespace;
31

32
HPX_DEFINE_COMPONENT_NAME(primary_namespace, hpx_primary_namespace)
×
33
HPX_DEFINE_GET_COMPONENT_TYPE_STATIC(
66,048✔
34
    primary_namespace, component_agas_primary_namespace)
35

36
HPX_REGISTER_ACTION_ID(primary_namespace::allocate_action,
4,608✔
37
    primary_namespace_allocate_action,
38
    hpx::actions::primary_namespace_allocate_action_id)
39

40
HPX_REGISTER_ACTION_ID(primary_namespace::bind_gid_action,
8,692✔
41
    primary_namespace_bind_gid_action,
42
    hpx::actions::primary_namespace_bind_gid_action_id)
43

44
HPX_REGISTER_ACTION_ID(primary_namespace::begin_migration_action,
8,612✔
45
    primary_namespace_begin_migration_action,
46
    hpx::actions::primary_namespace_begin_migration_action_id)
47

48
HPX_REGISTER_ACTION_ID(primary_namespace::end_migration_action,
4,608✔
49
    primary_namespace_end_migration_action,
50
    hpx::actions::primary_namespace_end_migration_action_id)
51

52
HPX_REGISTER_ACTION_ID(primary_namespace::decrement_credit_action,
38,493✔
53
    primary_namespace_decrement_credit_action,
54
    hpx::actions::primary_namespace_decrement_credit_action_id)
55

56
HPX_REGISTER_ACTION_ID(primary_namespace::increment_credit_action,
9,008✔
57
    primary_namespace_increment_credit_action,
58
    hpx::actions::primary_namespace_increment_credit_action_id)
59

60
HPX_REGISTER_ACTION_ID(primary_namespace::resolve_gid_action,
8,625✔
61
    primary_namespace_resolve_gid_action,
62
    hpx::actions::primary_namespace_resolve_gid_action_id)
63

64
HPX_REGISTER_ACTION_ID(primary_namespace::colocate_action,
22,205✔
65
    primary_namespace_colocate_action,
66
    hpx::actions::primary_namespace_colocate_action_id)
67

68
HPX_REGISTER_ACTION_ID(primary_namespace::unbind_gid_action,
4,692✔
69
    primary_namespace_unbind_gid_action,
70
    hpx::actions::primary_namespace_unbind_gid_action_id)
71

72
#if defined(HPX_HAVE_NETWORKING)
73
HPX_REGISTER_ACTION_ID(primary_namespace::route_action,
27,326✔
74
    primary_namespace_route_action,
75
    hpx::actions::primary_namespace_route_action_id)
76
#endif
77

78
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(hpx::naming::address, naming_address,
10,432✔
79
    hpx::actions::base_lco_with_value_naming_address_get,
80
    hpx::actions::base_lco_with_value_naming_address_set)
81
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(gva_tuple_type, gva_tuple,
13,382✔
82
    hpx::actions::base_lco_with_value_gva_tuple_get,
83
    hpx::actions::base_lco_with_value_gva_tuple_set)
84
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(std_pair_address_id_type,
13,372✔
85
    std_pair_address_id_type,
86
    hpx::actions::base_lco_with_value_std_pair_address_id_type_get,
87
    hpx::actions::base_lco_with_value_std_pair_address_id_type_set)
88
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(std_pair_gid_type, std_pair_gid_type,
10,368✔
89
    hpx::actions::base_lco_with_value_std_pair_gid_type_get,
90
    hpx::actions::base_lco_with_value_std_pair_gid_type_set)
91
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(std::vector<std::int64_t>,
10,498✔
92
    vector_std_int64_type,
93
    hpx::actions::base_lco_with_value_vector_std_int64_get,
94
    hpx::actions::base_lco_with_value_vector_std_int64_set)
95

96
namespace hpx { namespace agas {
97

98
    naming::gid_type primary_namespace::get_service_instance(
104,984✔
99
        std::uint32_t service_locality_id)
100
    {
101
        naming::gid_type service(agas::primary_ns_msb, agas::primary_ns_lsb);
104,984✔
102
        return naming::replace_locality_id(service, service_locality_id);
104,984✔
103
    }
104

105
    naming::gid_type primary_namespace::get_service_instance(
104,986✔
106
        naming::gid_type const& dest, error_code& ec)
107
    {
108
        std::uint32_t service_locality_id =
104,985✔
109
            naming::get_locality_id_from_gid(dest);
104,985✔
110
        if (service_locality_id == naming::invalid_locality_id)
104,985✔
111
        {
112
            HPX_THROWS_IF(ec, bad_parameter,
×
113
                "primary_namespace::get_service_instance",
114
                "can't retrieve a valid locality id from global address "
115
                "({1}): ",
116
                dest);
117
            return naming::gid_type();
×
118
        }
119
        return get_service_instance(service_locality_id);
104,978✔
120
    }
104,978✔
121

122
    bool primary_namespace::is_service_instance(naming::gid_type const& gid)
×
123
    {
124
        return gid.get_lsb() == agas::primary_ns_lsb &&
×
125
            (gid.get_msb() & ~naming::gid_type::locality_id_mask) ==
×
126
            agas::primary_ns_msb;
127
    }
128

129
    primary_namespace::primary_namespace()
594✔
130
      : server_(new server::primary_namespace())
594✔
131
    {
132
    }
594✔
133

134
    primary_namespace::~primary_namespace() {}
593✔
135

136
    naming::address::address_type primary_namespace::ptr() const
47,463✔
137
    {
138
        return reinterpret_cast<naming::address::address_type>(server_.get());
47,463✔
139
    }
140

141
    naming::address primary_namespace::addr() const
27,968✔
142
    {
143
        return naming::address(agas::get_locality(),
55,936✔
144
            hpx::components::component_agas_primary_namespace, this->ptr());
27,968✔
145
    }
146

147
    hpx::id_type primary_namespace::gid() const
×
148
    {
149
        return hpx::id_type(get_service_instance(agas::get_locality()),
×
150
            hpx::id_type::management_type::unmanaged);
151
    }
152

153
    hpx::future<std::pair<hpx::id_type, naming::address>>
154
    primary_namespace::begin_migration(naming::gid_type const& id)
3,240✔
155
    {
156
#if !defined(HPX_COMPUTE_DEVICE_CODE)
157
        hpx::id_type dest = hpx::id_type(
3,240✔
158
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
3,240✔
159

160
        if (naming::get_locality_id_from_gid(dest.get_gid()) ==
3,240✔
161
            agas::get_locality_id())
3,240✔
162
        {
163
            return hpx::make_ready_future(server_->begin_migration(id));
2,240✔
164
        }
165

166
        server::primary_namespace::begin_migration_action action;
167
        return hpx::async(action, HPX_MOVE(dest), id);
1,000✔
168
#else
169
        HPX_ASSERT(false);
170
        HPX_UNUSED(id);
171
        return hpx::make_ready_future(
172
            std::pair<hpx::id_type, naming::address>{});
173
#endif
174
    }
3,240✔
175
    bool primary_namespace::end_migration(naming::gid_type const& id)
3,240✔
176
    {
177
        HPX_ASSERT(naming::get_locality_id_from_gid(get_service_instance(id)) ==
3,240✔
178
            agas::get_locality_id());
179

180
        return server_->end_migration(id);
3,240✔
181
    }
182

183
    bool primary_namespace::bind_gid(gva const& g, naming::gid_type const& id,
5,202✔
184
        naming::gid_type const& locality)
185
    {
186
        return server_->bind_gid(g, id, locality);
5,202✔
187
    }
188

189
    future<bool> primary_namespace::bind_gid_async(
2,028✔
190
        gva g, naming::gid_type id, naming::gid_type locality)
191
    {
192
        hpx::id_type dest = hpx::id_type(
2,028✔
193
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
2,028✔
194
        if (naming::get_locality_id_from_gid(dest.get_gid()) ==
2,028✔
195
            agas::get_locality_id())
2,028✔
196
        {
197
            return hpx::make_ready_future(server_->bind_gid(g, id, locality));
1,008✔
198
        }
199
#if !defined(HPX_COMPUTE_DEVICE_CODE)
200
        server::primary_namespace::bind_gid_action action;
201
        return hpx::async(action, HPX_MOVE(dest), g, id, locality);
1,020✔
202
#else
203
        HPX_ASSERT(false);
204
        return hpx::make_ready_future(true);
205
#endif
206
    }
2,028✔
207

208
#if defined(HPX_HAVE_NETWORKING)
209
    void primary_namespace::route(parcelset::parcel&& p,
7,444✔
210
        hpx::function<void(std::error_code const&, parcelset::parcel const&)>&&
211
            f)
212
    {
213
        // compose request
214
        naming::gid_type const& id = p.destination();
7,444✔
215
        hpx::id_type dest = hpx::id_type(
7,444✔
216
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
7,444✔
217
        if (naming::get_locality_id_from_gid(dest.get_gid()) ==
7,444✔
218
            agas::get_locality_id())
7,444✔
219
        {
220
            hpx::post(
×
221
                &server::primary_namespace::route, server_.get(), HPX_MOVE(p));
×
222
            f(std::error_code(), parcelset::parcel());
×
223
            return;
×
224
        }
225

226
#if !defined(HPX_COMPUTE_DEVICE_CODE)
227
        server::primary_namespace::route_action action;
228
        hpx::post_cb(action, HPX_MOVE(dest), HPX_MOVE(f), HPX_MOVE(p));
7,444✔
229
#else
230
        HPX_ASSERT(false);
231
#endif
232
    }
7,444✔
233
#endif
234

235
    primary_namespace::resolved_type primary_namespace::resolve_gid(
115,535✔
236
        naming::gid_type const& id)
237
    {
238
        return server_->resolve_gid(id);
115,535✔
239
    }
240

241
    future<primary_namespace::resolved_type> primary_namespace::resolve_full(
3,240✔
242
        naming::gid_type id)
243
    {
244
        hpx::id_type dest = hpx::id_type(
3,240✔
245
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
3,240✔
246

247
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
3,240✔
248
        {
249
            return hpx::make_ready_future(server_->resolve_gid(id));
2,237✔
250
        }
251
#if !defined(HPX_COMPUTE_DEVICE_CODE)
252
        server::primary_namespace::resolve_gid_action action;
253
        return hpx::async(action, HPX_MOVE(dest), id);
1,003✔
254
#else
255
        HPX_ASSERT(false);
256
        return hpx::make_ready_future(primary_namespace::resolved_type{});
257
#endif
258
    }
3,240✔
259

260
    hpx::future<id_type> primary_namespace::colocate(naming::gid_type id)
40✔
261
    {
262
        hpx::id_type dest = hpx::id_type(
40✔
263
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
40✔
264

265
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
40✔
266
        {
267
            return hpx::make_ready_future(server_->colocate(id));
22✔
268
        }
269
#if !defined(HPX_COMPUTE_DEVICE_CODE)
270
        server::primary_namespace::colocate_action action;
271
        return hpx::async(action, HPX_MOVE(dest), id);
18✔
272
#else
273
        HPX_ASSERT(false);
274
        return hpx::make_ready_future(hpx::invalid_id);
275
#endif
276
    }
40✔
277

278
    future<naming::address> primary_namespace::unbind_gid_async(
17,250✔
279
        std::uint64_t count, naming::gid_type const& id)
280
    {
281
        hpx::id_type dest = hpx::id_type(
17,248✔
282
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
17,248✔
283
        naming::gid_type stripped_id = naming::detail::get_stripped_gid(id);
17,248✔
284

285
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
17,250✔
286
        {
287
            return hpx::make_ready_future(
17,230✔
288
                server_->unbind_gid(count, stripped_id));
17,230✔
289
        }
290
#if !defined(HPX_COMPUTE_DEVICE_CODE)
291
        server::primary_namespace::unbind_gid_action action;
292
        return hpx::async(action, HPX_MOVE(dest), count, stripped_id);
20✔
293
#else
294
        HPX_ASSERT(false);
295
        return hpx::make_ready_future(naming::address{});
296
#endif
297
    }
17,249✔
298

299
    naming::address primary_namespace::unbind_gid(
1,811✔
300
        std::uint64_t count, naming::gid_type const& id)
301
    {
302
        hpx::id_type dest = hpx::id_type(
1,811✔
303
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
1,811✔
304
        naming::gid_type stripped_id = naming::detail::get_stripped_gid(id);
1,811✔
305

306
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
1,811✔
307
        {
308
            return server_->unbind_gid(count, stripped_id);
1,811✔
309
        }
310
#if !defined(HPX_COMPUTE_DEVICE_CODE)
311
        server::primary_namespace::unbind_gid_action action;
312
        return action(HPX_MOVE(dest), count, stripped_id);
×
313
#else
314
        HPX_ASSERT(false);
315
        return naming::address{};
316
#endif
317
    }
1,811✔
318

319
    future<std::int64_t> primary_namespace::increment_credit(
9,556✔
320
        std::int64_t credits, naming::gid_type lower, naming::gid_type upper)
321
    {
322
        hpx::id_type dest = hpx::id_type(get_service_instance(lower),
9,556✔
323
            hpx::id_type::management_type::unmanaged);
324

325
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
9,556✔
326
        {
327
            return hpx::make_ready_future(
8,458✔
328
                server_->increment_credit(credits, lower, upper));
8,458✔
329
        }
330
#if !defined(HPX_COMPUTE_DEVICE_CODE)
331
        server::primary_namespace::increment_credit_action action;
332
        return hpx::async(action, HPX_MOVE(dest), credits, lower, upper);
1,098✔
333
#else
334
        HPX_ASSERT(false);
335
        return hpx::make_ready_future(std::int64_t{});
336
#endif
337
    }
9,556✔
338

339
    std::pair<naming::gid_type, naming::gid_type> primary_namespace::allocate(
3,175✔
340
        std::uint64_t count)
341
    {
342
        return server_->allocate(count);
3,175✔
343
    }
344

345
    void primary_namespace::set_local_locality(naming::gid_type const& g)
594✔
346
    {
347
        server_->set_local_locality(g);
594✔
348
    }
594✔
349

350
    void primary_namespace::register_server_instance(std::uint32_t locality_id)
594✔
351
    {
352
        std::string str("locality#" + std::to_string(locality_id) + "/");
594✔
353
        server_->register_server_instance(str.c_str(), locality_id);
594✔
354
    }
594✔
355

356
    void primary_namespace::unregister_server_instance(error_code& ec)
×
357
    {
358
        server_->unregister_server_instance(ec);
×
359
    }
×
360
}}    // namespace hpx::agas
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

© 2025 Coveralls, Inc