ViennaCL - The Vienna Computing Library: viennacl/linalg/ilu_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
ilu_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_ILU_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_ILU_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/range.hpp"
27 #include "viennacl/scalar.hpp"
28 #include "viennacl/tools/tools.hpp"
29 #include "viennacl/meta/predicate.hpp"
30 #include "viennacl/meta/enable_if.hpp"
31 #include "viennacl/traits/size.hpp"
32 #include "viennacl/traits/start.hpp"
33 #include "viennacl/traits/handle.hpp"
34 #include "viennacl/traits/stride.hpp"
35 #include "viennacl/linalg/host_based/ilu_operations.hpp"
36
37 #ifdef VIENNACL_WITH_OPENCL
38 #include "viennacl/linalg/opencl/ilu_operations.hpp"
39 #endif
40
41 #ifdef VIENNACL_WITH_CUDA
42 #include "viennacl/linalg/cuda/ilu_operations.hpp"
43 #endif
44
45 namespace viennacl
46 {
47 namespace linalg
48 {
49
55 template<typename NumericT>
56 void extract_L(compressed_matrix<NumericT> const & A,
57 compressed_matrix<NumericT> & L)
58 {
59 switch (viennacl::traits::handle(A).get_active_handle_id())
60 {
61 case viennacl::MAIN_MEMORY:
62 viennacl::linalg::host_based::extract_L(A, L);
63 break;
64 #ifdef VIENNACL_WITH_OPENCL
65 case viennacl::OPENCL_MEMORY:
66 viennacl::linalg::opencl::extract_L(A, L);
67 break;
68 #endif
69 #ifdef VIENNACL_WITH_CUDA
70 case viennacl::CUDA_MEMORY:
71 viennacl::linalg::cuda::extract_L(A, L);
72 break;
73 #endif
74 case viennacl::MEMORY_NOT_INITIALIZED:
75 throw memory_exception("not initialised!");
76 default:
77 throw memory_exception("not implemented");
78 }
79 }
80
86 template<typename NumericT>
87 void icc_scale(compressed_matrix<NumericT> const & A,
88 compressed_matrix<NumericT> & L)
89 {
90 switch (viennacl::traits::handle(A).get_active_handle_id())
91 {
92 case viennacl::MAIN_MEMORY:
93 viennacl::linalg::host_based::icc_scale(A, L);
94 break;
95 #ifdef VIENNACL_WITH_OPENCL
96 case viennacl::OPENCL_MEMORY:
97 viennacl::linalg::opencl::icc_scale(A, L);
98 break;
99 #endif
100 #ifdef VIENNACL_WITH_CUDA
101 case viennacl::CUDA_MEMORY:
102 viennacl::linalg::cuda::icc_scale(A, L);
103 break;
104 #endif
105 case viennacl::MEMORY_NOT_INITIALIZED:
106 throw memory_exception("not initialised!");
107 default:
108 throw memory_exception("not implemented");
109 }
110 }
111
120 template<typename NumericT>
121 void icc_chow_patel_sweep(compressed_matrix<NumericT> & L,
122 vector<NumericT> & aij_L)
123 {
124 switch (viennacl::traits::handle(L).get_active_handle_id())
125 {
126 case viennacl::MAIN_MEMORY:
127 viennacl::linalg::host_based::icc_chow_patel_sweep(L, aij_L);
128 break;
129 #ifdef VIENNACL_WITH_OPENCL
130 case viennacl::OPENCL_MEMORY:
131 viennacl::linalg::opencl::icc_chow_patel_sweep(L, aij_L);
132 break;
133 #endif
134 #ifdef VIENNACL_WITH_CUDA
135 case viennacl::CUDA_MEMORY:
136 viennacl::linalg::cuda::icc_chow_patel_sweep(L, aij_L);
137 break;
138 #endif
139 case viennacl::MEMORY_NOT_INITIALIZED:
140 throw memory_exception("not initialised!");
141 default:
142 throw memory_exception("not implemented");
143 }
144 }
145
146
147
149
155 template<typename NumericT>
156 void extract_LU(compressed_matrix<NumericT> const & A,
157 compressed_matrix<NumericT> & L,
158 compressed_matrix<NumericT> & U)
159 {
160 switch (viennacl::traits::handle(A).get_active_handle_id())
161 {
162 case viennacl::MAIN_MEMORY:
163 viennacl::linalg::host_based::extract_LU(A, L, U);
164 break;
165 #ifdef VIENNACL_WITH_OPENCL
166 case viennacl::OPENCL_MEMORY:
167 viennacl::linalg::opencl::extract_LU(A, L, U);
168 break;
169 #endif
170 #ifdef VIENNACL_WITH_CUDA
171 case viennacl::CUDA_MEMORY:
172 viennacl::linalg::cuda::extract_LU(A, L, U);
173 break;
174 #endif
175 case viennacl::MEMORY_NOT_INITIALIZED:
176 throw memory_exception("not initialised!");
177 default:
178 throw memory_exception("not implemented");
179 }
180 }
181
187 template<typename NumericT>
188 void ilu_scale(compressed_matrix<NumericT> const & A,
189 compressed_matrix<NumericT> & L,
190 compressed_matrix<NumericT> & U)
191 {
192 switch (viennacl::traits::handle(A).get_active_handle_id())
193 {
194 case viennacl::MAIN_MEMORY:
195 viennacl::linalg::host_based::ilu_scale(A, L, U);
196 break;
197 #ifdef VIENNACL_WITH_OPENCL
198 case viennacl::OPENCL_MEMORY:
199 viennacl::linalg::opencl::ilu_scale(A, L, U);
200 break;
201 #endif
202 #ifdef VIENNACL_WITH_CUDA
203 case viennacl::CUDA_MEMORY:
204 viennacl::linalg::cuda::ilu_scale(A, L, U);
205 break;
206 #endif
207 case viennacl::MEMORY_NOT_INITIALIZED:
208 throw memory_exception("not initialised!");
209 default:
210 throw memory_exception("not implemented");
211 }
212 }
213
219 template<typename NumericT>
220 void ilu_transpose(compressed_matrix<NumericT> const & A,
221 compressed_matrix<NumericT> & B)
222 {
223 viennacl::context orig_ctx = viennacl::traits::context(A);
224 viennacl::context cpu_ctx(viennacl::MAIN_MEMORY);
225 (void)orig_ctx;
226 (void)cpu_ctx;
227
228 viennacl::compressed_matrix<NumericT> A_host(0, 0, 0, cpu_ctx);
229 (void)A_host;
230
231 switch (viennacl::traits::handle(A).get_active_handle_id())
232 {
233 case viennacl::MAIN_MEMORY:
234 viennacl::linalg::host_based::ilu_transpose(A, B);
235 break;
236 #ifdef VIENNACL_WITH_OPENCL
237 case viennacl::OPENCL_MEMORY:
238 A_host = A;
239 B.switch_memory_context(cpu_ctx);
240 viennacl::linalg::host_based::ilu_transpose(A_host, B);
241 B.switch_memory_context(orig_ctx);
242 break;
243 #endif
244 #ifdef VIENNACL_WITH_CUDA
245 case viennacl::CUDA_MEMORY:
246 A_host = A;
247 B.switch_memory_context(cpu_ctx);
248 viennacl::linalg::host_based::ilu_transpose(A_host, B);
249 B.switch_memory_context(orig_ctx);
250 break;
251 #endif
252 case viennacl::MEMORY_NOT_INITIALIZED:
253 throw memory_exception("not initialised!");
254 default:
255 throw memory_exception("not implemented");
256 }
257 }
258
259
260
271 template<typename NumericT>
272 void ilu_chow_patel_sweep(compressed_matrix<NumericT> & L,
273 vector<NumericT> const & aij_L,
274 compressed_matrix<NumericT> & U_trans,
275 vector<NumericT> const & aij_U_trans)
276 {
277 switch (viennacl::traits::handle(L).get_active_handle_id())
278 {
279 case viennacl::MAIN_MEMORY:
280 viennacl::linalg::host_based::ilu_chow_patel_sweep(L, aij_L, U_trans, aij_U_trans);
281 break;
282 #ifdef VIENNACL_WITH_OPENCL
283 case viennacl::OPENCL_MEMORY:
284 viennacl::linalg::opencl::ilu_chow_patel_sweep(L, aij_L, U_trans, aij_U_trans);
285 break;
286 #endif
287 #ifdef VIENNACL_WITH_CUDA
288 case viennacl::CUDA_MEMORY:
289 viennacl::linalg::cuda::ilu_chow_patel_sweep(L, aij_L, U_trans, aij_U_trans);
290 break;
291 #endif
292 case viennacl::MEMORY_NOT_INITIALIZED:
293 throw memory_exception("not initialised!");
294 default:
295 throw memory_exception("not implemented");
296 }
297 }
298
304 template<typename NumericT>
305 void ilu_form_neumann_matrix(compressed_matrix<NumericT> & R,
306 vector<NumericT> & diag_R)
307 {
308 switch (viennacl::traits::handle(R).get_active_handle_id())
309 {
310 case viennacl::MAIN_MEMORY:
311 viennacl::linalg::host_based::ilu_form_neumann_matrix(R, diag_R);
312 break;
313 #ifdef VIENNACL_WITH_OPENCL
314 case viennacl::OPENCL_MEMORY:
315 viennacl::linalg::opencl::ilu_form_neumann_matrix(R, diag_R);
316 break;
317 #endif
318 #ifdef VIENNACL_WITH_CUDA
319 case viennacl::CUDA_MEMORY:
320 viennacl::linalg::cuda::ilu_form_neumann_matrix(R, diag_R);
321 break;
322 #endif
323 case viennacl::MEMORY_NOT_INITIALIZED:
324 throw memory_exception("not initialised!");
325 default:
326 throw memory_exception("not implemented");
327 }
328 }
329
330 } //namespace linalg
331 } //namespace viennacl
332
333
334 #endif
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
size.hpp
Generic size and resize functionality for different vector and matrix types.
viennacl::linalg::cuda::extract_LU
void extract_LU(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Definition: ilu_operations.hpp:387
start.hpp
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
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::extract_L
void extract_L(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Extracts the lower triangular part L from A.
Definition: ilu_operations.hpp:56
viennacl::linalg::opencl::ilu_scale
void ilu_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:186
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::linalg::host_based::icc_chow_patel_sweep
void icc_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > &aij_L)
Performs one nonlinear relaxation step in the Chow-Patel-ICC using OpenMP (cf. Algorithm 3 in paper...
Definition: ilu_operations.hpp:185
viennacl::linalg::ilu_chow_patel_sweep
void ilu_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L, compressed_matrix< NumericT > &U_trans, vector< NumericT > const &aij_U_trans)
Performs one nonlinear relaxation step in the Chow-Patel-ILU (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:272
ilu_operations.hpp
Implementations of specialized routines for the Chow-Patel parallel ILU preconditioner using OpenCL...
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
stride.hpp
Determines row and column increments for matrices and matrix proxies.
viennacl::linalg::host_based::extract_LU
void extract_LU(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Definition: ilu_operations.hpp:258
viennacl::linalg::opencl::ilu_chow_patel_sweep
void ilu_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L, compressed_matrix< NumericT > &U_trans, vector< NumericT > const &aij_U_trans)
Performs one nonlinear relaxation step in the Chow-Patel-ILU using OpenCL (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:213
viennacl::linalg::cuda::extract_L
void extract_L(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Definition: ilu_operations.hpp:107
viennacl::linalg::cuda::ilu_form_neumann_matrix
void ilu_form_neumann_matrix(compressed_matrix< NumericT > &R, vector< NumericT > &diag_R)
Definition: ilu_operations.hpp:649
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::host_based::ilu_scale
void ilu_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:349
viennacl::linalg::host_based::ilu_form_neumann_matrix
void ilu_form_neumann_matrix(compressed_matrix< NumericT > &R, vector< NumericT > &diag_R)
Definition: ilu_operations.hpp:626
viennacl::linalg::opencl::extract_L
void extract_L(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Definition: ilu_operations.hpp:51
viennacl::linalg::host_based::extract_L
void extract_L(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Definition: ilu_operations.hpp:53
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::CUDA_MEMORY
Definition: forwards.h:350
viennacl::linalg::icc_scale
void icc_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:87
viennacl::linalg::ilu_scale
void ilu_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:188
viennacl::linalg::extract_LU
void extract_LU(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Extracts the lower triangular part L and the upper triangular part U from A.
Definition: ilu_operations.hpp:156
viennacl::linalg::host_based::icc_scale
void icc_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:124
viennacl::vector< NumericT >
viennacl::linalg::cuda::ilu_scale
void ilu_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:438
predicate.hpp
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::linalg::ilu_form_neumann_matrix
void ilu_form_neumann_matrix(compressed_matrix< NumericT > &R, vector< NumericT > &diag_R)
Extracts the lower triangular part L and the upper triangular part U from A.
Definition: ilu_operations.hpp:305
viennacl::linalg::ilu_transpose
void ilu_transpose(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &B)
Transposition B <- A^T, where the aij-vector is permuted in the same way as the value array in A when...
Definition: ilu_operations.hpp:220
viennacl::linalg::cuda::icc_scale
void icc_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:203
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
viennacl::linalg::host_based::ilu_transpose
void ilu_transpose(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &B)
Definition: ilu_operations.hpp:431
ilu_operations.hpp
Implementations of specialized routines for the Chow-Patel parallel ILU preconditioner using the host...
viennacl::linalg::icc_chow_patel_sweep
void icc_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > &aij_L)
Performs one nonlinear relaxation step in the Chow-Patel-ICC (cf. Algorithm 3 in paper, but for L rather than U)
Definition: ilu_operations.hpp:121
viennacl::linalg::opencl::ilu_form_neumann_matrix
void ilu_form_neumann_matrix(compressed_matrix< NumericT > &R, vector< NumericT > &diag_R)
Definition: ilu_operations.hpp:243
range.hpp
Implementation of a range object for use with proxy objects.
viennacl::compressed_matrix< NumericT >
viennacl::linalg::opencl::icc_chow_patel_sweep
void icc_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L)
Performs one nonlinear relaxation step in the Chow-Patel-ILU using OpenCL (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:116
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::linalg::cuda::ilu_chow_patel_sweep
void ilu_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L, compressed_matrix< NumericT > &U_trans, vector< NumericT > const &aij_U_trans)
Performs one nonlinear relaxation step in the Chow-Patel-ILU using OpenMP (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:576
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
viennacl::linalg::opencl::extract_LU
void extract_LU(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L, compressed_matrix< NumericT > &U)
Definition: ilu_operations.hpp:137
ilu_operations.hpp
Implementations of specialized routines for the Chow-Patel parallel ILU preconditioner using CUDA...
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl::linalg::opencl::icc_scale
void icc_scale(compressed_matrix< NumericT > const &A, compressed_matrix< NumericT > &L)
Scales the values extracted from A such that A' = DAD has unit diagonal. Updates values from A in L a...
Definition: ilu_operations.hpp:93
viennacl::linalg::host_based::ilu_chow_patel_sweep
void ilu_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L, compressed_matrix< NumericT > &U_trans, vector< NumericT > const &aij_U_trans)
Performs one nonlinear relaxation step in the Chow-Patel-ILU using OpenMP (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:503
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
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::icc_chow_patel_sweep
void icc_chow_patel_sweep(compressed_matrix< NumericT > &L, vector< NumericT > const &aij_L)
Performs one nonlinear relaxation step in the Chow-Patel-ILU using OpenMP (cf. Algorithm 2 in paper) ...
Definition: ilu_operations.hpp:285