1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <vector>
#include <tuple>
#include <amgcl/adapter/crs_tuple.hpp>
#include <amgcl/make_solver.hpp>
#include <amgcl/amg.hpp>
#include <amgcl/coarsening/smoothed_aggregation.hpp>
#include <amgcl/relaxation/spai0.hpp>
#include <amgcl/solver/cg.hpp>
#include <amgcl/profiler.hpp>
#if defined(SOLVER_BACKEND_VEXCL)
# include <amgcl/backend/vexcl.hpp>
typedef amgcl::backend::vexcl<float> fBackend;
typedef amgcl::backend::vexcl<double> dBackend;
#else
# ifndef SOLVER_BACKEND_BUILTIN
# define SOLVER_BACKEND_BUILTIN
# endif
# include <amgcl/backend/builtin.hpp>
typedef amgcl::backend::builtin<float> fBackend;
typedef amgcl::backend::builtin<double> dBackend;
#endif
#include "sample_problem.hpp"
namespace amgcl { profiler<> prof; }
using amgcl::prof;
int main() {
// Combine single-precision preconditioner with a
// double-precision Krylov solver.
typedef amgcl::make_solver<
amgcl::amg<
fBackend,
amgcl::coarsening::smoothed_aggregation,
amgcl::relaxation::spai0
>,
amgcl::solver::cg< dBackend >
>
Solver;
std::vector<ptrdiff_t> ptr, col;
std::vector<double> val, rhs;
dBackend::params bprm;
#ifdef SOLVER_BACKEND_VEXCL
vex::Context ctx(vex::Filter::Env);
std::cout << ctx << std::endl;
bprm.q = ctx;
#endif
prof.tic("assemble");
int n = sample_problem(128, val, col, ptr, rhs);
prof.toc("assemble");
#if defined(SOLVER_BACKEND_VEXCL)
dBackend::matrix A_d(ctx, n, n, ptr, col, val);
vex::vector<double> f(ctx, rhs);
vex::vector<double> x(ctx, n);
x = 0;
#elif defined(SOLVER_BACKEND_BUILTIN)
auto A_d = std::tie(n, ptr, col, val);
std::vector<double> &f = rhs;
std::vector<double> x(n, 0.0);
#endif
prof.tic("setup");
Solver S(std::tie(n, ptr, col, val), Solver::params(), bprm);
prof.toc("setup");
std::cout << S << std::endl;
int iters;
double error;
prof.tic("solve");
std::tie(iters, error) = S(A_d, f, x);
prof.toc("solve");
std::cout << "Iterations: " << iters << std::endl
<< "Error: " << error << std::endl
<< prof << std::endl;
}
|