ginkgo/core/distributed/partition.hpp Source File

ginkgo/core/distributed/partition.hpp Source File#

Reference API: ginkgo/core/distributed/partition.hpp Source File
Reference API
partition.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 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/segmented_array.hpp>
12#include <ginkgo/core/base/types.hpp>
13
14
15namespace gko {
16namespace experimental {
22namespace distributed {
23
24
79template <typename LocalIndexType = int32, typename GlobalIndexType = int64>
81 Partition<LocalIndexType, GlobalIndexType>>,
83 Partition<LocalIndexType, GlobalIndexType>> {
85 static_assert(sizeof(GlobalIndexType) >= sizeof(LocalIndexType),
86 "GlobalIndexType must be at least as large as "
87 "LocalIndexType");
88
89public:
92
93 using local_index_type = LocalIndexType;
94 using global_index_type = GlobalIndexType;
95
101 size_type get_size() const { return size_; }
102
109 size_type get_num_ranges() const noexcept
110 {
111 return offsets_.get_size() - 1;
112 }
113
119 comm_index_type get_num_parts() const noexcept { return num_parts_; }
120
126 comm_index_type get_num_empty_parts() const noexcept
127 {
128 return num_empty_parts_;
129 }
130
138 const global_index_type* get_range_bounds() const noexcept
139 {
140 return offsets_.get_const_data();
141 }
142
150 const comm_index_type* get_part_ids() const noexcept
151 {
152 return part_ids_.get_const_data();
153 }
154
168 const local_index_type* get_range_starting_indices() const noexcept
169 {
170 return starting_indices_.get_const_data();
171 }
172
179 const local_index_type* get_part_sizes() const noexcept
180 {
181 return part_sizes_.get_const_data();
182 }
183
192 local_index_type get_part_size(comm_index_type part) const;
193
200 {
201 return ranges_by_part_;
202 }
203
210
218 bool has_ordered_parts() const;
219
229 static std::unique_ptr<Partition> build_from_mapping(
230 std::shared_ptr<const Executor> exec,
231 const array<comm_index_type>& mapping, comm_index_type num_parts);
232
246 static std::unique_ptr<Partition> build_from_contiguous(
247 std::shared_ptr<const Executor> exec,
248 const array<global_index_type>& ranges,
249 const array<comm_index_type>& part_ids = {});
250
262 static std::unique_ptr<Partition> build_from_global_size_uniform(
263 std::shared_ptr<const Executor> exec, comm_index_type num_parts,
264 global_index_type global_size);
265
266private:
267 Partition(std::shared_ptr<const Executor> exec,
268 comm_index_type num_parts = 0, size_type num_ranges = 0);
269
270 static std::unique_ptr<Partition> create(
271 std::shared_ptr<const Executor> exec, comm_index_type num_parts = 0,
272 size_type num_ranges = 0);
273
279 void finalize_construction();
280
281 comm_index_type num_parts_;
282 comm_index_type num_empty_parts_;
283 global_index_type size_;
285 array<local_index_type> starting_indices_;
286 array<local_index_type> part_sizes_;
287 array<comm_index_type> part_ids_;
288 segmented_array<size_type> ranges_by_part_;
289};
290
291
292} // namespace distributed
293} // namespace experimental
294} // namespace gko
295
296
297#endif // GKO_PUBLIC_CORE_DISTRIBUTED_PARTITION_HPP_
Definition polymorphic_object.hpp:743
void move_to(result_type *result) override
Definition polymorphic_object.hpp:751
void convert_to(result_type *result) const override
Definition polymorphic_object.hpp:749
Definition polymorphic_object.hpp:668
Definition array.hpp:166
const value_type * get_const_data() const noexcept
Definition array.hpp:682
size_type get_size() const noexcept
Definition array.hpp:656
comm_index_type get_num_empty_parts() const noexcept
Definition partition.hpp:126
size_type get_num_ranges() const noexcept
Definition partition.hpp:109
const local_index_type * get_part_sizes() const noexcept
Definition partition.hpp:179
const local_index_type * get_range_starting_indices() const noexcept
Definition partition.hpp:168
const segmented_array< size_type > & get_ranges_by_part() const
Definition partition.hpp:199
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)
const comm_index_type * get_part_ids() const noexcept
Definition partition.hpp:150
local_index_type get_part_size(comm_index_type part) const
size_type get_size() const
Definition partition.hpp:101
comm_index_type get_num_parts() const noexcept
Definition partition.hpp:119
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={})
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)
const global_index_type * get_range_bounds() const noexcept
Definition partition.hpp:138
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::size_t size_type
Definition types.hpp:89
A minimal interface for a segmented array.
Definition segmented_array.hpp:27