20#include "libmesh/partitioner.h"
23#include "libmesh/compare_elems_by_level.h"
24#include "libmesh/elem.h"
25#include "libmesh/enum_to_string.h"
26#include "libmesh/int_range.h"
27#include "libmesh/libmesh_logging.h"
28#include "libmesh/mesh_base.h"
29#include "libmesh/mesh_tools.h"
30#include "libmesh/mesh_communication.h"
31#include "libmesh/node_range.h"
32#include "libmesh/parallel_ghost_sync.h"
33#include "libmesh/wrapped_petsc.h"
34#include "libmesh/boundary_info.h"
37#include "libmesh/enum_partitioner_type.h"
38#include "libmesh/centroid_partitioner.h"
39#include "libmesh/hilbert_sfc_partitioner.h"
40#include "libmesh/linear_partitioner.h"
41#include "libmesh/mapped_subdomain_partitioner.h"
42#include "libmesh/metis_partitioner.h"
43#include "libmesh/morton_sfc_partitioner.h"
44#include "libmesh/parmetis_partitioner.h"
45#include "libmesh/sfc_partitioner.h"
46#include "libmesh/subdomain_partitioner.h"
53#ifdef LIBMESH_HAVE_PETSC
54#include "libmesh/ignore_warnings.h"
56#include "libmesh/restore_warnings.h"
57#include "libmesh/petsc_solver_exception.h"
70 std::unordered_set<dof_id_type> & _bad_pids) :
71 mesh(_mesh), bad_pids(_bad_pids) {}
74 std::unordered_set<dof_id_type> & bad_pids;
77 void gather_data (
const std::vector<dof_id_type> & ids,
78 std::vector<datum> & data)
81 data.resize(ids.size());
88 !bad_pids.count(ids[i]))
101 bool act_on_data (
const std::vector<dof_id_type> & ids,
102 const std::vector<datum> proc_ids)
104 bool data_changed =
false;
114 if (
const auto it = bad_pids.find(ids[i]);
115 (new_proc_id != proc_id || it != bad_pids.end()) &&
118 if (it != bad_pids.end())
120 proc_id = new_proc_id;
126 if (proc_id == new_proc_id)
159std::unique_ptr<Partitioner>
162 switch (partitioner_type)
165 return std::make_unique<CentroidPartitioner>();
167 return std::make_unique<LinearPartitioner>();
169 return std::make_unique<MappedSubdomainPartitioner>();
171 return std::make_unique<MetisPartitioner>();
173 return std::make_unique<ParmetisPartitioner>();
175 return std::make_unique<HilbertSFCPartitioner>();
177 return std::make_unique<MortonSFCPartitioner>();
179 return std::make_unique<SFCPartitioner>();
181 return std::make_unique<SubdomainPartitioner>();
183 libmesh_error_msg(
"Invalid partitioner type: " <<
198 const unsigned int n)
209 const unsigned int n_parts =
210 static_cast<unsigned int>
250 MeshTools::libmesh_assert_valid_procids<Elem>(
mesh);
257 MeshTools::libmesh_assert_valid_procids<Elem>(
mesh);
275 const unsigned int n)
279 const unsigned int n_parts =
280 static_cast<unsigned int>
320 mesh.elements_end());
352 LOG_SCOPE(
"single_partition_range()",
"Partitioner");
354 bool changed_pid =
false;
356 for (
auto & elem :
as_range(it, end))
358 if (elem->processor_id())
360 elem->processor_id() = 0;
363 for (
Node & node : elem->node_ref_range())
382 const unsigned int n_subdomains)
391 const unsigned int n_subdomains,
392 const bool spatial_indexing)
401 if (!n_unpartitioned_elements)
412 if (pid < n_subdomains)
414 tgt_subdomain_size = n_unpartitioned_elements/n_subdomains;
416 if (pid < n_unpartitioned_elements%n_subdomains)
417 tgt_subdomain_size++;
423 subdomain_bounds[0] = tgt_subdomain_size;
425 subdomain_bounds[pid] = subdomain_bounds[pid-1] + tgt_subdomain_size;
428 libmesh_assert_equal_to (subdomain_bounds.back(), n_unpartitioned_elements);
432 std::vector<dof_id_type> global_indices;
439 if (spatial_indexing)
447 for (
auto & elem :
as_range(it, end))
449 libmesh_assert (!spatial_indexing || cnt < global_indices.size());
451 spatial_indexing ? global_indices[cnt++] : cnt++;
453 libmesh_assert_less (global_index, subdomain_bounds.back());
454 libmesh_assert_less (global_index, n_unpartitioned_elements);
457 cast_int<processor_id_type>
458 (std::distance(subdomain_bounds.begin(),
459 std::upper_bound(subdomain_bounds.begin(),
460 subdomain_bounds.end(),
462 libmesh_assert_less (subdomain_id, n_subdomains);
464 elem->processor_id() = subdomain_id;
479 LOG_SCOPE(
"set_parent_processor_ids()",
"Partitioner");
481#ifdef LIBMESH_ENABLE_AMR
493 for (
auto & elem :
mesh.active_element_ptr_range())
496 std::vector<Elem *> subactive_family;
497 elem->total_family_tree(subactive_family);
498 for (
const auto & f : subactive_family)
499 f->processor_id() = elem->processor_id();
516 child.processor_id());
518 parent = parent->
parent();
531 for (
auto & child :
mesh.active_element_ptr_range())
533 std::vector<Elem *> subactive_family;
535 for (
const auto & f : subactive_family)
536 f->processor_id() = child->processor_id();
550 mesh.unpartitioned_elements_end()) == 0);
554 std::vector<processor_id_type>
558 for (
dof_id_type blk=0, last_elem_id=0; last_elem_id<max_elem_id; blk++)
565 std::fill (parent_processor_ids.begin(),
566 parent_processor_ids.end(),
570 bool have_parent_in_block =
false;
572 for (
auto & parent :
as_range(
mesh.ancestor_elements_begin(),
573 mesh.ancestor_elements_end()))
576 libmesh_assert_less (parent_idx, max_elem_id);
578 if ((parent_idx >= first_elem_id) &&
579 (parent_idx < last_elem_id))
581 have_parent_in_block =
true;
584 std::vector<const Elem *> active_family;
585 parent->active_family_tree(active_family);
586 for (
const auto & f : active_family)
587 parent_pid = std::min (parent_pid, f->processor_id());
589 const dof_id_type packed_idx = parent_idx - first_elem_id;
590 libmesh_assert_less (packed_idx, parent_processor_ids.size());
592 parent_processor_ids[packed_idx] = parent_pid;
600 if (have_parent_in_block)
601 for (
auto & parent :
as_range(
mesh.ancestor_elements_begin(),
602 mesh.ancestor_elements_end()))
606 if ((parent_idx >= first_elem_id) &&
607 (parent_idx < last_elem_id))
609 const dof_id_type packed_idx = parent_idx - first_elem_id;
610 libmesh_assert_less (packed_idx, parent_processor_ids.size());
613 parent_processor_ids[packed_idx];
617 parent->processor_id() = parent_pid;
628 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> & processor_pair_to_nodes)
633 processor_pair_to_nodes.clear();
635 std::set<dof_id_type> mynodes;
636 std::set<dof_id_type> neighbor_nodes;
637 std::vector<dof_id_type> common_nodes;
640 for (
auto & elem :
mesh.active_element_ptr_range())
646 auto n_nodes = elem->n_nodes();
650 neighbor_nodes.clear();
651 common_nodes.clear();
653 for (
unsigned int inode = 0; inode <
n_nodes; inode++)
654 mynodes.insert(elem->node_id(inode));
656 for (
auto i : elem->side_index_range())
658 auto neigh = elem->neighbor_ptr(i);
659 if (neigh && !neigh->is_remote() && neigh->processor_id() != elem->processor_id())
661 neighbor_nodes.clear();
662 common_nodes.clear();
663 auto neigh_n_nodes = neigh->n_nodes();
664 for (
unsigned int inode = 0; inode < neigh_n_nodes; inode++)
665 neighbor_nodes.insert(neigh->node_id(inode));
667 std::set_intersection(mynodes.begin(), mynodes.end(),
668 neighbor_nodes.begin(), neighbor_nodes.end(),
669 std::back_inserter(common_nodes));
671 auto & map_set = processor_pair_to_nodes[std::make_pair(std::min(elem->processor_id(), neigh->processor_id()),
672 std::max(elem->processor_id(), neigh->processor_id()))];
673 for (
auto global_node_id : common_nodes)
674 map_set.insert(global_node_id);
685 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> processor_pair_to_nodes;
689 for (
auto & pmap : processor_pair_to_nodes)
691 std::size_t n_own_nodes = pmap.second.size()/2, i = 0;
696 if (i <= n_own_nodes)
712 libmesh_experimental();
714 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> processor_pair_to_nodes;
718 std::unordered_map<dof_id_type, std::vector<const Elem *>> nodes_to_elem_map;
722 std::vector<const Node *> neighbors;
723 std::set<dof_id_type> neighbors_order;
724 std::vector<dof_id_type> common_nodes;
725 std::queue<dof_id_type> nodes_queue;
726 std::set<dof_id_type> visted_nodes;
728 for (
auto & pmap : processor_pair_to_nodes)
730 std::size_t n_own_nodes = pmap.second.size()/2;
736 visted_nodes.clear();
741 if (visted_nodes.count(
id))
745 nodes_queue.push(
id);
746 visted_nodes.insert(
id);
747 if (visted_nodes.size() >= n_own_nodes)
751 while (!nodes_queue.empty())
758 neighbors_order.clear();
759 for (
auto & neighbor : neighbors)
760 neighbors_order.insert(neighbor->id());
762 common_nodes.clear();
763 std::set_intersection(pmap.second.begin(), pmap.second.end(),
764 neighbors_order.begin(), neighbors_order.end(),
765 std::back_inserter(common_nodes));
767 for (
auto c_node : common_nodes)
768 if (!visted_nodes.count(c_node))
770 nodes_queue.push(c_node);
771 visted_nodes.insert(c_node);
772 if (visted_nodes.size() >= n_own_nodes)
776 if (visted_nodes.size() >= n_own_nodes)
781 for (
auto node : visted_nodes)
793#ifdef LIBMESH_HAVE_PETSC
794 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> processor_pair_to_nodes;
798 std::vector<std::vector<const Elem *>> nodes_to_elem_map;
802 std::vector<const Node *> neighbors;
803 std::set<dof_id_type> neighbors_order;
804 std::vector<dof_id_type> common_nodes;
806 std::vector<dof_id_type> rows;
807 std::vector<dof_id_type> cols;
809 std::map<dof_id_type, dof_id_type> global_to_local;
811 for (
auto & pmap : processor_pair_to_nodes)
816 rows.resize(pmap.second.size()+1);
819 global_to_local[
id] = i++;
822 for (
auto id : pmap.second)
827 neighbors_order.clear();
828 for (
auto & neighbor : neighbors)
829 neighbors_order.insert(neighbor->id());
831 common_nodes.clear();
832 std::set_intersection(pmap.second.begin(), pmap.second.end(),
833 neighbors_order.begin(), neighbors_order.end(),
834 std::back_inserter(common_nodes));
836 rows[i+1] = rows[i] + cast_int<dof_id_type>(common_nodes.size());
838 for (
auto c_node : common_nodes)
839 cols.push_back(global_to_local[c_node]);
847 PetscInt *adj_i, *adj_j;
848 LibmeshPetscCall2(
mesh.
comm(), PetscCalloc1(rows.size(), &adj_i));
849 LibmeshPetscCall2(
mesh.
comm(), PetscCalloc1(cols.size(), &adj_j));
850 PetscInt rows_size = cast_int<PetscInt>(rows.size());
851 for (PetscInt ii=0; ii<rows_size; ii++)
852 adj_i[ii] = rows[ii];
854 PetscInt cols_size = cast_int<PetscInt>(cols.size());
855 for (PetscInt ii=0; ii<cols_size; ii++)
856 adj_j[ii] = cols[ii];
858 const PetscInt sz = cast_int<PetscInt>(pmap.second.size());
862 LibmeshPetscCall2(
mesh.
comm(), MatCreateMPIAdj(PETSC_COMM_SELF, sz, sz, adj_i, adj_j,
nullptr, adj.
get()));
866 LibmeshPetscCall2(
mesh.
comm(), MatPartitioningCreate(PETSC_COMM_SELF, part.
get()));
869 LibmeshPetscCall2(
mesh.
comm(), MatPartitioningSetAdjacency(part, adj));
870 LibmeshPetscCall2(
mesh.
comm(), MatPartitioningSetNParts(part, 2));
871 LibmeshPetscCall2(
mesh.
comm(), PetscObjectSetOptionsPrefix((PetscObject)(*part),
"balance_"));
872 LibmeshPetscCall2(
mesh.
comm(), MatPartitioningSetFromOptions(part));
873 LibmeshPetscCall2(
mesh.
comm(), MatPartitioningApply(part,
is.
get()));
877 const PetscInt *indices;
878 LibmeshPetscCall2(
mesh.
comm(), ISGetLocalSize(
is, &local_size));
879 LibmeshPetscCall2(
mesh.
comm(), ISGetIndices(
is, &indices));
882 for (
auto id : pmap.second)
892 LibmeshPetscCall2(
mesh.
comm(), ISRestoreIndices(
is, &indices));
895 libmesh_error_msg(
"PETSc is required");
902 LOG_SCOPE(
"set_node_processor_ids()",
"Partitioner");
910 mesh.unpartitioned_elements_end()) == 0);
916 { node->processor_id() = DofObject::invalid_processor_id; });
919 for (
auto & elem :
mesh.active_element_ptr_range())
926 for (
Node & node : elem->node_ref_range())
936 const bool load_balanced_nodes_linear =
939 const bool load_balanced_nodes_bfs =
942 const bool load_balanced_nodes_petscpartition =
945 unsigned int n_load_balance_options = load_balanced_nodes_linear;
946 n_load_balance_options += load_balanced_nodes_bfs;
947 n_load_balance_options += load_balanced_nodes_petscpartition;
948 libmesh_error_msg_if(n_load_balance_options > 1,
949 "Cannot perform more than one load balancing type at a time");
951 if (load_balanced_nodes_linear)
953 else if (load_balanced_nodes_bfs)
955 else if (load_balanced_nodes_petscpartition)
975 std::unordered_set<dof_id_type> bad_pids;
980 [&bad_pids, &pid_mtx](
const NodeRange & range)
982 std::unordered_set<dof_id_type> my_bad_pids;
983 for (const Node * node : range)
984 if (node->processor_id() == DofObject::invalid_processor_id)
985 my_bad_pids.insert(node->id());
987 Threads::spin_mutex::scoped_lock lock(pid_mtx);
989 bad_pids.merge(my_bad_pids);
1004 std::unordered_map<dof_id_type, processor_id_type>>
1008 for (
unsigned int level = n_levels; level > 0; --level)
1010 for (
auto & elem :
as_range(
mesh.level_elements_begin(level-1),
1011 mesh.level_elements_end(level-1)))
1013 libmesh_assert_not_equal_to (elem->processor_id(),
1019 for (
Node & node : elem->node_ref_range())
1022 if (bad_pids.count(node.
id()))
1024 else if (!is_serial)
1025 potential_pids[elem_pid][node.
id()] = pid;
1034 std::vector<std::pair<dof_id_type, processor_id_type>>>
1035 potential_pids_vecs;
1037 for (
auto & pair : potential_pids)
1038 potential_pids_vecs[pair.first].assign(pair.second.begin(), pair.second.end());
1040 auto pids_action_functor =
1041 [&
mesh, & bad_pids]
1043 const std::vector<std::pair<dof_id_type, processor_id_type>> & data)
1045 for (
auto pair : data)
1049 if (
const auto it = bad_pids.find(pair.first);
1050 it != bad_pids.end())
1061 (
mesh.
comm(), potential_pids_vecs, pids_action_functor);
1067 CorrectProcIds correct_pids(
mesh, bad_pids);
1080 mesh.elements_begin(),
mesh.elements_end(),
1092 MeshTools::libmesh_assert_valid_procids<Node>(
mesh);
1103 typedef std::unordered_map<dof_id_type, dof_id_type>
map_type;
1110 std::vector<datum> & local_ids)
const
1112 local_ids.resize(ids.size());
1115 local_ids[i] =
id_map[ids[i]];
1119 const std::vector<datum> & local_ids)
1122 id_map[ids[i]] = local_ids[i];
1142 n_active_elem_before_proc[i+1] =
1152 mesh.active_local_elements_begin(),
1153 mesh.active_local_elements_end(),
1159 (
mesh.
comm(),
mesh.active_elements_begin(),
mesh.active_elements_end(), sync);
1161 for (
const auto & elem :
mesh.active_element_ptr_range())
1172 LOG_SCOPE(
"build_graph()",
"Partitioner");
1180 typedef std::unordered_multimap<const Elem *, const Elem *> map_type;
1181 map_type interior_to_boundary_map;
1187 map_type elems_constrained_by;
1191 for (
const Elem * elem :
mesh.active_element_ptr_range())
1193 if (!mesh_constrained_nodes.empty())
1195 const auto end_it = mesh_constrained_nodes.end();
1199 std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
1200 for (
const Node & node : elem->node_ref_range())
1202 if (
const auto row_it = mesh_constrained_nodes.find(&node);
1204 for (
const auto & [pr, coef] : row_it->second)
1207 constraining_elems.insert(pr.first);
1210 for (
const Elem * constraining_elem : constraining_elems)
1211 elems_constrained_by.emplace(constraining_elem, elem);
1216 if (elem->interior_parent())
1219 std::set<const Elem *> neighbor_set;
1220 elem->find_interior_neighbors(neighbor_set);
1222 for (
const auto & neighbor : neighbor_set)
1223 interior_to_boundary_map.emplace(neighbor, elem);
1227#ifdef LIBMESH_ENABLE_AMR
1228 std::vector<const Elem *> neighbors_offspring;
1248 std::vector<std::pair<dof_id_type, dof_id_type>>> connections_to_push;
1250 for (
const auto & elem :
mesh.active_local_element_ptr_range())
1257 global_index_by_pid - first_local_elem;
1258 libmesh_assert_less (local_index, n_active_local_elem);
1260 std::vector<dof_id_type> & graph_row =
_dual_graph[local_index];
1267 for (
auto neighbor : elem->neighbor_ptr_range())
1269 if (neighbor !=
nullptr)
1273 if (neighbor->active())
1279 graph_row.push_back(neighbor_global_index_by_pid);
1282#ifdef LIBMESH_ENABLE_AMR
1291 const unsigned int ns =
1292 neighbor->which_neighbor_am_i (elem);
1293 libmesh_assert_less (ns, neighbor->n_neighbors());
1306 neighbor->active_family_tree (neighbors_offspring);
1311 for (
const auto & child : neighbors_offspring)
1316 if (child->neighbor_ptr(ns) == elem)
1323 graph_row.push_back(child_global_index_by_pid);
1334 if ((elem->dim() < LIBMESH_DIM) &&
1335 elem->interior_parent())
1338 std::set<const Elem *> neighbor_set;
1339 elem->find_interior_neighbors(neighbor_set);
1341 for (
const auto & neighbor : neighbor_set)
1346 graph_row.push_back(neighbor_global_index_by_pid);
1351 for (
const auto & pr :
as_range(interior_to_boundary_map.equal_range(elem)))
1353 const Elem * neighbor = pr.second;
1358 graph_row.push_back(neighbor_global_index_by_pid);
1362 if (!mesh_constrained_nodes.empty())
1364 const auto end_it = mesh_constrained_nodes.end();
1368 std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
1369 for (
const Node & node : elem->node_ref_range())
1371 if (
const auto row_it = mesh_constrained_nodes.find(&node);
1373 for (
const auto & [pr, coef] : row_it->second)
1376 constraining_elems.insert(pr.first);
1379 for (
const Elem * constraining_elem : constraining_elems)
1381 const dof_id_type constraining_global_index_by_pid =
1384 graph_row.push_back(constraining_global_index_by_pid);
1390 connections_to_push[constraining_elem->processor_id()].emplace_back
1391 (global_index_by_pid, constraining_global_index_by_pid);
1396 for (
const auto & pr :
as_range(elems_constrained_by.equal_range(elem)))
1398 const Elem * constrained = pr.second;
1399 const dof_id_type constrained_global_index_by_pid =
1402 graph_row.push_back(constrained_global_index_by_pid);
1408 connections_to_push[constrained->
processor_id()].emplace_back
1409 (global_index_by_pid, constrained_global_index_by_pid);
1418 auto symmetrize_entries =
1419 [
this, first_local_elem]
1421 const std::vector<std::pair<dof_id_type, dof_id_type>> & incoming_entries)
1423 for (
auto [i, j] : incoming_entries)
1425 libmesh_assert_greater_equal(j, first_local_elem);
1426 const std::size_t jl = j - first_local_elem;
1428 std::vector<dof_id_type> & graph_row =
_dual_graph[jl];
1429 if (std::find(graph_row.begin(), graph_row.end(), i) == graph_row.end())
1432 graph_row.push_back(i);
1438 connections_to_push,
1439 symmetrize_entries);
1447 std::vector<dof_id_type> first_local_index_on_proc(n_proc, 0);
1454 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, dof_id_type>>> entries_to_send;
1457 const std::vector<dof_id_type> & graph_row =
_dual_graph[il];
1459 const auto i = il + first_local_elem;
1461 for (
auto j : graph_row)
1465 while (target_pid+1 < n_proc &&
1466 j >= first_local_index_on_proc[target_pid+1])
1469 entries_to_send[target_pid].emplace_back(i,j);
1473 std::vector<std::tuple<processor_id_type, dof_id_type, dof_id_type>> bad_entries;
1475 auto check_incoming_entries =
1476 [
this, first_local_elem, &bad_entries]
1478 const std::vector<std::pair<dof_id_type, dof_id_type>> & incoming_entries)
1480 for (
auto [i, j] : incoming_entries)
1482 if (j < first_local_elem)
1484 bad_entries.emplace_back(src_pid,i,j);
1487 const std::size_t jl = j - first_local_elem;
1490 bad_entries.emplace_back(src_pid,i,j);
1493 const std::vector<dof_id_type> & graph_row =
_dual_graph[jl];
1494 if (std::find(graph_row.begin(), graph_row.end(), i) ==
1497 bad_entries.emplace_back(src_pid,i,j);
1506 (
mesh.
comm(), entries_to_send, check_incoming_entries);
1507 bool bad_entries_exist = !bad_entries.empty();
1509 if (bad_entries_exist)
1512 if (!bad_entries.empty())
1515 for (
auto [p, i, j] : bad_entries)
1516 std::cerr <<
'(' << p <<
", " << i <<
", " << j <<
"), ";
1517 std::cerr << std::endl;
1520 libmesh_error_msg(
"Asymmetric partitioner graph detected");
1527 LOG_SCOPE(
"assign_partitioning()",
"Partitioner");
1530 libmesh_parallel_only(
mesh.
comm());
1540 std::map<processor_id_type, std::vector<dof_id_type>>
1545 std::map<processor_id_type, std::vector<processor_id_type>>
1548 for (
auto & elem :
mesh.active_element_ptr_range())
1553 requested_ids[elem->processor_id()].push_back(elem->id());
1556 auto gather_functor =
1561 n_active_local_elem,
1565 std::vector<processor_id_type> & data)
1567 const std::size_t ids_size = ids.size();
1568 data.resize(ids.size());
1570 for (std::size_t i=0; i != ids_size; i++)
1580 global_index_by_pid - first_local_elem;
1582 libmesh_assert_less (local_index, parts.size());
1583 libmesh_assert_less (local_index, n_active_local_elem);
1586 cast_int<processor_id_type>(parts[local_index]);
1590 data[i] = elem_procid;
1594 auto action_functor =
1597 const std::vector<dof_id_type> &,
1598 const std::vector<processor_id_type> & new_procids)
1600 filled_request[pid] = new_procids;
1606 (
mesh.
comm(), requested_ids, gather_functor, action_functor, ex);
1613 for (
auto & elem :
mesh.active_element_ptr_range())
1617 libmesh_assert_less (counters[current_pid], requested_ids[current_pid].size());
1620 filled_request[current_pid][counters[current_pid]++];
1623 elem->processor_id() = elem_procid;
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
Defines a Cartesian bounding box by the two corner extremum.
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
processor_id_type processor_id() const
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
This is the base class from which all geometric element types are derived.
const Elem * parent() const
void total_family_tree(std::vector< const Elem * > &family, bool reset=true) const
Same as the family_tree() member, but also adds any subactive descendants.
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
This is the MeshBase class.
virtual const Node & node_ref(const dof_id_type i) const
virtual bool is_serial() const
virtual bool is_replicated() const
virtual void redistribute()
Redistribute elements between processors.
const NodeRange & node_stored_range()
virtual void update_post_partitioning()
Recalculate any cached data (or invalidate any caches that are computed on the fly) after elements an...
unsigned int n_partitions() const
virtual dof_id_type max_elem_id() const =0
constraint_rows_type & get_constraint_rows()
Constraint rows accessors.
dof_id_type n_active_local_elem() const
virtual dof_id_type n_active_elem() const =0
unsigned int & set_n_partitions()
This is the MeshCommunication class.
void find_local_indices(const libMesh::BoundingBox &, const ForwardIterator &, const ForwardIterator &, std::unordered_map< dof_id_type, dof_id_type > &) const
This method determines a locally unique, contiguous index for each object in the input range.
void find_global_indices(const Parallel::Communicator &communicator, const libMesh::BoundingBox &, const ForwardIterator &, const ForwardIterator &, std::vector< dof_id_type > &) const
This method determines a globally unique, partition-agnostic index for each object in the input range...
A Node is like a Point, but with more information.
processor_id_type choose_processor_id(processor_id_type pid1, processor_id_type pid2) const
Return which of pid1 and pid2 would be preferred by the current load-balancing heuristic applied to t...
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
bool single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
static void set_interface_node_processor_ids_petscpartitioner(MeshBase &mesh)
Nodes on the partitioning interface is partitioned into two groups using a PETSc partitioner for each...
std::vector< dof_id_type > _n_active_elem_on_proc
The number of active elements on each processor.
virtual void partition(MeshBase &mesh, const unsigned int n)
Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.
static void set_parent_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the inactive parent elements.
static void processor_pairs_to_interface_nodes(MeshBase &mesh, std::map< std::pair< processor_id_type, processor_id_type >, std::set< dof_id_type > > &processor_pair_to_nodes)
On the partitioning interface, a surface is shared by two and only two processors.
static void partition_unpartitioned_elements(MeshBase &mesh)
These functions assign processor IDs to newly-created elements (in parallel) which are currently assi...
std::unordered_map< dof_id_type, dof_id_type > _global_index_by_pid_map
Maps active element ids into a contiguous range, as needed by parallel partitioner.
static void set_interface_node_processor_ids_BFS(MeshBase &mesh)
Nodes on the partitioning interface is clustered into two groups BFS (Breadth First Search)scheme for...
std::vector< std::vector< dof_id_type > > _dual_graph
A dual graph corresponds to the mesh, and it is typically used in paritioner.
static std::unique_ptr< Partitioner > build(const PartitionerType solver_package)
Builds a Partitioner of the type specified by partitioner_type.
virtual void _do_repartition(MeshBase &mesh, const unsigned int n)
This is the actual re-partitioning method which can be overridden in derived classes.
virtual void _do_partition(MeshBase &mesh, const unsigned int n)=0
This is the actual partitioning method which must be overridden in derived classes.
virtual void build_graph(const MeshBase &mesh)
Build a dual graph for partitioner.
static void set_node_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the nodes.
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Construct contiguous global indices for the current partitioning.
static void set_interface_node_processor_ids_linear(MeshBase &mesh)
Nodes on the partitioning interface is linearly assigned to each pair of processors.
void repartition(MeshBase &mesh, const unsigned int n)
Repartitions the MeshBase into n parts.
void assign_partitioning(MeshBase &mesh, const std::vector< dof_id_type > &parts)
Assign the computed partitioning to the mesh.
static const dof_id_type communication_blocksize
The blocksize to use when doing blocked parallel communication.
bool single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Slightly generalized version of single_partition which acts on a range of elements defined by the pai...
std::vector< Elem * > _local_id_to_elem
virtual PartitionerType type() const
The StoredRange class defines a contiguous, divisible set of objects.
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)
void sync_node_data_by_element_id(MeshBase &mesh, const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, const ElemCheckFunctor &elem_check, const NodeCheckFunctor &node_check, SyncFunctor &sync)
Synchronize data about a range of ghost nodes uniquely identified by an element id and local node id,...
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.
void parallel_for_each(Range &&range, Body &&body, unsigned int n_threads=libMesh::n_threads())
A nicer syntax for parallel_for calls in cases where no setup or teardown is needed outside the subra...
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
std::string enum_to_string(const T e)
The libMesh namespace provides an interface to certain functionality in the library.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
PartitionerType
Defines an enum for mesh partitioner types.
@ MAPPED_SUBDOMAIN_PARTITIONER
@ HILBERT_SFC_PARTITIONER
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
void libmesh_ignore(const Args &...)
PetscErrorCode PetscInt const PetscInt IS * is
bool on_command_line(std::string arg)
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
The definition of the element_iterator struct.
SyncLocalIDs(map_type &_id_map)
void act_on_data(const std::vector< dof_id_type > &ids, const std::vector< datum > &local_ids)
void gather_data(const std::vector< dof_id_type > &ids, std::vector< datum > &local_ids) const
std::unordered_map< dof_id_type, dof_id_type > map_type
const dof_id_type n_nodes