ViennaCL - The Vienna Computing Library: viennacl/linalg/amg_operations.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_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-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 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"
30 #include "viennacl/linalg/detail/amg/amg_base.hpp"
31 #include "viennacl/linalg/host_based/amg_operations.hpp"
32
33 #ifdef VIENNACL_WITH_OPENCL
34 #include "viennacl/linalg/opencl/amg_operations.hpp"
35 #endif
36
37 #ifdef VIENNACL_WITH_CUDA
38 #include "viennacl/linalg/cuda/amg_operations.hpp"
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 {
55 case viennacl::MAIN_MEMORY:
56 viennacl::linalg::host_based::amg::amg_influence(A, amg_context, tag);
57 break;
58 #ifdef VIENNACL_WITH_OPENCL
59 case viennacl::OPENCL_MEMORY:
60 viennacl::linalg::opencl::amg::amg_influence(A, amg_context, tag);
61 break;
62 #endif
63 #ifdef VIENNACL_WITH_CUDA
64 case viennacl::CUDA_MEMORY:
65 viennacl::linalg::cuda::amg::amg_influence(A, amg_context, tag);
66 break;
67 #endif
68 case viennacl::MEMORY_NOT_INITIALIZED:
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 {
81 case viennacl::MAIN_MEMORY:
82 viennacl::linalg::host_based::amg::amg_coarse(A, amg_context, tag);
83 break;
84 #ifdef VIENNACL_WITH_OPENCL
85 case viennacl::OPENCL_MEMORY:
86 viennacl::linalg::opencl::amg::amg_coarse(A, amg_context, tag);
87 break;
88 #endif
89 #ifdef VIENNACL_WITH_CUDA
90 case viennacl::CUDA_MEMORY:
91 viennacl::linalg::cuda::amg::amg_coarse(A, amg_context, tag);
92 break;
93 #endif
94 case viennacl::MEMORY_NOT_INITIALIZED:
95 throw memory_exception("not initialised!");
96 default:
97 throw memory_exception("not implemented");
98 }
99 }
100
101
102 template<typename NumericT, typename AMGContextT>
103 void amg_interpol(compressed_matrix<NumericT> const & A,
104 compressed_matrix<NumericT> & P,
105 AMGContextT & amg_context,
106 amg_tag & tag)
107 {
108 switch (viennacl::traits::handle(A).get_active_handle_id())
109 {
110 case viennacl::MAIN_MEMORY:
111 viennacl::linalg::host_based::amg::amg_interpol(A, P, amg_context, tag);
112 break;
113 #ifdef VIENNACL_WITH_OPENCL
114 case viennacl::OPENCL_MEMORY:
115 viennacl::linalg::opencl::amg::amg_interpol(A, P, amg_context, tag);
116 break;
117 #endif
118 #ifdef VIENNACL_WITH_CUDA
119 case viennacl::CUDA_MEMORY:
120 viennacl::linalg::cuda::amg::amg_interpol(A, P, amg_context, tag);
121 break;
122 #endif
123 case viennacl::MEMORY_NOT_INITIALIZED:
124 throw memory_exception("not initialised!");
125 default:
126 throw memory_exception("not implemented");
127 }
128 }
129
130
131 template<typename NumericT>
132 void amg_transpose(compressed_matrix<NumericT> & A,
133 compressed_matrix<NumericT> & B)
134 {
135 viennacl::context orig_ctx = viennacl::traits::context(A);
136 viennacl::context cpu_ctx(viennacl::MAIN_MEMORY);
137 (void)orig_ctx;
138 (void)cpu_ctx;
139
140 switch (viennacl::traits::handle(A).get_active_handle_id())
141 {
142 case viennacl::MAIN_MEMORY:
143 viennacl::linalg::host_based::amg::amg_transpose(A, B);
144 break;
145 #ifdef VIENNACL_WITH_OPENCL
146 case viennacl::OPENCL_MEMORY:
147 A.switch_memory_context(cpu_ctx);
148 B.switch_memory_context(cpu_ctx);
149 viennacl::linalg::host_based::amg::amg_transpose(A, B);
150 A.switch_memory_context(orig_ctx);
151 B.switch_memory_context(orig_ctx);
152 break;
153 #endif
154 #ifdef VIENNACL_WITH_CUDA
155 case viennacl::CUDA_MEMORY:
156 A.switch_memory_context(cpu_ctx);
157 B.switch_memory_context(cpu_ctx);
158 viennacl::linalg::host_based::amg::amg_transpose(A, B);
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
164 case viennacl::MEMORY_NOT_INITIALIZED:
165 throw memory_exception("not initialised!");
166 default:
167 throw memory_exception("not implemented");
168 }
169 }
170
172 template<typename SparseMatrixType, typename NumericT>
173 typename viennacl::enable_if< viennacl::is_any_sparse_matrix<SparseMatrixType>::value>::type
174 assign_to_dense(SparseMatrixType const & A,
175 viennacl::matrix_base<NumericT> & B)
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
180 switch (viennacl::traits::handle(A).get_active_handle_id())
181 {
182 case viennacl::MAIN_MEMORY:
183 viennacl::linalg::host_based::amg::assign_to_dense(A, B);
184 break;
185 #ifdef VIENNACL_WITH_OPENCL
186 case viennacl::OPENCL_MEMORY:
187 viennacl::linalg::opencl::amg::assign_to_dense(A, B);
188 break;
189 #endif
190 #ifdef VIENNACL_WITH_CUDA
191 case viennacl::CUDA_MEMORY:
192 viennacl::linalg::cuda::amg::assign_to_dense(A, B);
193 break;
194 #endif
195 case viennacl::MEMORY_NOT_INITIALIZED:
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 {
212 case viennacl::MAIN_MEMORY:
213 viennacl::linalg::host_based::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
214 break;
215 #ifdef VIENNACL_WITH_OPENCL
216 case viennacl::OPENCL_MEMORY:
217 viennacl::linalg::opencl::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
218 break;
219 #endif
220 #ifdef VIENNACL_WITH_CUDA
221 case viennacl::CUDA_MEMORY:
222 viennacl::linalg::cuda::amg::smooth_jacobi(iterations, A, x, x_backup, rhs_smooth, weight);
223 break;
224 #endif
225 case viennacl::MEMORY_NOT_INITIALIZED:
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
viennacl::enable_if
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
viennacl::linalg::opencl::amg::amg_influence
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.
Definition: amg_operations.hpp:82
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
viennacl::linalg::detail::amg::amg_interpol
void amg_interpol(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &P, AMGContextT &amg_context, amg_tag &tag)
Definition: amg_operations.hpp:103
amg_operations.hpp
Implementations of routines for AMG in OpenCL.
matrix.hpp
Implementation of the dense matrix class.
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::compressed_matrix::switch_memory_context
void switch_memory_context(viennacl::context new_ctx)
Switches the memory context of the matrix.
Definition: compressed_matrix.hpp:957
viennacl::linalg::detail::amg::amg_influence
void amg_influence(compressed_matrix< NumericT > const &A, AMGContextT &amg_context, amg_tag &tag)
Definition: amg_operations.hpp:51
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::matrix_base< NumericT >
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
amg_operations.hpp
Implementations of routines for AMG using the CPU on the host (with OpenMP if enabled).
viennacl::linalg::cuda::amg::amg_coarse
void amg_coarse(InternalT1 &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Calls the right coarsening procedure.
Definition: amg_operations.hpp:526
viennacl::linalg::detail::amg::amg_coarse
void amg_coarse(compressed_matrix< NumericT > const &A, AMGContextT &amg_context, amg_tag &tag)
Definition: amg_operations.hpp:77
NumericT
float NumericT
Definition: bisect.cpp:40
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::cuda::amg::amg_interpol
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.
Definition: amg_operations.hpp:693
viennacl::linalg::opencl::amg::assign_to_dense
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
Definition: amg_operations.hpp:400
viennacl::linalg::detail::amg::assign_to_dense
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type assign_to_dense(SparseMatrixType const &A, viennacl::matrix_base< NumericT > &B)
Definition: amg_operations.hpp:174
viennacl::linalg::host_based::amg::amg_transpose
void amg_transpose(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &B)
Computes B = trans(A).
Definition: amg_operations.hpp:972
viennacl::linalg::detail::amg::smooth_jacobi
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: amg_operations.hpp:203
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::CUDA_MEMORY
Definition: forwards.h:350
viennacl::linalg::opencl::amg::amg_interpol
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.
Definition: amg_operations.hpp:385
viennacl::linalg::host_based::amg::assign_to_dense
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
Definition: amg_operations.hpp:1042
viennacl::linalg::cuda::amg::assign_to_dense
void assign_to_dense(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, viennacl::matrix_base< NumericT > &B)
Definition: amg_operations.hpp:730
amg_operations.hpp
Implementations of routines for AMG in OpenCL.
viennacl::linalg::cuda::amg::smooth_jacobi
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)
Definition: amg_operations.hpp:791
viennacl::linalg::detail::amg::amg_transpose
void amg_transpose(compressed_matrix< NumericT > &A, compressed_matrix< NumericT > &B)
Definition: amg_operations.hpp:132
viennacl::vector< NumericT >
viennacl::matrix_base::size1
size_type size1() const
Returns the number of rows.
Definition: matrix_def.hpp:224
viennacl::linalg::host_based::amg::smooth_jacobi
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)
Definition: amg_operations.hpp:1074
viennacl::MAIN_MEMORY
Definition: forwards.h:348
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::host_based::amg::amg_influence
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.
Definition: amg_operations.hpp:224
viennacl::linalg::opencl::amg::smooth_jacobi
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)
Definition: amg_operations.hpp:427
viennacl::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::linalg::host_based::amg::amg_coarse
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.
Definition: amg_operations.hpp:697
viennacl::compressed_matrix< NumericT >
viennacl::linalg::opencl::amg::amg_coarse
void amg_coarse(InternalT1 &A, viennacl::linalg::detail::amg::amg_level_context &amg_context, viennacl::linalg::amg_tag &tag)
Calls the right coarsening procedure.
Definition: amg_operations.hpp:286
amg_base.hpp
Helper classes and functions for the AMG preconditioner. Experimental.
viennacl::linalg::host_based::amg::amg_interpol
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.
Definition: amg_operations.hpp:952
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl::backend::mem_handle::get_active_handle_id
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
viennacl::linalg::cuda::amg::amg_influence
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.
Definition: amg_operations.hpp:103