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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

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

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

24
#include <cstdint>
25
#include <string>
26
#include <system_error>
27
#include <utility>
28
#include <vector>
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(primary_namespace,
34
    to_int(components::component_enum_type::agas_primary_namespace))
×
35

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

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

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

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

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

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

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

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

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

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

78
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(hpx::naming::address, naming_address,
79
    hpx::actions::base_lco_with_value_naming_address_get,
80
    hpx::actions::base_lco_with_value_naming_address_set)
192✔
81
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(gva_tuple_type, gva_tuple,
82
    hpx::actions::base_lco_with_value_gva_tuple_get,
83
    hpx::actions::base_lco_with_value_gva_tuple_set)
192✔
84
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(std_pair_address_id_type,
85
    std_pair_address_id_type,
86
    hpx::actions::base_lco_with_value_std_pair_address_id_type_get,
192✔
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,
89
    hpx::actions::base_lco_with_value_std_pair_gid_type_get,
90
    hpx::actions::base_lco_with_value_std_pair_gid_type_set)
192✔
91
HPX_REGISTER_BASE_LCO_WITH_VALUE_ID(std::vector<std::int64_t>,
92
    vector_std_int64_type,
93
    hpx::actions::base_lco_with_value_vector_std_int64_get,
192✔
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(
99
        std::uint32_t service_locality_id)
100
    {
2,312✔
101
        naming::gid_type service(agas::primary_ns_msb, agas::primary_ns_lsb);
102
        return naming::replace_locality_id(service, service_locality_id);
103
    }
104

2,312✔
105
    naming::gid_type primary_namespace::get_service_instance(
106
        naming::gid_type const& dest, error_code& ec)
107
    {
2,312✔
108
        std::uint32_t service_locality_id =
109
            naming::get_locality_id_from_gid(dest);
110
        if (service_locality_id == naming::invalid_locality_id)
111
        {
112
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
2,312✔
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);
×
120
    }
121

2,312✔
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 & ~naming::gid_type::locality_id_mask);
×
127
    }
×
128

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

134
    primary_namespace::~primary_namespace() = default;
32✔
135

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

157✔
141
    naming::address primary_namespace::addr() const
142
    {
143
        return naming::address(agas::get_locality(),
122✔
144
            to_int(components::component_enum_type::agas_primary_namespace),
145
            this->ptr());
146
    }
122✔
147

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

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

×
161
        if (naming::get_locality_id_from_gid(dest.get_gid()) ==
162
            agas::get_locality_id())
×
163
        {
×
164
            return hpx::make_ready_future(server_->begin_migration(id));
165
        }
×
166

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

181
        return server_->end_migration(id);
182
    }
×
183

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

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

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

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

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

242
    hpx::future_or_value<primary_namespace::resolved_type>
243
    primary_namespace::resolve_full(naming::gid_type id)
244
    {
×
245
        hpx::id_type dest = hpx::id_type(
246
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
247

×
248
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
249
        {
×
250
            return server_->resolve_gid(id);
251
        }
×
252

253
#if !defined(HPX_COMPUTE_DEVICE_CODE)
254
        server::primary_namespace::resolve_gid_action action;
255
        return hpx::async(action, HPX_MOVE(dest), id);
256
#else
×
257
        HPX_ASSERT(false);
258
        return primary_namespace::resolved_type{};
259
#endif
260
    }
261

262
    hpx::future_or_value<id_type> primary_namespace::colocate(
263
        naming::gid_type id)
×
264
    {
265
        hpx::id_type dest = hpx::id_type(
266
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
267

×
268
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
269
        {
×
270
            return server_->colocate(id);
271
        }
×
272

273
#if !defined(HPX_COMPUTE_DEVICE_CODE)
274
        server::primary_namespace::colocate_action action;
275
        return hpx::async(action, HPX_MOVE(dest), id);
276
#else
×
277
        HPX_ASSERT(false);
278
        return hpx::invalid_id;
279
#endif
280
    }
281

282
    future<naming::address> primary_namespace::unbind_gid_async(
283
        std::uint64_t count, naming::gid_type const& id)
1,055✔
284
    {
285
        hpx::id_type dest = hpx::id_type(
286
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
287
        naming::gid_type stripped_id = naming::detail::get_stripped_gid(id);
1,055✔
288

289
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
290
        {
1,055✔
291
            return hpx::make_ready_future(
292
                server_->unbind_gid(count, stripped_id));
293
        }
2,110✔
294
#if !defined(HPX_COMPUTE_DEVICE_CODE)
295
        server::primary_namespace::unbind_gid_action action;
296
        return hpx::async(action, HPX_MOVE(dest), count, stripped_id);
297
#else
298
        HPX_ASSERT(false);
299
        return hpx::make_ready_future(naming::address{});
300
#endif
301
    }
302

303
    naming::address primary_namespace::unbind_gid(
304
        std::uint64_t count, naming::gid_type const& id)
102✔
305
    {
306
        hpx::id_type dest = hpx::id_type(
307
            get_service_instance(id), hpx::id_type::management_type::unmanaged);
308
        naming::gid_type stripped_id = naming::detail::get_stripped_gid(id);
102✔
309

310
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
311
        {
102✔
312
            return server_->unbind_gid(count, stripped_id);
313
        }
102✔
314
#if !defined(HPX_COMPUTE_DEVICE_CODE)
315
        server::primary_namespace::unbind_gid_action action;
316
        return action(HPX_MOVE(dest), count, stripped_id);
317
#else
318
        HPX_ASSERT(false);
319
        return naming::address{};
320
#endif
321
    }
322

323
    future_or_value<std::int64_t> primary_namespace::increment_credit(
324
        std::int64_t credits, naming::gid_type lower, naming::gid_type upper)
28✔
325
    {
326
        hpx::id_type dest = hpx::id_type(get_service_instance(lower),
327
            hpx::id_type::management_type::unmanaged);
56✔
328

28✔
329
        if (naming::get_locality_id_from_id(dest) == agas::get_locality_id())
330
        {
28✔
331
            return server_->increment_credit(credits, lower, upper);
332
        }
28✔
333

334
#if !defined(HPX_COMPUTE_DEVICE_CODE)
335
        server::primary_namespace::increment_credit_action action;
336
        return hpx::async(action, HPX_MOVE(dest), credits, lower, upper);
337
#else
×
338
        HPX_ASSERT(false);
339
        return std::int64_t(-1);
340
#endif
341
    }
342

343
    std::pair<naming::gid_type, naming::gid_type> primary_namespace::allocate(
344
        std::uint64_t count)
32✔
345
    {
346
        return server_->allocate(count);
347
    }
32✔
348

349
    void primary_namespace::set_local_locality(naming::gid_type const& g)
350
    {
32✔
351
        server_->set_local_locality(g);
352
    }
353

32✔
354
    void primary_namespace::register_server_instance(std::uint32_t locality_id)
355
    {
32✔
356
        std::string str("locality#" + std::to_string(locality_id) + "/");
357
        server_->register_server_instance(str.c_str(), locality_id);
64✔
358
    }
32✔
359

32✔
360
    void primary_namespace::unregister_server_instance(error_code& ec)
361
    {
×
362
        server_->unregister_server_instance(ec);
363
    }
×
364
}}    // 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