libMesh
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
RowPartitioner Class Reference
Inheritance diagram for RowPartitioner:
[legend]

Public Member Functions

 RowPartitioner (bool repartitioned)
 
std::unique_ptr< Partitioner > clone () const override
 
virtual PartitionerType type () const
 
virtual void partition (MeshBase &mesh, const unsigned int n)
 Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.
 
virtual void partition (MeshBase &mesh)
 Partitions the MeshBase into mesh.n_processors() by setting processor_id() on Nodes and Elems.
 
virtual void partition_range (MeshBase &, MeshBase::element_iterator, MeshBase::element_iterator, const unsigned int)
 Partitions elements in the range (it, end) into n parts.
 
void repartition (MeshBase &mesh, const unsigned int n)
 Repartitions the MeshBase into n parts.
 
void repartition (MeshBase &mesh)
 Repartitions the MeshBase into mesh.n_processors() parts.
 
virtual void attach_weights (ErrorVector *)
 Attach weights that can be used for partitioning.
 
virtual bool partitions_from_scratch () const
 

Static Public Member Functions

static std::unique_ptr< Partitioner > build (const PartitionerType solver_package)
 Builds a Partitioner of the type specified by partitioner_type.
 
static void partition_unpartitioned_elements (MeshBase &mesh)
 These functions assign processor IDs to newly-created elements (in parallel) which are currently assigned to processor 0.
 
static void partition_unpartitioned_elements (MeshBase &mesh, const unsigned int n)
 
static void partition_unpartitioned_elements (MeshBase &mesh, const unsigned int n, const bool spatial_indexing)
 As above, but spatial_indexing selects how the elements are mapped onto the partitions.
 
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 set_node_processor_ids (MeshBase &mesh)
 This function is called after partitioning to set the processor IDs for the nodes.
 
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 set_interface_node_processor_ids_linear (MeshBase &mesh)
 Nodes on the partitioning interface is linearly assigned to each pair of processors.
 
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 per pair of processors.
 
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 pair of processors.
 

Protected Member Functions

void _do_partition (MeshBase &mesh, const unsigned int) override
 This is the actual partitioning method which must be overridden in derived classes.
 
bool single_partition (MeshBase &mesh)
 Trivially "partitions" the mesh for one processor.
 
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 pair of iterators (it, end).
 
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 _find_global_index_by_pid_map (const MeshBase &mesh)
 Construct contiguous global indices for the current partitioning.
 
virtual void build_graph (const MeshBase &mesh)
 Build a dual graph for partitioner.
 
void assign_partitioning (MeshBase &mesh, const std::vector< dof_id_type > &parts)
 Assign the computed partitioning to the mesh.
 

Protected Attributes

ErrorVector * _weights
 The weights that might be used for partitioning.
 
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.
 
std::vector< dof_id_type > _n_active_elem_on_proc
 The number of active elements on each processor.
 
std::vector< std::vector< dof_id_type > > _dual_graph
 A dual graph corresponds to the mesh, and it is typically used in paritioner.
 
std::vector< Elem * > _local_id_to_elem
 

Static Protected Attributes

static const dof_id_type communication_blocksize
 The blocksize to use when doing blocked parallel communication.
 

Private Attributes

bool _repartitioned
 

Detailed Description

Definition at line 165 of file periodic_bc_test.C.

Constructor & Destructor Documentation

◆ RowPartitioner()

RowPartitioner::RowPartitioner ( bool  repartitioned)
inline

Definition at line 168 of file periodic_bc_test.C.

168: _repartitioned(repartitioned) {}

Member Function Documentation

◆ _do_partition()

void RowPartitioner::_do_partition ( MeshBase &  mesh,
const unsigned int  n 
)
inlineoverrideprotectedvirtual

This is the actual partitioning method which must be overridden in derived classes.

It is called via the public partition() method above by the user.

Implements libMesh::Partitioner.

Definition at line 174 of file periodic_bc_test.C.

175 {
176 for (auto & elem : mesh.active_element_ptr_range())
177 {
178 const auto row = static_cast<unsigned int>(elem->vertex_average()(1) * 8);
179 const bool on_proc_1 = _repartitioned ? (row == 0 || row == 2) : (row == 2);
180 elem->processor_id() = on_proc_1;
181 }
182 }
MeshBase & mesh
LIBMESH_DEVICE_INLINE ResultVector row(const TensorLike &T_in, const unsigned int row_index)

References _repartitioned, and mesh.

◆ _do_repartition()

virtual void libMesh::Partitioner::_do_repartition ( MeshBase &  mesh,
const unsigned int  n 
)
inlineprotectedvirtualinherited

This is the actual re-partitioning method which can be overridden in derived classes.

Note
The default behavior is to simply call the partition function.

Reimplemented in libMesh::ParmetisPartitioner.

Definition at line 281 of file partitioner.h.

282 { this->_do_partition (mesh, n); }
virtual void _do_partition(MeshBase &mesh, const unsigned int n)=0
This is the actual partitioning method which must be overridden in derived classes.

References libMesh::Partitioner::_do_partition().

Referenced by libMesh::Partitioner::repartition().

◆ _find_global_index_by_pid_map()

void libMesh::Partitioner::_find_global_index_by_pid_map ( const MeshBase &  mesh)
protectedvirtualinherited

Construct contiguous global indices for the current partitioning.

The global indices are ordered part-by-part

Definition at line 1126 of file partitioner.C.

1127{
1128 const dof_id_type n_active_local_elem = mesh.n_active_local_elem();
1129
1130 // Find the number of active elements on each processor. We cannot use
1131 // mesh.n_active_elem_on_proc(pid) since that only returns the number of
1132 // elements assigned to pid which are currently stored on the calling
1133 // processor. This will not in general be correct for parallel meshes
1134 // when (pid!=mesh.processor_id()).
1135 auto n_proc = mesh.n_processors();
1136 _n_active_elem_on_proc.resize(n_proc);
1137 mesh.comm().allgather(n_active_local_elem, _n_active_elem_on_proc);
1138
1139 std::vector<dof_id_type> n_active_elem_before_proc(mesh.n_processors());
1140
1141 for (auto i : make_range(n_proc-1))
1142 n_active_elem_before_proc[i+1] =
1143 n_active_elem_before_proc[i] + _n_active_elem_on_proc[i];
1144
1147
1149
1150 // create the mapping which is contiguous by processor
1152 mesh.active_local_elements_begin(),
1153 mesh.active_local_elements_end(),
1155
1157
1159 (mesh.comm(), mesh.active_elements_begin(), mesh.active_elements_end(), sync);
1160
1161 for (const auto & elem : mesh.active_element_ptr_range())
1162 {
1163 const processor_id_type pid = elem->processor_id();
1164 libmesh_assert_less (_global_index_by_pid_map[elem->id()], _n_active_elem_on_proc[pid]);
1165
1166 _global_index_by_pid_map[elem->id()] += n_active_elem_before_proc[pid];
1167 }
1168}
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
Defines a Cartesian bounding box by the two corner extremum.
dof_id_type n_active_local_elem() const
Definition mesh_base.h:719
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.
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
std::vector< dof_id_type > _n_active_elem_on_proc
The number of active elements on each processor.
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.
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:630
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.
uint8_t dof_id_type
Definition id_types.h:67
uint8_t processor_id_type
Definition id_types.h:104
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...
Definition int_range.h:176

