Reference documentation for deal.II version 9.4.1
\(\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// Copyright (C) 2019 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_base_mpi_compute_index_owner_internal_h
17#define dealii_base_mpi_compute_index_owner_internal_h
18
19#include <deal.II/base/config.h>
20
21#include <deal.II/base/mpi.h>
23
25
26namespace Utilities
27{
28 namespace MPI
29 {
30 namespace internal
31 {
36 namespace ComputeIndexOwner
37 {
39 {
40 public:
41 using index_type = unsigned int;
44
45 FlexibleIndexStorage(const bool use_vector = true);
46
47 void
48 reinit(const bool use_vector,
49 const bool index_range_contiguous,
50 const std::size_t size);
51
52 void
53 fill(const std::size_t start,
54 const std::size_t end,
55 const index_type &value);
56
58 operator[](const std::size_t index);
59
61 operator[](const std::size_t index) const;
62
63 bool
64 entry_has_been_set(const std::size_t index) const;
65
66 private:
68 std::size_t size;
69 std::vector<index_type> data;
70 std::map<std::size_t, index_type> data_map;
71 };
72
82 std::vector<
83 std::pair<types::global_dof_index, types::global_dof_index>>,
84 std::vector<unsigned int>>
85 {
86 public:
91 const std::map<unsigned int,
92 std::vector<std::pair<types::global_dof_index,
94 & buffers,
96 const std::pair<types::global_dof_index, types::global_dof_index>
98 std::vector<unsigned int> &actually_owning_rank_list);
99
104 virtual std::vector<unsigned int>
105 compute_targets() override;
106
111 virtual void
112 create_request(const unsigned int other_rank,
113 std::vector<std::pair<types::global_dof_index,
115 &send_buffer) override;
116
121 virtual void
123 const unsigned int other_rank,
124 const std::vector<std::pair<types::global_dof_index,
125 types::global_dof_index>> &buffer_recv,
126 std::vector<unsigned int> &request_buffer) override;
127
128 private:
129 const std::map<unsigned int,
130 std::vector<std::pair<types::global_dof_index,
133
135
136 const std::pair<types::global_dof_index, types::global_dof_index>
138
139 std::vector<unsigned int> &actually_owning_rank_list;
140 };
141
142
143
150 {
172 static constexpr unsigned int range_minimum_grain_size = 64;
173
180 static constexpr unsigned int sparsity_factor = 4;
181
189
194 std::vector<unsigned int> actually_owning_rank_list;
195
203
209 std::pair<types::global_dof_index, types::global_dof_index>
211
218
223
229
235 unsigned int stride_small_size;
236
242 void
243 reinit(const IndexSet &owned_indices, const MPI_Comm &comm);
244
250 unsigned int
252
258 get_index_offset(const unsigned int rank);
259
265 unsigned int
266 get_owning_rank_index(const unsigned int rank_in_owned_indices,
267 const unsigned int guess = 0);
268
269 private:
274 void
275 partition(const IndexSet &owned_indices, const MPI_Comm &comm);
276 };
277
278
279
288 std::vector<
289 std::pair<types::global_dof_index, types::global_dof_index>>,
290 std::vector<unsigned int>>
291 {
292 public:
298 const MPI_Comm &comm,
299 std::vector<unsigned int> &owning_ranks,
300 const bool track_index_requests = false);
301
306
312
317
321 const unsigned int my_rank;
322
327 const unsigned int n_procs;
328
335
341 std::vector<unsigned int> &owning_ranks;
342
352 std::vector<std::vector<
353 std::pair<unsigned int,
354 std::vector<std::pair<unsigned int, unsigned int>>>>>
356
361
366 std::map<unsigned int, std::vector<types::global_dof_index>>
368
373 std::map<unsigned int, std::vector<unsigned int>> recv_indices;
374
382 virtual void
384 const unsigned int other_rank,
385 const std::vector<std::pair<types::global_dof_index,
386 types::global_dof_index>> &buffer_recv,
387 std::vector<unsigned int> &request_buffer) override;
388
393 virtual std::vector<unsigned int>
394 compute_targets() override;
395
400 virtual void
401 create_request(const unsigned int other_rank,
402 std::vector<std::pair<types::global_dof_index,
404 &send_buffer) override;
405
410 virtual void
411 read_answer(const unsigned int other_rank,
412 const std::vector<unsigned int> &recv_buffer) override;
413
423 std::map<unsigned int, IndexSet>
425
426 private:
440 void
442 unsigned int & owner_index,
443 const unsigned int rank_of_request);
444 };
445
446 /* ------------------------- inline functions ----------------------- */
447
448 inline unsigned int
450 {
451 // note: this formula is also explicitly used in
452 // get_index_offset(), so keep the two in sync
453 return (i / dofs_per_process) * stride_small_size;
454 }
455
456
458 Dictionary::get_index_offset(const unsigned int rank)
459 {
461 static_cast<types::global_dof_index>(
462 (rank + stride_small_size - 1) /
464 size);
465 }
466
467
468
469 inline unsigned int
471 const unsigned int rank_in_owned_indices,
472 const unsigned int guess)
473 {
475 if (actually_owning_rank_list[guess] == rank_in_owned_indices)
476 return guess;
477 else
478 {
479 auto it = std::lower_bound(actually_owning_rank_list.begin(),
481 rank_in_owned_indices);
483 Assert(*it == rank_in_owned_indices, ExcInternalError());
484 return it - actually_owning_rank_list.begin();
485 }
486 }
487
488
489 } // namespace ComputeIndexOwner
490 } // namespace internal
491 } // namespace MPI
492} // namespace Utilities
493
495
496#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< unsigned int, unsigned int > > > > > requesters
void append_index_origin(const types::global_dof_index index, unsigned int &owner_index, const unsigned int rank_of_request)
std::map< unsigned int, std::vector< types::global_dof_index > > indices_to_look_up_by_dict_rank
const std::map< unsigned int, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > & buffers
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 create_request(const unsigned int other_rank, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &send_buffer) override
const std::pair< types::global_dof_index, types::global_dof_index > & local_range
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:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
static ::ExceptionBase & ExcInternalError()
static const unsigned int invalid_unsigned_int
Definition: types.h:201
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
Definition: types.h:76
void reinit(const IndexSet &owned_indices, const MPI_Comm &comm)
unsigned int dof_to_dict_rank(const types::global_dof_index i)
types::global_dof_index get_index_offset(const unsigned int rank)
std::pair< types::global_dof_index, types::global_dof_index > local_range
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)
const MPI_Comm & comm