• 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

0.0
/libs/full/collectives/src/create_communication_set.cpp
1
//  Copyright (c) 2020-2023 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

9
#if !defined(HPX_COMPUTE_DEVICE_CODE)
10
#include <hpx/assert.hpp>
11
#include <hpx/collectives/argument_types.hpp>
12
#include <hpx/collectives/communication_set.hpp>
13
#include <hpx/collectives/create_communicator.hpp>
14
#include <hpx/collectives/detail/communication_set_node.hpp>
15
#include <hpx/collectives/detail/communicator.hpp>
16
#include <hpx/components/basename_registration.hpp>
17
#include <hpx/components_base/agas_interface.hpp>
18
#include <hpx/modules/runtime_local.hpp>
19
#include <hpx/naming_base/id_type.hpp>
20

21
#include <cstddef>
22
#include <cstdint>
23
#include <string>
24

25
namespace hpx::collectives {
26

27
    // This function creates P/A communicator objects, (where P is the number
28
    // of participating sites, and A is the arity). Each invocation of the
29
    // function returns the communication node closest to the caller.
30
    /*
31
                     /                     \
32
                    0                       8
33
                   / \                     / \
34
                  /   \                   /   \
35
                 /     \                 /     \
36
                /       \               /       \
37
               /         \             /         \
38
              0           4           8           2
39
             / \         / \         / \         / \
40
            /   \       /   \       /   \       /   \
41
           0     2     4     6     8     0     2     4    <-- communicator nodes
42
          / \   / \   / \   / \   / \   / \   / \   / \
43
         0   1 2   3 4   5 6   7 8   9 0   1 2   3 4   5  <-- participants
44
    */
45
    // As can be seen from the graph, every evenly numbered participant should
46
    // create an communication node, while every odd numbered participant should
47
    // connect to its left neighbor (similar for other arities).
48
    //
49
    // The number of participants that will depend on a communication node is
50
    // calculated by counting the nodes that have a given node as its parent.
51
    //
52
    // The node some other node connects to is calculated by clearing the lowest
53
    // significant bit set (for arities == 2, similar for other arities).
54

55
    ///////////////////////////////////////////////////////////////////////////
56
    communicator create_communication_set(char const* basename,
×
57
        num_sites_arg num_sites, this_site_arg this_site,
58
        generation_arg generation, arity_arg arity)
59
    {
60
        // set defaults for arguments
61
        if (num_sites == static_cast<std::size_t>(-1))
×
62
        {
63
            num_sites = static_cast<std::size_t>(
64
                agas::get_num_localities(hpx::launch::sync));
×
65
        }
66
        if (this_site == static_cast<std::size_t>(-1))
×
67
        {
68
            this_site = static_cast<std::size_t>(agas::get_locality_id());
×
69
        }
70
        if (arity == static_cast<std::size_t>(-1))
×
71
        {
72
            arity = std::stoull(
73
                get_config_entry("hpx.lcos.collectives.arity", "32"));
×
74
        }
75

76
        HPX_ASSERT(this_site < num_sites);
77

78
        std::string name(basename);
×
79
        if (generation != static_cast<std::size_t>(-1))
×
80
        {
81
            name += std::to_string(generation) + "/";
×
82
        }
83

84
        // the arity has to be a power of two but not equal to zero
85
        HPX_ASSERT(arity != 0 && detail::next_power_of_two(arity) == arity);
86

87
        hpx::future<hpx::id_type> node_id;
×
88
        if ((this_site % arity) == 0)
×
89
        {
90
            node_id = detail::create_communication_set_node(
×
91
                HPX_MOVE(name), num_sites, this_site, arity);
92
        }
93
        else
94
        {
95
            node_id = hpx::find_from_basename(
×
96
                HPX_MOVE(name), (this_site / arity) * arity);
×
97
        }
98
        return communicator(HPX_MOVE(node_id));
×
99
    }
100
}    // namespace hpx::collectives
101

102
#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