1 #ifndef VIENNACL_LINALG_AMG_HPP_ 
    2 #define VIENNACL_LINALG_AMG_HPP_ 
   44 #ifdef VIENNACL_WITH_OPENMP 
   48 #define VIENNACL_AMG_MAX_LEVELS 20 
   77   template<
typename NumericT>
 
  104   template<
typename NumericT, 
typename AMGContextListT>
 
  108                        AMGContextListT & list_of_amg_level_context,
 
  119       list_of_amg_level_context[i].resize(list_of_A[i].
size1(), list_of_A[i].nnz());
 
  125       unsigned int c_points = list_of_amg_level_context[i].num_coarse_;
 
  126       unsigned int f_points = 
static_cast<unsigned int>(list_of_A[i].size1()) - c_points;
 
  130         std::stringstream ss;
 
  131         ss << 
"No further coarsening possible (" << c_points << 
" coarse points). Consider changing the strong connection threshold or increasing the coarsening cutoff." << std::endl;
 
  136       if (c_points == 0 || f_points == 0)
 
  168   template<
typename MatrixT, 
typename InternalT1, 
typename InternalT2>
 
  169   void amg_init(MatrixT 
const & mat, InternalT1 & list_of_A, InternalT1 & list_of_P, InternalT1 & list_of_R, InternalT2 & list_of_amg_level_context, 
amg_tag & tag)
 
  171     typedef typename InternalT1::value_type SparseMatrixType;
 
  178     list_of_amg_level_context.resize(num_levels);
 
  198   template<
typename InternalVectorT, 
typename SparseMatrixT>
 
  200                        InternalVectorT & result_backup,
 
  201                        InternalVectorT & rhs,
 
  202                        InternalVectorT & residual,
 
  203                        SparseMatrixT 
const & A,
 
  207     typedef typename InternalVectorT::value_type VectorType;
 
  209     result.resize(coarse_levels + 1);
 
  210     result_backup.resize(coarse_levels + 1);
 
  211     rhs.resize(coarse_levels + 1);
 
  212     residual.resize(coarse_levels);
 
  214     for (
vcl_size_t level=0; level <= coarse_levels; ++level)
 
  220     for (
vcl_size_t level=0; level < coarse_levels; ++level)
 
  235   template<
typename NumericT, 
typename SparseMatrixT>
 
  237               SparseMatrixT 
const & A,
 
  241     op.
resize(A.size1(), A.size2(), 
false);
 
  252 template<
typename MatrixT>
 
  260 template<
typename NumericT, 
unsigned int AlignmentV>
 
  293     detail::amg_setup_apply(result_list_, result_backup_list_, rhs_list_, residual_list_, A_list_, num_coarse_levels, tag_);
 
  304   template<
typename VectorT>
 
  313     for (level=0; level < residual_list_.size(); level++)
 
  315       result_list_[level].clear();
 
  321                                                    result_backup_list_[level],
 
  323                                                    static_cast<NumericT>(tag_.get_jacobi_weight()));
 
  328       residual_list_[level] = rhs_list_[level] - residual_list_[level];
 
  336     result_list_[level] = rhs_list_[level];
 
  340     for (
int level2 = static_cast<int>(residual_list_.size()-1); level2 >= 0; level2--)
 
  346       result_list_[level] += result_backup_list_[level];
 
  352                                                    result_backup_list_[level],
 
  354                                                    static_cast<NumericT>(tag_.get_jacobi_weight()));
 
  356     vec = result_list_[0];
 
  369     assert(level < levels() && 
bool(
"Level index out of bounds!"));
 
  370     return residual_list_[level].size();
 
  377   std::vector<SparseMatrixType> A_list_;
 
  378   std::vector<SparseMatrixType> P_list_;
 
  379   std::vector<SparseMatrixType> R_list_;
 
  380   std::vector<AMGContextType>   amg_context_list_;
 
  384   mutable std::vector<VectorType> result_list_;
 
  385   mutable std::vector<VectorType> result_backup_list_;
 
  386   mutable std::vector<VectorType> rhs_list_;
 
  387   mutable std::vector<VectorType> residual_list_;
 