References libMesh::Partitioner::_global_index_by_pid_map, libMesh::Partitioner::_n_active_elem_on_proc, libMesh::Parallel::Communicator::allgather(), libMesh::ParallelObject::comm(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshCommunication::find_local_indices(), libMesh::make_range(), mesh, libMesh::MeshBase::n_active_local_elem(), libMesh::ParallelObject::n_processors(), and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by libMesh::Partitioner::build_graph().

◆ assign_partitioning()

void libMesh::Partitioner::assign_partitioning ( MeshBase &  mesh,
const std::vector< dof_id_type > &  parts 
)
protectedinherited

Assign the computed partitioning to the mesh.

Definition at line 1525 of file partitioner.C.

1526{
1527 LOG_SCOPE("assign_partitioning()", "Partitioner");
1528
1529 // This function must be run on all processors at once
1530 libmesh_parallel_only(mesh.comm());
1531
1532 dof_id_type first_local_elem = 0;
1533 for (auto pid : make_range(mesh.processor_id()))
1534 first_local_elem += _n_active_elem_on_proc[pid];
1535
1536#ifndef NDEBUG
1537 const dof_id_type n_active_local_elem = mesh.n_active_local_elem();
1538#endif
1539
1540 std::map<processor_id_type, std::vector<dof_id_type>>
1541 requested_ids;
1542
1543 // Results to gather from each processor - kept in a map so we
1544 // do only one loop over elements after all receives are done.
1545 std::map<processor_id_type, std::vector<processor_id_type>>
1546 filled_request;
1547
1548 for (auto & elem : mesh.active_element_ptr_range())
1549 {
1550 // we need to get the index from the owning processor
1551 // (note we cannot assign it now -- we are iterating
1552 // over elements again and this will be bad!)
1553 requested_ids[elem->processor_id()].push_back(elem->id());
1554 }
1555
1556 auto gather_functor =
1557 [this,
1558 & parts,
1559#ifndef NDEBUG
1560 & mesh,
1561 n_active_local_elem,
1562#endif
1563 first_local_elem]
1564 (processor_id_type, const std::vector<dof_id_type> & ids,
1565 std::vector<processor_id_type> & data)
1566 {
1567 const std::size_t ids_size = ids.size();
1568 data.resize(ids.size());
1569
1570 for (std::size_t i=0; i != ids_size; i++)
1571 {
1572 const dof_id_type requested_elem_index = ids[i];
1573
1574 libmesh_assert(_global_index_by_pid_map.count(requested_elem_index));
1575
1576 const dof_id_type global_index_by_pid =
1577 _global_index_by_pid_map[requested_elem_index];
1578
1579 const dof_id_type local_index =
1580 global_index_by_pid - first_local_elem;
1581
1582 libmesh_assert_less (local_index, parts.size());
1583 libmesh_assert_less (local_index, n_active_local_elem);
1584
1585 const processor_id_type elem_procid =
1586 cast_int<processor_id_type>(parts[local_index]);
1587
1588 libmesh_assert_less (elem_procid, mesh.n_partitions());
1589
1590 data[i] = elem_procid;
1591 }
1592 };
1593
1594 auto action_functor =
1595 [&filled_request]
1596 (processor_id_type pid,
1597 const std::vector<dof_id_type> &,
1598 const std::vector<processor_id_type> & new_procids)
1599 {
1600 filled_request[pid] = new_procids;
1601 };
1602
1603 // Trade requests with other processors
1604 const processor_id_type * ex = nullptr;
1606 (mesh.comm(), requested_ids, gather_functor, action_functor, ex);
1607
1608 // and finally assign the partitioning.
1609 // note we are iterating in exactly the same order
1610 // used to build up the request, so we can expect the
1611 // required entries to be in the proper sequence.
1612 std::vector<unsigned int> counters(mesh.n_processors(), 0);
1613 for (auto & elem : mesh.active_element_ptr_range())
1614 {
1615 const processor_id_type current_pid = elem->processor_id();
1616
1617 libmesh_assert_less (counters[current_pid], requested_ids[current_pid].size());
1618
1619 const processor_id_type elem_procid =
1620 filled_request[current_pid][counters[current_pid]++];
1621
1622 libmesh_assert_less (elem_procid, mesh.n_partitions());
1623 elem->processor_id() = elem_procid;
1624 }
1625}
unsigned int n_partitions() const
Definition mesh_base.h:1552
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
libmesh_assert(ctx)

References libMesh::Partitioner::_global_index_by_pid_map, libMesh::Partitioner::_n_active_elem_on_proc, libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::make_range(), mesh, libMesh::MeshBase::n_active_local_elem(), libMesh::MeshBase::n_partitions(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), and TIMPI::pull_parallel_vector_data().

◆ attach_weights()

virtual void libMesh::Partitioner::attach_weights ( ErrorVector *  )
inlinevirtualinherited

Attach weights that can be used for partitioning.

This ErrorVector should be exactly the same on every processor and should have mesh->max_elem_id() entries.

Reimplemented in libMesh::MetisPartitioner.

Definition at line 224 of file partitioner.h.

224{ libmesh_not_implemented(); }

◆ build()

std::unique_ptr< Partitioner > libMesh::Partitioner::build ( const PartitionerType  solver_package)
staticinherited

Builds a Partitioner of the type specified by partitioner_type.

Definition at line 160 of file partitioner.C.

161{
162 switch (partitioner_type)
163 {
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>();
178 case SFC_PARTITIONER:
179 return std::make_unique<SFCPartitioner>();
181 return std::make_unique<SubdomainPartitioner>();
182 default:
183 libmesh_error_msg("Invalid partitioner type: " <<
184 Utility::enum_to_string(partitioner_type));
185 }
186}
std::string enum_to_string(const T e)

References libMesh::CENTROID_PARTITIONER, libMesh::Utility::enum_to_string(), libMesh::HILBERT_SFC_PARTITIONER, libMesh::LINEAR_PARTITIONER, libMesh::MAPPED_SUBDOMAIN_PARTITIONER, libMesh::METIS_PARTITIONER, libMesh::MORTON_SFC_PARTITIONER, libMesh::PARMETIS_PARTITIONER, libMesh::SFC_PARTITIONER, and libMesh::SUBDOMAIN_PARTITIONER.

Referenced by libMesh::DistributedMesh::DistributedMesh(), libMesh::ReplicatedMesh::ReplicatedMesh(), PartitionerTest< PartitionerSubclass, MeshClass >::testBuild(), and MeshDeletionsTest::testDeleteElem().

◆ build_graph()

void libMesh::Partitioner::build_graph ( const MeshBase &  mesh)
protectedvirtualinherited

Build a dual graph for partitioner.

Reimplemented in libMesh::ParmetisPartitioner.

Definition at line 1170 of file partitioner.C.

1171{
1172 LOG_SCOPE("build_graph()", "Partitioner");
1173
1174 const dof_id_type n_active_local_elem = mesh.n_active_local_elem();
1175
1176 // If we have boundary elements in this mesh, we want to account for
1177 // the connectivity between them and interior elements. We can find
1178 // interior elements from boundary elements, but we need to build up
1179 // a lookup map to do the reverse.
1180 typedef std::unordered_multimap<const Elem *, const Elem *> map_type;
1181 map_type interior_to_boundary_map;
1182
1183 // If we have spline nodes in this mesh, we want to account for the
1184 // connectivity between them and integration elements. We can find
1185 // spline nodes from integration elements, but need a reverse map
1186 // {integration_elements} = elems_constrained_by[spline_nodeelem]
1187 map_type elems_constrained_by;
1188
1189 const auto & mesh_constrained_nodes = mesh.get_constraint_rows();
1190
1191 for (const Elem * elem : mesh.active_element_ptr_range())
1192 {
1193 if (!mesh_constrained_nodes.empty()) // quick test for non-IGA cases
1194 {
1195 const auto end_it = mesh_constrained_nodes.end();
1196
1197 // Use a set to avoid duplicates. Use a well-defined method
1198 // of ordering that set to make debugging easier.
1199 std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
1200 for (const Node & node : elem->node_ref_range())
1201 {
1202 if (const auto row_it = mesh_constrained_nodes.find(&node);
1203 row_it != end_it)
1204 for (const auto & [pr, coef] : row_it->second)
1205 {
1206 libmesh_ignore(coef); // avoid gcc 7 warning
1207 constraining_elems.insert(pr.first);
1208 }
1209 }
1210 for (const Elem * constraining_elem : constraining_elems)
1211 elems_constrained_by.emplace(constraining_elem, elem);
1212 }
1213
1214 // If we don't have an interior_parent and we don't have any
1215 // constrained nodes then there's nothing else to look up.
1216 if (elem->interior_parent())
1217 {
1218 // get all relevant interior elements
1219 std::set<const Elem *> neighbor_set;
1220 elem->find_interior_neighbors(neighbor_set);
1221
1222 for (const auto & neighbor : neighbor_set)
1223 interior_to_boundary_map.emplace(neighbor, elem);
1224 }
1225 }
1226
1227#ifdef LIBMESH_ENABLE_AMR
1228 std::vector<const Elem *> neighbors_offspring;
1229#endif
1230
1231 // This is costly, and we only need to do it if the mesh has
1232 // changed since we last partitioned... but the mesh probably has
1233 // changed since we last partitioned, and if it hasn't we don't
1234 // have a reliable way to be sure of that.
1236
1237 dof_id_type first_local_elem = 0;
1238 for (auto pid : make_range(mesh.processor_id()))
1239 first_local_elem += _n_active_elem_on_proc[pid];
1240
1241 _dual_graph.clear();
1242 _dual_graph.resize(n_active_local_elem);
1243 _local_id_to_elem.resize(n_active_local_elem);
1244
1245 // We may need to communicate constraint-row-based connections
1246 // between processors
1247 std::unordered_map<processor_id_type,
1248 std::vector<std::pair<dof_id_type, dof_id_type>>> connections_to_push;
1249
1250 for (const auto & elem : mesh.active_local_element_ptr_range())
1251 {
1252 libmesh_assert (_global_index_by_pid_map.count(elem->id()));
1253 const dof_id_type global_index_by_pid =
1254 _global_index_by_pid_map[elem->id()];
1255
1256 const dof_id_type local_index =
1257 global_index_by_pid - first_local_elem;
1258 libmesh_assert_less (local_index, n_active_local_elem);
1259
1260 std::vector<dof_id_type> & graph_row = _dual_graph[local_index];
1261
1262 // Save this off to make it easy to index later
1263 _local_id_to_elem[local_index] = const_cast<Elem*>(elem);
1264
1265 // Loop over the element's neighbors. An element
1266 // adjacency corresponds to a face neighbor
1267 for (auto neighbor : elem->neighbor_ptr_range())
1268 {
1269 if (neighbor != nullptr)
1270 {
1271 // If the neighbor is active treat it
1272 // as a connection
1273 if (neighbor->active())
1274 {
1275 libmesh_assert(_global_index_by_pid_map.count(neighbor->id()));
1276 const dof_id_type neighbor_global_index_by_pid =
1277 _global_index_by_pid_map[neighbor->id()];
1278
1279 graph_row.push_back(neighbor_global_index_by_pid);
1280 }
1281
1282#ifdef LIBMESH_ENABLE_AMR
1283
1284 // Otherwise we need to find all of the
1285 // neighbor's children that are connected to
1286 // us and add them
1287 else
1288 {
1289 // The side of the neighbor to which
1290 // we are connected
1291 const unsigned int ns =
1292 neighbor->which_neighbor_am_i (elem);
1293 libmesh_assert_less (ns, neighbor->n_neighbors());
1294
1295 // Get all the active children (& grandchildren, etc...)
1296 // of the neighbor
1297
1298 // FIXME - this is the wrong thing, since we
1299 // should be getting the active family tree on
1300 // our side only. But adding too many graph
1301 // links may cause hanging nodes to tend to be
1302 // on partition interiors, which would reduce
1303 // communication overhead for constraint
1304 // equations, so we'll leave it.
1305
1306 neighbor->active_family_tree (neighbors_offspring);
1307
1308 // Get all the neighbor's children that
1309 // live on that side and are thus connected
1310 // to us
1311 for (const auto & child : neighbors_offspring)
1312 {
1313 // This does not assume a level-1 mesh.
1314 // Note that since children have sides numbered
1315 // coincident with the parent then this is a sufficient test.
1316 if (child->neighbor_ptr(ns) == elem)
1317 {
1318 libmesh_assert (child->active());
1319 libmesh_assert (_global_index_by_pid_map.count(child->id()));
1320 const dof_id_type child_global_index_by_pid =
1321 _global_index_by_pid_map[child->id()];
1322
1323 graph_row.push_back(child_global_index_by_pid);
1324 }
1325 }
1326 }
1327
1328#endif /* ifdef LIBMESH_ENABLE_AMR */
1329
1330
1331 }
1332 }
1333
1334 if ((elem->dim() < LIBMESH_DIM) &&
1335 elem->interior_parent())
1336 {
1337 // get all relevant interior elements
1338 std::set<const Elem *> neighbor_set;
1339 elem->find_interior_neighbors(neighbor_set);
1340
1341 for (const auto & neighbor : neighbor_set)
1342 {
1343 const dof_id_type neighbor_global_index_by_pid =
1344 _global_index_by_pid_map[neighbor->id()];
1345
1346 graph_row.push_back(neighbor_global_index_by_pid);
1347 }
1348 }
1349
1350 // Check for any boundary neighbors
1351 for (const auto & pr : as_range(interior_to_boundary_map.equal_range(elem)))
1352 {
1353 const Elem * neighbor = pr.second;
1354
1355 const dof_id_type neighbor_global_index_by_pid =
1356 _global_index_by_pid_map[neighbor->id()];
1357
1358 graph_row.push_back(neighbor_global_index_by_pid);
1359 }
1360
1361 // Check for any constraining elements
1362 if (!mesh_constrained_nodes.empty()) // quick test for non-IGA cases
1363 {
1364 const auto end_it = mesh_constrained_nodes.end();
1365
1366 // Use a set to avoid duplicates. Use a well-defined method
1367 // of ordering that set to make debugging easier.
1368 std::set<const Elem *, CompareElemIdsByLevel> constraining_elems;
1369 for (const Node & node : elem->node_ref_range())
1370 {
1371 if (const auto row_it = mesh_constrained_nodes.find(&node);
1372 row_it != end_it)
1373 for (const auto & [pr, coef] : row_it->second)
1374 {
1375 libmesh_ignore(coef); // avoid gcc 7 warning
1376 constraining_elems.insert(pr.first);
1377 }
1378 }
1379 for (const Elem * constraining_elem : constraining_elems)
1380 {
1381 const dof_id_type constraining_global_index_by_pid =
1382 _global_index_by_pid_map[constraining_elem->id()];
1383
1384 graph_row.push_back(constraining_global_index_by_pid);
1385
1386 // We can't be sure if the constraining element's owner sees
1387 // the assembly element, so to get a symmetric connectivity
1388 // graph we'll need to tell them about us to be safe.
1389 if (constraining_elem->processor_id() != mesh.processor_id())
1390 connections_to_push[constraining_elem->processor_id()].emplace_back
1391 (global_index_by_pid, constraining_global_index_by_pid);
1392 }
1393 }
1394
1395 // Check for any constrained elements
1396 for (const auto & pr : as_range(elems_constrained_by.equal_range(elem)))
1397 {
1398 const Elem * constrained = pr.second;
1399 const dof_id_type constrained_global_index_by_pid =
1400 _global_index_by_pid_map[constrained->id()];
1401
1402 graph_row.push_back(constrained_global_index_by_pid);
1403
1404 // We can't be sure if the constrained element's owner sees
1405 // the assembly element, so to get a symmetric connectivity
1406 // graph we'll need to tell them about us to be safe.
1407 if (constrained->processor_id() != mesh.processor_id())
1408 connections_to_push[constrained->processor_id()].emplace_back
1409 (global_index_by_pid, constrained_global_index_by_pid);
1410 }
1411 }
1412
1413 // Partitioners like Parmetis require a symmetric adjacency matrix,
1414 // but if we have an assembly element constrained by a spline
1415 // NodeElem owned by another processor, it's possible that that
1416 // processor doesn't see our assembly element. Let's push those
1417 // entries, to ensure they're counted on both sides.
1418 auto symmetrize_entries =
1419 [this, first_local_elem]
1420 (processor_id_type /*src_pid*/,
1421 const std::vector<std::pair<dof_id_type, dof_id_type>> & incoming_entries)
1422 {
1423 for (auto [i, j] : incoming_entries)
1424 {
1425 libmesh_assert_greater_equal(j, first_local_elem);
1426 const std::size_t jl = j - first_local_elem;
1427 libmesh_assert_less(jl, _dual_graph.size());
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())
1430 {
1431// std::cerr << "Pushing back (" << j << ", " << i << ") from " << src_pid << std::endl;
1432 graph_row.push_back(i);
1433 }
1434 }
1435 };
1436
1438 connections_to_push,
1439 symmetrize_entries);
1440
1441 // *Now* we should have a symmetric adjacency matrix. Let's check
1442 // that, so any failures get caught before they e.g. confuse
1443 // Parmetis in hard-to-debug ways. That's a global communication so
1444 // we'll only do it in debug mode.
1445#ifdef DEBUG
1446 auto n_proc = mesh.n_processors();
1447 std::vector<dof_id_type> first_local_index_on_proc(n_proc, 0);
1448 for (auto pid : make_range(1u,n_proc))
1449 first_local_index_on_proc[pid] = first_local_index_on_proc[pid-1] + _n_active_elem_on_proc[pid-1];
1450
1451 libmesh_assert_equal_to(first_local_index_on_proc[mesh.processor_id()],
1452 first_local_elem);
1453
1454 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, dof_id_type>>> entries_to_send;
1455 for (auto il : index_range(_dual_graph))
1456 {
1457 const std::vector<dof_id_type> & graph_row = _dual_graph[il];
1458
1459 const auto i = il + first_local_elem;
1460
1461 for (auto j : graph_row)
1462 {
1463 // Stupid graph rows aren't sorted yet...
1464 processor_id_type target_pid = 0;
1465 while (target_pid+1 < n_proc &&
1466 j >= first_local_index_on_proc[target_pid+1])
1467 ++target_pid;
1468
1469 entries_to_send[target_pid].emplace_back(i,j);
1470 }
1471 }
1472
1473 std::vector<std::tuple<processor_id_type, dof_id_type, dof_id_type>> bad_entries;
1474
1475 auto check_incoming_entries =
1476 [this, first_local_elem, &bad_entries]
1477 (processor_id_type src_pid,
1478 const std::vector<std::pair<dof_id_type, dof_id_type>> & incoming_entries)
1479 {
1480 for (auto [i, j] : incoming_entries)
1481 {
1482 if (j < first_local_elem)
1483 {
1484 bad_entries.emplace_back(src_pid,i,j);
1485 continue;
1486 }
1487 const std::size_t jl = j - first_local_elem;
1488 if (jl >= _dual_graph.size())
1489 {
1490 bad_entries.emplace_back(src_pid,i,j);
1491 continue;
1492 }
1493 const std::vector<dof_id_type> & graph_row = _dual_graph[jl];
1494 if (std::find(graph_row.begin(), graph_row.end(), i) ==
1495 graph_row.end())
1496 {
1497 bad_entries.emplace_back(src_pid,i,j);
1498 continue;
1499 }
1500 }
1501 };
1502
1503 // Keep any failures in sync in parallel, for easier debugging in
1504 // unit tests where the failure exception will be caught.
1506 (mesh.comm(), entries_to_send, check_incoming_entries);
1507 bool bad_entries_exist = !bad_entries.empty();
1508 mesh.comm().max(bad_entries_exist);
1509 if (bad_entries_exist)
1510 {
1511#if 0 // Optional verbosity for if this breaks again...
1512 if (!bad_entries.empty())
1513 {
1514 std::cerr << "Bad entries on processor " << mesh.processor_id() << ": ";
1515 for (auto [p, i, j] : bad_entries)
1516 std::cerr << '(' << p << ", " << i << ", " << j << "), ";
1517 std::cerr << std::endl;
1518 }
1519#endif
1520 libmesh_error_msg("Asymmetric partitioner graph detected");
1521 }
1522#endif
1523}
void max(const T &r, T &o, Request &req) const
processor_id_type processor_id() const
Definition dof_object.h:895
dof_id_type id() const
Definition dof_object.h:833
This is the base class from which all geometric element types are derived.
Definition elem.h:96
constraint_rows_type & get_constraint_rows()
Constraint rows accessors.
Definition mesh_base.h:1994
A Node is like a Point, but with more information.
Definition node.h:55
processor_id_type processor_id() const
std::vector< std::vector< dof_id_type > > _dual_graph
A dual graph corresponds to the mesh, and it is typically used in paritioner.
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Construct contiguous global indices for the current partitioning.
std::vector< Elem * > _local_id_to_elem
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
void libmesh_ignore(const Args &...)

