partitioning.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2023 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 // Domain partitioning
27 
28 #ifndef OOMPH_PARTITIONING_HEADER
29 #define OOMPH_PARTITIONING_HEADER
30 
31 // Config header generated by autoconfig
32 #ifdef HAVE_CONFIG_H
33 #include <oomph-lib-config.h>
34 #endif
35 #ifdef OOMPH_HAS_MPI
36 #include "mpi.h"
37 #endif
38 
39 // ooomph-lib includes
40 #include "Vector.h"
41 #include "problem.h"
42 
43 
44 namespace oomph
45 {
46  //==================================================================
47  // Interfaces to METIS functions
48  //==================================================================
49  extern "C"
50  {
51  /// Metis graph partitioning function
53  int*, int*, int*, int*, int*, int*, int*, int*, int*, int*, int*);
54 
55 #ifndef OOMPH_TRANSITION_TO_VERSION_3
56  // function from old API which no longer exists in METIS 5.1,
57  // remove this moving to oomph-lib version 3
58 
59  /// Metis graph partitioning function -- decomposes
60  /// nodal graph based on minimum communication volume
62  int*, int*, int*, int*, int*, int*, int*, int*, int*, int*, int*);
63 
64 #endif
65  }
66 
67 
68  //====================================================================
69  /// Namespace for METIS graph partitioning routines
70  //====================================================================
71  namespace METIS
72  {
73  /// Default function that translates spatial
74  /// error into weight for METIS partitioning (unit weight regardless
75  /// of input)
76  extern void default_error_to_weight_fct(const double& spatial_error,
77  const double& max_error,
78  const double& min_error,
79  int& weight);
80 
81  /// Typedef for function pointer to to function that translates
82  /// spatial error into weight for METIS partitioning.
83  typedef void (*ErrorToWeightFctPt)(const double& spatial_error,
84  const double& max_error,
85  const double& min_error,
86  int& weight);
87 
88  /// Function pointer to to function that translates spatial
89  /// error into weight for METIS partitioning.
91 
92  /// Partition mesh uniformly by dividing elements
93  /// equally over the partitions, in the order
94  /// in which they are returned by problem.
95  /// On return, element_domain[ielem] contains the number
96  /// of the domain [0,1,...,ndomain-1] to which
97  /// element ielem has been assigned.
98  extern void uniform_partition_mesh(Problem* problem_pt,
99  const unsigned& ndomain,
100  Vector<unsigned>& element_domain);
101 
102 
103  /// Use METIS to assign each element to a domain.
104  /// On return, element_domain[ielem] contains the number
105  /// of the domain [0,1,...,ndomain-1] to which
106  /// element ielem has been assigned.
107  /// - objective=0: minimise edgecut.
108  /// - objective=1: minimise total communications volume.
109  /// .
110  /// Partioning is based on nodal graph of mesh.
111  extern void partition_mesh(Problem* problem_pt,
112  const unsigned& ndomain,
113  const unsigned& objective,
114  Vector<unsigned>& element_domain);
115 
116 
117  /// Use METIS to assign each element to a domain.
118  /// On return, element_domain[ielem] contains the number
119  /// of the domain [0,1,...,ndomain-1] to which
120  /// element ielem has been assigned.
121  /// - objective=0: minimise edgecut.
122  /// - objective=1: minimise total communications volume.
123  /// .
124  /// Partioning is based on nodal graph of mesh.
125  extern void partition_mesh(OomphCommunicator* comm_pt,
126  Mesh* mesh_pt,
127  const unsigned& ndomain,
128  const unsigned& objective,
129  Vector<unsigned>& element_domain);
130 
131  // /// Use METIS to assign each element to a domain.
132  // /// On return, element_domain[ielem] contains the number
133  // /// of the domain [0,1,...,ndomain-1] to which
134  // /// element ielem has been assigned.
135  // /// - objective=0: minimise edgecut.
136  // /// - objective=1: minimise total communications volume.
137  // /// .
138  // /// Partioning is based on "Data" graph of mesh.
139  // extern void partition_mesh_data(Problem* problem_pt,
140  // const unsigned& ndomain,
141  // const unsigned& objective,
142  // Vector<unsigned>& element_domain);
143 
144 #ifdef OOMPH_HAS_MPI
145 
146 
147  /// Use METIS to assign each element in an already-distributed mesh
148  /// to a domain. On return, element_domain_on_this_proc[e] contains the
149  /// number of the domain [0,1,...,ndomain-1] to which non-halo element e on
150  /// THE CURRENT PROCESSOR ONLY has been assigned. The order of the non-halo
151  /// elements is the same as in the Problem's mesh, with the halo
152  /// elements being skipped.
153  ///
154  /// Objective:
155  /// - objective=0: minimise edgecut.
156  /// - objective=1: minimise total communications volume.
157  /// .
158  /// The partioning is based on the dof graph of the complete mesh by
159  /// taking into
160  /// account which global equation numbers are affected by each element and
161  /// connecting elements which affect the same global equation number.
162  /// Partitioning is done such that all elements associated with the
163  /// same tree root move together. Non-refineable elements are
164  /// treated as their own root elements. If the optional boolean
165  /// flag is set to true (it defaults to false) each processor
166  /// assigns a dumb-but-repeatable equidistribution of its non-halo
167  /// elements over the domains and outputs the input that would have
168  /// gone into METIS in the file metis_input_for_validation.dat
169  extern void partition_distributed_mesh(
170  Problem* problem_pt,
171  const unsigned& objective,
172  Vector<unsigned>& element_domain_on_this_proc,
173  const bool& bypass_metis = false);
174 
175 #endif
176 
177  } // namespace METIS
178 
179 
180 } // namespace oomph
181 
182 #endif
A general mesh class.
Definition: mesh.h:67
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
Definition: communicator.h:54
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Definition: problem.h:151
void uniform_partition_mesh(Problem *problem_pt, const unsigned &ndomain, Vector< unsigned > &element_domain)
Partition mesh uniformly by dividing elements equally over the partitions, in the order in which they...
Definition: partitioning.cc:76
void partition_distributed_mesh(Problem *problem_pt, const unsigned &objective, Vector< unsigned > &element_domain_on_this_proc, const bool &bypass_metis=false)
Use METIS to assign each element in an already-distributed mesh to a domain. On return,...
void partition_mesh(Problem *problem_pt, const unsigned &ndomain, const unsigned &objective, Vector< unsigned > &element_domain)
Use METIS to assign each element to a domain. On return, element_domain[ielem] contains the number of...
void(* ErrorToWeightFctPt)(const double &spatial_error, const double &max_error, const double &min_error, int &weight)
Typedef for function pointer to to function that translates spatial error into weight for METIS parti...
Definition: partitioning.h:83
ErrorToWeightFctPt Error_to_weight_fct_pt
Function pointer to to function that translates spatial error into weight for METIS partitioning.
Definition: partitioning.cc:63
void default_error_to_weight_fct(const double &spatial_error, const double &max_error, const double &min_error, int &weight)
Default function that translates spatial error into weight for METIS partitioning (unit weight regard...
Definition: partitioning.cc:53
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
void METIS_PartGraphKway(int *, int *, int *, int *, int *, int *, int *, int *, int *, int *, int *)
Metis graph partitioning function.
void METIS_PartGraphVKway(int *, int *, int *, int *, int *, int *, int *, int *, int *, int *, int *)
Metis graph partitioning function – decomposes nodal graph based on minimum communication volume.