22#include <boost/program_options.hpp>
23#include <boost/preprocessor/seq/for_each.hpp>
25#include "arccore/alina/BuiltinBackend.h"
26#include "arccore/alina/StaticMatrix.h"
27#include "arccore/alina/PreconditionedSolver.h"
28#include "arccore/alina/AMG.h"
29#include "arccore/alina/SolverRuntime.h"
30#include "arccore/alina/CoarseningRuntime.h"
31#include "arccore/alina/RelaxationRuntime.h"
32#include "arccore/alina/Relaxation.h"
33#include "arccore/alina/CPRPreconditioner.h"
34#include "arccore/alina/Adapters.h"
35#include "arccore/alina/IO.h"
36#include "arccore/alina/Profiler.h"
40using Alina::precondition;
43template <
class Matrix>
46 auto& prof = Alina::Profiler::globalProfiler();
48 auto t1 = prof.scoped_tic(
"CPR");
60 std::cout << solve.precond() << std::endl;
62 std::vector<double> x(rhs.size(), 0.0);
68 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
69 <<
"Error: " << r.residual() << std::endl;
73template <
int B,
class Matrix>
76 auto& prof = Alina::Profiler::globalProfiler();
77 auto t1 = prof.scoped_tic(
"CPR");
91 solve(Alina::adapter::block_matrix<val_type>(K), prm);
94 std::cout << solve.precond() << std::endl;
96 std::vector<rhs_type> x(rhs.size(), Alina::math::zero<rhs_type>());
98 auto rhs_ptr =
reinterpret_cast<const rhs_type*
>(rhs.data());
99 size_t n = Alina::backend::nbRow(K) / B;
105 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
106 <<
"Error: " << r.residual() << std::endl;
110int main(
int argc,
char* argv[])
112 auto& prof = Alina::Profiler::globalProfiler();
113 using Alina::precondition;
117 namespace po = boost::program_options;
118 namespace io = Alina::IO;
120 po::options_description desc(
"Options");
122 desc.add_options()(
"help,h",
"show help")(
124 po::bool_switch()->default_value(
false),
125 "When specified, treat input files as binary instead of as MatrixMarket. "
126 "It is assumed the files were converted to binary format with mm2bin utility. ")(
128 po::value<string>()->required(),
129 "The system matrix in MatrixMarket format")(
132 "The right-hand side in MatrixMarket format")(
133 "runtime-block-size,b",
135 "The block size of the system matrix set at runtime")(
136 "static-block-size,c",
137 po::value<int>()->default_value(1),
138 "The block size of the system matrix set at compiletime")(
141 "parameter file in json format")(
143 po::value<vector<string>>()->multitoken(),
144 "Parameters specified as name=value pairs. "
145 "May be provided multiple times. Examples:\n"
146 " -p solver.tol=1e-3\n"
147 " -p precond.coarse_enough=300");
149 po::variables_map vm;
150 po::store(po::parse_command_line(argc, argv, desc), vm);
152 if (vm.count(
"help")) {
153 std::cout << desc << std::endl;
160 if (vm.count(
"params"))
161 prm.read_json(vm[
"params"].as<string>());
163 if (vm.count(
"prm")) {
164 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
169 int cb = vm[
"static-block-size"].as<
int>();
171 if (vm.count(
"runtime-block-size"))
172 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
174 prm.put(
"precond.block_size", cb);
177 vector<ptrdiff_t> ptr, col;
178 vector<double> val, rhs;
179 std::vector<char> pm;
182 auto t = prof.scoped_tic(
"reading");
184 string Afile = vm[
"matrix"].as<
string>();
185 bool binary = vm[
"binary"].as<
bool>();
188 io::read_crs(Afile, rows, ptr, col, val);
192 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
193 precondition(rows == cols,
"Non-square system matrix");
196 if (vm.count(
"rhs")) {
197 string bfile = vm[
"rhs"].as<
string>();
202 io::read_dense(bfile, n, m, rhs);
205 std::tie(n, m) = io::mm_reader(bfile)(rhs);
208 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
211 rhs.resize(rows, 1.0);
215#define CALL_BLOCK_SOLVER(z, data, B) \
217 solve_block_cpr<B>(std::tie(rows, ptr, col, val), rhs, prm); \
222 solve_cpr(std::tie(rows, ptr, col, val), rhs, prm);
225 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
228 precondition(
false,
"Unsupported block size");
232 std::cout << prof << std::endl;
Algebraic multigrid method.
Convenience class that bundles together a preconditioner and an iterative solver.
Allows to use an AMG smoother as standalone preconditioner.
Two stage preconditioner of the Constrained Pressure Residual type.
Matrix class, to be used by user.
Vue d'un tableau d'éléments de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Runtime-configurable wrappers around iterative solvers.