References libMesh::Partitioner::_dual_graph, libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::Partitioner::_global_index_by_pid_map, libMesh::Partitioner::_local_id_to_elem, libMesh::Partitioner::_n_active_elem_on_proc, libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::MeshBase::get_constraint_rows(), libMesh::DofObject::id(), libMesh::index_range(), libMesh::libmesh_assert(), libMesh::libmesh_ignore(), libMesh::make_range(), libMesh::Parallel::Communicator::max(), mesh, libMesh::MeshBase::n_active_local_elem(), libMesh::ParallelObject::n_processors(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), and TIMPI::push_parallel_vector_data().

◆ clone()

std::unique_ptr< Partitioner > RowPartitioner::clone ( ) const
inlineoverridevirtual
Returns
A copy of this partitioner wrapped in a smart pointer.

This is used when copying meshes, and must be overridden in the derived classes.

Implements libMesh::Partitioner.

Definition at line 170 of file periodic_bc_test.C.

171 { return std::make_unique<RowPartitioner>(*this); }

◆ partition() [1/2]

void libMesh::Partitioner::partition ( MeshBase &  mesh)
virtualinherited

Partitions the MeshBase into mesh.n_processors() by setting processor_id() on Nodes and Elems.

Note
If you are implementing a new type of Partitioner, you most likely do not want to override the partition() function, see instead the protected virtual _do_partition() method below. The partition() function is responsible for doing a lot of libmesh-internals-specific setup and finalization before and after the _do_partition() function is called. The only responsibility of the _do_partition() function, on the other hand, is to set the processor IDs of the elements according to a specific partitioning algorithm. See, e.g. MetisPartitioner for an example.

