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 
47 {
51 };
52 
55 {
59 };
60 
61 
64 class amg_tag
65 {
66 public:
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 
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 
179  {
185  }
186 
187  enum
188  {
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::context const & get_setup_context() const
Returns the ViennaCL context for the preconditioenr setup.
Definition: amg_base.hpp:142
amg_coarsening_method get_coarsening_method() const
Returns the current coarsening strategy.
Definition: amg_base.hpp:88
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
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
void set_jacobi_weight(double w)
Sets the weight (damping) for the Jacobi smoother.
Definition: amg_base.hpp:111
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
double get_jacobi_weight() const
Returns the Jacobi smoother weight (damping).
Definition: amg_base.hpp:113
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
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
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
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
Implementation of a OpenCL-like context, which serves as a unification of {OpenMP, CUDA, OpenCL} at the user API.
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
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
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
void set_interpolation_method(amg_interpolation_method interpol)
Sets the interpolation method to the provided method.
Definition: amg_base.hpp:91
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
double get_strong_connection_threshold() const
Returns the strong connection threshold parameter.
Definition: amg_base.hpp:105
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
std::size_t vcl_size_t
Definition: forwards.h:75
void set_coarsening_method(amg_coarsening_method s)
Sets the strategy used for constructing coarse grids.
Definition: amg_base.hpp:86
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
A tag for algebraic multigrid (AMG). Used to transport information from the user to the implementatio...
Definition: amg_base.hpp:64
void switch_context(viennacl::context ctx)
Definition: amg_base.hpp:178
viennacl::vector< unsigned int > point_types_
Definition: amg_base.hpp:197
amg_interpolation_method get_interpolation_method() const
Returns the current interpolation method.
Definition: amg_base.hpp:93
amg_coarsening_method
Enumeration of coarsening methods for algebraic multigrid.
Definition: amg_base.hpp:46
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
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
amg_tag()
The constructor, setting default values for the various parameters.
Definition: amg_base.hpp:78
viennacl::vector< unsigned int > coarse_id_
Definition: amg_base.hpp:198
viennacl::vector< unsigned int > influence_values_
Definition: amg_base.hpp:196
amg_interpolation_method
Enumeration of interpolation methods for algebraic multigrid.
Definition: amg_base.hpp:54
viennacl::vector< unsigned int > influence_ids_
Definition: amg_base.hpp:195
enum viennacl::linalg::detail::amg::amg_level_context::@21 amg_point_types
void switch_memory_context(viennacl::context new_ctx)
Definition: vector.hpp:1064
void resize(vcl_size_t num_points, vcl_size_t max_nnz)
Definition: amg_base.hpp:169
viennacl::vector< unsigned int > influence_jumper_
Definition: amg_base.hpp:194