ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
amg_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_AMG_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_AMG_OPERATIONS_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2015, 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 PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include "viennacl/forwards.h"
26 #include "viennacl/scalar.hpp"
27 #include "viennacl/vector.hpp"
28 #include "viennacl/matrix.hpp"
29 #include "viennacl/tools/tools.hpp"
32 
33 #ifdef VIENNACL_WITH_OPENCL
35 #endif
36 
37 #ifdef VIENNACL_WITH_CUDA
39 #endif
40 
41 namespace viennacl
42 {
43 namespace linalg
44 {
45 namespace detail
46 {
47 namespace amg
48 {
49 
50 template<typename NumericT, typename AMGContextT>
51 void amg_influence(compressed_matrix<NumericT> const & A, AMGContextT & amg_context, amg_tag & tag)
52 {
53  switch (viennacl::traits::handle(A).get_active_handle_id())
54  {
57  break;
58 #ifdef VIENNACL_WITH_OPENCL
61  break;
62 #endif
63 #ifdef VIENNACL_WITH_CUDA
65  viennacl::linalg::cuda::amg::amg_influence(A, amg_context, tag);
66  break;
67 #endif
69  throw memory_exception("not initialised!");
70  default:
71  throw memory_exception("not implemented");
72  }
73 }
74 
75 
76 template<typename NumericT, typename AMGContextT>
77 void amg_coarse(compressed_matrix<NumericT> const & A, AMGContextT & amg_context, amg_tag & tag)
78 {
79  switch (viennacl::traits::handle(A).get_active_handle_id())
80  {
83  break;
84 #ifdef VIENNACL_WITH_OPENCL
86  viennacl::linalg::opencl::amg::amg_coarse(A, amg_context, tag);
87  break;
88 #endif
89 #ifdef VIENNACL_WITH_CUDA
91  viennacl::linalg::cuda::amg::amg_coarse(A, amg_context, tag);
92  break;
93 #endif
95  throw memory_exception("not initialised!");
96  default:
97  throw memory_exception("not implemented");
98  }
99 }
100 
101 
102 template<typename NumericT, typename AMGContextT>
105  AMGContextT & amg_context,
106  amg_tag & tag)
107 {
108  switch (viennacl::traits::handle(A).get_active_handle_id())
109  {
111  viennacl::linalg::host_based::amg::amg_interpol(A, P, amg_context, tag);
112  break;
113 #ifdef VIENNACL_WITH_OPENCL
115  viennacl::linalg::opencl::amg::amg_interpol(A, P, amg_context, tag);
116  break;
117 #endif
118 #ifdef VIENNACL_WITH_CUDA
120  viennacl::linalg::cuda::amg::amg_interpol(A, P, amg_context, tag);
121  break;
122 #endif
124  throw memory_exception("not initialised!");
125  default:
126  throw memory_exception("not implemented");
127  }
128 }
129 
130 
131 template<typename NumericT>
134 {
137  (void)orig_ctx;
138  (void)cpu_ctx;
139 
141  {
144  break;
145 #ifdef VIENNACL_WITH_OPENCL
147  A.switch_memory_context(cpu_ctx);
148  B.switch_memory_context(cpu_ctx);
150  A.switch_memory_context(orig_ctx);
151  B.switch_memory_context(orig_ctx);
152  break;
153 #endif
154 #ifdef VIENNACL_WITH_CUDA
156  A.switch_memory_context(cpu_ctx);
157  B.switch_memory_context(cpu_ctx);
159  A.switch_memory_context(orig_ctx);
160  B.switch_memory_context(orig_ctx);
161  //viennacl::linalg::cuda::amg_transpose(A, B);
162  break;
163 #endif
165  throw memory_exception("not initialised!");
166  default:
167  throw memory_exception("not implemented");
168  }
169 }
170 
172 template<typename SparseMatrixType, typename NumericT>
174 assign_to_dense(SparseMatrixType const & A,
176 {
177  assert( (A.size1() == B.size1()) && bool("Size check failed for assignment to dense matrix: size1(A) != size1(B)"));
178  assert( (A.size2() == B.size1()) && bool("Size check failed for assignment to dense matrix: size2(A) != size2(B)"));
179 
181  {
184  break;
185 #ifdef VIENNACL_WITH_OPENCL
188  break;
189 #endif
190 #ifdef VIENNACL_WITH_CUDA
193  break;
194 #endif
196  throw memory_exception("not initialised!");
197  default:
198  throw memory_exception("not implemented");
199  }
200 }
201 
202 template<typename NumericT>
203 void smooth_jacobi(unsigned int iterations,
204  compressed_matrix<NumericT> const & A,
205  vector<NumericT> & x,
206  vector<NumericT> & x_backup,
207  vector<NumericT> const & rhs_smooth,
208  NumericT weight)
209 {
210  switch (viennacl::traits::handle(A).get_active_handle_id())
211  {
213  viennacl::linalg::host_based::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
214  break;
215 #ifdef VIENNACL_WITH_OPENCL
217  viennacl::linalg::opencl::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
218  break;
219 #endif
220 #ifdef VIENNACL_WITH_CUDA
222  viennacl::linalg::cuda::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
223  break;
224 #endif
226  throw memory_exception("not initialised!");
227  default:
228  throw memory_exception("not implemented");
229  }
230 }
231 
232 } //namespace amg
233 } //namespace detail
234 } //namespace linalg
235 } //namespace viennacl
236 
237 
238 #endif
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
void amg_influence(compressed_matrix< NumericT > const &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for influence processing.
Exception class in case of memory errors.
Definition: forwards.h:572
void amg_interpol(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &P, AMGContextT &amg_context, amg_tag &tag)
Implementations of routines for AMG in OpenCL.
Implementation of the dense matrix class.
Various little tools used here and there in ViennaCL.
void switch_memory_context(viennacl::context new_ctx)
Switches the memory context of the matrix.
void amg_influence(compressed_matrix< NumericT > const &A, AMGContextT &amg_context, amg_tag &tag)
This file provides the forward declarations for the main types used within ViennaCL.
Implementations of routines for AMG using the CPU on the host (with OpenMP if enabled).
void amg_coarse(InternalT1 &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Calls the right coarsening procedure.
void amg_coarse(compressed_matrix< NumericT > const &A, AMGContextT &amg_context, amg_tag &tag)
float NumericT
Definition: bisect.cpp:40
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
void amg_interpol(MatrixT const &A, MatrixT &P, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for building the interpolation matrix.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type assign_to_dense(SparseMatrixType const &A, viennacl::matrix_base< NumericT > &B)
void amg_transpose(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &B)
Computes B = trans(A).
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)
Definition: blas3.hpp:36
void amg_interpol(MatrixT const &A, MatrixT &P, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for building the interpolation matrix.
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
Implementations of routines for AMG in OpenCL.
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)
Damped Jacobi Smoother (CUDA version)
void amg_transpose(compressed_matrix< NumericT > &A, compressed_matrix< NumericT > &B)
size_type size1() const
Returns the number of rows.
Definition: matrix_def.hpp:224
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)
Damped Jacobi Smoother (CUDA version)
A tag for algebraic multigrid (AMG). Used to transport information from the user to the implementatio...
Definition: amg_base.hpp:64
void amg_influence(compressed_matrix< NumericT > const &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for influence processing.
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)
Jacobi Smoother (OpenCL version)
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void amg_coarse(MatrixT &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Entry point and dispatcher for coarsening procedures.
void amg_coarse(InternalT1 &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Calls the right coarsening procedure.
Helper classes and functions for the AMG preconditioner. Experimental.
void amg_interpol(MatrixT const &A, MatrixT &P, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for building the interpolation matrix.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
Implementation of the ViennaCL scalar class.
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:118
void amg_influence(compressed_matrix< NumericT > const &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Dispatcher for influence processing.