Definition at line 190 of file partitioner.C.

191{
192 this->partition(mesh,mesh.n_processors());
193}
virtual void partition(MeshBase &mesh, const unsigned int n)
Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.

References mesh, libMesh::ParallelObject::n_processors(), and libMesh::Partitioner::partition().

◆ partition() [2/2]

void libMesh::Partitioner::partition ( MeshBase &  mesh,
const unsigned int  n 
)
virtualinherited

Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.

Note
If you are implementing a new type of Partitioner, you most likely do not want to override the partition() function, see instead the protected virtual _do_partition() method below. The partition() function is responsible for doing a lot of libmesh-internals-specific setup and finalization before and after the _do_partition() function is called. The only responsibility of the _do_partition() function, on the other hand, is to set the processor IDs of the elements according to a specific partitioning algorithm. See, e.g. MetisPartitioner for an example.

Definition at line 197 of file partitioner.C.

199{
200 libmesh_parallel_only(mesh.comm());
201
202 // BSK - temporary fix while redistribution is integrated 6/26/2008
203 // Uncomment this to not repartition in parallel
204 // if (!mesh.is_serial())
205 // return;
206
207 // we cannot partition into more pieces than we have
208 // active elements!
209 const unsigned int n_parts =
210 static_cast<unsigned int>
211 (std::min(mesh.n_active_elem(), static_cast<dof_id_type>(n)));
212
213 // Set the number of partitions in the mesh
214 mesh.set_n_partitions()=n_parts;
215
216 if (n_parts == 1)
217 {
218 this->single_partition (mesh);
219 return;
220 }
221
222 // First assign a temporary partitioning to any unpartitioned elements. A spatially
223 // coherent assignment is only worth its parallel sort for a partitioner that refines what
224 // it is handed; the other partitioners just need one that is consistent across processors,
225 // which the cheap traversal-order assignment already is on a replicated mesh.
227 (mesh, n_parts,
228 /*spatial_indexing=*/!(mesh.is_replicated() && this->partitions_from_scratch()));
229
230 // Call the partitioning function
231 this->_do_partition(mesh,n_parts);
232
233 // Set the parent's processor ids
235
236 // Ghosting functors may iterate over local elements while we
237 // redistribute, so cached local ranges must reflect the new element
238 // processor ids
240
241 // Redistribute elements if necessary, before setting node processor
242 // ids, to make sure those will be set consistently
244
245#ifdef DEBUG
247
248 // Messed up elem processor_id()s can leave us without the child
249 // elements we need to restrict vectors on a distributed mesh
250 MeshTools::libmesh_assert_valid_procids<Elem>(mesh);
251#endif
252
253 // Set the node's processor ids
255
256#ifdef DEBUG
257 MeshTools::libmesh_assert_valid_procids<Elem>(mesh);
258#endif
259
260 // Give derived Mesh classes a chance to update any cached data to
261 // reflect the new partitioning
263}
virtual bool is_replicated() const
Definition mesh_base.h:387
virtual void redistribute()
Redistribute elements between processors.
Definition mesh_base.C:1256
virtual void update_post_partitioning()
Recalculate any cached data (or invalidate any caches that are computed on the fly) after elements an...
Definition mesh_base.C:1268
virtual dof_id_type n_active_elem() const =0
unsigned int & set_n_partitions()
Definition mesh_base.h:2247
bool single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
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 partition_unpartitioned_elements(MeshBase &mesh)
These functions assign processor IDs to newly-created elements (in parallel) which are currently assi...
static void set_node_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the nodes.
void libmesh_assert_valid_remote_elems(const MeshBase &mesh)
A function for verifying that active local elements' neighbors are never remote elements.
Definition mesh_tools.h:670

References libMesh::Partitioner::_do_partition(), libMesh::ParallelObject::comm(), libMesh::MeshBase::is_replicated(), libMesh::MeshTools::libmesh_assert_valid_remote_elems(), mesh, libMesh::MeshBase::n_active_elem(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::MeshBase::redistribute(), libMesh::MeshBase::set_n_partitions(), libMesh::Partitioner::set_node_processor_ids(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::Partitioner::single_partition(), and libMesh::MeshBase::update_post_partitioning().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), and libMesh::Partitioner::partition().

◆ partition_range()

virtual void libMesh::Partitioner::partition_range ( MeshBase &  ,
MeshBase::element_iterator  ,
MeshBase::element_iterator  ,
const unsigned int   
)
inlinevirtualinherited

Partitions elements in the range (it, end) into n parts.

The mesh from which the iterators are created must also be passed in, since it is a parallel object and has other useful information in it.

Although partition_range() is part of the public Partitioner interface, it should not generally be called by applications. Its main purpose is to support the SubdomainPartitioner, which uses it internally to individually partition ranges of elements before combining them into the final partitioning. Most of the time, the protected _do_partition() function is implemented in terms of partition_range() by passing a range which includes all the elements of the Mesh.

Reimplemented in libMesh::CentroidPartitioner, libMesh::LinearPartitioner, libMesh::MappedSubdomainPartitioner, libMesh::MetisPartitioner, and libMesh::SFCPartitioner.

Definition at line 137 of file partitioner.h.

141 { libmesh_not_implemented(); }

Referenced by libMesh::SubdomainPartitioner::_do_partition().

◆ partition_unpartitioned_elements() [1/3]

void libMesh::Partitioner::partition_unpartitioned_elements ( MeshBase &  mesh)
staticinherited

◆ partition_unpartitioned_elements() [2/3]

void libMesh::Partitioner::partition_unpartitioned_elements ( MeshBase &  mesh,
const unsigned int  n 
)
staticinherited

Definition at line 381 of file partitioner.C.

383{
385 /*spatial_indexing=*/true);
386}

References mesh, and libMesh::Partitioner::partition_unpartitioned_elements().

◆ partition_unpartitioned_elements() [3/3]

void libMesh::Partitioner::partition_unpartitioned_elements ( MeshBase &  mesh,
const unsigned int  n,
const bool  spatial_indexing 
)
staticinherited

As above, but spatial_indexing selects how the elements are mapped onto the partitions.

With true they are ordered along a space-filling curve, so that each partition gets a spatially compact set; this costs a parallel sort. With false their position in the traversal of the range is used, which is free but is only consistent across processors for a replicated mesh.

Definition at line 390 of file partitioner.C.

