partitioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
void single_partition(MeshBase &mesh)
Definition: partitioner.C:159
static void set_interface_node_processor_ids_petscpartitioner(MeshBase &mesh)
Definition: partitioner.C:575
std::unordered_map< dof_id_type, dof_id_type > _global_index_by_pid_map
Definition: partitioner.h:272
static void set_interface_node_processor_ids_BFS(MeshBase &mesh)
Definition: partitioner.C:498
virtual void attach_weights(ErrorVector *)
Definition: partitioner.h:203
static void set_node_processor_ids(MeshBase &mesh)
Definition: partitioner.C:679
static void set_interface_node_processor_ids_linear(MeshBase &mesh)
Definition: partitioner.C:474
MeshBase & mesh
IterBase * end
virtual std::unique_ptr< Partitioner > clone() const =0
void assign_partitioning(const MeshBase &mesh, const std::vector< dof_id_type > &parts)
Definition: partitioner.C:1113
virtual void partition_range(MeshBase &, MeshBase::element_iterator, MeshBase::element_iterator, const unsigned int)
Definition: partitioner.h:127
virtual void build_graph(const MeshBase &mesh)
Definition: partitioner.C:950
std::vector< Elem * > _local_id_to_elem
Definition: partitioner.h:291
Base class for Mesh.
Definition: mesh_base.h:77
Base class for all concrete Partitioner instantiations.
Definition: partitioner.h:50
virtual void _do_repartition(MeshBase &mesh, const unsigned int n)
Definition: partitioner.h:237
void repartition(MeshBase &mesh, const unsigned int n)
Definition: partitioner.C:124
ErrorVector * _weights
Definition: partitioner.h:267
void single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Definition: partitioner.C:172
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)
Definition: partitioner.C:421
virtual void _find_global_index_by_pid_map(const MeshBase &mesh)
Definition: partitioner.C:907
virtual ~Partitioner()=default
virtual void _do_partition(MeshBase &mesh, const unsigned int n)=0
static void partition_unpartitioned_elements(MeshBase &mesh)
Definition: partitioner.C:187
Partitioner & operator=(const Partitioner &)=default
static const dof_id_type communication_blocksize
Definition: partitioner.h:244
virtual void partition(MeshBase &mesh, const unsigned int n)
Definition: partitioner.C:57
static void set_parent_processor_ids(MeshBase &mesh)
Definition: partitioner.C:268
std::vector< std::vector< dof_id_type > > _dual_graph
Definition: partitioner.h:288
std::vector< dof_id_type > _n_active_elem_on_proc
Definition: partitioner.h:281
uint8_t dof_id_type
Definition: id_types.h:64