Flow123d  3.9.0-c09ffe475
partitioning.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file partitioning.hh
15  * @brief
16  */
17 
18 #ifndef PARTITIONING_HH_
19 #define PARTITIONING_HH_
20 
21 
22 #include <memory> // for shared_ptr
23 #include <string> // for string
24 #include <vector> // for vector
25 #include "input/accessors.hh" // for Record
26 #include "input/input_exception.hh" // for DECLARE_INPUT_EXCEPTION, Exception
27 #include "system/exceptions.hh" // for operator<<, ExcStream, EI, TYPED...
28 #include "system/index_types.hh" // for LongIdx
29 
30 class Distribution;
31 class Mesh;
32 class SparseGraph;
33 namespace Input {
34  namespace Type {
35  class Record;
36  class Selection;
37  }
38 }
39 
40 
41 /**
42  * @brief Class for the mesh partitioning.
43  * This should provide:
44  * - construction of cenectivity graph from the mesh
45  * - call a partitioner
46  * - provide new element numbering and new element distribution
47  * (global numbers for the local part - at least for ghost part)
48  * (+ old indices of elements for the local part of the mesh - in order to do not change current implementation)
49  * TODO:
50  * - deal with partitioining of boundary mesh
51  */
52 class Partitioning {
53 public:
54 
55  /// Input specification objects.
57  static const Input::Type::Selection & get_tool_sel();
58  static const Input::Type::Record & get_input_type();
59 
60  TYPEDEF_ERR_INFO(EI_MeshFile, std::string);
61  TYPEDEF_ERR_INFO(EI_NElems, unsigned int);
62  TYPEDEF_ERR_INFO(EI_NProcs, unsigned int);
63  DECLARE_INPUT_EXCEPTION(ExcDecomposeMesh,
64  << "Number of processors " << EI_NProcs::val << " greater then number of elements "
65  << EI_NElems::val << ". Can not make partitioning of the mesh " << EI_MeshFile::qval << ".\n" );
66 
67  /**
68  * Constructor. A pointer to the mesh and accessor to an input record have to be provided.
69  */
70  Partitioning(Mesh *mesh, Input::Record in);
71 
72  /**
73  * Get initial distribution.
74  */
75  const Distribution *get_init_distr() const;
76  /**
77  * Get local part of mesh partition.
78  */
79  const LongIdx *get_loc_part() const;
80 
81  /**
82  * Creates and returns vector with element partitioning for output.
83  */
84  shared_ptr< vector<int> > subdomain_id_field_data();
85 
86  /**
87  * Obsolete see source file for doc.
88  */
89  void id_maps(int n_ids, LongIdx *id_4_old,
90  Distribution * &new_ds, LongIdx * &id_4_loc, LongIdx * &new_4_id);
91 
92 
93  static void id_maps(int n_ids, LongIdx *id_4_old,
94  const Distribution &old_ds, LongIdx *loc_part,
95  Distribution * &new_ds, LongIdx * &id_4_loc, LongIdx * &new_4_id);
96 
97  /// Destructor.
98  ~Partitioning();
99 
100 private:
101  /**
102  * Types of partitioning algorithms.
103  */
105  PETSc, ///< Use PETSc interface to various partitioing tools.
106  METIS ///< Use direct interface to Metis.
107  };
108 
109  /**
110  * Types of weights used for element partitioning.
111  */
113  any_neighboring, ///< Add edge for any pair of neighboring elements
114  any_weight_lower_dim_cuts, ///< Same as before and assign higher weight to cuts of lower dimension in order to make them stick to one face
115  same_dimension_neighboring, ///< Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply)
116  };
117 
118  /// The input mesh
120  /// Input Record accessor.
122 
123  /// Graph used to partitioning the mesh.
125  /// Partition numbers for local elements in original distribution of elements given be @p init_el_ds_.
127  /// Original distribution of elements. Depends on type of partitioner
129  /// Sequential partitioning for output.
130  shared_ptr< vector<int> > seq_part_;
131 
132  /**
133  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_
134  */
136  /**
137  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_)
138  * calls partitioning tool given by the key "tool" of the input record accessor @p in_)
139  * result is local part of the partitioning. Can be retrieved by @p get_loc_part().
140  */
141  void make_partition();
142 
143 
144 };
145 
146 
147 #endif /* PARTITIONING_HH_ */
Partitioning::Partitioning
Partitioning(Mesh *mesh, Input::Record in)
Definition: partitioning.cc:61
Partitioning::make_partition
void make_partition()
Definition: partitioning.cc:141
Partitioning::in_
Input::Record in_
Input Record accessor.
Definition: partitioning.hh:121
Input
Abstract linear system class.
Definition: balance.hh:40
Partitioning::METIS
@ METIS
Use direct interface to Metis.
Definition: partitioning.hh:106
Partitioning::subdomain_id_field_data
shared_ptr< vector< int > > subdomain_id_field_data()
Definition: partitioning.cc:238
Partitioning::mesh_
Mesh * mesh_
The input mesh.
Definition: partitioning.hh:119
Partitioning::~Partitioning
~Partitioning()
Destructor.
Definition: partitioning.cc:69
Partitioning::loc_part_
LongIdx * loc_part_
Partition numbers for local elements in original distribution of elements given be init_el_ds_.
Definition: partitioning.hh:126
Partitioning
Class for the mesh partitioning. This should provide:
Definition: partitioning.hh:52
Partitioning::DECLARE_INPUT_EXCEPTION
DECLARE_INPUT_EXCEPTION(ExcDecomposeMesh,<< "Number of processors "<< EI_NProcs::val<< " greater then number of elements "<< EI_NElems::val<< ". Can not make partitioning of the mesh "<< EI_MeshFile::qval<< ".\n")
Partitioning::get_loc_part
const LongIdx * get_loc_part() const
Definition: partitioning.cc:85
index_types.hh
exceptions.hh
Partitioning::get_graph_type_sel
static const Input::Type::Selection & get_graph_type_sel()
Input specification objects.
Definition: partitioning.cc:31
Partitioning::graph_
SparseGraph * graph_
Graph used to partitioning the mesh.
Definition: partitioning.hh:124
Distribution
Definition: distribution.hh:50
Partitioning::init_el_ds_
Distribution * init_el_ds_
Original distribution of elements. Depends on type of partitioner.
Definition: partitioning.hh:128
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Partitioning::get_tool_sel
static const Input::Type::Selection & get_tool_sel()
Definition: partitioning.cc:42
Partitioning::PartitionTool
PartitionTool
Definition: partitioning.hh:104
accessors.hh
Partitioning::any_neighboring
@ any_neighboring
Add edge for any pair of neighboring elements.
Definition: partitioning.hh:113
input_exception.hh
Partitioning::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_MeshFile, std::string)
Partitioning::same_dimension_neighboring
@ same_dimension_neighboring
Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply)
Definition: partitioning.hh:115
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
Partitioning::PartitionGraphType
PartitionGraphType
Definition: partitioning.hh:112
Partitioning::get_input_type
static const Input::Type::Record & get_input_type()
Definition: partitioning.cc:49
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
LongIdx
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
Mesh
Definition: mesh.h:361
Partitioning::get_init_distr
const Distribution * get_init_distr() const
Definition: partitioning.cc:78
Partitioning::seq_part_
shared_ptr< vector< int > > seq_part_
Sequential partitioning for output.
Definition: partitioning.hh:130
Partitioning::id_maps
void id_maps(int n_ids, LongIdx *id_4_old, Distribution *&new_ds, LongIdx *&id_4_loc, LongIdx *&new_4_id)
Definition: partitioning.cc:232
Partitioning::make_element_connection_graph
void make_element_connection_graph()
Definition: partitioning.cc:92
Partitioning::PETSc
@ PETSc
Use PETSc interface to various partitioing tools.
Definition: partitioning.hh:105
Partitioning::any_weight_lower_dim_cuts
@ any_weight_lower_dim_cuts
Same as before and assign higher weight to cuts of lower dimension in order to make them stick to one...
Definition: partitioning.hh:114
SparseGraph
Virtual class for construction and partitioning of a distributed sparse graph.
Definition: sparse_graph.hh:56