2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
6
/// Rheolef is free software; you can redistribute it and/or modify
7
/// it under the terms of the GNU General Public License as published by
8
/// the Free Software Foundation; either version 2 of the License, or
9
/// (at your option) any later version.
11
/// Rheolef is distributed in the hope that it will be useful,
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
/// GNU General Public License for more details.
16
/// You should have received a copy of the GNU General Public License
17
/// along with Rheolef; if not, write to the Free Software
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/// =========================================================================
22
// This code presents various solvers
24
// also print matlab code for non-regression test purpose, i.e.
27
// makefish 4 | solve_iterative_tst | octave -q
28
// machine-precision independent computation:
29
// makefish 4 | solve_iterative_tst -ndigits 12 | octave -q
31
# include "rheolef/skit.h"
34
extern int solve_bicg (const csr<Float>&, const vec<Float>&);
35
extern int solve_bicgstab (const csr<Float>&, const vec<Float>&);
36
extern int solve_cg (const csr<Float>&, const vec<Float>&);
37
extern int solve_cgs (const csr<Float>&, const vec<Float>&);
38
extern int solve_cheby (const csr<Float>&, const vec<Float>&);
39
extern int solve_gmres (const csr<Float>&, const vec<Float>&);
40
extern int solve_ir (const csr<Float>&, const vec<Float>&);
41
extern int solve_qmr (const csr<Float>&, const vec<Float>&);
48
inline T my_round (const T& x) { return eps1*T(int(x/eps1+0.5)); }
50
template <class Iterator>
52
round_value (Iterator first, Iterator last)
54
while (first != last) {
55
*first = my_round(*first);
59
void check (const char* method, int max_iter, const csr<Float>& a,
60
const vec<Float>& x, const vec<Float>& b)
64
round_value(x1.begin(), x1.end());
65
cout << "x=" << x1 << ";" << endl;
67
cout << "x=" << x << ";" << endl;
69
cout << "error_" << method << "_" << max_iter;
71
cout << "=norm(a*x-b)\n\n";
73
cout << "=eps1*round(norm(a*x-b)/eps1)\n\n";
76
int main (int argc, char** argv)
79
int digits10 = numeric_limits<Float>::digits10;
80
// cout.setf(ios::scientific, !(ios::fixed | ios::floatfield) );
83
// non-regression mode:
84
// avoid machine-dependent output digits in non-regression mode
86
// avoid variation of output formats
87
// when double, doubledouble or bigfloat
88
numeric_flags<Float>::output_as_double(true);
91
// cout.setf(ios::scientific);
92
cout.setf(ios::fixed);
93
digits10 = atoi(argv[2]);
94
cout << "eps1=sqrt(10^(-" << digits10 << "));\n";
95
eps1=pow(Float(10), Float(-digits10/2));
98
cout << setprecision(digits10);
102
vec<Float> x(a.ncol());
106
cout << ml << "a=" << a << ";" << endl;
107
cout << "b=" << b << ";" << endl;
110
solve_bicgstab(a, b);