ViennaCL - The Vienna Computing Library: viennacl/linalg/detail/ilu/chow_patel_ilu.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
chow_patel_ilu.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_DETAIL_CHOW_PATEL_ILU_HPP_
2 #define VIENNACL_LINALG_DETAIL_CHOW_PATEL_ILU_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
27 #include <vector>
28 #include <cmath>
29 #include <iostream>
30 #include "viennacl/forwards.h"
31 #include "viennacl/tools/tools.hpp"
32 #include "viennacl/linalg/detail/ilu/common.hpp"
33 #include "viennacl/linalg/ilu_operations.hpp"
34 #include "viennacl/linalg/prod.hpp"
35 #include "viennacl/backend/memory.hpp"
36
37 namespace viennacl
38 {
39 namespace linalg
40 {
41
44 class chow_patel_tag
45 {
46 public:
52 chow_patel_tag(vcl_size_t num_sweeps = 3, vcl_size_t num_jacobi_iters = 2) : sweeps_(num_sweeps), jacobi_iters_(num_jacobi_iters) {}
53
55 vcl_size_t sweeps() const { return sweeps_; }
57 void sweeps(vcl_size_t num) { sweeps_ = num; }
58
60 vcl_size_t jacobi_iters() const { return jacobi_iters_; }
62 void jacobi_iters(vcl_size_t num) { jacobi_iters_ = num; }
63
64 private:
65 vcl_size_t sweeps_;
66 vcl_size_t jacobi_iters_;
67 };
68
69 namespace detail
70 {
76 template<typename NumericT>
77 void precondition(viennacl::compressed_matrix<NumericT> const & A,
78 viennacl::compressed_matrix<NumericT> & L,
79 viennacl::vector<NumericT> & diag_L,
80 viennacl::compressed_matrix<NumericT> & L_trans,
81 chow_patel_tag const & tag)
82 {
83 // make sure L and U have correct dimensions:
84 L.resize(A.size1(), A.size2(), false);
85
86 // initialize L and U from values in A:
87 viennacl::linalg::extract_L(A, L);
88
89 // diagonally scale values from A in L:
90 viennacl::linalg::icc_scale(A, L);
91
92 viennacl::vector<NumericT> aij_L(L.nnz(), viennacl::traits::context(A));
93 viennacl::backend::memory_copy(L.handle(), aij_L.handle(), 0, 0, sizeof(NumericT) * L.nnz());
94
95 // run sweeps:
96 for (vcl_size_t i=0; i<tag.sweeps(); ++i)
97 viennacl::linalg::icc_chow_patel_sweep(L, aij_L);
98
99 // transpose L to obtain L_trans:
100 viennacl::linalg::ilu_transpose(L, L_trans);
101
102 // form (I - D_L^{-1}L) and (I - D_U^{-1} U), with U := L_trans
103 viennacl::linalg::ilu_form_neumann_matrix(L, diag_L);
104 viennacl::linalg::ilu_form_neumann_matrix(L_trans, diag_L);
105 }
106
107
109 template<typename NumericT>
110 void precondition(viennacl::compressed_matrix<NumericT> const & A,
111 viennacl::compressed_matrix<NumericT> & L,
112 viennacl::vector<NumericT> & diag_L,
113 viennacl::compressed_matrix<NumericT> & U,
114 viennacl::vector<NumericT> & diag_U,
115 chow_patel_tag const & tag)
116 {
117 // make sure L and U have correct dimensions:
118 L.resize(A.size1(), A.size2(), false);
119 U.resize(A.size1(), A.size2(), false);
120
121 // initialize L and U from values in A:
122 viennacl::linalg::extract_LU(A, L, U);
123
124 // diagonally scale values from A in L and U:
125 viennacl::linalg::ilu_scale(A, L, U);
126
127 // transpose storage layout of U from CSR to CSC via transposition
128 viennacl::compressed_matrix<NumericT> U_trans;
129 viennacl::linalg::ilu_transpose(U, U_trans);
130
131 // keep entries of a_ij for the sweeps
132 viennacl::vector<NumericT> aij_L (L.nnz(), viennacl::traits::context(A));
133 viennacl::vector<NumericT> aij_U_trans(U_trans.nnz(), viennacl::traits::context(A));
134
135 viennacl::backend::memory_copy( L.handle(), aij_L.handle(), 0, 0, sizeof(NumericT) * L.nnz());
136 viennacl::backend::memory_copy(U_trans.handle(), aij_U_trans.handle(), 0, 0, sizeof(NumericT) * U_trans.nnz());
137
138 // run sweeps:
139 for (vcl_size_t i=0; i<tag.sweeps(); ++i)
140 viennacl::linalg::ilu_chow_patel_sweep(L, aij_L, U_trans, aij_U_trans);
141
142 // transpose U_trans back:
143 viennacl::linalg::ilu_transpose(U_trans, U);
144
145 // form (I - D_L^{-1}L) and (I - D_U^{-1} U)
146 viennacl::linalg::ilu_form_neumann_matrix(L, diag_L);
147 viennacl::linalg::ilu_form_neumann_matrix(U, diag_U);
148 }
149
150 }
151
152
153
154
157 template<typename MatrixT>
158 class chow_patel_icc_precond
159 {
160 // only works with compressed_matrix!
161 typedef typename MatrixT::CHOW_PATEL_ICC_ONLY_WORKS_WITH_COMPRESSED_MATRIX error_type;
162 };
163
164
169 template<typename NumericT, unsigned int AlignmentV>
170 class chow_patel_icc_precond< viennacl::compressed_matrix<NumericT, AlignmentV> >
171 {
172
173 public:
174 chow_patel_icc_precond(viennacl::compressed_matrix<NumericT, AlignmentV> const & A, chow_patel_tag const & tag)
175 : tag_(tag),
176 L_(0, 0, 0, viennacl::traits::context(A)),
177 diag_L_(A.size1(), viennacl::traits::context(A)),
178 L_trans_(0, 0, 0, viennacl::traits::context(A)),
179 x_k_(A.size1(), viennacl::traits::context(A)),
180 b_(A.size1(), viennacl::traits::context(A))
181 {
182 viennacl::linalg::detail::precondition(A, L_, diag_L_, L_trans_, tag_);
183 }
184
189 template<typename VectorT>
190 void apply(VectorT & vec) const
191 {
192 //
193 // y = L^{-1} b through Jacobi iteration y_{k+1} = (I - D^{-1}L)y_k + D^{-1}x
194 //
195 b_ = viennacl::linalg::element_div(vec, diag_L_);
196 x_k_ = b_;
197 for (unsigned int i=0; i<tag_.jacobi_iters(); ++i)
198 {
199 vec = viennacl::linalg::prod(L_, x_k_);
200 x_k_ = vec + b_;
201 }
202
203 //
204 // x = U^{-1} y through Jacobi iteration x_{k+1} = (I - D^{-1}L^T)x_k + D^{-1}b
205 //
206 b_ = viennacl::linalg::element_div(x_k_, diag_L_);
207 x_k_ = b_; // x_1 if x_0 \equiv 0
208 for (unsigned int i=0; i<tag_.jacobi_iters(); ++i)
209 {
210 vec = viennacl::linalg::prod(L_trans_, x_k_);
211 x_k_ = vec + b_;
212 }
213
214 // return result:
215 vec = x_k_;
216 }
217
218 private:
219 chow_patel_tag tag_;
220 viennacl::compressed_matrix<NumericT> L_;
221 viennacl::vector<NumericT> diag_L_;
222 viennacl::compressed_matrix<NumericT> L_trans_;
223
224 mutable viennacl::vector<NumericT> x_k_;
225 mutable viennacl::vector<NumericT> b_;
226 };
227
228
229
230
231
232
235 template<typename MatrixT>
236 class chow_patel_ilu_precond
237 {
238 // only works with compressed_matrix!
239 typedef typename MatrixT::CHOW_PATEL_ILU_ONLY_WORKS_WITH_COMPRESSED_MATRIX error_type;
240 };
241
242
247 template<typename NumericT, unsigned int AlignmentV>
248 class chow_patel_ilu_precond< viennacl::compressed_matrix<NumericT, AlignmentV> >
249 {
250
251 public:
252 chow_patel_ilu_precond(viennacl::compressed_matrix<NumericT, AlignmentV> const & A, chow_patel_tag const & tag)
253 : tag_(tag),
254 L_(0, 0, 0, viennacl::traits::context(A)),
255 diag_L_(A.size1(), viennacl::traits::context(A)),
256 U_(0, 0, 0, viennacl::traits::context(A)),
257 diag_U_(A.size1(), viennacl::traits::context(A)),
258 x_k_(A.size1(), viennacl::traits::context(A)),
259 b_(A.size1(), viennacl::traits::context(A))
260 {
261 viennacl::linalg::detail::precondition(A, L_, diag_L_, U_, diag_U_, tag_);
262 }
263
268 template<typename VectorT>
269 void apply(VectorT & vec) const
270 {
271 //
272 // y = L^{-1} b through Jacobi iteration y_{k+1} = (I - D^{-1}L)y_k + D^{-1}x
273 //
274 b_ = viennacl::linalg::element_div(vec, diag_L_);
275 x_k_ = b_;
276 for (unsigned int i=0; i<tag_.jacobi_iters(); ++i)
277 {
278 vec = viennacl::linalg::prod(L_, x_k_);
279 x_k_ = vec + b_;
280 }
281
282 //
283 // x = U^{-1} y through Jacobi iteration x_{k+1} = (I - D^{-1}U)x_k + D^{-1}b
284 //
285 b_ = viennacl::linalg::element_div(x_k_, diag_U_);
286 x_k_ = b_; // x_1 if x_0 \equiv 0
287 for (unsigned int i=0; i<tag_.jacobi_iters(); ++i)
288 {
289 vec = viennacl::linalg::prod(U_, x_k_);
290 x_k_ = vec + b_;
291 }
292
293 // return result:
294 vec = x_k_;
295 }
296
297 private:
298 chow_patel_tag tag_;
299 viennacl::compressed_matrix<NumericT> L_;
300 viennacl::vector<NumericT> diag_L_;
301 viennacl::compressed_matrix<NumericT> U_;
302 viennacl::vector<NumericT> diag_U_;
303
304 mutable viennacl::vector<NumericT> x_k_;
305 mutable viennacl::vector<NumericT> b_;
306 };
307
308
309 } // namespace linalg
310 } // namespace viennacl
311
312
313 #endif
314
315
316
viennacl::compressed_matrix::size2
const vcl_size_t & size2() const
Returns the number of columns.
Definition: compressed_matrix.hpp:929
viennacl::linalg::chow_patel_icc_precond< viennacl::compressed_matrix< NumericT, AlignmentV > >::apply
void apply(VectorT &vec) const
Preconditioner application: LL^Tx = b, computed via Ly = b, L^Tx = y using Jacobi iterations...
Definition: chow_patel_ilu.hpp:190
viennacl::linalg::element_div
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_div > > element_div(vector_base< T > const &v1, vector_base< T > const &v2)
viennacl::linalg::chow_patel_tag
A tag for incomplete LU and incomplete Cholesky factorization with static pattern (Parallel-ILU0...
Definition: chow_patel_ilu.hpp:44
viennacl::linalg::chow_patel_tag::jacobi_iters
void jacobi_iters(vcl_size_t num)
Sets the number of Jacobi iterations for each triangular 'solve' when applying the preconditioner to ...
Definition: chow_patel_ilu.hpp:62
viennacl::compressed_matrix::size1
const vcl_size_t & size1() const
Returns the number of rows.
Definition: compressed_matrix.hpp:927
prod.hpp
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::traits::size1
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:163
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::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
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::linalg::chow_patel_icc_precond
Parallel Chow-Patel ILU preconditioner class, can be supplied to solve()-routines.
Definition: chow_patel_ilu.hpp:158
viennacl::linalg::chow_patel_tag::sweeps
void sweeps(vcl_size_t num)
Sets the number of sweeps (i.e. number of nonlinear iterations) in the solver setup stage...
Definition: chow_patel_ilu.hpp:57
viennacl::compressed_matrix::handle
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_matrix.hpp:942
viennacl::compressed_matrix::nnz
const vcl_size_t & nnz() const
Returns the number of nonzero entries.
Definition: compressed_matrix.hpp:931
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
ilu_operations.hpp
Implementations of specialized routines for the Chow-Patel parallel ILU preconditioner.
viennacl::linalg::chow_patel_tag::sweeps
vcl_size_t sweeps() const
Returns the number of sweeps (i.e. number of nonlinear iterations) in the solver setup stage...
Definition: chow_patel_ilu.hpp:55
viennacl::linalg::prod
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
viennacl::linalg::chow_patel_tag::chow_patel_tag
chow_patel_tag(vcl_size_t num_sweeps=3, vcl_size_t num_jacobi_iters=2)
Constructor allowing to set the number of sweeps and Jacobi iterations.
Definition: chow_patel_ilu.hpp:52
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::chow_patel_icc_precond< viennacl::compressed_matrix< NumericT, AlignmentV > >::chow_patel_icc_precond
chow_patel_icc_precond(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, chow_patel_tag const &tag)
Definition: chow_patel_ilu.hpp:174
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::vector< NumericT >
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::backend::memory_copy
void memory_copy(mem_handle const &src_buffer, mem_handle &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
Definition: memory.hpp:140
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::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::compressed_matrix< NumericT >
common.hpp
Common routines used within ILU-type preconditioners.
viennacl::linalg::detail::precondition
void precondition(viennacl::compressed_matrix< NumericT > const &A, viennacl::compressed_matrix< NumericT > &L, viennacl::vector< NumericT > &diag_L, viennacl::compressed_matrix< NumericT > &L_trans, chow_patel_tag const &tag)
Implementation of the parallel ICC0 factorization, Algorithm 3 in Chow-Patel paper.
Definition: chow_patel_ilu.hpp:77
viennacl::compressed_matrix::resize
void resize(vcl_size_t new_size1, vcl_size_t new_size2, bool preserve=true)
Resize the matrix.
Definition: compressed_matrix.hpp:829
viennacl::linalg::chow_patel_ilu_precond
Parallel Chow-Patel ILU preconditioner class, can be supplied to solve()-routines.
Definition: chow_patel_ilu.hpp:236
memory.hpp
Main interface routines for memory management.
viennacl::linalg::chow_patel_ilu_precond< viennacl::compressed_matrix< NumericT, AlignmentV > >::apply
void apply(VectorT &vec) const
Preconditioner application: LUx = b, computed via Ly = b, Ux = y using Jacobi iterations.
Definition: chow_patel_ilu.hpp:269
viennacl::linalg::chow_patel_tag::jacobi_iters
vcl_size_t jacobi_iters() const
Returns the number of Jacobi iterations (i.e. applications of x_{k+1} = (I - D^{-1}R)x_k + D^{-1} b) ...
Definition: chow_patel_ilu.hpp:60
viennacl::linalg::chow_patel_ilu_precond< viennacl::compressed_matrix< NumericT, AlignmentV > >::chow_patel_ilu_precond
chow_patel_ilu_precond(viennacl::compressed_matrix< NumericT, AlignmentV > const &A, chow_patel_tag const &tag)
Definition: chow_patel_ilu.hpp:252