393{
394 MeshBase::element_iterator it = mesh.unpartitioned_elements_begin();
395 const MeshBase::element_iterator end = mesh.unpartitioned_elements_end();
396
397 const dof_id_type n_unpartitioned_elements = MeshTools::n_elem (it, end);
398
399 // the unpartitioned elements must exist on all processors. If the range is empty on one
400 // it is empty on all, and we can quit right here.
401 if (!n_unpartitioned_elements)
402 return;
403
404 // find the target subdomain sizes
405 std::vector<dof_id_type> subdomain_bounds(mesh.n_processors());
406
407 for (auto pid : make_range(mesh.n_processors()))
408 {
409 dof_id_type tgt_subdomain_size = 0;
410
411 // watch out for the case that n_subdomains < n_processors
412 if (pid < n_subdomains)
413 {
414 tgt_subdomain_size = n_unpartitioned_elements/n_subdomains;
415
416 if (pid < n_unpartitioned_elements%n_subdomains)
417 tgt_subdomain_size++;
418
419 }
420
421 //libMesh::out << "pid, #= " << pid << ", " << tgt_subdomain_size << std::endl;
422 if (pid == 0)
423 subdomain_bounds[0] = tgt_subdomain_size;
424 else
425 subdomain_bounds[pid] = subdomain_bounds[pid-1] + tgt_subdomain_size;
426 }
427
428 libmesh_assert_equal_to (subdomain_bounds.back(), n_unpartitioned_elements);
429
430 // create the unique mapping for all unpartitioned elements independent of partitioning
431 // determine the global indexing for all the unpartitioned elements
432 std::vector<dof_id_type> global_indices;
433
434 // Calling this on all processors a unique range in [0,n_unpartitioned_elements) is constructed.
435 // Only the indices for the elements we pass in are returned in the array.
436 // Without the spatial indexing an element's position in the traversal of the range is used
437 // instead, which a replicated mesh reaches in the same order on every processor and which
438 // therefore indexes [0, n_unpartitioned_elements) just as uniquely, at no cost.
439 if (spatial_indexing)
442 global_indices);
443 else
445
446 dof_id_type cnt=0;
447 for (auto & elem : as_range(it, end))
448 {
449 libmesh_assert (!spatial_indexing || cnt < global_indices.size());
450 const dof_id_type global_index =
451 spatial_indexing ? global_indices[cnt++] : cnt++;
452
453 libmesh_assert_less (global_index, subdomain_bounds.back());
454 libmesh_assert_less (global_index, n_unpartitioned_elements);
455
456 const processor_id_type subdomain_id =
457 cast_int<processor_id_type>
458 (std::distance(subdomain_bounds.begin(),
459 std::upper_bound(subdomain_bounds.begin(),
460 subdomain_bounds.end(),
461 global_index)));
462 libmesh_assert_less (subdomain_id, n_subdomains);
463
464 elem->processor_id() = subdomain_id;
465 //libMesh::out << "assigning " << global_index << " to " << subdomain_id << std::endl;
466 }
467
468 // Even a temporary partitioning may invalidate some mesh caches
470}
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...
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
The definition of the element_iterator struct.
Definition mesh_base.h:2708

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshCommunication::find_global_indices(), libMesh::MeshBase::is_replicated(), libMesh::libmesh_assert(), libMesh::make_range(), mesh, libMesh::MeshTools::n_elem(), libMesh::ParallelObject::n_processors(), and libMesh::MeshBase::update_post_partitioning().

◆ partitions_from_scratch()

virtual bool libMesh::Partitioner::partitions_from_scratch ( ) const
inlinevirtualinherited
Returns
Whether this partitioner computes its partitioning without reference to the partitioning the mesh already carries.

A partitioner that instead refines what it is handed is sensitive to the temporary assignment partition_unpartitioned_elements() gives to unpartitioned elements, and so should have that assignment be spatially coherent rather than merely consistent across processors.

The base-class default is conservative, so that a sub-class partitioner which has not considered whether to override this virtual keeps a spatially coherent temporary partitioning assignment. Overriding it to return true buys a cheaper temporary partitioning on a replicated mesh.

Todo:
Make this pure virtual, so that every partitioner has to state which kind it is, once the partitioners outside the library have been given an override.

Reimplemented in libMesh::CentroidPartitioner, libMesh::LinearPartitioner, libMesh::MappedSubdomainPartitioner, libMesh::MetisPartitioner, libMesh::ParmetisPartitioner, libMesh::SFCPartitioner, libMesh::SubdomainPartitioner, GhostDofConstraintPartitioner, ContrivedPartitioner, NonManifoldTestPartitioner, and OverlappingTestPartitioner.

Definition at line 243 of file partitioner.h.

243{ return false; }

◆ processor_pairs_to_interface_nodes()

void libMesh::Partitioner::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 
)
staticinherited

On the partitioning interface, a surface is shared by two and only two processors.

Try to find which pair of processors corresponds to which surfaces, and store their nodes.

Definition at line 627 of file partitioner.C.

629{
630 // This function must be run on all processors at once
631 libmesh_parallel_only(mesh.comm());
632
633 processor_pair_to_nodes.clear();
634
635 std::set<dof_id_type> mynodes;
636 std::set<dof_id_type> neighbor_nodes;
637 std::vector<dof_id_type> common_nodes;
638
639 // Loop over all the active elements
640 for (auto & elem : mesh.active_element_ptr_range())
641 {
642 libmesh_assert(elem);
643
644 libmesh_assert_not_equal_to (elem->processor_id(), DofObject::invalid_processor_id);
645
646 auto n_nodes = elem->n_nodes();
647
648 // prepare data for this element
649 mynodes.clear();
650 neighbor_nodes.clear();
651 common_nodes.clear();
652
653 for (unsigned int inode = 0; inode < n_nodes; inode++)
654 mynodes.insert(elem->node_id(inode));
655
656 for (auto i : elem->side_index_range())
657 {
658 auto neigh = elem->neighbor_ptr(i);
659 if (neigh && !neigh->is_remote() && neigh->processor_id() != elem->processor_id())
660 {
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));
666
667 std::set_intersection(mynodes.begin(), mynodes.end(),
668 neighbor_nodes.begin(), neighbor_nodes.end(),
669 std::back_inserter(common_nodes));
670
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);
675 }
676 }
677 }
678}
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition dof_object.h:484
const dof_id_type n_nodes
Definition tecplot_io.C:67

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), mesh, and n_nodes.

Referenced by libMesh::Partitioner::set_interface_node_processor_ids_BFS(), libMesh::Partitioner::set_interface_node_processor_ids_linear(), and libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner().

◆ repartition() [1/2]

void libMesh::Partitioner::repartition ( MeshBase &  mesh)
inherited

Repartitions the MeshBase into mesh.n_processors() parts.

This is required since some partitioning algorithms can repartition more efficiently than computing a new partitioning from scratch.

Definition at line 267 of file partitioner.C.

268{
269 this->repartition(mesh,mesh.n_processors());
270}
void repartition(MeshBase &mesh, const unsigned int n)
Repartitions the MeshBase into n parts.

References mesh, libMesh::ParallelObject::n_processors(), and libMesh::Partitioner::repartition().

◆ repartition() [2/2]

void libMesh::Partitioner::repartition ( MeshBase &  mesh,
const unsigned int  n 
)
inherited

Repartitions the MeshBase into n parts.

(Some partitioning algorithms can repartition more efficiently than computing a new partitioning from scratch.) The default behavior is to simply call this->partition(mesh,n).

Definition at line 274 of file partitioner.C.

276{
277 // we cannot partition into more pieces than we have
278 // active elements!
279 const unsigned int n_parts =
280 static_cast<unsigned int>
281 (std::min(mesh.n_active_elem(), static_cast<dof_id_type>(n)));
282
283 // Set the number of partitions in the mesh
284 mesh.set_n_partitions()=n_parts;
285
286 if (n_parts == 1)
287 {
288 this->single_partition (mesh);
289 return;
290 }
291
292 // First assign a temporary partitioning to any unpartitioned elements; see partition()
293 // for why the indexing is chosen this way.
295 (mesh, n_parts,
296 /*spatial_indexing=*/!(mesh.is_replicated() && this->partitions_from_scratch()));
297
298 // Call the partitioning function
299 this->_do_repartition(mesh,n_parts);
300
301 // Set the parent's processor ids
303
304 // Set the node's processor ids
306
307 // Give derived Mesh classes a chance to update any cached data to
308 // reflect the new partitioning
310}
virtual void _do_repartition(MeshBase &mesh, const unsigned int n)
This is the actual re-partitioning method which can be overridden in derived classes.

