Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
mpi_compute_index_owner_internal.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_base_mpi_compute_index_owner_internal_h
16#define dealii_base_mpi_compute_index_owner_internal_h
17
18#include <deal.II/base/config.h>
19
22
24
25namespace Utilities
26{
27 namespace MPI
28 {
29 namespace internal
30 {
35 namespace ComputeIndexOwner
36 {
38 {
39 public:
40 using index_type = unsigned int;
43
44 FlexibleIndexStorage(const bool use_vector = true);
45
46 void
47 reinit(const bool use_vector,
48 const bool index_range_contiguous,
49 const std::size_t size);
50
51 void
52 fill(const std::size_t start,
53 const std::size_t end,
54 const index_type &value);
55
57 operator[](const std::size_t index);
58
60 operator[](const std::size_t index) const;
61
62 bool
63 entry_has_been_set(const std::size_t index) const;
64
65 private:
67 std::size_t size;
68 std::vector<index_type> data;
69 std::map<std::size_t, index_type> data_map;
70 };
71
72
73
80 {
102 static constexpr unsigned int range_minimum_grain_size = 64;
103
110 static constexpr unsigned int sparsity_factor = 4;
111
119
124 std::vector<unsigned int> actually_owning_rank_list;
125
133
139 std::pair<types::global_dof_index, types::global_dof_index>
141
148
153
159
165 unsigned int stride_small_size;
166
172 void
173 reinit(const IndexSet &owned_indices, const MPI_Comm comm);
174
180 unsigned int
182
188 get_index_offset(const unsigned int rank);
189
195 unsigned int
196 get_owning_rank_index(const unsigned int rank_in_owned_indices,
197 const unsigned int guess = 0);
198
199 private:
204 void
205 partition(const IndexSet &owned_indices, const MPI_Comm comm);
206 };
207
208
209
218 std::vector<
219 std::pair<types::global_dof_index, types::global_dof_index>>,
220 std::vector<unsigned int>>
221 {
222 public:
228 const MPI_Comm comm,
229 std::vector<unsigned int> &owning_ranks,
230 const bool track_index_requests = false);
231
236
242
247
251 const unsigned int my_rank;
252
257 const unsigned int n_procs;
258
266
272 std::vector<unsigned int> &owning_ranks;
273
283 std::vector<std::vector<
284 std::pair<unsigned int,
285 std::vector<std::pair<types::global_dof_index,
288
293
299 std::map<unsigned int,
300 std::pair<std::vector<types::global_dof_index>,
301 std::vector<unsigned int>>>
303
311 virtual void
313 const unsigned int other_rank,
314 const std::vector<std::pair<types::global_dof_index,
315 types::global_dof_index>> &buffer_recv,
316 std::vector<unsigned int> &request_buffer) override;
317
322 virtual std::vector<unsigned int>
323 compute_targets() override;
324
329 virtual void
330 create_request(const unsigned int other_rank,
331 std::vector<std::pair<types::global_dof_index,
333 &send_buffer) override;
334
339 virtual void
340 read_answer(const unsigned int other_rank,
341 const std::vector<unsigned int> &recv_buffer) override;
342
352 std::map<unsigned int, IndexSet>
354
355 private:
369 void
371 const types::global_dof_index index_within_dictionary,
372 const unsigned int rank_of_request,
373 const unsigned int rank_of_owner,
374 unsigned int &owner_index_guess);
375 };
376
377 /* ------------------------- inline functions ----------------------- */
378
379 inline unsigned int
381 {
382 // note: this formula is also explicitly used in
383 // get_index_offset(), so keep the two in sync
384 return (i / dofs_per_process) * stride_small_size;
385 }
386
387
389 Dictionary::get_index_offset(const unsigned int rank)
390 {
392 static_cast<types::global_dof_index>(
393 (rank + stride_small_size - 1) /
395 size);
396 }
397
398
399
400 inline unsigned int
402 const unsigned int rank_in_owned_indices,
403 const unsigned int guess)
404 {
406 if (actually_owning_rank_list[guess] == rank_in_owned_indices)
407 return guess;
408 else
409 {
410 auto it = std::lower_bound(actually_owning_rank_list.begin(),
412 rank_in_owned_indices);
414 Assert(*it == rank_in_owned_indices, ExcInternalError());
415 return it - actually_owning_rank_list.begin();
416 }
417 }
418
419
420 } // namespace ComputeIndexOwner
421 } // namespace internal
422 } // namespace MPI
423} // namespace Utilities
424
426
427#endif
virtual void answer_request(const unsigned int other_rank, const std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &buffer_recv, std::vector< unsigned int > &request_buffer) override
virtual void read_answer(const unsigned int other_rank, const std::vector< unsigned int > &recv_buffer) override
virtual void create_request(const unsigned int other_rank, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &send_buffer) override
std::vector< std::vector< std::pair< unsigned int, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > > > requesters
std::map< unsigned int, std::pair< std::vector< types::global_dof_index >, std::vector< unsigned int > > > indices_to_look_up_by_dict_rank
ConsensusAlgorithmsPayload(const IndexSet &owned_indices, const IndexSet &indices_to_look_up, const MPI_Comm comm, std::vector< unsigned int > &owning_ranks, const bool track_index_requests=false)
void append_index_origin(const types::global_dof_index index_within_dictionary, const unsigned int rank_of_request, const unsigned int rank_of_owner, unsigned int &owner_index_guess)
void reinit(const bool use_vector, const bool index_range_contiguous, const std::size_t size)
void fill(const std::size_t start, const std::size_t end, const index_type &value)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static const unsigned int invalid_unsigned_int
Definition types.h:220
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
Definition types.h:81
*braid_SplitCommworld & comm
types::global_dof_index get_index_offset(const unsigned int rank)
std::pair< types::global_dof_index, types::global_dof_index > local_range
void reinit(const IndexSet &owned_indices, const MPI_Comm comm)
void partition(const IndexSet &owned_indices, const MPI_Comm comm)
unsigned int get_owning_rank_index(const unsigned int rank_in_owned_indices, const unsigned int guess=0)