void apply(VectorT &vec) const 
Precondition Operation. 
viennacl::context const & get_setup_context() const 
Returns the ViennaCL context for the preconditioenr setup. 
void amg_interpol(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &P, AMGContextT &amg_context, amg_tag &tag)
vcl_size_t size(vcl_size_t level) const 
Returns the problem/operator size at the respective multigrid level. 
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.) 
void lu_substitute(matrix< NumericT, F1, AlignmentV1 > const &A, matrix< NumericT, F2, AlignmentV2 > &B)
LU substitution for the system LU = rhs. 
void amg_lu(viennacl::matrix< NumericT > &op, SparseMatrixT const &A, amg_tag const &tag)
Pre-compute LU factorization for direct solve (ublas library). 
vcl_size_t levels() const 
Returns the total number of multigrid levels in the hierarchy including the finest level...
This file provides the forward declarations for the main types used within ViennaCL. 
void amg_coarse(compressed_matrix< NumericT > const &A, AMGContextT &amg_context, amg_tag &tag)
vcl_size_t get_coarsening_cutoff() const 
Returns the coarse grid size for which the recursive multigrid scheme is stopped and a direct solver ...
void amg_setup_apply(InternalVectorT &result, InternalVectorT &result_backup, InternalVectorT &rhs, InternalVectorT &residual, SparseMatrixT const &A, vcl_size_t coarse_levels, amg_tag const &tag)
Setup data structures for precondition phase for later use on the GPU. 
void amg_init(MatrixT const &mat, InternalT1 &list_of_A, InternalT1 &list_of_P, InternalT1 &list_of_R, InternalT2 &list_of_amg_level_context, amg_tag &tag)
Initialize AMG preconditioner. 
void resize(size_type rows, size_type columns, bool preserve=true)
Resizes the matrix. Existing entries can optionally be preserved. 
#define VIENNACL_AMG_MAX_LEVELS
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
viennacl::context const & get_target_context() const 
Returns the ViennaCL context for the solver cycle stage (i.e. preconditioner applications). 
void switch_memory_context(viennacl::context new_ctx)
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type assign_to_dense(SparseMatrixType const &A, viennacl::matrix_base< NumericT > &B)
vcl_size_t coarse_points() const 
Returns the number of coarse points for which no further coarsening could be applied. 
void smooth_jacobi(unsigned int iterations, compressed_matrix< NumericT > const &A, vector< NumericT > &x, vector< NumericT > &x_backup, vector< NumericT > const &rhs_smooth, NumericT weight)
Implementation of the compressed_matrix class. 
Implementations of operations using sparse matrices. 
AMG preconditioner class, can be supplied to solve()-routines. 
void amg_transpose(compressed_matrix< NumericT > &A, compressed_matrix< NumericT > &B)
amg_tag const & tag() const 
Returns the associated preconditioner tag containing the configuration for the multigrid precondition...
Implementations of LU factorization for row-major and column-major dense matrices. 
Implementations of dense direct solvers are found here. 
amg_precond(compressed_matrix< NumericT, AlignmentV > const &mat, amg_tag const &tag)
The constructor. Builds data structures. 
vcl_size_t get_coarse_levels() const 
Returns the number of coarse levels. If zero, then coarse levels are constructed until the cutoff siz...
A simple, yet (mostly) sufficiently accurate timer for benchmarking and profiling. 
A tag for algebraic multigrid (AMG). Used to transport information from the user to the implementatio...
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object. 
void setup()
Start setup phase for this class and copy data structures. 
vcl_size_t amg_setup(std::vector< compressed_matrix< NumericT > > &list_of_A, std::vector< compressed_matrix< NumericT > > &list_of_P, std::vector< compressed_matrix< NumericT > > &list_of_R, AMGContextListT &list_of_amg_level_context, amg_tag &tag)
Setup AMG preconditioner. 
Helper classes and functions for the AMG preconditioner. Experimental. 
amg_coarse_problem_too_large_exception(std::string const &msg, vcl_size_t num_points)
Implementations of operations for algebraic multigrid. 
void amg_galerkin_prod(compressed_matrix< NumericT > &A_fine, compressed_matrix< NumericT > &P, compressed_matrix< NumericT > &R, compressed_matrix< NumericT > &A_coarse)
Sparse Galerkin product: Calculates A_coarse = trans(P)*A_fine*P = R*A_fine*P. 
void lu_factorize(matrix< NumericT, viennacl::row_major > &A)
LU factorization of a row-major dense matrix.