References libMesh::Partitioner::_do_repartition(), libMesh::MeshBase::is_replicated(), mesh, libMesh::MeshBase::n_active_elem(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::MeshBase::set_n_partitions(), libMesh::Partitioner::set_node_processor_ids(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::Partitioner::single_partition(), and libMesh::MeshBase::update_post_partitioning().

Referenced by libMesh::Partitioner::repartition().

◆ set_interface_node_processor_ids_BFS()

void libMesh::Partitioner::set_interface_node_processor_ids_BFS ( MeshBase &  mesh)
staticinherited

Nodes on the partitioning interface is clustered into two groups BFS (Breadth First Search)scheme for per pair of processors.

Definition at line 705 of file partitioner.C.

706{
707 // This function must be run on all processors at once
708 libmesh_parallel_only(mesh.comm());
709
710 // I see occasional consistency failures when using this on a
711 // distributed mesh
712 libmesh_experimental();
713
714 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> processor_pair_to_nodes;
715
716 processor_pairs_to_interface_nodes(mesh, processor_pair_to_nodes);
717
718 std::unordered_map<dof_id_type, std::vector<const Elem *>> nodes_to_elem_map;
719
720 MeshTools::build_nodes_to_elem_map(mesh, nodes_to_elem_map);
721
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;
727
728 for (auto & pmap : processor_pair_to_nodes)
729 {
730 std::size_t n_own_nodes = pmap.second.size()/2;
731
732 // Initialize node assignment
733 for (dof_id_type id : pmap.second)
734 mesh.node_ref(id).processor_id() = pmap.first.second;
735
736 visted_nodes.clear();
737 for (dof_id_type id : pmap.second)
738 {
739 mesh.node_ref(id).processor_id() = pmap.first.second;
740
741 if (visted_nodes.count(id))
742 continue;
743 else
744 {
745 nodes_queue.push(id);
746 visted_nodes.insert(id);
747 if (visted_nodes.size() >= n_own_nodes)
748 break;
749 }
750
751 while (!nodes_queue.empty())
752 {
753 auto & node = mesh.node_ref(nodes_queue.front());
754 nodes_queue.pop();
755
756 neighbors.clear();
757 MeshTools::find_nodal_neighbors(mesh, node, nodes_to_elem_map, neighbors);
758 neighbors_order.clear();
759 for (auto & neighbor : neighbors)
760 neighbors_order.insert(neighbor->id());
761
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));
766
767 for (auto c_node : common_nodes)
768 if (!visted_nodes.count(c_node))
769 {
770 nodes_queue.push(c_node);
771 visted_nodes.insert(c_node);
772 if (visted_nodes.size() >= n_own_nodes)
773 goto queue_done;
774 }
775
776 if (visted_nodes.size() >= n_own_nodes)
777 goto queue_done;
778 }
779 }
780 queue_done:
781 for (auto node : visted_nodes)
782 mesh.node_ref(node).processor_id() = pmap.first.first;
783 }
784}
virtual const Node & node_ref(const dof_id_type i) const
Definition mesh_base.h:750
virtual void clear()
Deletes all the element and node data that is currently stored.
Definition mesh_base.C:1123
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.
void build_nodes_to_elem_map(const MeshBase &mesh, std::vector< std::vector< dof_id_type > > &nodes_to_elem_map)
After calling this function the input vector nodes_to_elem_map will contain the node to element conne...
Definition mesh_tools.C:520
void find_nodal_neighbors(const MeshBase &mesh, const Node &n, const std::vector< std::vector< const Elem * > > &nodes_to_elem_map, std::vector< const Node * > &neighbors)
Given a mesh and a node in the mesh, the vector will be filled with every node directly attached to t...

References libMesh::MeshTools::build_nodes_to_elem_map(), libMesh::ParallelObject::comm(), libMesh::MeshTools::find_nodal_neighbors(), mesh, libMesh::MeshBase::node_ref(), libMesh::DofObject::processor_id(), and libMesh::Partitioner::processor_pairs_to_interface_nodes().

Referenced by libMesh::Partitioner::set_node_processor_ids().

◆ set_interface_node_processor_ids_linear()

void libMesh::Partitioner::set_interface_node_processor_ids_linear ( MeshBase &  mesh)
staticinherited

Nodes on the partitioning interface is linearly assigned to each pair of processors.

Definition at line 680 of file partitioner.C.

681{
682 // This function must be run on all processors at once
683 libmesh_parallel_only(mesh.comm());
684
685 std::map<std::pair<processor_id_type, processor_id_type>, std::set<dof_id_type>> processor_pair_to_nodes;
686
687 processor_pairs_to_interface_nodes(mesh, processor_pair_to_nodes);
688
689 for (auto & pmap : processor_pair_to_nodes)
690 {
691 std::size_t n_own_nodes = pmap.second.size()/2, i = 0;
692
693 for (dof_id_type id : pmap.second)
694 {
695 auto & node = mesh.node_ref(id);
696 if (i <= n_own_nodes)
697 node.processor_id() = pmap.first.first;
698 else
699 node.processor_id() = pmap.first.second;
700 i++;
701 }
702 }
703}

References libMesh::ParallelObject::comm(), mesh, libMesh::MeshBase::node_ref(), libMesh::DofObject::processor_id(), and libMesh::Partitioner::processor_pairs_to_interface_nodes().

Referenced by libMesh::Partitioner::set_node_processor_ids().

◆ set_interface_node_processor_ids_petscpartitioner()

void libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner ( MeshBase &  mesh)
staticinherited

Nodes on the partitioning interface is partitioned into two groups using a PETSc partitioner for each pair of processors.

Definition at line 786 of file partitioner.C.

787{
788 libmesh_ignore(mesh); // Only used if LIBMESH_HAVE_PETSC
789
790 // This function must be run on all processors at once
791 libmesh_parallel_only(mesh.comm());
792
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;
795
796 processor_pairs_to_interface_nodes(mesh, processor_pair_to_nodes);
797
798 std::vector<std::vector<const Elem *>> nodes_to_elem_map;
799
800 MeshTools::build_nodes_to_elem_map(mesh, nodes_to_elem_map);
801
802 std::vector<const Node *> neighbors;
803 std::set<dof_id_type> neighbors_order;
804 std::vector<dof_id_type> common_nodes;
805
806 std::vector<dof_id_type> rows;
807 std::vector<dof_id_type> cols;
808
809 std::map<dof_id_type, dof_id_type> global_to_local;
810
811 for (auto & pmap : processor_pair_to_nodes)
812 {
813 unsigned int i = 0;
814
815 rows.clear();
816 rows.resize(pmap.second.size()+1);
817 cols.clear();
818 for (dof_id_type id : pmap.second)
819 global_to_local[id] = i++;
820
821 i = 0;
822 for (auto id : pmap.second)
823 {
824 auto & node = mesh.node_ref(id);
825 neighbors.clear();
826 MeshTools::find_nodal_neighbors(mesh, node, nodes_to_elem_map, neighbors);
827 neighbors_order.clear();
828 for (auto & neighbor : neighbors)
829 neighbors_order.insert(neighbor->id());
830
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));
835
836 rows[i+1] = rows[i] + cast_int<dof_id_type>(common_nodes.size());
837
838 for (auto c_node : common_nodes)
839 cols.push_back(global_to_local[c_node]);
840
841 i++;
842 }
843
844 // Next we construct an IS from a MatPartitioning
846 {
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];
853
854 PetscInt cols_size = cast_int<PetscInt>(cols.size());
855 for (PetscInt ii=0; ii<cols_size; ii++)
856 adj_j[ii] = cols[ii];
857
858 const PetscInt sz = cast_int<PetscInt>(pmap.second.size());
859
860 // Create sparse matrix representing an adjacency list
862 LibmeshPetscCall2(mesh.comm(), MatCreateMPIAdj(PETSC_COMM_SELF, sz, sz, adj_i, adj_j, nullptr, adj.get()));
863
864 // Create MatPartitioning object
866 LibmeshPetscCall2(mesh.comm(), MatPartitioningCreate(PETSC_COMM_SELF, part.get()));
867
868 // Apply MatPartitioning, storing results in "is"
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()));
874 }
875
876 PetscInt local_size;
877 const PetscInt *indices;
878 LibmeshPetscCall2(mesh.comm(), ISGetLocalSize(is, &local_size));
879 LibmeshPetscCall2(mesh.comm(), ISGetIndices(is, &indices));
880
881 i = 0;
882 for (auto id : pmap.second)
883 {
884 auto & node = mesh.node_ref(id);
885 if (indices[i])
886 node.processor_id() = pmap.first.second;
887 else
888 node.processor_id() = pmap.first.first;
889
890 i++;
891 }
892 LibmeshPetscCall2(mesh.comm(), ISRestoreIndices(is, &indices));
893 }
894#else
895 libmesh_error_msg("PETSc is required");
896#endif
897}
PetscErrorCode PetscInt const PetscInt IS * is

References libMesh::MeshTools::build_nodes_to_elem_map(), libMesh::ParallelObject::comm(), libMesh::MeshTools::find_nodal_neighbors(), libMesh::WrappedPetsc< T >::get(), libMesh::is, libMesh::libmesh_ignore(), mesh, libMesh::MeshBase::node_ref(), libMesh::DofObject::processor_id(), and libMesh::Partitioner::processor_pairs_to_interface_nodes().

Referenced by libMesh::Partitioner::set_node_processor_ids().

◆ set_node_processor_ids()

void libMesh::Partitioner::set_node_processor_ids ( MeshBase &  mesh)
staticinherited

This function is called after partitioning to set the processor IDs for the nodes.

By definition, a Node's processor ID is the minimum processor ID for all of the elements which share the node.

Definition at line 900 of file partitioner.C.

