libMesh
partitioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PARTITIONER_H
21 #define LIBMESH_PARTITIONER_H
22 
23 // Local Includes
24 #include "libmesh/libmesh.h"
25 #include "libmesh/id_types.h"
26 #include "libmesh/mesh_base.h" // for MeshBase::element_iterator
27 
28 // C++ Includes
29 #include <cstddef>
30 #include <memory>
31 #include <unordered_map>
32 #include <queue>
33 
34 namespace libMesh
35 {
36 
37 // Forward Declarations
38 class ErrorVector;
39 
51 {
52 public:
53 
57  Partitioner () : _weights(nullptr) {}
58 
63  Partitioner (const Partitioner &) = default;
64  Partitioner (Partitioner &&) = default;
65  Partitioner & operator= (const Partitioner &) = default;
66  Partitioner & operator= (Partitioner &&) = default;
67  virtual ~Partitioner() = default;
68 
75  virtual std::unique_ptr<Partitioner> clone () const = 0;
76 
92  virtual void partition (MeshBase & mesh,
93  const unsigned int n);
94 
110  virtual void partition (MeshBase & mesh);
111 
127  virtual void partition_range (MeshBase & /*mesh*/,
130  const unsigned int /*n_parts*/)
131  { libmesh_not_implemented(); }
132 
139  void repartition (MeshBase & mesh,
140  const unsigned int n);
141 
147  void repartition (MeshBase & mesh);
148 
154 
156  const unsigned int n);
157 
163  static void set_parent_processor_ids(MeshBase & mesh);
164 
170  static void set_node_processor_ids(MeshBase & mesh);
171 
177  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);
178 
184 
190 
191 
197 
203  virtual void attach_weights(ErrorVector * /*weights*/) { libmesh_not_implemented(); }
204 
205 protected:
206 
213  void single_partition (MeshBase & mesh);
214 
221 
227  virtual void _do_partition(MeshBase & mesh,
228  const unsigned int n) = 0;
229 
237  virtual void _do_repartition (MeshBase & mesh,
238  const unsigned int n) { this->_do_partition (mesh, n); }
239 
245 
250  virtual void _find_global_index_by_pid_map(const MeshBase & mesh);
251 
252 
257  virtual void build_graph(const MeshBase & mesh);
258 
262  void assign_partitioning (const MeshBase & mesh, const std::vector<dof_id_type> & parts);
263 
268 
272  std::unordered_map<dof_id_type, dof_id_type> _global_index_by_pid_map;
273 
281  std::vector<dof_id_type> _n_active_elem_on_proc;
282 
288  std::vector<std::vector<dof_id_type>> _dual_graph;
289 
290 
291  std::vector<Elem *> _local_id_to_elem;
292 };
293 
294 } // namespace libMesh
295 
296 #endif // LIBMESH_PARTITIONER_H
libMesh::Partitioner::single_partition_range
void 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...
Definition: partitioner.C:179
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::MeshBase::element_iterator
The definition of the element_iterator struct.
Definition: mesh_base.h:1873
libMesh::Partitioner::partition_unpartitioned_elements
static void partition_unpartitioned_elements(MeshBase &mesh)
These functions assign processor IDs to newly-created elements (in parallel) which are currently assi...
Definition: partitioner.C:194
libMesh::Partitioner::_do_partition
virtual void _do_partition(MeshBase &mesh, const unsigned int n)=0
This is the actual partitioning method which must be overridden in derived classes.
libMesh::Partitioner::_find_global_index_by_pid_map
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Construct contiguous global indices for the current partitioning.
Definition: partitioner.C:917
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Partitioner::set_parent_processor_ids
static void set_parent_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the inactive parent elements.
Definition: partitioner.C:275
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
libMesh::Partitioner::operator=
Partitioner & operator=(const Partitioner &)=default
libMesh::Partitioner
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:50
libMesh::Partitioner::_n_active_elem_on_proc
std::vector< dof_id_type > _n_active_elem_on_proc
The number of active elements on each processor.
Definition: partitioner.h:281
libMesh::Partitioner::communication_blocksize
static const dof_id_type communication_blocksize
The blocksize to use when doing blocked parallel communication.
Definition: partitioner.h:244
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::Partitioner::partition
virtual void partition(MeshBase &mesh, const unsigned int n)
Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.
Definition: partitioner.C:64
libMesh::Partitioner::_global_index_by_pid_map
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.
Definition: partitioner.h:272
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner
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...
Definition: partitioner.C:583
libMesh::Partitioner::_dual_graph
std::vector< std::vector< dof_id_type > > _dual_graph
A dual graph corresponds to the mesh, and it is typically used in paritioner.
Definition: partitioner.h:288
libMesh::Partitioner::Partitioner
Partitioner()
Constructor.
Definition: partitioner.h:57
libMesh::Partitioner::set_interface_node_processor_ids_BFS
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...
Definition: partitioner.C:506
libMesh::ErrorVector
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Definition: error_vector.h:50
libMesh::Partitioner::single_partition
void single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
Definition: partitioner.C:166
libMesh::Partitioner::partition_range
virtual void partition_range(MeshBase &, MeshBase::element_iterator, MeshBase::element_iterator, const unsigned int)
Partitions elements in the range (it, end) into n parts.
Definition: partitioner.h:127
libMesh::Partitioner::set_node_processor_ids
static void set_node_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the nodes.
Definition: partitioner.C:691
libMesh::Partitioner::build_graph
virtual void build_graph(const MeshBase &mesh)
Build a dual graph for partitioner.
Definition: partitioner.C:960
libMesh::Partitioner::clone
virtual std::unique_ptr< Partitioner > clone() const =0
libMesh::Partitioner::assign_partitioning
void assign_partitioning(const MeshBase &mesh, const std::vector< dof_id_type > &parts)
Assign the computed partitioning to the mesh.
Definition: partitioner.C:1120
libMesh::Partitioner::attach_weights
virtual void attach_weights(ErrorVector *)
Attach weights that can be used for partitioning.
Definition: partitioner.h:203
libMesh::Partitioner::set_interface_node_processor_ids_linear
static void set_interface_node_processor_ids_linear(MeshBase &mesh)
Nodes on the partitioning interface is linearly assigned to each pair of processors.
Definition: partitioner.C:481
libMesh::Partitioner::repartition
void repartition(MeshBase &mesh, const unsigned int n)
Repartitions the MeshBase into n parts.
Definition: partitioner.C:131
libMesh::Partitioner::_do_repartition
virtual void _do_repartition(MeshBase &mesh, const unsigned int n)
This is the actual re-partitioning method which can be overridden in derived classes.
Definition: partitioner.h:237
libMesh::Partitioner::processor_pairs_to_interface_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.
Definition: partitioner.C:428
libMesh::Partitioner::_local_id_to_elem
std::vector< Elem * > _local_id_to_elem
Definition: partitioner.h:291
libMesh::Partitioner::~Partitioner
virtual ~Partitioner()=default
libMesh::Partitioner::_weights
ErrorVector * _weights
The weights that might be used for partitioning.
Definition: partitioner.h:267