1 #ifndef VIENNACL_LINALG_MIXED_PRECISION_CG_HPP_
2 #define VIENNACL_LINALG_MIXED_PRECISION_CG_HPP_
66 unsigned int iters()
const {
return iters_taken_; }
67 void iters(
unsigned int i)
const { iters_taken_ = i; }
70 double error()
const {
return last_error_; }
72 void error(
double e)
const { last_error_ = e; }
77 unsigned int iterations_;
81 mutable unsigned int iters_taken_;
82 mutable double last_error_;
95 template<
typename MatrixType,
typename VectorType>
103 VectorType result(rhs);
106 VectorType residual = rhs;
109 CPU_ScalarType new_ip_rr = 0;
110 CPU_ScalarType norm_rhs_squared = ip_rr;
112 if (norm_rhs_squared <= 0)
119 float inner_ip_rr =
static_cast<float>(ip_rr);
120 float new_inner_ip_rr = 0;
121 float initial_inner_rhs_norm_squared =
static_cast<float>(ip_rr);
126 p_low_precision = rhs;
127 residual_low_precision = p_low_precision;
136 matrix_elements_low_precision = matrix_elements_high_precision;
137 matrix_low_precision.generate_row_block_information();
147 result_low_precision += alpha * p_low_precision;
148 residual_low_precision -= alpha * tmp_low_precision;
152 beta = new_inner_ip_rr / inner_ip_rr;
153 inner_ip_rr = new_inner_ip_rr;
155 p_low_precision = residual_low_precision + beta * p_low_precision;
163 residual = result_low_precision;
168 residual = rhs - residual;
174 p_low_precision = residual;
176 result_low_precision.
clear();
177 residual_low_precision = p_low_precision;
178 initial_inner_rhs_norm_squared =
static_cast<float>(new_ip_rr);
179 inner_ip_rr =
static_cast<float>(new_ip_rr);
184 tag.
error(std::sqrt(new_ip_rr / norm_rhs_squared));
189 template<
typename MatrixType,
typename VectorType>
192 return solve(matrix, rhs, tag);
Generic size and resize functionality for different vector and matrix types.
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
float inner_tolerance() const
Returns the relative tolerance.
void clear(VectorType &vec)
Generic routine for setting all entries of a vector to zero. This is the version for non-ViennaCL obj...
This file provides the forward declarations for the main types used within ViennaCL.
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)
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
A tag class representing the use of no preconditioner.
Implementations of incomplete factorization preconditioners. Convenience header file.
unsigned int max_iterations() const
Returns the maximum number of iterations.
double tolerance() const
Returns the relative tolerance.
Common base class for dense vectors, vector ranges, and vector slices.
Generic clear functionality for different vector and matrix types.
mixed_precision_cg_tag(double tol=1e-8, unsigned int max_iterations=300, float inner_tol=1e-2f)
The constructor.
double error() const
Returns the estimated relative error at the end of the solver run.
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Proxy classes for vectors.
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...
void clear()
Resets all entries to zero. Does not change the size of the vector.
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
void iters(unsigned int i) const
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
A tag for the conjugate gradient Used for supplying solver parameters and for dispatching the solve()...
void error(double e) const
Sets the estimated relative error at the end of the solver run.
A collection of compile time type deductions.
unsigned int iters() const
Return the number of solver iterations:
Main interface routines for memory management.