ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmres.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_GMRES_HPP_
2 #define VIENNACL_GMRES_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2014, 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 <vector>
26 #include <cmath>
27 #include <limits>
28 #include "viennacl/forwards.h"
29 #include "viennacl/tools/tools.hpp"
31 #include "viennacl/linalg/prod.hpp"
34 #include "viennacl/traits/size.hpp"
37 
40 
41 
42 namespace viennacl
43 {
44 namespace linalg
45 {
46 
49 class gmres_tag //generalized minimum residual
50 {
51 public:
58  gmres_tag(double tol = 1e-10, unsigned int max_iterations = 300, unsigned int krylov_dim = 20)
59  : tol_(tol), iterations_(max_iterations), krylov_dim_(krylov_dim), iters_taken_(0) {}
60 
62  double tolerance() const { return tol_; }
64  unsigned int max_iterations() const { return iterations_; }
66  unsigned int krylov_dim() const { return krylov_dim_; }
68  unsigned int max_restarts() const
69  {
70  unsigned int ret = iterations_ / krylov_dim_;
71  if (ret > 0 && (ret * krylov_dim_ == iterations_) )
72  return ret - 1;
73  return ret;
74  }
75 
77  unsigned int iters() const { return iters_taken_; }
79  void iters(unsigned int i) const { iters_taken_ = i; }
80 
82  double error() const { return last_error_; }
84  void error(double e) const { last_error_ = e; }
85 
86 private:
87  double tol_;
88  unsigned int iterations_;
89  unsigned int krylov_dim_;
90 
91  //return values from solver
92  mutable unsigned int iters_taken_;
93  mutable double last_error_;
94 };
95 
96 namespace detail
97 {
98 
99  template<typename SrcVectorT, typename DestVectorT>
100  void gmres_copy_helper(SrcVectorT const & src, DestVectorT & dest, vcl_size_t len, vcl_size_t start = 0)
101  {
102  for (vcl_size_t i=0; i<len; ++i)
103  dest[start+i] = src[start+i];
104  }
105 
106  template<typename NumericT, typename DestVectorT>
107  void gmres_copy_helper(viennacl::vector<NumericT> const & src, DestVectorT & dest, vcl_size_t len, vcl_size_t start = 0)
108  {
109  typedef typename viennacl::vector<NumericT>::difference_type difference_type;
110  viennacl::copy( src.begin() + static_cast<difference_type>(start),
111  src.begin() + static_cast<difference_type>(start + len),
112  dest.begin() + static_cast<difference_type>(start));
113  }
114 
123  template<typename VectorT, typename NumericT>
124  void gmres_setup_householder_vector(VectorT const & input_vec, VectorT & hh_vec, NumericT & beta, NumericT & mu, vcl_size_t j)
125  {
126  NumericT input_j = input_vec(j);
127 
128  // copy entries from input vector to householder vector:
129  detail::gmres_copy_helper(input_vec, hh_vec, viennacl::traits::size(hh_vec) - (j+1), j+1);
130 
131  NumericT sigma = viennacl::linalg::norm_2(hh_vec);
132  sigma *= sigma;
133 
134  if (sigma <= 0)
135  {
136  beta = 0;
137  mu = input_j;
138  }
139  else
140  {
141  mu = std::sqrt(sigma + input_j*input_j);
142 
143  NumericT hh_vec_0 = (input_j <= 0) ? (input_j - mu) : (-sigma / (input_j + mu));
144 
145  beta = NumericT(2) * hh_vec_0 * hh_vec_0 / (sigma + hh_vec_0 * hh_vec_0);
146 
147  //divide hh_vec by its diagonal element hh_vec_0
148  hh_vec /= hh_vec_0;
149  hh_vec[j] = NumericT(1);
150  }
151  }
152 
153  // Apply (I - beta h h^T) to x (Householder reflection with Householder vector h)
154  template<typename VectorT, typename NumericT>
155  void gmres_householder_reflect(VectorT & x, VectorT const & h, NumericT beta)
156  {
157  NumericT hT_in_x = viennacl::linalg::inner_prod(h, x);
158  x -= (beta * hT_in_x) * h;
159  }
160 
161 }
162 
163 
173 template <typename MatrixType, typename ScalarType>
174 viennacl::vector<ScalarType> solve(MatrixType const & A,
175  viennacl::vector<ScalarType> const & rhs,
176  gmres_tag const & tag,
178 {
179  viennacl::vector<ScalarType> residual(rhs);
181 
182  viennacl::vector<ScalarType> device_krylov_basis(rhs.internal_size() * tag.krylov_dim(), viennacl::traits::context(rhs)); // not using viennacl::matrix here because of spurious padding in column number
184  std::vector<ScalarType> host_buffer_R(device_buffer_R.size());
185 
186  vcl_size_t buffer_size_per_vector = 128;
187  vcl_size_t num_buffer_chunks = 3;
188  viennacl::vector<ScalarType> device_inner_prod_buffer = viennacl::zero_vector<ScalarType>(num_buffer_chunks*buffer_size_per_vector, viennacl::traits::context(rhs)); // temporary buffer
189  viennacl::vector<ScalarType> device_r_dot_vk_buffer = viennacl::zero_vector<ScalarType>(buffer_size_per_vector * tag.krylov_dim(), viennacl::traits::context(rhs)); // holds result of first reduction stage for <r, v_k> on device
190  viennacl::vector<ScalarType> device_vi_in_vk_buffer = viennacl::zero_vector<ScalarType>(buffer_size_per_vector * tag.krylov_dim(), viennacl::traits::context(rhs)); // holds <v_i, v_k> for i=0..k-1 on device
191  viennacl::vector<ScalarType> device_values_xi_k = viennacl::zero_vector<ScalarType>(tag.krylov_dim(), viennacl::traits::context(rhs)); // holds values \xi_k = <r, v_k> on device
192  std::vector<ScalarType> host_r_dot_vk_buffer(device_r_dot_vk_buffer.size());
193  std::vector<ScalarType> host_values_xi_k(tag.krylov_dim());
194  std::vector<ScalarType> host_values_eta_k_buffer(tag.krylov_dim());
195  std::vector<ScalarType> host_update_coefficients(tag.krylov_dim());
196 
197  ScalarType norm_rhs = viennacl::linalg::norm_2(residual);
198  ScalarType rho_0 = norm_rhs;
199  ScalarType rho = ScalarType(1);
200 
201  tag.iters(0);
202 
203  for (unsigned int restart_count = 0; restart_count <= tag.max_restarts(); ++restart_count)
204  {
205  //
206  // prepare restart:
207  //
208  if (restart_count > 0)
209  {
210  // compute new residual without introducing a temporary for A*x:
211  residual = viennacl::linalg::prod(A, result);
212  residual = rhs - residual;
213 
214  rho_0 = viennacl::linalg::norm_2(residual);
215  }
216  residual /= rho_0;
217  rho = ScalarType(1);
218 
219  // check for convergence:
220  if (rho_0 / norm_rhs < tag.tolerance())
221  break;
222 
223  //
224  // minimize in Krylov basis:
225  //
226  vcl_size_t k = 0;
227  for (k = 0; k < static_cast<vcl_size_t>(tag.krylov_dim()); ++k)
228  {
229  tag.iters( tag.iters() + 1 ); //increase iteration counter
230 
231  if (k == 0)
232  {
233  // compute v0 = A*r and perform first reduction stage for ||v0||
234  viennacl::vector_range<viennacl::vector<ScalarType> > v0(device_krylov_basis, viennacl::range(0, rhs.size()));
235  viennacl::linalg::pipelined_gmres_prod(A, residual, v0, device_inner_prod_buffer);
236 
237  // Normalize v_1 and compute first reduction stage for <r, v_0> in device_r_dot_vk_buffer:
239  device_buffer_R, k*tag.krylov_dim() + k,
240  device_inner_prod_buffer, device_r_dot_vk_buffer,
241  buffer_size_per_vector, k*buffer_size_per_vector);
242  }
243  else
244  {
245  // compute v0 = A*r and perform first reduction stage for ||v0||
246  viennacl::vector_range<viennacl::vector<ScalarType> > vk (device_krylov_basis, viennacl::range( k *rhs.internal_size(), k *rhs.internal_size() + rhs.size()));
247  viennacl::vector_range<viennacl::vector<ScalarType> > vk_minus_1(device_krylov_basis, viennacl::range((k-1)*rhs.internal_size(), (k-1)*rhs.internal_size() + rhs.size()));
248  viennacl::linalg::pipelined_gmres_prod(A, vk_minus_1, vk, device_inner_prod_buffer);
249 
250  //
251  // Gram-Schmidt, stage 1: compute first reduction stage of <v_i, v_k>
252  //
253  viennacl::linalg::pipelined_gmres_gram_schmidt_stage1(device_krylov_basis, rhs.size(), rhs.internal_size(), k, device_vi_in_vk_buffer, buffer_size_per_vector);
254 
255  //
256  // Gram-Schmidt, stage 2: compute second reduction stage of <v_i, v_k> and use that to compute v_k -= sum_i <v_i, v_k> v_i.
257  // Store <v_i, v_k> in R-matrix and compute first reduction stage for ||v_k||
258  //
259  viennacl::linalg::pipelined_gmres_gram_schmidt_stage2(device_krylov_basis, rhs.size(), rhs.internal_size(), k,
260  device_vi_in_vk_buffer,
261  device_buffer_R, tag.krylov_dim(),
262  device_inner_prod_buffer, buffer_size_per_vector);
263 
264  //
265  // Normalize v_k and compute first reduction stage for <r, v_k> in device_r_dot_vk_buffer:
266  //
268  device_buffer_R, k*tag.krylov_dim() + k,
269  device_inner_prod_buffer, device_r_dot_vk_buffer,
270  buffer_size_per_vector, k*buffer_size_per_vector);
271  }
272  }
273 
274  //
275  // Run reduction to obtain the values \xi_k = <r, v_k>.
276  // Note that unlike Algorithm 2.1 in Walker: "A Simpler GMRES", we do not update the residual
277  //
278  viennacl::fast_copy(device_r_dot_vk_buffer.begin(), device_r_dot_vk_buffer.end(), host_r_dot_vk_buffer.begin());
279  for (std::size_t i=0; i<k; ++i)
280  {
281  host_values_xi_k[i] = ScalarType(0);
282  for (std::size_t j=0; j<buffer_size_per_vector; ++j)
283  host_values_xi_k[i] += host_r_dot_vk_buffer[i*buffer_size_per_vector + j];
284  }
285 
286  //
287  // Bring values in R back to host:
288  //
289  viennacl::fast_copy(device_buffer_R.begin(), device_buffer_R.end(), host_buffer_R.begin());
290 
291  //
292  // Check for premature convergence: If the diagonal element drops too far below the first norm, we're done and restrict the Krylov size accordingly.
293  //
294  vcl_size_t full_krylov_dim = k; //needed for proper access to R
295  for (std::size_t i=0; i<k; ++i)
296  {
297  if (std::fabs(host_buffer_R[i + i*k]) < tag.tolerance() * host_buffer_R[0])
298  {
299  k = i;
300  break;
301  }
302  }
303 
304 
305  // Compute error estimator:
306  for (std::size_t i=0; i<k; ++i)
307  rho *= std::sin( std::acos(host_values_xi_k[i] / rho) );
308 
309  //
310  // Solve minimization problem:
311  //
312  host_values_eta_k_buffer = host_values_xi_k;
313 
314  for (int i2=static_cast<int>(k)-1; i2>-1; --i2)
315  {
316  vcl_size_t i = static_cast<vcl_size_t>(i2);
317  for (vcl_size_t j=static_cast<vcl_size_t>(i)+1; j<k; ++j)
318  host_values_eta_k_buffer[i] -= host_buffer_R[i + j*full_krylov_dim] * host_values_eta_k_buffer[j];
319 
320  host_values_eta_k_buffer[i] /= host_buffer_R[i + i*full_krylov_dim];
321  }
322 
323  //
324  // Update x += rho * z with z = \eta_0 * residual + sum_{i=0}^{k-1} \eta_{i+1} v_i
325  // Note that we have not updated the residual yet, hence this slightly modified as compared to the form given in Algorithm 2.1 in Walker: "A Simpler GMRES"
326  //
327  for (vcl_size_t i=0; i<k; ++i)
328  host_update_coefficients[i] = rho_0 * host_values_eta_k_buffer[i];
329 
330  viennacl::fast_copy(host_update_coefficients.begin(), host_update_coefficients.end(), device_values_xi_k.begin()); //reuse device_values_xi_k_buffer here for simplicity
331 
333  device_krylov_basis, rhs.size(), rhs.internal_size(),
334  device_values_xi_k, k);
335 
336  tag.error( std::fabs(rho*rho_0 / norm_rhs) );
337  }
338 
339  return result;
340 }
341 
342 
343 
344 
355 template<typename MatrixT, typename VectorT, typename PreconditionerT>
356 VectorT solve(MatrixT const & matrix, VectorT const & rhs, gmres_tag const & tag, PreconditionerT const & precond)
357 {
358  typedef typename viennacl::result_of::value_type<VectorT>::type NumericType;
359  typedef typename viennacl::result_of::cpu_value_type<NumericType>::type CPU_NumericType;
360  unsigned int problem_size = static_cast<unsigned int>(viennacl::traits::size(rhs));
361  VectorT result = rhs;
362  viennacl::traits::clear(result);
363 
364  vcl_size_t krylov_dim = static_cast<vcl_size_t>(tag.krylov_dim());
365  if (problem_size < krylov_dim)
366  krylov_dim = problem_size; //A Krylov space larger than the matrix would lead to seg-faults (mathematically, error is certain to be zero already)
367 
368  VectorT res = rhs;
369  VectorT v_k_tilde = rhs;
370  VectorT v_k_tilde_temp = rhs;
371 
372  std::vector< std::vector<CPU_NumericType> > R(krylov_dim, std::vector<CPU_NumericType>(tag.krylov_dim()));
373  std::vector<CPU_NumericType> projection_rhs(krylov_dim);
374 
375  std::vector<VectorT> householder_reflectors(krylov_dim, rhs);
376  std::vector<CPU_NumericType> betas(krylov_dim);
377 
378  CPU_NumericType norm_rhs = viennacl::linalg::norm_2(rhs);
379 
380  if (norm_rhs <= 0) //solution is zero if RHS norm is zero
381  return result;
382 
383  tag.iters(0);
384 
385  for (unsigned int it = 0; it <= tag.max_restarts(); ++it)
386  {
387  //
388  // (Re-)Initialize residual: r = b - A*x (without temporary for the result of A*x)
389  //
390  res = rhs;
391  res -= viennacl::linalg::prod(matrix, result); //initial guess zero
392  precond.apply(res);
393 
394  CPU_NumericType rho_0 = viennacl::linalg::norm_2(res);
395 
396  //
397  // Check for premature convergence
398  //
399  if (rho_0 / norm_rhs < tag.tolerance() ) // norm_rhs is known to be nonzero here
400  {
401  tag.error(rho_0 / norm_rhs);
402  return result;
403  }
404 
405  //
406  // Normalize residual and set 'rho' to 1 as requested in 'A Simpler GMRES' by Walker and Zhou.
407  //
408  res /= rho_0;
409  CPU_NumericType rho = static_cast<CPU_NumericType>(1.0);
410 
411 
412  //
413  // Iterate up until maximal Krylove space dimension is reached:
414  //
415  vcl_size_t k = 0;
416  for (k = 0; k < krylov_dim; ++k)
417  {
418  tag.iters( tag.iters() + 1 ); //increase iteration counter
419 
420  // prepare storage:
422  viennacl::traits::clear(householder_reflectors[k]);
423 
424  //compute v_k = A * v_{k-1} via Householder matrices
425  if (k == 0)
426  {
427  v_k_tilde = viennacl::linalg::prod(matrix, res);
428  precond.apply(v_k_tilde);
429  }
430  else
431  {
432  viennacl::traits::clear(v_k_tilde);
433  v_k_tilde[k-1] = CPU_NumericType(1);
434 
435  //Householder rotations, part 1: Compute P_1 * P_2 * ... * P_{k-1} * e_{k-1}
436  for (int i = static_cast<int>(k)-1; i > -1; --i)
437  detail::gmres_householder_reflect(v_k_tilde, householder_reflectors[vcl_size_t(i)], betas[vcl_size_t(i)]);
438 
439  v_k_tilde_temp = viennacl::linalg::prod(matrix, v_k_tilde);
440  precond.apply(v_k_tilde_temp);
441  v_k_tilde = v_k_tilde_temp;
442 
443  //Householder rotations, part 2: Compute P_{k-1} * ... * P_{1} * v_k_tilde
444  for (vcl_size_t i = 0; i < k; ++i)
445  detail::gmres_householder_reflect(v_k_tilde, householder_reflectors[i], betas[i]);
446  }
447 
448  //
449  // Compute Householder reflection for v_k_tilde such that all entries below k-th entry are zero:
450  //
451  CPU_NumericType rho_k_k = 0;
452  detail::gmres_setup_householder_vector(v_k_tilde, householder_reflectors[k], betas[k], rho_k_k, k);
453 
454  //
455  // copy first k entries from v_k_tilde to R[k] in order to fill k-th column with result of
456  // P_k * v_k_tilde = (v[0], ... , v[k-1], norm(v), 0, 0, ...) =: (rho_{1,k}, rho_{2,k}, ..., rho_{k,k}, 0, ..., 0);
457  //
458  detail::gmres_copy_helper(v_k_tilde, R[k], k);
459  R[k][k] = rho_k_k;
460 
461  //
462  // Update residual: r = P_k r
463  // Set zeta_k = r[k] including machine precision considerations: mathematically we have |r[k]| <= rho
464  // Set rho *= sin(acos(r[k] / rho))
465  //
466  detail::gmres_householder_reflect(res, householder_reflectors[k], betas[k]);
467 
468  if (res[k] > rho) //machine precision reached
469  res[k] = rho;
470  if (res[k] < -rho) //machine precision reached
471  res[k] = -rho;
472  projection_rhs[k] = res[k];
473 
474  rho *= std::sin( std::acos(projection_rhs[k] / rho) );
475 
476  if (std::fabs(rho * rho_0 / norm_rhs) < tag.tolerance()) // Residual is sufficiently reduced, stop here
477  {
478  tag.error( std::fabs(rho*rho_0 / norm_rhs) );
479  ++k;
480  break;
481  }
482  } // for k
483 
484  //
485  // Triangular solver stage:
486  //
487 
488  for (int i2=static_cast<int>(k)-1; i2>-1; --i2)
489  {
490  vcl_size_t i = static_cast<vcl_size_t>(i2);
491  for (vcl_size_t j=i+1; j<k; ++j)
492  projection_rhs[i] -= R[j][i] * projection_rhs[j]; //R is transposed
493 
494  projection_rhs[i] /= R[i][i];
495  }
496 
497  //
498  // Note: 'projection_rhs' now holds the solution (eta_1, ..., eta_k)
499  //
500 
501  res *= projection_rhs[0];
502 
503  if (k > 0)
504  {
505  for (unsigned int i = 0; i < k-1; ++i)
506  res[i] += projection_rhs[i+1];
507  }
508 
509  //
510  // Form z inplace in 'res' by applying P_1 * ... * P_{k}
511  //
512  for (int i=static_cast<int>(k)-1; i>=0; --i)
513  detail::gmres_householder_reflect(res, householder_reflectors[vcl_size_t(i)], betas[vcl_size_t(i)]);
514 
515  res *= rho_0;
516  result += res; // x += rho_0 * z in the paper
517 
518  //
519  // Check for convergence:
520  //
521  tag.error(std::fabs(rho*rho_0 / norm_rhs));
522  if ( tag.error() < tag.tolerance() )
523  return result;
524  }
525 
526  return result;
527 }
528 
531 template<typename MatrixT, typename VectorT>
532 VectorT solve(MatrixT const & A, VectorT const & rhs, gmres_tag const & tag)
533 {
534  return solve(A, rhs, tag, no_precond());
535 }
536 
537 
538 }
539 }
540 
541 #endif
unsigned int max_restarts() const
Returns the maximum number of GMRES restarts.
Definition: gmres.hpp:68
T norm_2(std::vector< T, A > const &v1)
Definition: norm_2.hpp:86
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
unsigned int max_iterations() const
Returns the maximum number of iterations.
Definition: gmres.hpp:64
Generic size and resize functionality for different vector and matrix types.
unsigned int iters() const
Return the number of solver iterations:
Definition: gmres.hpp:77
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Various little tools used here and there in ViennaCL.
void pipelined_gmres_gram_schmidt_stage1(vector_base< T > const &device_krylov_basis, vcl_size_t v_k_size, vcl_size_t v_k_internal_size, vcl_size_t k, vector_base< T > &vi_in_vk_buffer, vcl_size_t buffer_chunk_size)
Computes the first reduction stage for multiple inner products , i=0..k-1.
void pipelined_gmres_update_result(vector_base< T > &result, vector_base< T > const &residual, vector_base< T > const &krylov_basis, vcl_size_t v_k_size, vcl_size_t v_k_internal_size, vector_base< T > const &coefficients, vcl_size_t k)
Computes x += eta_0 r + sum_{i=1}^{k-1} eta_i v_{i-1}.
void pipelined_gmres_gram_schmidt_stage2(vector_base< T > &device_krylov_basis, vcl_size_t v_k_size, vcl_size_t v_k_internal_size, vcl_size_t k, vector_base< T > const &vi_in_vk_buffer, vector_base< T > &R_buffer, vcl_size_t krylov_dim, vector_base< T > &inner_prod_buffer, vcl_size_t buffer_chunk_size)
Computes the second reduction stage for multiple inner products , i=0..k-1, then updates v_k -= v_i and computes the first reduction stage for ||v_k||.
void iters(unsigned int i) const
Set the number of solver iterations (should only be modified by the solver)
Definition: gmres.hpp:79
void clear(VectorType &vec)
Generic routine for setting all entries of a vector to zero. This is the version for non-ViennaCL obj...
Definition: clear.hpp:57
This file provides the forward declarations for the main types used within ViennaCL.
A dense matrix class.
Definition: forwards.h:374
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
Definition: inner_prod.hpp:89
void error(double e) const
Sets the estimated relative error at the end of the solver run.
Definition: gmres.hpp:84
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
A tag for the solver GMRES. Used for supplying solver parameters and for dispatching the solve() func...
Definition: gmres.hpp:49
gmres_tag(double tol=1e-10, unsigned int max_iterations=300, unsigned int krylov_dim=20)
The constructor.
Definition: gmres.hpp:58
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:91
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
Class for representing non-strided subvectors of a bigger vector x.
Definition: forwards.h:433
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
Definition: vector.hpp:827
A tag class representing the use of no preconditioner.
Definition: forwards.h:833
void pipelined_gmres_prod(MatrixType const &A, vector_base< T > const &p, vector_base< T > &Ap, vector_base< T > &inner_prod_buffer)
Performs a joint vector update operation needed for an efficient pipelined GMRES algorithm.
base_type::difference_type difference_type
Definition: vector.hpp:943
vcl_size_t size() const
Definition: vector_def.hpp:47
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
Extracts the underlying context from objects.
void pipelined_gmres_normalize_vk(vector_base< T > &v_k, vector_base< T > const &residual, vector_base< T > &R_buffer, vcl_size_t offset_in_R, vector_base< T > const &inner_prod_buffer, vector_base< T > &r_dot_vk_buffer, vcl_size_t buffer_chunk_size, vcl_size_t buffer_chunk_offset)
Performs a vector normalization needed for an efficient pipelined GMRES algorithm.
void gmres_setup_householder_vector(VectorT const &input_vec, VectorT &hh_vec, NumericT &beta, NumericT &mu, vcl_size_t j)
Computes the householder vector 'hh_vec' which rotates 'input_vec' such that all entries below the j-...
Definition: gmres.hpp:124
void gmres_copy_helper(SrcVectorT const &src, DestVectorT &dest, vcl_size_t len, vcl_size_t start=0)
Definition: gmres.hpp:100
std::size_t vcl_size_t
Definition: forwards.h:74
Generic clear functionality for different vector and matrix types.
double tolerance() const
Returns the relative tolerance.
Definition: gmres.hpp:62
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:238
Proxy classes for vectors.
Implementations of specialized routines for the iterative solvers.
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:423
float ScalarType
Definition: fft_1d.cpp:42
double error() const
Returns the estimated relative error at the end of the solver run.
Definition: gmres.hpp:82
size_type internal_size() const
Returns the internal length of the vector, which is given by size() plus the extra memory due to padd...
Definition: vector_def.hpp:120
A collection of compile time type deductions.
unsigned int krylov_dim() const
Returns the maximum dimension of the Krylov space before restart.
Definition: gmres.hpp:66
void gmres_householder_reflect(VectorT &x, VectorT const &h, NumericT beta)
Definition: gmres.hpp:155
viennacl::vector< NumericT > solve(MatrixT const &A, viennacl::vector_base< NumericT > const &rhs, bicgstab_tag const &tag, viennacl::linalg::no_precond)
Implementation of a pipelined stabilized Bi-conjugate gradient solver.
Definition: bicgstab.hpp:88
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)