Reference documentation for deal.II version 9.5.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// Copyright (C) 2019 - 2023 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
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
73
74
81 {
103 static constexpr unsigned int range_minimum_grain_size = 64;
104
111 static constexpr unsigned int sparsity_factor = 4;
112
120
125 std::vector<unsigned int> actually_owning_rank_list;
126
134
140 std::pair<types::global_dof_index, types::global_dof_index>
142
149
154
160
166 unsigned int stride_small_size;
167
173 void
174 reinit(const IndexSet &owned_indices, const MPI_Comm comm);
175
181 unsigned int
183
189 get_index_offset(const unsigned int rank);
190
196 unsigned int
197 get_owning_rank_index(const unsigned int rank_in_owned_indices,
198 const unsigned int guess = 0);
199
200 private:
205 void
206 partition(const IndexSet &owned_indices, const MPI_Comm comm);
207 };
208
209
210
219 std::vector<
220 std::pair<types::global_dof_index, types::global_dof_index>>,
221 std::vector<unsigned int>>
222 {
223 public:
229 const MPI_Comm comm,
230 std::vector<unsigned int> &owning_ranks,
231 const bool track_index_requests = false);
232
237
243
248
252 const unsigned int my_rank;
253
258 const unsigned int n_procs;
259
266
272 std::vector<unsigned int> &owning_ranks;
273
283 std::vector<std::vector<
284 std::pair<unsigned int,
285 std::vector<std::pair<unsigned int, unsigned int>>>>>
287
292
298 std::map<unsigned int,
299 std::pair<std::vector<types::global_dof_index>,
300 std::vector<unsigned int>>>
302
310 virtual void
312 const unsigned int other_rank,
313 const std::vector<std::pair<types::global_dof_index,
314 types::global_dof_index>> &buffer_recv,
315 std::vector<unsigned int> &request_buffer) override;
316
321 virtual std::vector<unsigned int>
322 compute_targets() override;
323
328 virtual void
329 create_request(const unsigned int other_rank,
330 std::vector<std::pair<types::global_dof_index,
332 &send_buffer) override;
333
338 virtual void
339 read_answer(const unsigned int other_rank,
340 const std::vector<unsigned int> &recv_buffer) override;
341
351 std::map<unsigned int, IndexSet>
353
354 private:
368 void
369 append_index_origin(const unsigned int index_within_dictionary,
370 const unsigned int rank_of_request,
371 const unsigned int rank_of_owner,
372 unsigned int & owner_index_guess);
373 };
374
375 /* ------------------------- inline functions ----------------------- */
376
377 inline unsigned int
379 {
380 // note: this formula is also explicitly used in
381 // get_index_offset(), so keep the two in sync
382 return (i / dofs_per_process) * stride_small_size;
383 }
384
385
387 Dictionary::get_index_offset(const unsigned int rank)
388 {
390 static_cast<types::global_dof_index>(
391 (rank + stride_small_size - 1) /
393 size);
394 }
395
396
397
398 inline unsigned int
400 const unsigned int rank_in_owned_indices,
401 const unsigned int guess)
402 {
404 if (actually_owning_rank_list[guess] == rank_in_owned_indices)
405 return guess;
406 else
407 {
408 auto it = std::lower_bound(actually_owning_rank_list.begin(),
410 rank_in_owned_indices);
412 Assert(*it == rank_in_owned_indices, ExcInternalError());
413 return it - actually_owning_rank_list.begin();
414 }
415 }
416
417
418 } // namespace ComputeIndexOwner
419 } // namespace internal
420 } // namespace MPI
421} // namespace Utilities
422
424
425#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
std::map< unsigned int, std::pair< std::vector< types::global_dof_index >, std::vector< unsigned int > > > indices_to_look_up_by_dict_rank
void append_index_origin(const unsigned int 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:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static const unsigned int invalid_unsigned_int
Definition types.h:213
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
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)
const MPI_Comm comm