70 #ifndef GMM_KRYLOV_GMRES_H
71 #define GMM_KRYLOV_GMRES_H
87 template <
typename Mat,
typename Vec,
typename VecB,
typename Precond,
89 void gmres(
const Mat &A, Vec &x,
const VecB &b,
const Precond &M,
90 int restart,
iteration &outer, Basis& KS) {
92 typedef typename linalg_traits<Vec>::value_type T;
93 typedef typename number_traits<T>::magnitude_type R;
95 std::vector<T> w(vect_size(x)), r(vect_size(x)), u(vect_size(x));
96 std::vector<T> c_rot(restart+1), s_rot(restart+1), s(restart+1);
97 gmm::dense_matrix<T> H(restart+1, restart);
99 double t_ref, t_prec = MPI_Wtime(), t_tot = 0;
100 static double tmult_tot = 0.0;
102 cout <<
"GMRES " << endl;
106 if (outer.get_rhsnorm() == 0.0) {
clear(x);
return; }
108 mult(A, scaled(x, T(-1)), b, w);
114 inner.reduce_noisy();
115 inner.set_maxiter(restart);
116 inner.set_name(
"GMRes inner");
118 while (! outer.finished(beta)) {
120 gmm::copy(gmm::scaled(r, R(1)/beta), KS[0]);
124 size_type i = 0; inner.init();
129 orthogonalize(KS, mat_col(H, i), i);
132 gmm::scale(KS[i+1], T(1) / a);
133 for (size_type k = 0; k < i; ++k)
134 Apply_Givens_rotation_left(H(k,i), H(k+1,i), c_rot[k], s_rot[k]);
136 Givens_rotation(H(i,i), H(i+1,i), c_rot[i], s_rot[i]);
137 Apply_Givens_rotation_left(H(i,i), H(i+1,i), c_rot[i], s_rot[i]);
138 Apply_Givens_rotation_left(s[i], s[i+1], c_rot[i], s_rot[i]);
140 ++inner, ++outer, ++i;
141 }
while (! inner.finished(gmm::abs(s[i])));
143 upper_tri_solve(H, s, i,
false);
144 combine(KS, s, x, i);
145 mult(A, gmm::scaled(x, T(-1)), b, w);
148 if (
int(inner.get_iteration()) < restart -1 || beta_old <= beta)
149 ++blocked;
else blocked = 0;
151 if (outer.get_noisy()) cout <<
"Gmres is blocked, exiting\n";
155 t_tot = MPI_Wtime() - t_ref;
156 cout <<
"temps GMRES : " << t_tot << endl;
162 template <
typename Mat,
typename Vec,
typename VecB,
typename Precond >
163 void gmres(
const Mat &A, Vec &x,
const VecB &b,
164 const Precond &M,
int restart, iteration& outer) {
165 typedef typename linalg_traits<Vec>::value_type T;
166 modified_gram_schmidt<T> orth(restart, vect_size(x));
167 gmres(A, x, b, M, restart, outer, orth);
The Iteration object calculates whether the solution has reached the desired accuracy,...
void copy(const L1 &l1, L2 &l2)
*/
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
Include the base gmm files.
Modified Gram-Schmidt orthogonalization.
void gmres(const Mat &A, Vec &x, const VecB &b, const Precond &M, int restart, iteration &outer, Basis &KS)
Generalized Minimum Residual.