ViennaCL - The Vienna Computing Library: viennacl/linalg/detail/amg/amg_base.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
amg_base.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_DETAIL_AMG_AMG_BASE_HPP_
2 #define VIENNACL_LINALG_DETAIL_AMG_AMG_BASE_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
27 #include <cmath>
28 #include <set>
29 #include <list>
30 #include <stdexcept>
31 #include <algorithm>
32
33 #include <map>
34 #ifdef VIENNACL_WITH_OPENMP
35 #include <omp.h>
36 #endif
37
38 #include "viennacl/context.hpp"
39
40 namespace viennacl
41 {
42 namespace linalg
43 {
44
46 enum amg_coarsening_method
47 {
48 AMG_COARSENING_METHOD_ONEPASS = 1,
49 AMG_COARSENING_METHOD_AGGREGATION,
50 AMG_COARSENING_METHOD_MIS2_AGGREGATION
51 };
52
54 enum amg_interpolation_method
55 {
56 AMG_INTERPOLATION_METHOD_DIRECT = 1,
57 AMG_INTERPOLATION_METHOD_AGGREGATION,
58 AMG_INTERPOLATION_METHOD_SMOOTHED_AGGREGATION
59 };
60
61
64 class amg_tag
65 {
66 public:
78 amg_tag()
79 : coarsening_method_(AMG_COARSENING_METHOD_MIS2_AGGREGATION), interpolation_method_(AMG_INTERPOLATION_METHOD_AGGREGATION),
80 strong_connection_threshold_(0.1), jacobi_weight_(1.0),
81 presmooth_steps_(2), postsmooth_steps_(2),
82 coarse_levels_(0), coarse_cutoff_(50) {}
83
84 // Getter-/Setter-Functions
86 void set_coarsening_method(amg_coarsening_method s) { coarsening_method_ = s; }
88 amg_coarsening_method get_coarsening_method() const { return coarsening_method_; }
89
91 void set_interpolation_method(amg_interpolation_method interpol) { interpolation_method_ = interpol; }
93 amg_interpolation_method get_interpolation_method() const { return interpolation_method_; }
94
100 void set_strong_connection_threshold(double threshold) { if (threshold > 0) strong_connection_threshold_ = threshold; }
105 double get_strong_connection_threshold() const { return strong_connection_threshold_; }
106
111 void set_jacobi_weight(double w) { if (w > 0) jacobi_weight_ = w; }
113 double get_jacobi_weight() const { return jacobi_weight_; }
114
116 void set_presmooth_steps(vcl_size_t steps) { presmooth_steps_ = steps; }
118 vcl_size_t get_presmooth_steps() const { return presmooth_steps_; }
119
121 void set_postsmooth_steps(vcl_size_t steps) { postsmooth_steps_ = steps; }
123 vcl_size_t get_postsmooth_steps() const { return postsmooth_steps_; }
124
126 void set_coarse_levels(vcl_size_t levels) { coarse_levels_ = levels; }
128 vcl_size_t get_coarse_levels() const { return coarse_levels_; }
129
131 void set_coarsening_cutoff(vcl_size_t size) { coarse_cutoff_ = size; }
133 vcl_size_t get_coarsening_cutoff() const { return coarse_cutoff_; }
134
140 void set_setup_context(viennacl::context ctx) { setup_ctx_ = ctx; }
142 viennacl::context const & get_setup_context() const { return setup_ctx_; }
143
148 void set_target_context(viennacl::context ctx) { target_ctx_ = ctx; }
150 viennacl::context const & get_target_context() const { return target_ctx_; }
151
152 private:
153 amg_coarsening_method coarsening_method_;
154 amg_interpolation_method interpolation_method_;
155 double strong_connection_threshold_, jacobi_weight_;
156 vcl_size_t presmooth_steps_, postsmooth_steps_, coarse_levels_, coarse_cutoff_;
157 viennacl::context setup_ctx_, target_ctx_;
158 };
159
160
161 namespace detail
162 {
163 namespace amg
164 {
165
166
167 struct amg_level_context
168 {
169 void resize(vcl_size_t num_points, vcl_size_t max_nnz)
170 {
171 influence_jumper_.resize(num_points + 1, false);
172 influence_ids_.resize(max_nnz, false);
173 influence_values_.resize(num_points, false);
174 point_types_.resize(num_points, false);
175 coarse_id_.resize(num_points, false);
176 }
177
178 void switch_context(viennacl::context ctx)
179 {
180 influence_jumper_.switch_memory_context(ctx);
181 influence_ids_.switch_memory_context(ctx);
182 influence_values_.switch_memory_context(ctx);
183 point_types_.switch_memory_context(ctx);
184 coarse_id_.switch_memory_context(ctx);
185 }
186
187 enum
188 {
189 POINT_TYPE_UNDECIDED = 0,
190 POINT_TYPE_COARSE,
191 POINT_TYPE_FINE
192 } amg_point_types;
193
194 viennacl::vector<unsigned int> influence_jumper_; // similar to row_buffer for CSR matrices
195 viennacl::vector<unsigned int> influence_ids_; // IDs of influencing points
196 viennacl::vector<unsigned int> influence_values_; // Influence measure for each point
197 viennacl::vector<unsigned int> point_types_; // 0: undecided, 1: coarse point, 2: fine point. Using char here because type for enum might be a larger type
198 viennacl::vector<unsigned int> coarse_id_; // coarse ID used on the next level. Only valid for coarse points. Fine points may (ab)use their entry for something else.
199 unsigned int num_coarse_;
200 };
201
202
203 } //namespace amg
204 }
205 }
206 }
207
208 #endif
viennacl::linalg::amg_tag::get_setup_context
viennacl::context const & get_setup_context() const
Returns the ViennaCL context for the preconditioenr setup.
Definition: amg_base.hpp:142
viennacl::linalg::amg_tag::get_coarsening_method
amg_coarsening_method get_coarsening_method() const
Returns the current coarsening strategy.
Definition: amg_base.hpp:88
viennacl::linalg::amg_tag::set_setup_context
void set_setup_context(viennacl::context ctx)
Sets the ViennaCL context for the setup stage. Set this to a host context if you want to run the setu...
Definition: amg_base.hpp:140
viennacl::linalg::detail::amg::amg_level_context
Definition: amg_base.hpp:167
viennacl::linalg::amg_tag::set_strong_connection_threshold
void set_strong_connection_threshold(double threshold)
Sets the strong connection threshold. Customizations by the user essential for best results! ...
Definition: amg_base.hpp:100
viennacl::linalg::amg_tag::set_jacobi_weight
void set_jacobi_weight(double w)
Sets the weight (damping) for the Jacobi smoother.
Definition: amg_base.hpp:111
viennacl::linalg::amg_tag::set_target_context
void set_target_context(viennacl::context ctx)
Sets the ViennaCL context for the solver cycle stage (i.e. preconditioner applications).
Definition: amg_base.hpp:148
viennacl::linalg::amg_tag::get_jacobi_weight
double get_jacobi_weight() const
Returns the Jacobi smoother weight (damping).
Definition: amg_base.hpp:113
viennacl::linalg::AMG_INTERPOLATION_METHOD_AGGREGATION
Definition: amg_base.hpp:57
viennacl::linalg::amg_tag::get_presmooth_steps
vcl_size_t get_presmooth_steps() const
Returns the number of smoother applications on the fine level before restriction to the coarser level...
Definition: amg_base.hpp:118
viennacl::linalg::amg_tag::set_postsmooth_steps
void set_postsmooth_steps(vcl_size_t steps)
Sets the number of smoother applications on the coarse level before interpolation to the finer level...
Definition: amg_base.hpp:121
viennacl::linalg::amg_tag::get_postsmooth_steps
vcl_size_t get_postsmooth_steps() const
Returns the number of smoother applications on the coarse level before interpolation to the finer lev...
Definition: amg_base.hpp:123
viennacl::linalg::AMG_INTERPOLATION_METHOD_DIRECT
Definition: amg_base.hpp:56
viennacl::linalg::amg_tag::get_coarsening_cutoff
vcl_size_t get_coarsening_cutoff() const
Returns the coarse grid size for which the recursive multigrid scheme is stopped and a direct solver ...
Definition: amg_base.hpp:133
viennacl::linalg::AMG_COARSENING_METHOD_MIS2_AGGREGATION
Definition: amg_base.hpp:50
context.hpp
Implementation of a OpenCL-like context, which serves as a unification of {OpenMP, CUDA, OpenCL} at the user API.
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::linalg::amg_tag::get_target_context
viennacl::context const & get_target_context() const
Returns the ViennaCL context for the solver cycle stage (i.e. preconditioner applications).
Definition: amg_base.hpp:150
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::linalg::AMG_COARSENING_METHOD_AGGREGATION
Definition: amg_base.hpp:49
viennacl::linalg::amg_tag::set_interpolation_method
void set_interpolation_method(amg_interpolation_method interpol)
Sets the interpolation method to the provided method.
Definition: amg_base.hpp:91
viennacl::linalg::AMG_INTERPOLATION_METHOD_SMOOTHED_AGGREGATION
Definition: amg_base.hpp:58
viennacl::linalg::amg_tag::set_presmooth_steps
void set_presmooth_steps(vcl_size_t steps)
Sets the number of smoother applications on the fine level before restriction to the coarser level...
Definition: amg_base.hpp:116
viennacl::linalg::amg_tag::get_strong_connection_threshold
double get_strong_connection_threshold() const
Returns the strong connection threshold parameter.
Definition: amg_base.hpp:105
viennacl::vector::resize
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'AlignmentV'.
Definition: vector.hpp:1046
viennacl::linalg::detail::amg::amg_level_context::num_coarse_
unsigned int num_coarse_
Definition: amg_base.hpp:199
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::linalg::detail::amg::amg_level_context::POINT_TYPE_UNDECIDED
Definition: amg_base.hpp:189
viennacl::vector< unsigned int >
viennacl::linalg::amg_tag::set_coarsening_method
void set_coarsening_method(amg_coarsening_method s)
Sets the strategy used for constructing coarse grids.
Definition: amg_base.hpp:86
viennacl::linalg::detail::amg::amg_level_context::POINT_TYPE_FINE
Definition: amg_base.hpp:191
viennacl::linalg::amg_tag::get_coarse_levels
vcl_size_t get_coarse_levels() const
Returns the number of coarse levels. If zero, then coarse levels are constructed until the cutoff siz...
Definition: amg_base.hpp:128
viennacl::linalg::amg_tag
A tag for algebraic multigrid (AMG). Used to transport information from the user to the implementatio...
Definition: amg_base.hpp:64
viennacl::linalg::detail::amg::amg_level_context::switch_context
void switch_context(viennacl::context ctx)
Definition: amg_base.hpp:178
viennacl::linalg::detail::amg::amg_level_context::point_types_
viennacl::vector< unsigned int > point_types_
Definition: amg_base.hpp:197
viennacl::linalg::amg_tag::get_interpolation_method
amg_interpolation_method get_interpolation_method() const
Returns the current interpolation method.
Definition: amg_base.hpp:93
viennacl::linalg::amg_coarsening_method
amg_coarsening_method
Enumeration of coarsening methods for algebraic multigrid.
Definition: amg_base.hpp:46
viennacl::linalg::amg_tag::set_coarsening_cutoff
void set_coarsening_cutoff(vcl_size_t size)
Sets the coarse grid size for which the recursive multigrid scheme is stopped and a direct solver is ...
Definition: amg_base.hpp:131
viennacl::linalg::amg_tag::set_coarse_levels
void set_coarse_levels(vcl_size_t levels)
Sets the number of coarse levels. If set to zero, then coarse levels are constructed until the cutoff...
Definition: amg_base.hpp:126
viennacl::linalg::amg_tag::amg_tag
amg_tag()
The constructor, setting default values for the various parameters.
Definition: amg_base.hpp:78
viennacl::linalg::detail::amg::amg_level_context::POINT_TYPE_COARSE
Definition: amg_base.hpp:190
viennacl::linalg::detail::amg::amg_level_context::coarse_id_
viennacl::vector< unsigned int > coarse_id_
Definition: amg_base.hpp:198
viennacl::linalg::AMG_COARSENING_METHOD_ONEPASS
Definition: amg_base.hpp:48
viennacl::linalg::detail::amg::amg_level_context::influence_values_
viennacl::vector< unsigned int > influence_values_
Definition: amg_base.hpp:196
viennacl::linalg::amg_interpolation_method
amg_interpolation_method
Enumeration of interpolation methods for algebraic multigrid.
Definition: amg_base.hpp:54
viennacl::linalg::detail::amg::amg_level_context::influence_ids_
viennacl::vector< unsigned int > influence_ids_
Definition: amg_base.hpp:195
viennacl::linalg::detail::amg::amg_level_context::amg_point_types
enum viennacl::linalg::detail::amg::amg_level_context::@21 amg_point_types
viennacl::vector::switch_memory_context
void switch_memory_context(viennacl::context new_ctx)
Definition: vector.hpp:1064
viennacl::linalg::detail::amg::amg_level_context::resize
void resize(vcl_size_t num_points, vcl_size_t max_nnz)
Definition: amg_base.hpp:169
viennacl::linalg::detail::amg::amg_level_context::influence_jumper_
viennacl::vector< unsigned int > influence_jumper_
Definition: amg_base.hpp:194