31 template <
int dim,
int spacedim>
33 add_indices_recursively_for_first_child_policy(
40 if (cell->level() > 0 && cell->parent()->child(0) == cell)
41 add_indices_recursively_for_first_child_policy(cell->parent(),
48 template <
int dim,
int spacedim>
53 template <
int dim,
int spacedim>
68#ifndef DEAL_II_WITH_MPI
73 const auto comm = tria->get_mpi_communicator();
75 const unsigned int process_has_active_locally_owned_cells =
76 tria->n_locally_owned_active_cells() > 0;
77 const unsigned int n_processes_with_active_locally_owned_cells =
80 if (n_processes_with_active_locally_owned_cells ==
84 unsigned int offset = 0;
87 MPI_Exscan(&process_has_active_locally_owned_cells,
91 decltype(process_has_active_locally_owned_cells)>,
97 tria->global_active_cell_index_partitioner().lock());
107 template <
int dim,
int spacedim>
110 : n_coarse_cells(tria_fine.n_global_coarse_cells())
111 , n_global_levels(tria_fine.n_global_levels())
116 "FirstChildPolicy is only working for pure hex meshes at the moment."));
123 if (cell->is_locally_owned())
124 add_indices_recursively_for_first_child_policy(cell,
131 template <
int dim,
int spacedim>
144 if (cell->is_locally_owned())
147 const std::vector<unsigned int> owning_ranks_of_coarse_cells =
158 tria->global_active_cell_index_partitioner().lock());
162 partition[cell->global_active_cell_index()] =
170 template <
int dim,
int spacedim>
172 const unsigned int n_min_cells)
173 : n_min_cells(n_min_cells)
178 template <
int dim,
int spacedim>
190 tria->global_active_cell_index_partitioner().lock());
194 const unsigned int n_locally_owned_active_cells =
198 [](
const auto &cell) { return cell.is_locally_owned(); });
212 const unsigned int n_partitions =
213 std::max<unsigned int>(1,
214 std::min<types::global_cell_index>(
215 n_global_active_cells / n_min_cells,
218 const unsigned int min_cells = n_global_active_cells / n_partitions;
220 const auto convert = [&](
const unsigned int i) {
225 const unsigned int n_partitions_with_additional_cell =
226 n_global_active_cells - min_cells * n_partitions;
228 const unsigned int rank =
229 (i < (min_cells + 1) * n_partitions_with_additional_cell) ?
230 (i / (min_cells + 1)) :
231 ((i - n_partitions_with_additional_cell) / min_cells);
238 for (
const auto i : partition.locally_owned_elements())
239 partition[i] = convert(i);
246 template <
int dim,
int spacedim>
251 : weighting_function(weighting_function)
256 template <
int dim,
int spacedim>
261#ifndef DEAL_II_WITH_MPI
272 const auto partitioner =
273 tria->global_active_cell_index_partitioner().lock();
275 std::vector<unsigned int> weights(partitioner->locally_owned_size());
281 for (
const auto &cell :
283 weights[partitioner->global_to_local(cell->global_active_cell_index())] =
287 std::uint64_t process_local_weight = 0;
288 for (
const auto &weight : weights)
289 process_local_weight += weight;
293 const auto [process_local_weight_offset, total_weight] =
295 tria->get_mpi_communicator());
300 for (std::uint64_t i = 0, weight = process_local_weight_offset;
301 i < partition.locally_owned_size();
302 weight += weights[i], ++i)
303 partition.local_element(i) =
304 static_cast<double>(weight * n_subdomains / total_weight);
316#include "repartitioning_policy_tools.inst"
size_type index_within_set(const size_type global_index) const
void set_size(const size_type size)
void add_index(const size_type index)
virtual types::global_cell_index n_global_active_cells() const
bool all_reference_cells_are_hyper_cube() const
virtual MPI_Comm get_mpi_communicator() const
cell_iterator end() const
active_cell_iterator begin_active(const unsigned int level=0) const
types::global_cell_index translate(const TriaIterator< Accessor > &cell) const
types::global_cell_index size() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
IteratorRange< active_cell_iterator > active_cell_iterators() const
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
#define Assert(cond, exc)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::pair< T, T > partial_and_total_sum(const T &value, const MPI_Comm comm)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T min(const T &t, const MPI_Comm mpi_communicator)
std::vector< unsigned int > compute_index_owner(const IndexSet &owned_indices, const IndexSet &indices_to_look_up, const MPI_Comm comm)
const MPI_Datatype mpi_type_id_for_type