All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
amg_base.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_DETAIL_AMG_AMG_BASE_HPP_
#define VIENNACL_LINALG_DETAIL_AMG_AMG_BASE_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <cmath>
#include <set>
#include <list>
#include <stdexcept>
#include <algorithm>
#include <map>
#ifdef VIENNACL_WITH_OPENMP
#include <omp.h>
#endif
#include "viennacl/context.hpp"
namespace viennacl
{
namespace linalg
{
enum amg_coarsening_method
{
AMG_COARSENING_METHOD_ONEPASS = 1,
AMG_COARSENING_METHOD_AGGREGATION,
AMG_COARSENING_METHOD_MIS2_AGGREGATION
};
enum amg_interpolation_method
{
AMG_INTERPOLATION_METHOD_DIRECT = 1,
AMG_INTERPOLATION_METHOD_AGGREGATION,
AMG_INTERPOLATION_METHOD_SMOOTHED_AGGREGATION
};
class amg_tag
{
public:
amg_tag()
: coarsening_method_(AMG_COARSENING_METHOD_MIS2_AGGREGATION), interpolation_method_(AMG_INTERPOLATION_METHOD_AGGREGATION),
strong_connection_threshold_(0.1), jacobi_weight_(1.0),
presmooth_steps_(2), postsmooth_steps_(2),
coarse_levels_(0), coarse_cutoff_(50) {}
// Getter-/Setter-Functions
void set_coarsening_method(amg_coarsening_method s) { coarsening_method_ = s; }
amg_coarsening_method get_coarsening_method() const { return coarsening_method_; }
void set_interpolation_method(amg_interpolation_method interpol) { interpolation_method_ = interpol; }
amg_interpolation_method get_interpolation_method() const { return interpolation_method_; }
void set_strong_connection_threshold(double threshold) { if (threshold > 0) strong_connection_threshold_ = threshold; }
double get_strong_connection_threshold() const { return strong_connection_threshold_; }
void set_jacobi_weight(double w) { if (w > 0) jacobi_weight_ = w; }
double get_jacobi_weight() const { return jacobi_weight_; }
void set_presmooth_steps(vcl_size_t steps) { presmooth_steps_ = steps; }
vcl_size_t get_presmooth_steps() const { return presmooth_steps_; }
void set_postsmooth_steps(vcl_size_t steps) { postsmooth_steps_ = steps; }
vcl_size_t get_postsmooth_steps() const { return postsmooth_steps_; }
void set_coarse_levels(vcl_size_t levels) { coarse_levels_ = levels; }
vcl_size_t get_coarse_levels() const { return coarse_levels_; }
void set_coarsening_cutoff(vcl_size_t size) { coarse_cutoff_ = size; }
vcl_size_t get_coarsening_cutoff() const { return coarse_cutoff_; }
void set_setup_context(viennacl::context ctx) { setup_ctx_ = ctx; }
viennacl::context const & get_setup_context() const { return setup_ctx_; }
void set_target_context(viennacl::context ctx) { target_ctx_ = ctx; }
viennacl::context const & get_target_context() const { return target_ctx_; }
private:
amg_coarsening_method coarsening_method_;
amg_interpolation_method interpolation_method_;
double strong_connection_threshold_, jacobi_weight_;
vcl_size_t presmooth_steps_, postsmooth_steps_, coarse_levels_, coarse_cutoff_;
viennacl::context setup_ctx_, target_ctx_;
};
namespace detail
{
namespace amg
{
struct amg_level_context
{
void resize(vcl_size_t num_points, vcl_size_t max_nnz)
{
influence_jumper_.resize(num_points + 1, false);
influence_ids_.resize(max_nnz, false);
influence_values_.resize(num_points, false);
point_types_.resize(num_points, false);
coarse_id_.resize(num_points, false);
}
void switch_context(viennacl::context ctx)
{
influence_jumper_.switch_memory_context(ctx);
influence_ids_.switch_memory_context(ctx);
influence_values_.switch_memory_context(ctx);
point_types_.switch_memory_context(ctx);
coarse_id_.switch_memory_context(ctx);
}
enum
{
POINT_TYPE_UNDECIDED = 0,
POINT_TYPE_COARSE,
POINT_TYPE_FINE
} amg_point_types;
viennacl::vector<unsigned int> influence_jumper_; // similar to row_buffer for CSR matrices
viennacl::vector<unsigned int> influence_ids_; // IDs of influencing points
viennacl::vector<unsigned int> influence_values_; // Influence measure for each point
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
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.
unsigned int num_coarse_;
};
} //namespace amg
}
}
}
#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