Reference documentation for deal.II version GIT 9042b9283b 2023-12-02 14:50:02+00:00
\(\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\}}\)
number_cache.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 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 
17 #include <deal.II/base/mpi.h>
18 
20 
21 #include <numeric>
22 
23 
25 
26 namespace internal
27 {
28  namespace DoFHandlerImplementation
29  {
31  : NumberCache(0)
32  {}
33 
34 
35 
37  : n_global_dofs(n_global_dofs)
38  , n_locally_owned_dofs(n_global_dofs)
39  , locally_owned_dofs(complete_index_set(n_global_dofs))
40  , n_locally_owned_dofs_per_processor(1, n_global_dofs)
41  , locally_owned_dofs_per_processor(1, complete_index_set(n_global_dofs))
42  {}
43 
44 
45 
47  const std::vector<IndexSet> &locally_owned_dofs_per_processor,
48  const unsigned int my_rank)
49  : locally_owned_dofs_per_processor(locally_owned_dofs_per_processor)
50  {
51  const unsigned int n_procs = locally_owned_dofs_per_processor.size();
52 
53  // compress IndexSet representation before using it for anything else
54  for (unsigned int p = 0; p < n_procs; ++p)
56 
57  n_locally_owned_dofs_per_processor.resize(n_procs);
58  for (unsigned int p = 0; p < n_procs; ++p)
60  locally_owned_dofs_per_processor[p].n_elements();
63 
64 
66  std::accumulate(n_locally_owned_dofs_per_processor.begin(),
69  }
70 
71 
72 
73  void
75  {
76  n_global_dofs = 0;
81  }
82 
83 
84 
85  std::vector<types::global_dof_index>
87  const MPI_Comm mpi_communicator) const
88  {
89  if (n_global_dofs == 0)
90  return std::vector<types::global_dof_index>();
91  else if (n_locally_owned_dofs_per_processor.empty() == false)
92  {
94  Utilities::MPI::n_mpi_processes(mpi_communicator));
96  }
97  else
98  {
99  return Utilities::MPI::all_gather(mpi_communicator,
101  }
102  }
103 
104 
105 
106  std::vector<IndexSet>
108  const MPI_Comm mpi_communicator) const
109  {
111  if (n_global_dofs == 0)
112  return std::vector<IndexSet>();
113  else if (locally_owned_dofs_per_processor.empty() == false)
114  {
116  Utilities::MPI::n_mpi_processes(mpi_communicator));
118  }
119  else
120  {
121  return Utilities::MPI::all_gather(mpi_communicator,
123  }
124  }
125 
126 
127  std::size_t
129  {
137  }
138  } // namespace DoFHandlerImplementation
139 } // namespace internal
140 
size_type size() const
Definition: index_set.h:1761
void clear()
Definition: index_set.h:1737
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1820
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1189
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
std::vector< T > all_gather(const MPI_Comm comm, const T &object_to_send)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition: mpi.cc:149
std::string compress(const std::string &input)
Definition: utilities.cc:390
unsigned int global_dof_index
Definition: types.h:82
std::vector< types::global_dof_index > n_locally_owned_dofs_per_processor
Definition: number_cache.h:169
std::vector< IndexSet > locally_owned_dofs_per_processor
Definition: number_cache.h:180
std::vector< IndexSet > get_locally_owned_dofs_per_processor(const MPI_Comm mpi_communicator) const
std::vector< types::global_dof_index > get_n_locally_owned_dofs_per_processor(const MPI_Comm mpi_communicator) const
Definition: number_cache.cc:86