libMesh
Loading...
Searching...
No Matches
partitioner.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
34namespace libMesh
35{
36
37// Forward Declarations
38class ErrorVector;
39enum PartitionerType : int;
40
52{
53public:
54
58 Partitioner () : _weights(nullptr) {}
59
64 Partitioner (const Partitioner &) = default;
65 Partitioner (Partitioner &&) = default;
66 Partitioner & operator= (const 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
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
215protected:
216
226
235
242 const unsigned int n) = 0;
243
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
void ErrorVector unsigned int
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
This is the MeshBase class.
Definition mesh_base.h:81
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition partitioner.h:52
bool single_partition(MeshBase &mesh)
Trivially "partitions" the mesh for one processor.
ErrorVector * _weights
The weights that might be used for partitioning.
static void set_interface_node_processor_ids_petscpartitioner(MeshBase &mesh)
Nodes on the partitioning interface is partitioned into two groups using a PETSc partitioner for each...
std::vector< dof_id_type > _n_active_elem_on_proc
The number of active elements on each processor.
virtual void partition(MeshBase &mesh, const unsigned int n)
Partitions the MeshBase into n parts by setting processor_id() on Nodes and Elems.
static void set_parent_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the inactive parent elements.
static void processor_pairs_to_interface_nodes(MeshBase &mesh, std::map< std::pair< processor_id_type, processor_id_type >, std::set< dof_id_type > > &processor_pair_to_nodes)
On the partitioning interface, a surface is shared by two and only two processors.
static void partition_unpartitioned_elements(MeshBase &mesh)
These functions assign processor IDs to newly-created elements (in parallel) which are currently assi...
std::unordered_map< dof_id_type, dof_id_type > _global_index_by_pid_map
Maps active element ids into a contiguous range, as needed by parallel partitioner.
Partitioner(Partitioner &&)=default
static void set_interface_node_processor_ids_BFS(MeshBase &mesh)
Nodes on the partitioning interface is clustered into two groups BFS (Breadth First Search)scheme for...
std::vector< std::vector< dof_id_type > > _dual_graph
A dual graph corresponds to the mesh, and it is typically used in paritioner.
static std::unique_ptr< Partitioner > build(const PartitionerType solver_package)
Builds a Partitioner of the type specified by partitioner_type.
Partitioner(const Partitioner &)=default
Copy/move ctor, copy/move assignment operator, and destructor are all explicitly defaulted for this c...
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 ~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.
Partitioner()
Constructor.
Definition partitioner.h:58
virtual void build_graph(const MeshBase &mesh)
Build a dual graph for partitioner.
Partitioner & operator=(const Partitioner &)=default
virtual void partition_range(MeshBase &, MeshBase::element_iterator, MeshBase::element_iterator, const unsigned int)
Partitions elements in the range (it, end) into n parts.
virtual std::unique_ptr< Partitioner > clone() const =0
static void set_node_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the nodes.
virtual void attach_weights(ErrorVector *)
Attach weights that can be used for partitioning.
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Construct contiguous global indices for the current partitioning.
static void set_interface_node_processor_ids_linear(MeshBase &mesh)
Nodes on the partitioning interface is linearly assigned to each pair of processors.
void repartition(MeshBase &mesh, const unsigned int n)
Repartitions the MeshBase into n parts.
void assign_partitioning(MeshBase &mesh, const std::vector< dof_id_type > &parts)
Assign the computed partitioning to the mesh.
static const dof_id_type communication_blocksize
The blocksize to use when doing blocked parallel communication.
bool single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Slightly generalized version of single_partition which acts on a range of elements defined by the pai...
std::vector< Elem * > _local_id_to_elem
virtual PartitionerType type() const
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
PartitionerType
Defines an enum for mesh partitioner types.
uint8_t dof_id_type
Definition id_types.h:67
The definition of the element_iterator struct.
Definition mesh_base.h:2538