901{
902 LOG_SCOPE("set_node_processor_ids()","Partitioner");
903
904 // This function must be run on all processors at once
905 libmesh_parallel_only(mesh.comm());
906
907 // If we have any unpartitioned elements at this
908 // stage there is a problem
909 libmesh_assert (MeshTools::n_elem(mesh.unpartitioned_elements_begin(),
910 mesh.unpartitioned_elements_end()) == 0);
911
912 // Start from scratch here: nodes we used to own may not be
913 // eligible for us to own any more.
915 (mesh.node_stored_range(), [](Node * node)
916 { node->processor_id() = DofObject::invalid_processor_id; });
917
918 // Loop over all the active elements
919 for (auto & elem : mesh.active_element_ptr_range())
920 {
921 libmesh_assert(elem);
922
923 libmesh_assert_not_equal_to (elem->processor_id(), DofObject::invalid_processor_id);
924
925 // Consider updating the processor id on this element's nodes
926 for (Node & node : elem->node_ref_range())
927 {
928 processor_id_type & pid = node.processor_id();
929 pid = node.choose_processor_id(pid, elem->processor_id());
930 }
931 }
932
933 // How we finish off the node partitioning depends on our command
934 // line options.
935
936 const bool load_balanced_nodes_linear =
937 libMesh::on_command_line ("--load-balanced-nodes-linear");
938
939 const bool load_balanced_nodes_bfs =
940 libMesh::on_command_line ("--load-balanced-nodes-bfs");
941
942 const bool load_balanced_nodes_petscpartition =
943 libMesh::on_command_line ("--load-balanced-nodes-petscpartitioner");
944
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");
950
951 if (load_balanced_nodes_linear)
953 else if (load_balanced_nodes_bfs)
955 else if (load_balanced_nodes_petscpartition)
957
958 // Node balancing algorithm will response to assign owned nodes.
959 // We still need to sync PIDs
960 {
961 // For inactive elements, we will have already gotten most of
962 // these nodes, *except* for the case of a parent with a subset
963 // of active descendants which are remote elements. In that
964 // case some of the parent nodes will not have been properly
965 // handled yet on our processor.
966 //
967 // We don't want to inadvertently give one of them an incorrect
968 // processor id, but if we're not in serial then we have to
969 // assign them temporary pids to make querying work, so we'll
970 // save our *valid* pids before assigning temporaries.
971 //
972 // Even in serial we'll want to check and make sure we're not
973 // overwriting valid active node pids with pids from subactive
974 // elements.
975 std::unordered_set<dof_id_type> bad_pids;
976 Threads::spin_mutex pid_mtx;
977
980 [&bad_pids, &pid_mtx](const NodeRange & range)
981 {
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());
986
987 Threads::spin_mutex::scoped_lock lock(pid_mtx);
988
989 bad_pids.merge(my_bad_pids);
990 });
991
992 // If we assign our temporary ids by looping from finer elements
993 // to coarser elements, we'll always get an id from the finest
994 // ghost element we can see, which will usually be "closer" to
995 // the true processor we want to query and so will reduce query
996 // cycles that don't reach that processor.
997
998 // But we can still end up with a query cycle that dead-ends, so
999 // we need to prepare a "push" communication step here.
1000
1001 const bool is_serial = mesh.is_serial();
1002 std::unordered_map
1004 std::unordered_map<dof_id_type, processor_id_type>>
1005 potential_pids;
1006
1007 const unsigned int n_levels = MeshTools::n_levels(mesh);
1008 for (unsigned int level = n_levels; level > 0; --level)
1009 {
1010 for (auto & elem : as_range(mesh.level_elements_begin(level-1),
1011 mesh.level_elements_end(level-1)))
1012 {
1013 libmesh_assert_not_equal_to (elem->processor_id(),
1015
1016 const processor_id_type elem_pid = elem->processor_id();
1017
1018 // Consider updating the processor id on this element's nodes
1019 for (Node & node : elem->node_ref_range())
1020 {
1021 processor_id_type & pid = node.processor_id();
1022 if (bad_pids.count(node.id()))
1023 pid = node.choose_processor_id(pid, elem_pid);
1024 else if (!is_serial)
1025 potential_pids[elem_pid][node.id()] = pid;
1026 }
1027 }
1028 }
1029
1030 if (!is_serial)
1031 {
1032 std::unordered_map
1034 std::vector<std::pair<dof_id_type, processor_id_type>>>
1035 potential_pids_vecs;
1036
1037 for (auto & pair : potential_pids)
1038 potential_pids_vecs[pair.first].assign(pair.second.begin(), pair.second.end());
1039
1040 auto pids_action_functor =
1041 [& mesh, & bad_pids]
1042 (processor_id_type /* src_pid */,
1043 const std::vector<std::pair<dof_id_type, processor_id_type>> & data)
1044 {
1045 for (auto pair : data)
1046 {
1047 Node & node = mesh.node_ref(pair.first);
1048 processor_id_type & pid = node.processor_id();
1049 if (const auto it = bad_pids.find(pair.first);
1050 it != bad_pids.end())
1051 {
1052 pid = pair.second;
1053 bad_pids.erase(it);
1054 }
1055 else
1056 pid = node.choose_processor_id(pid, pair.second);
1057 }
1058 };
1059
1061 (mesh.comm(), potential_pids_vecs, pids_action_functor);
1062
1063 // Using default libMesh options, we'll just need to sync
1064 // between processors now. The catch here is that we can't
1065 // initially trust Node::choose_processor_id() because some
1066 // of those node processor ids are the temporary ones.
1067 CorrectProcIds correct_pids(mesh, bad_pids);
1069 (mesh, mesh.elements_begin(), mesh.elements_end(),
1071 correct_pids);
1072
1073 // But once we've got all the non-temporary pids synced, we
1074 // may need to sync again to get any pids on nodes only
1075 // connected to subactive elements, for which *only*
1076 // "temporary" pids are possible.
1077 bad_pids.clear();
1079 (mesh,
1080 mesh.elements_begin(), mesh.elements_end(),
1082 correct_pids);
1083 }
1084 }
1085
1086 // We can't assert that all nodes are connected to elements, because
1087 // a DistributedMesh with NodeConstraints might have pulled in some
1088 // remote nodes solely for evaluating those constraints.
1089 // MeshTools::libmesh_assert_connected_nodes(mesh);
1090
1091#ifdef DEBUG
1092 MeshTools::libmesh_assert_valid_procids<Node>(mesh);
1093 //MeshTools::libmesh_assert_canonical_node_procids(mesh);
1094#endif
1095}
virtual bool is_serial() const
Definition mesh_base.h:365
const NodeRange & node_stored_range()
Definition mesh_base.C:2180
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...
Definition node.C:78
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...
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...
static void set_interface_node_processor_ids_linear(MeshBase &mesh)
Nodes on the partitioning interface is linearly assigned to each pair of processors.
The StoredRange class defines a contiguous, divisible set of objects.
unsigned int n_levels(const MeshBase &mesh)
Definition mesh_tools.C:889
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 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...
Definition threads.h:308
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.
bool on_command_line(std::string arg)
Definition libmesh.C:934

References libMesh::as_range(), libMesh::Node::choose_processor_id(), libMesh::ParallelObject::comm(), libMesh::DofObject::id(), libMesh::DofObject::invalid_processor_id, libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), mesh, libMesh::MeshTools::n_elem(), libMesh::MeshTools::n_levels(), libMesh::MeshBase::node_ref(), libMesh::MeshBase::node_stored_range(), libMesh::on_command_line(), libMesh::Threads::parallel_for(), libMesh::Threads::parallel_for_each(), libMesh::DofObject::processor_id(), TIMPI::push_parallel_vector_data(), libMesh::Partitioner::set_interface_node_processor_ids_BFS(), libMesh::Partitioner::set_interface_node_processor_ids_linear(), libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner(), and libMesh::Parallel::sync_node_data_by_element_id().

Referenced by libMesh::UnstructuredMesh::all_first_order(), libMesh::Partitioner::partition(), libMesh::XdrIO::read(), libMesh::Partitioner::repartition(), and libMesh::BoundaryInfo::sync().

◆ set_parent_processor_ids()

void libMesh::Partitioner::set_parent_processor_ids ( MeshBase &  mesh)
staticinherited

This function is called after partitioning to set the processor IDs for the inactive parent elements.

A parent's processor ID is the same as its first child.

Definition at line 474 of file partitioner.C.

