ViennaCL - The Vienna Computing Library  1.6.1
Free open-source GPU-accelerated linear algebra and solver library.
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 
217  if (rho_0 <= ScalarType(0)) // trivial right hand side?
218  break;
219 
220  residual /= rho_0;
221  rho = ScalarType(1);
222 
223  // check for convergence:
224  if (rho_0 / norm_rhs < tag.tolerance())
225  break;
226 
227  //
228  // minimize in Krylov basis:
229  //
230  vcl_size_t k = 0;
231  for (k = 0; k < static_cast<vcl_size_t>(tag.krylov_dim()); ++k)
232  {
233  if (k == 0)
234  {
235  // compute v0 = A*r and perform first reduction stage for ||v0||
236  viennacl::vector_range<viennacl::vector<ScalarType> > v0(device_krylov_basis, viennacl::range(0, rhs.size()));
237  viennacl::linalg::pipelined_gmres_prod(A, residual, v0, device_inner_prod_buffer);
238 
239  // Normalize v_1 and compute first reduction stage for <r, v_0> in device_r_dot_vk_buffer:
241  device_buffer_R, k*tag.krylov_dim() + k,
242  device_inner_prod_buffer, device_r_dot_vk_buffer,
243  buffer_size_per_vector, k*buffer_size_per_vector);
244  }
245  else
246  {
247  // compute v0 = A*r and perform first reduction stage for ||v0||
248  viennacl::vector_range<viennacl::vector<ScalarType> > vk (device_krylov_basis, viennacl::range( k *rhs.internal_size(), k *rhs.internal_size() + rhs.size()));
249  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()));
250  viennacl::linalg::pipelined_gmres_prod(A, vk_minus_1, vk, device_inner_prod_buffer);
251 
252  //
253  // Gram-Schmidt, stage 1: compute first reduction stage of <v_i, v_k>
254  //
255  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);
256 
257  //
258  // 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.
259  // Store <v_i, v_k> in R-matrix and compute first reduction stage for ||v_k||
260  //
261  viennacl::linalg::pipelined_gmres_gram_schmidt_stage2(device_krylov_basis, rhs.size(), rhs.internal_size(), k,
262  device_vi_in_vk_buffer,
263  device_buffer_R, tag.krylov_dim(),
264  device_inner_prod_buffer, buffer_size_per_vector);
265 
266  //
267  // Normalize v_k and compute first reduction stage for <r, v_k> in device_r_dot_vk_buffer:
268  //
270  device_buffer_R, k*tag.krylov_dim() + k,
271  device_inner_prod_buffer, device_r_dot_vk_buffer,
272  buffer_size_per_vector, k*buffer_size_per_vector);
273  }
274  }
275 
276  //
277  // Run reduction to obtain the values \xi_k = <r, v_k>.
278  // Note that unlike Algorithm 2.1 in Walker: "A Simpler GMRES", we do not update the residual
279  //
280  viennacl::fast_copy(device_r_dot_vk_buffer.begin(), device_r_dot_vk_buffer.end(), host_r_dot_vk_buffer.begin());
281  for (std::size_t i=0; i<k; ++i)
282  {
283  host_values_xi_k[i] = ScalarType(0);
284  for (std::size_t j=0; j<buffer_size_per_vector; ++j)
285  host_values_xi_k[i] += host_r_dot_vk_buffer[i*buffer_size_per_vector + j];
286  }
287 
288  //
289  // Bring values in R back to host:
290  //
291  viennacl::fast_copy(device_buffer_R.begin(), device_buffer_R.end(), host_buffer_R.begin());
292 
293  //
294  // Check for premature convergence: If the diagonal element drops too far below the first norm, we're done and restrict the Krylov size accordingly.
295  //
296  vcl_size_t full_krylov_dim = k; //needed for proper access to R
297  for (std::size_t i=0; i<k; ++i)
298  {
299  if (std::fabs(host_buffer_R[i + i*k]) < tag.tolerance() * host_buffer_R[0])
300  {
301  k = i;
302  break;
303  }
304  }
305 
306 
307  // Compute error estimator:
308  for (std::size_t i=0; i<k; ++i)
309  {
310  tag.iters( tag.iters() + 1 ); //increase iteration counter
311 
312  // check for accumulation of round-off errors for poorly conditioned systems
313  if (host_values_xi_k[i] >= rho || host_values_xi_k[i] <= -rho)
314  {
315  k = i;
316  break; // restrict Krylov space at this point. No gain from using additional basis vectors, since orthogonality is lost.
317  }
318 
319  // update error estimator
320  rho *= std::sin( std::acos(host_values_xi_k[i] / rho) );
321  }
322 
323  //
324  // Solve minimization problem:
325  //
326  host_values_eta_k_buffer = host_values_xi_k;
327 
328  for (int i2=static_cast<int>(k)-1; i2>-1; --i2)
329  {
330  vcl_size_t i = static_cast<vcl_size_t>(i2);
331  for (vcl_size_t j=static_cast<vcl_size_t>(i)+1; j<k; ++j)
332  host_values_eta_k_buffer[i] -= host_buffer_R[i + j*full_krylov_dim] * host_values_eta_k_buffer[j];
333 
334  host_values_eta_k_buffer[i] /= host_buffer_R[i + i*full_krylov_dim];
335  }
336 
337  //
338  // Update x += rho * z with z = \eta_0 * residual + sum_{i=0}^{k-1} \eta_{i+1} v_i
339  // 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"
340  //
341  for (vcl_size_t i=0; i<k; ++i)
342  host_update_coefficients[i] = rho_0 * host_values_eta_k_buffer[i];
343 
344  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
345 
347  device_krylov_basis, rhs.size(), rhs.internal_size(),
348  device_values_xi_k, k);
349 
350  tag.error( std::fabs(rho*rho_0 / norm_rhs) );
351  }
352 
353  return result;
354 }
355 
356 
357 
358 
369 template<typename MatrixT, typename VectorT, typename PreconditionerT>
370 VectorT solve(MatrixT const & matrix, VectorT const & rhs, gmres_tag const & tag, PreconditionerT const & precond)
371 {
372  typedef typename viennacl::result_of::value_type<VectorT>::type NumericType;
373  typedef typename viennacl::result_of::cpu_value_type<NumericType>::type CPU_NumericType;
374  unsigned int problem_size = static_cast<unsigned int>(viennacl::traits::size(rhs));
375  VectorT result = rhs;
376  viennacl::traits::clear(result);
377 
378  vcl_size_t krylov_dim = static_cast<vcl_size_t>(tag.krylov_dim());
379  if (problem_size < krylov_dim)
380  krylov_dim = problem_size; //A Krylov space larger than the matrix would lead to seg-faults (mathematically, error is certain to be zero already)
381 
382  VectorT res = rhs;
383  VectorT v_k_tilde = rhs;
384  VectorT v_k_tilde_temp = rhs;
385 
386  std::vector< std::vector<CPU_NumericType> > R(krylov_dim, std::vector<CPU_NumericType>(tag.krylov_dim()));
387  std::vector<CPU_NumericType> projection_rhs(krylov_dim);
388 
389  std::vector<VectorT> householder_reflectors(krylov_dim, rhs);
390  std::vector<CPU_NumericType> betas(krylov_dim);
391 
392  CPU_NumericType norm_rhs = viennacl::linalg::norm_2(rhs);
393 
394  if (norm_rhs <= 0) //solution is zero if RHS norm is zero
395  return result;
396 
397  tag.iters(0);
398 
399  for (unsigned int it = 0; it <= tag.max_restarts(); ++it)
400  {
401  //
402  // (Re-)Initialize residual: r = b - A*x (without temporary for the result of A*x)
403  //
404  res = rhs;
405  res -= viennacl::linalg::prod(matrix, result); //initial guess zero
406  precond.apply(res);
407 
408  CPU_NumericType rho_0 = viennacl::linalg::norm_2(res);
409 
410  //
411  // Check for premature convergence
412  //
413  if (rho_0 / norm_rhs < tag.tolerance() ) // norm_rhs is known to be nonzero here
414  {
415  tag.error(rho_0 / norm_rhs);
416  return result;
417  }
418 
419  //
420  // Normalize residual and set 'rho' to 1 as requested in 'A Simpler GMRES' by Walker and Zhou.
421  //
422  res /= rho_0;
423  CPU_NumericType rho = static_cast<CPU_NumericType>(1.0);
424 
425 
426  //
427  // Iterate up until maximal Krylove space dimension is reached:
428  //
429  vcl_size_t k = 0;
430  for (k = 0; k < krylov_dim; ++k)
431  {
432  tag.iters( tag.iters() + 1 ); //increase iteration counter
433 
434  // prepare storage:
436  viennacl::traits::clear(householder_reflectors[k]);
437 
438  //compute v_k = A * v_{k-1} via Householder matrices
439  if (k == 0)
440  {
441  v_k_tilde = viennacl::linalg::prod(matrix, res);
442  precond.apply(v_k_tilde);
443  }
444  else
445  {
446  viennacl::traits::clear(v_k_tilde);
447  v_k_tilde[k-1] = CPU_NumericType(1);
448 
449  //Householder rotations, part 1: Compute P_1 * P_2 * ... * P_{k-1} * e_{k-1}
450  for (int i = static_cast<int>(k)-1; i > -1; --i)
451  detail::gmres_householder_reflect(v_k_tilde, householder_reflectors[vcl_size_t(i)], betas[vcl_size_t(i)]);
452 
453  v_k_tilde_temp = viennacl::linalg::prod(matrix, v_k_tilde);
454  precond.apply(v_k_tilde_temp);
455  v_k_tilde = v_k_tilde_temp;
456 
457  //Householder rotations, part 2: Compute P_{k-1} * ... * P_{1} * v_k_tilde
458  for (vcl_size_t i = 0; i < k; ++i)
459  detail::gmres_householder_reflect(v_k_tilde, householder_reflectors[i], betas[i]);
460  }
461 
462  //
463  // Compute Householder reflection for v_k_tilde such that all entries below k-th entry are zero:
464  //
465  CPU_NumericType rho_k_k = 0;
466  detail::gmres_setup_householder_vector(v_k_tilde, householder_reflectors[k], betas[k], rho_k_k, k);
467 
468  //
469  // copy first k entries from v_k_tilde to R[k] in order to fill k-th column with result of
470  // 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);
471  //
472  detail::gmres_copy_helper(v_k_tilde, R[k], k);
473  R[k][k] = rho_k_k;
474 
475  //
476  // Update residual: r = P_k r
477  // Set zeta_k = r[k] including machine precision considerations: mathematically we have |r[k]| <= rho
478  // Set rho *= sin(acos(r[k] / rho))
479  //
480  detail::gmres_householder_reflect(res, householder_reflectors[k], betas[k]);
481 
482  if (res[k] > rho) //machine precision reached
483  res[k] = rho;
484  if (res[k] < -rho) //machine precision reached
485  res[k] = -rho;
486  projection_rhs[k] = res[k];
487 
488  rho *= std::sin( std::acos(projection_rhs[k] / rho) );
489 
490  if (std::fabs(rho * rho_0 / norm_rhs) < tag.tolerance()) // Residual is sufficiently reduced, stop here
491  {
492  tag.error( std::fabs(rho*rho_0 / norm_rhs) );
493  ++k;
494  break;
495  }
496  } // for k
497 
498  //
499  // Triangular solver stage:
500  //
501 
502  for (int i2=static_cast<int>(k)-1; i2>-1; --i2)
503  {
504  vcl_size_t i = static_cast<vcl_size_t>(i2);
505  for (vcl_size_t j=i+1; j<k; ++j)
506  projection_rhs[i] -= R[j][i] * projection_rhs[j]; //R is transposed
507 
508  projection_rhs[i] /= R[i][i];
509  }
510 
511  //
512  // Note: 'projection_rhs' now holds the solution (eta_1, ..., eta_k)
513  //
514 
515  res *= projection_rhs[0];
516 
517  if (k > 0)
518  {
519  for (unsigned int i = 0; i < k-1; ++i)
520  res[i] += projection_rhs[i+1];
521  }
522 
523  //
524  // Form z inplace in 'res' by applying P_1 * ... * P_{k}
525  //
526  for (int i=static_cast<int>(k)-1; i>=0; --i)
527  detail::gmres_householder_reflect(res, householder_reflectors[vcl_size_t(i)], betas[vcl_size_t(i)]);
528 
529  res *= rho_0;
530  result += res; // x += rho_0 * z in the paper
531 
532  //
533  // Check for convergence:
534  //
535  tag.error(std::fabs(rho*rho_0 / norm_rhs));
536  if ( tag.error() < tag.tolerance() )
537  return result;
538  }
539 
540  return result;
541 }
542 
545 template<typename MatrixT, typename VectorT>
546 VectorT solve(MatrixT const & A, VectorT const & rhs, gmres_tag const & tag)
547 {
548  return solve(A, rhs, tag, no_precond());
549 }
550 
551 
552 }
553 }
554 
555 #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.
base_type::difference_type difference_type
Definition: vector.hpp:943
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
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
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
Definition: blas3.hpp:36
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.
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)