Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
partition.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_DISTRIBUTED_PARTITION_HPP_
6#define GKO_PUBLIC_CORE_DISTRIBUTED_PARTITION_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/polymorphic_object.hpp>
11#include <ginkgo/core/base/types.hpp>
12
13
14namespace gko {
15namespace experimental {
21namespace distributed {
22
23
78template <typename LocalIndexType = int32, typename GlobalIndexType = int64>
79class Partition : public EnablePolymorphicObject<
80 Partition<LocalIndexType, GlobalIndexType>>,
81 public EnablePolymorphicAssignment<
82 Partition<LocalIndexType, GlobalIndexType>> {
83 friend class EnablePolymorphicObject<Partition>;
84 static_assert(sizeof(GlobalIndexType) >= sizeof(LocalIndexType),
85 "GlobalIndexType must be at least as large as "
86 "LocalIndexType");
87
88public:
89 using EnablePolymorphicAssignment<Partition>::convert_to;
90 using EnablePolymorphicAssignment<Partition>::move_to;
91
92 using local_index_type = LocalIndexType;
93 using global_index_type = GlobalIndexType;
94
100 size_type get_size() const { return size_; }
101
108 size_type get_num_ranges() const noexcept
109 {
110 return offsets_.get_size() - 1;
111 }
112
118 comm_index_type get_num_parts() const noexcept { return num_parts_; }
119
126 {
127 return num_empty_parts_;
128 }
129
137 const global_index_type* get_range_bounds() const noexcept
138 {
139 return offsets_.get_const_data();
140 }
141
149 const comm_index_type* get_part_ids() const noexcept
150 {
151 return part_ids_.get_const_data();
152 }
153
167 const local_index_type* get_range_starting_indices() const noexcept
168 {
169 return starting_indices_.get_const_data();
170 }
171
178 const local_index_type* get_part_sizes() const noexcept
179 {
180 return part_sizes_.get_const_data();
181 }
182
191 local_index_type get_part_size(comm_index_type part) const;
192
199
207 bool has_ordered_parts() const;
208
218 static std::unique_ptr<Partition> build_from_mapping(
219 std::shared_ptr<const Executor> exec,
220 const array<comm_index_type>& mapping, comm_index_type num_parts);
221
235 static std::unique_ptr<Partition> build_from_contiguous(
236 std::shared_ptr<const Executor> exec,
237 const array<global_index_type>& ranges,
238 const array<comm_index_type>& part_ids = {});
239
251 static std::unique_ptr<Partition> build_from_global_size_uniform(
252 std::shared_ptr<const Executor> exec, comm_index_type num_parts,
253 global_index_type global_size);
254
255private:
256 Partition(std::shared_ptr<const Executor> exec,
257 comm_index_type num_parts = 0, size_type num_ranges = 0);
258
259 static std::unique_ptr<Partition> create(
260 std::shared_ptr<const Executor> exec, comm_index_type num_parts = 0,
261 size_type num_ranges = 0);
262
268 void finalize_construction();
269
270 comm_index_type num_parts_;
271 comm_index_type num_empty_parts_;
272 global_index_type size_;
274 array<local_index_type> starting_indices_;
275 array<local_index_type> part_sizes_;
276 array<comm_index_type> part_ids_;
277};
278
279
280} // namespace distributed
281} // namespace experimental
282} // namespace gko
283
284
285#endif // GKO_PUBLIC_CORE_DISTRIBUTED_PARTITION_HPP_
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition logger.hpp:25
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition array.hpp:682
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition array.hpp:656
Represents a partition of a range of indices [0, size) into a disjoint set of parts.
Definition vector.hpp:36
comm_index_type get_num_empty_parts() const noexcept
Returns the number of empty parts within this partition.
Definition partition.hpp:125
size_type get_num_ranges() const noexcept
Returns the number of ranges stored by this partition.
Definition partition.hpp:108
const local_index_type * get_part_sizes() const noexcept
Returns the part size array.
Definition partition.hpp:178
const local_index_type * get_range_starting_indices() const noexcept
Returns the part-local starting index for each range in this partition.
Definition partition.hpp:167
static std::unique_ptr< Partition > build_from_global_size_uniform(std::shared_ptr< const Executor > exec, comm_index_type num_parts, global_index_type global_size)
Builds a partition by evenly distributing the global range.
bool has_connected_parts() const
Checks if each part has no more than one contiguous range.
const comm_index_type * get_part_ids() const noexcept
Returns the part IDs of the ranges in this partition.
Definition partition.hpp:149
local_index_type get_part_size(comm_index_type part) const
Returns the size of a part given by its part ID.
size_type get_size() const
Returns the total number of elements represented by this partition.
Definition partition.hpp:100
comm_index_type get_num_parts() const noexcept
Returns the number of parts represented in this partition.
Definition partition.hpp:118
static std::unique_ptr< Partition > build_from_contiguous(std::shared_ptr< const Executor > exec, const array< global_index_type > &ranges, const array< comm_index_type > &part_ids={})
Builds a partition consisting of contiguous ranges, one for each part.
static std::unique_ptr< Partition > build_from_mapping(std::shared_ptr< const Executor > exec, const array< comm_index_type > &mapping, comm_index_type num_parts)
Builds a partition from a given mapping global_index -> part_id.
bool has_ordered_parts() const
Checks if the ranges are ordered by their part index.
const global_index_type * get_range_bounds() const noexcept
Returns the ranges boundary array stored by this partition.
Definition partition.hpp:137
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition types.hpp:967
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89