FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
parti_parmetis.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9
10#if defined(FEAT_HAVE_PARMETIS) || defined(DOXYGEN)
11#include <kernel/util/dist.hpp>
12#include <kernel/adjacency/graph.hpp>
13#include <kernel/adjacency/coloring.hpp>
14#include <kernel/geometry/conformal_mesh.hpp>
15
16namespace FEAT
17{
18 namespace Geometry
19 {
26 {
27 private:
47 std::vector<Real> _midpoints;
49 std::vector<Real> _weights;
51 std::vector<Index> _parts;
54
55 public:
67 explicit PartiParMETIS(const Dist::Comm& comm, Index min_elems = 1000u, int max_procs = 1000);
68
70 virtual ~PartiParMETIS();
71
98 template<int nf_, int nv_, typename VertexSet_>
99 bool execute(const IndexSet<nf_>& faces_at_elem, const IndexSet<nv_>& verts_at_elem,
100 const VertexSet_& vertices, const Index num_parts, const std::vector<Real>& weights)
101 {
103 _create_subgraph(graph, num_parts);
104 _compute_midpoints(verts_at_elem, vertices);
105 _weights = weights;
106 return _execute();
107 }
108
113 {
115 }
116
123 {
124 return _sub_comm.size();
125 }
126
127 protected:
129 void _create_subgraph(const Adjacency::Graph& faces_at_elem, const Index num_parts);
131 bool _execute();
137 bool _broadcast_coloring(bool metis_ok);
139 template<int nv_, typename VertexSet_>
140 void _compute_midpoints(const IndexSet<nv_>& verts_at_elem, const VertexSet_& vertices)
141 {
142 typename VertexSet_::VertexType vx;
143 const Real sc = Real(1) / Real(verts_at_elem.num_indices);
144 static constexpr int nc = VertexSet_::num_coords;
145 _midpoints.reserve(_num_local_elems * Index(nc));
146 for(Index i(0); i < _num_local_elems; ++i)
147 {
148 vx.format();
149 for(int j(0); j < verts_at_elem.num_indices; ++j)
150 vx += vertices[verts_at_elem(i,j)];
151 for(int k(0); k < nc; ++k)
152 _midpoints.push_back(Real(vx[k]) * sc);
153 }
154 }
155 }; // class PartiParMETIS
156 } // namespace Geometry
157} // namespace FEAT
158
159#endif // FEAT_HAVE_PARMETIS
FEAT Kernel base header.
Coloring object implementation.
Definition: coloring.hpp:37
Graph create_partition_graph() const
Creates a color partition graph.
Definition: coloring.cpp:292
Adjacency Graph implementation.
Definition: graph.hpp:34
Communicator class.
Definition: dist.hpp:1349
int size() const
Returns the size of this communicator.
Definition: dist.hpp:1506
Conformal Index-Set class template.
Definition: index_set.hpp:82
static constexpr int num_indices
number of indices per entry
Definition: index_set.hpp:87
ParMETIS mesh/graph partitioner backend.
void _compute_midpoints(const IndexSet< nv_ > &verts_at_elem, const VertexSet_ &vertices)
auxiliary function: compute element midpoints from vertex coordinates
int get_sub_comm_size() const
Returns the size of the internal sub-communicator.
Dist::Comm _sub_comm
a sub-communicator for the partitioner
Index _num_elems
the total number of elements
std::vector< Index > _parts
element partitioning
Adjacency::Graph _subgraph
the adjacency sub-graph for this process
bool _broadcast_coloring(bool metis_ok)
auxiliary function: broadcasts the coloring from the root process
Index _first_elem
first element for this process
bool _execute()
auxiliary function: executes the partitioner
Adjacency::Coloring _coloring
the element coloring
bool execute(const IndexSet< nf_ > &faces_at_elem, const IndexSet< nv_ > &verts_at_elem, const VertexSet_ &vertices, const Index num_parts, const std::vector< Real > &weights)
Executes the ParMETIS graph partitioner.
std::vector< Real > _weights
elements weights; empty if not weighted
Index _num_local_elems
number of elements for this process
bool _gather_coloring()
auxiliary function: gathers the partitioned coloring onto the root process
void _create_subgraph(const Adjacency::Graph &faces_at_elem, const Index num_parts)
auxiliary function: builds a hypergraph from the adjacency graph
Index _min_elems
minimum number of elements per MPI process
int _max_procs
maximum number of MPI processes to use
Index _num_parts
the desired number of partitions
const Dist::Comm & _comm
our main communicator
Adjacency::Graph build_elems_at_rank() const
Builds and returns the elements-at-rank graph representing the partitioning.
std::vector< Real > _midpoints
element midpoints
PartiParMETIS(const Dist::Comm &comm, Index min_elems=1000u, int max_procs=1000)
Constructor.
virtual ~PartiParMETIS()
virtual destructor
bool _apply_parmetis()
auxiliary function: applies the actual ParMETIS call
@ as_is
Render-As-Is mode.
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.
std::uint64_t Index
Index data type.