libMesh
partitioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 enum PartitionerType : int;
40 
52 {
53 public:
54 
58  Partitioner () : _weights(nullptr) {}
59 
64  Partitioner (const Partitioner &) = default;
65  Partitioner (Partitioner &&) = default;
66  Partitioner & operator= (const Partitioner &) = default;
67  Partitioner & operator= (Partitioner &&) = default;
68  virtual ~Partitioner() = default;
69 
70  virtual PartitionerType type () const;
71 
76  static std::unique_ptr<Partitioner>
77  build(const PartitionerType solver_package);
78 
85  virtual std::unique_ptr<Partitioner> clone () const = 0;
86 
102  virtual void partition (MeshBase & mesh,
103  const unsigned int n);
104 
120  virtual void partition (MeshBase & mesh);
121 
137  virtual void partition_range (MeshBase & /*mesh*/,
140  const unsigned int /*n_parts*/)
141  { libmesh_not_implemented(); }
142 
149  void repartition (MeshBase & mesh,
150  const unsigned int n);
151 
157  void repartition (MeshBase & mesh);
158 
164 
166  const unsigned int n);
167 
173  static void set_parent_processor_ids(MeshBase & mesh);
174 
180  static void set_node_processor_ids(MeshBase & mesh);
181 
187  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);
188 
194 
200 
201 
207 
213  virtual void attach_weights(ErrorVector * /*weights*/) { libmesh_not_implemented(); }
214 
215 protected:
216 
225  bool single_partition (MeshBase & mesh);
226 
235 
241  virtual void _do_partition(MeshBase & mesh,
242  const unsigned int n) = 0;
243 
251  virtual void _do_repartition (MeshBase & mesh,
252  const unsigned int n) { this->_do_partition (mesh, n); }
253 
259 
264  virtual void _find_global_index_by_pid_map(const MeshBase & mesh);
265 
266 
271  virtual void build_graph(const MeshBase & mesh);
272 
276  void assign_partitioning (MeshBase & mesh, const std::vector<dof_id_type> & parts);
277 
282 
286  std::unordered_map<dof_id_type, dof_id_type> _global_index_by_pid_map;
287 
295  std::vector<dof_id_type> _n_active_elem_on_proc;
296 
302  std::vector<std::vector<dof_id_type>> _dual_graph;
303 
304 
305  std::vector<Elem *> _local_id_to_elem;
306 };
307 
308 } // namespace libMesh
309 
310 #endif // LIBMESH_PARTITIONER_H
The definition of the element_iterator struct.
Definition: mesh_base.h:2103
Partitioner()
Constructor.
Definition: partitioner.h:58
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:737
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:286
bool single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
Definition: partitioner.C:297
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:656
virtual void attach_weights(ErrorVector *)
Attach weights that can be used for partitioning.
Definition: partitioner.h:213
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...
Definition: partitioner.C:319
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Definition: error_vector.h:50
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:851
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:631
MeshBase & mesh
void assign_partitioning(MeshBase &mesh, const std::vector< dof_id_type > &parts)
Assign the computed partitioning to the mesh.
Definition: partitioner.C:1334
virtual std::unique_ptr< Partitioner > clone() const =0
The libMesh namespace provides an interface to certain functionality in the library.
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:137
virtual void build_graph(const MeshBase &mesh)
Build a dual graph for partitioner.
Definition: partitioner.C:1111
std::vector< Elem * > _local_id_to_elem
Definition: partitioner.h:305
This is the MeshBase class.
Definition: mesh_base.h:74
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:51
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:251
void repartition(MeshBase &mesh, const unsigned int n)
Repartitions the MeshBase into n parts.
Definition: partitioner.C:262
ErrorVector * _weights
The weights that might be used for partitioning.
Definition: partitioner.h:281
PartitionerType
Defines an enum for mesh partitioner types.
static std::unique_ptr< Partitioner > build(const PartitionerType solver_package)
Builds a Partitioner of the type specified by partitioner_type.
Definition: partitioner.C:158
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:578
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Construct contiguous global indices for the current partitioning.
Definition: partitioner.C:1067
virtual ~Partitioner()=default
virtual void _do_partition(MeshBase &mesh, const unsigned int n)=0
This is the actual partitioning method which must be overridden in derived classes.
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:344
Partitioner & operator=(const Partitioner &)=default
static const dof_id_type communication_blocksize
The blocksize to use when doing blocked parallel communication.
Definition: partitioner.h:258
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:195
virtual PartitionerType type() const
Definition: partitioner.C:151
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:425
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:302
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
std::vector< dof_id_type > _n_active_elem_on_proc
The number of active elements on each processor.
Definition: partitioner.h:295
uint8_t dof_id_type
Definition: id_types.h:67