22#include <boost/preprocessor/seq/for_each.hpp>
24#include "arccore/alina/BuiltinBackend.h"
25#include "arccore/alina/StaticMatrix.h"
26#include "arccore/alina/PreconditionedSolver.h"
27#include "arccore/alina/AMG.h"
28#include "arccore/alina/SolverRuntime.h"
29#include "arccore/alina/CoarseningRuntime.h"
30#include "arccore/alina/RelaxationRuntime.h"
31#include "arccore/alina/Relaxation.h"
32#include "arccore/alina/CPRPreconditioner.h"
33#include "arccore/alina/Adapters.h"
34#include "arccore/alina/IO.h"
35#include "arccore/alina/Profiler.h"
37#include "arccore/common/internal/ProgramOptions.h"
41using Alina::precondition;
44template <
class Matrix>
47 auto& prof = Alina::Profiler::globalProfiler();
49 auto t1 = prof.scoped_tic(
"CPR");
58 solve(context, K, prm);
61 std::cout << solve.precond() << std::endl;
63 std::vector<double> x(rhs.size(), 0.0);
69 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
70 <<
"Error: " << r.residual() << std::endl;
74template <
int B,
class Matrix>
77 auto& prof = Alina::Profiler::globalProfiler();
78 auto t1 = prof.scoped_tic(
"CPR");
92 solve(context, Alina::adapter::block_matrix<val_type>(K), prm);
95 std::cout << solve.precond() << std::endl;
97 std::vector<rhs_type> x(rhs.size(), Alina::math::zero<rhs_type>());
99 auto rhs_ptr =
reinterpret_cast<const rhs_type*
>(rhs.data());
100 size_t n = Alina::backend::nbRow(K) / B;
106 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
107 <<
"Error: " << r.residual() << std::endl;
111int main(
int argc,
char* argv[])
113 auto& prof = Alina::Profiler::globalProfiler();
114 using Alina::precondition;
118 namespace po = Arcane::ProgramOptions;
119 namespace io = Alina::IO;
125 desc.add_options()(
"help,h",
"show help")(
127 po::bool_switch()->default_value(
false),
128 "When specified, treat input files as binary instead of as MatrixMarket. "
129 "It is assumed the files were converted to binary format with mm2bin utility. ")(
131 po::value<string>()->required(),
132 "The system matrix in MatrixMarket format")(
135 "The right-hand side in MatrixMarket format")(
136 "runtime-block-size,b",
138 "The block size of the system matrix set at runtime")(
139 "static-block-size,c",
140 po::value<int>()->default_value(1),
141 "The block size of the system matrix set at compiletime")(
144 "parameter file in json format")(
146 po::value<vector<string>>()->multitoken(),
147 "Parameters specified as name=value pairs. "
148 "May be provided multiple times. Examples:\n"
149 " -p solver.tol=1e-3\n"
150 " -p precond.coarse_enough=300");
153 po::store(po::parse_command_line(argc, argv, desc), vm);
155 if (vm.count(
"help")) {
156 std::cout << desc << std::endl;
163 if (vm.count(
"params"))
164 prm.read_json(vm[
"params"].as<string>());
166 if (vm.count(
"prm")) {
167 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
172 int cb = vm[
"static-block-size"].as<
int>();
174 if (vm.count(
"runtime-block-size"))
175 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
177 prm.put(
"precond.block_size", cb);
180 vector<ptrdiff_t> ptr, col;
181 vector<double> val, rhs;
182 std::vector<char> pm;
185 auto t = prof.scoped_tic(
"reading");
187 string Afile = vm[
"matrix"].as<
string>();
188 bool binary = vm[
"binary"].as<
bool>();
191 io::read_crs(Afile, rows, ptr, col, val);
195 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
196 precondition(rows == cols,
"Non-square system matrix");
199 if (vm.count(
"rhs")) {
200 string bfile = vm[
"rhs"].as<
string>();
205 io::read_dense(bfile, n, m, rhs);
208 std::tie(n, m) = io::mm_reader(bfile)(rhs);
211 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
214 rhs.resize(rows, 1.0);
218#define CALL_BLOCK_SOLVER(z, data, B) \
220 solve_block_cpr<B>(context, std::tie(rows, ptr, col, val), rhs, prm); \
225 solve_cpr(context, std::tie(rows, ptr, col, val), rhs, prm);
228 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
231 precondition(
false,
"Unsupported block size");
235 std::cout << prof << std::endl;
Algebraic multigrid method.
Convenience class that bundles together a preconditioner and an iterative solver.
Classe pour stocker les paramètres sous forme d'arbre hiérarchique clé/valeur.
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.
Décrit un ensemble d'options en ligne de commande.
Stocke les valeurs d'options analysées.
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.