23#include "arccore/alina/AMG.h"
24#include "arccore/alina/PreconditionedSolver.h"
25#include "arccore/alina/BuiltinBackend.h"
26#include "arccore/alina/Adapters.h"
27#include "arccore/alina/Coarsening.h"
28#include "arccore/alina/Relaxation.h"
29#include "arccore/alina/ConjugateGradientSolver.h"
30#include "arccore/alina/Profiler.h"
32#include "SampleProblemCommon.h"
35using namespace Arcane::Alina;
40 typedef double val_type;
41 typedef ptrdiff_t col_type;
48 , h2i((n - 1) * (n - 1))
51 size_t rows()
const {
return n * n; }
52 size_t nonzeros()
const {
return 5 * rows(); }
54 void operator()(
size_t row,
55 std::vector<col_type>& col,
56 std::vector<val_type>& val)
const
62 col.push_back(row - n);
67 col.push_back(row - 1);
72 val.push_back(4 * h2i);
75 col.push_back(row + 1);
80 col.push_back(row + n);
89double norm(
const Vec& v)
91 return sqrt(Arcane::Alina::backend::inner_product(v, v));
95int main(
int argc,
char* argv[])
99 auto& prof = Alina::Profiler::globalProfiler();
100 int m = argc > 1 ? atoi(argv[1]) : 1024;
113 Solver solve(context, Alina::adapter::make_matrix(
poisson_2d(m)));
116 std::cout << solve.precond() << std::endl;
118 std::vector<double> f(n, 1);
119 std::vector<double> x(n, 0);
125 std::cout <<
"Solver:" << std::endl
126 <<
" Iterations: " << r.nbIteration() << std::endl
127 <<
" Error: " << r.residual() << std::endl
140 std::fill(x.begin(), x.end(), 0);
142 prof.tic(
"nested solver");
143 r = S(solve.system_matrix(), solve, f, x);
144 prof.toc(
"nested solver");
146 std::cout <<
"Nested solver:" << std::endl
147 <<
" Iterations: " << r.nbIteration() << std::endl
148 <<
" Error: " << r.residual() << std::endl
151 std::cout << prof << std::endl;
Conjugate Gradients solver.
Convenience class that bundles together a preconditioner and an iterative solver.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Smoothed aggregation coarsening.