475{
476 // Ignore the parameter when !LIBMESH_ENABLE_AMR
478
479 LOG_SCOPE("set_parent_processor_ids()", "Partitioner");
480
481#ifdef LIBMESH_ENABLE_AMR
482
483 // If the mesh is serial we have access to all the elements,
484 // in particular all the active ones. We can therefore set
485 // the parent processor ids indirectly through their children, and
486 // set the subactive processor ids while examining their active
487 // ancestors.
488 // By convention a parent is assigned to the minimum processor
489 // of all its children, and a subactive is assigned to the processor
490 // of its active ancestor.
491 if (mesh.is_serial())
492 {
493 for (auto & elem : mesh.active_element_ptr_range())
494 {
495 // First set descendents
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();
500
501 // Then set ancestors
502 Elem * parent = elem->parent();
503
504 while (parent)
505 {
506 // invalidate the parent id, otherwise the min below
507 // will not work if the current parent id is less
508 // than all the children!
509 parent->invalidate_processor_id();
510
511 for (auto & child : parent->child_ref_range())
512 {
513 libmesh_assert(!child.is_remote());
514 libmesh_assert_not_equal_to (child.processor_id(), DofObject::invalid_processor_id);
515 parent->processor_id() = std::min(parent->processor_id(),
516 child.processor_id());
517 }
518 parent = parent->parent();
519 }
520 }
521 }
522
523 // When the mesh is parallel we cannot guarantee that parents have access to
524 // all their children.
525 else
526 {
527 // Setting subactive processor ids is easy: we can guarantee
528 // that children have access to all their parents.
529
530 // Loop over all the active elements in the mesh
531 for (auto & child : mesh.active_element_ptr_range())
532 {
533 std::vector<Elem *> subactive_family;
534 child->total_family_tree(subactive_family);
535 for (const auto & f : subactive_family)
536 f->processor_id() = child->processor_id();
537 }
538
539 // When the mesh is parallel we cannot guarantee that parents have access to
540 // all their children.
541
542 // We will use a brute-force approach here. Each processor finds its parent
543 // elements and sets the parent pid to the minimum of its
544 // semilocal descendants.
545 // A global reduction is then performed to make sure the true minimum is found.
546 // As noted, this is required because we cannot guarantee that a parent has
547 // access to all its children on any single processor.
548 libmesh_parallel_only(mesh.comm());
549 libmesh_assert(MeshTools::n_elem(mesh.unpartitioned_elements_begin(),
550 mesh.unpartitioned_elements_end()) == 0);
551
552 const dof_id_type max_elem_id = mesh.max_elem_id();
553
554 std::vector<processor_id_type>
555 parent_processor_ids (std::min(communication_blocksize,
556 max_elem_id));
557
558 for (dof_id_type blk=0, last_elem_id=0; last_elem_id<max_elem_id; blk++)
559 {
560 last_elem_id =
561 std::min(static_cast<dof_id_type>((blk+1)*communication_blocksize),
562 max_elem_id);
563 const dof_id_type first_elem_id = blk*communication_blocksize;
564
565 std::fill (parent_processor_ids.begin(),
566 parent_processor_ids.end(),
568
569 // first build up local contributions to parent_processor_ids
570 bool have_parent_in_block = false;
571
572 for (auto & parent : as_range(mesh.ancestor_elements_begin(),
573 mesh.ancestor_elements_end()))
574 {
575 const dof_id_type parent_idx = parent->id();
576 libmesh_assert_less (parent_idx, max_elem_id);
577
578 if ((parent_idx >= first_elem_id) &&
579 (parent_idx < last_elem_id))
580 {
581 have_parent_in_block = true;
583
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());
588
589 const dof_id_type packed_idx = parent_idx - first_elem_id;
590 libmesh_assert_less (packed_idx, parent_processor_ids.size());
591
592 parent_processor_ids[packed_idx] = parent_pid;
593 }
594 }
595
596 // then find the global minimum
597 mesh.comm().min (parent_processor_ids);
598
599 // and assign the ids, if we have a parent in this block.
600 if (have_parent_in_block)
601 for (auto & parent : as_range(mesh.ancestor_elements_begin(),
602 mesh.ancestor_elements_end()))
603 {
604 const dof_id_type parent_idx = parent->id();
605
606 if ((parent_idx >= first_elem_id) &&
607 (parent_idx < last_elem_id))
608 {
609 const dof_id_type packed_idx = parent_idx - first_elem_id;
610 libmesh_assert_less (packed_idx, parent_processor_ids.size());
611
612 const processor_id_type parent_pid =
613 parent_processor_ids[packed_idx];
614
615 libmesh_assert_not_equal_to (parent_pid, DofObject::invalid_processor_id);
616
617 parent->processor_id() = parent_pid;
618 }
619 }
620 }
621 }
622
623#endif // LIBMESH_ENABLE_AMR
624}
void min(const T &r, T &o, Request &req) const
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
Definition dof_object.h:785
const Elem * parent() const
Definition elem.h:3168
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.
Definition elem.C:2228
void active_family_tree(std::vector< const Elem * > &active_family, bool reset=true) const
Same as the family_tree() member, but only adds the active children.
Definition elem.C:2244
virtual dof_id_type max_elem_id() const =0
static const dof_id_type communication_blocksize
The blocksize to use when doing blocked parallel communication.

References libMesh::as_range(), libMesh::Elem::child_ref_range(), libMesh::ParallelObject::comm(), libMesh::Partitioner::communication_blocksize, libMesh::DofObject::invalid_processor_id, libMesh::DofObject::invalidate_processor_id(), libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), libMesh::libmesh_ignore(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Parallel::Communicator::min(), libMesh::MeshTools::n_elem(), libMesh::Elem::parent(), libMesh::DofObject::processor_id(), and libMesh::Elem::total_family_tree().

Referenced by libMesh::Partitioner::partition(), and libMesh::Partitioner::repartition().

◆ single_partition()

bool libMesh::Partitioner::single_partition ( MeshBase &  mesh)
protectedinherited

Trivially "partitions" the mesh for one processor.

Simply loops through the elements and assigns all of them to processor 0. Is is provided as a separate function so that derived classes may use it without reimplementing it.

Returns true iff any processor id was changed.

Definition at line 316 of file partitioner.C.

317{
318 bool changed_pid =
319 this->single_partition_range(mesh.elements_begin(),
320 mesh.elements_end());
321
322 // If we have a distributed mesh with an empty rank (or where rank
323 // 0 has only its own component of a disconnected mesh, I guess),
324 // that rank might need to be informed of a change.
325 mesh.comm().max(changed_pid);
326
327 if (changed_pid)
328 {
329 // Ghosting functors may iterate over local elements while we
330 // redistribute, so cached local ranges must reflect the new
331 // element processor ids
333
334 // We may need to redistribute, in case someone (like our unit
335 // tests) is doing something silly (like moving a whole
336 // already-distributed mesh back onto rank 0).
338
339 // Even single_partition can be a change, if we're starting with
340 // any unpartitioned elements or nodes
342 }
343
344 return changed_pid;
345}
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...

References libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), mesh, libMesh::MeshBase::redistribute(), libMesh::Partitioner::single_partition_range(), and libMesh::MeshBase::update_post_partitioning().

Referenced by libMesh::SubdomainPartitioner::_do_partition(), libMesh::Partitioner::partition(), and libMesh::Partitioner::repartition().

◆ single_partition_range()

bool libMesh::Partitioner::single_partition_range ( MeshBase::element_iterator  it,
MeshBase::element_iterator  end 
)
protectedinherited

Slightly generalized version of single_partition which acts on a range of elements defined by the pair of iterators (it, end).

Returns true iff any processor id was changed.

Definition at line 349 of file partitioner.C.

351{
352 LOG_SCOPE("single_partition_range()", "Partitioner");
353
354 bool changed_pid = false;
355
356 for (auto & elem : as_range(it, end))
357 {
358 if (elem->processor_id())
359 changed_pid = true;
360 elem->processor_id() = 0;
361
362 // Assign all this element's nodes to processor 0 as well.
363 for (Node & node : elem->node_ref_range())
364 {
365 if (node.processor_id())
366 changed_pid = true;
367 node.processor_id() = 0;
368 }
369 }
370
371 return changed_pid;
372}

References libMesh::as_range(), and libMesh::DofObject::processor_id().

Referenced by NonManifoldTestPartitioner::_do_partition(), OverlappingTestPartitioner::_do_partition(), libMesh::CentroidPartitioner::partition_range(), libMesh::LinearPartitioner::partition_range(), libMesh::MappedSubdomainPartitioner::partition_range(), libMesh::MetisPartitioner::partition_range(), libMesh::SFCPartitioner::partition_range(), and libMesh::Partitioner::single_partition().

◆ type()

PartitionerType libMesh::Partitioner::type ( ) const
virtualinherited

Member Data Documentation

◆ _dual_graph

std::vector<std::vector<dof_id_type> > libMesh::Partitioner::_dual_graph
protectedinherited

A dual graph corresponds to the mesh, and it is typically used in paritioner.

A vertex represents an element, and its neighbors are the element neighbors.

Definition at line 332 of file partitioner.h.

Referenced by libMesh::Partitioner::build_graph().

◆ _global_index_by_pid_map

std::unordered_map<dof_id_type, dof_id_type> libMesh::Partitioner::_global_index_by_pid_map
protectedinherited

Maps active element ids into a contiguous range, as needed by parallel partitioner.

Definition at line 316 of file partitioner.h.

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::Partitioner::assign_partitioning(), and libMesh::Partitioner::build_graph().

◆ _local_id_to_elem

std::vector<Elem *> libMesh::Partitioner::_local_id_to_elem
protectedinherited

Definition at line 335 of file partitioner.h.

Referenced by libMesh::Partitioner::build_graph().

◆ _n_active_elem_on_proc

std::vector<dof_id_type> libMesh::Partitioner::_n_active_elem_on_proc
protectedinherited

The number of active elements on each processor.

Note
ParMETIS requires that each processor have some active elements; it will abort if any processor passes a nullptr _part array.

Definition at line 325 of file partitioner.h.

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::Partitioner::assign_partitioning(), and libMesh::Partitioner::build_graph().

◆ _repartitioned

bool RowPartitioner::_repartitioned
private

Definition at line 185 of file periodic_bc_test.C.

Referenced by _do_partition().

◆ _weights

ErrorVector* libMesh::Partitioner::_weights
protectedinherited

The weights that might be used for partitioning.

Definition at line 311 of file partitioner.h.

Referenced by libMesh::MetisPartitioner::attach_weights(), and libMesh::MetisPartitioner::partition_range().

◆ communication_blocksize

const dof_id_type libMesh::Partitioner::communication_blocksize
staticprotectedinherited
Initial value:
=
dof_id_type(1000000)

The blocksize to use when doing blocked parallel communication.

This limits the maximum vector size which can be used in a single communication step.

Definition at line 288 of file partitioner.h.

Referenced by libMesh::Partitioner::set_parent_processor_ids().


The documentation for this class was generated from the following file: