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");
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(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;
123 desc.add_options()(
"help,h",
"show help")(
125 po::bool_switch()->default_value(
false),
126 "When specified, treat input files as binary instead of as MatrixMarket. "
127 "It is assumed the files were converted to binary format with mm2bin utility. ")(
129 po::value<string>()->required(),
130 "The system matrix in MatrixMarket format")(
133 "The right-hand side in MatrixMarket format")(
134 "runtime-block-size,b",
136 "The block size of the system matrix set at runtime")(
137 "static-block-size,c",
138 po::value<int>()->default_value(1),
139 "The block size of the system matrix set at compiletime")(
142 "parameter file in json format")(
144 po::value<vector<string>>()->multitoken(),
145 "Parameters specified as name=value pairs. "
146 "May be provided multiple times. Examples:\n"
147 " -p solver.tol=1e-3\n"
148 " -p precond.coarse_enough=300");
151 po::store(po::parse_command_line(argc, argv, desc), vm);
153 if (vm.count(
"help")) {
154 std::cout << desc << std::endl;
161 if (vm.count(
"params"))
162 prm.read_json(vm[
"params"].as<string>());
164 if (vm.count(
"prm")) {
165 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
170 int cb = vm[
"static-block-size"].as<
int>();
172 if (vm.count(
"runtime-block-size"))
173 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
175 prm.put(
"precond.block_size", cb);
178 vector<ptrdiff_t> ptr, col;
179 vector<double> val, rhs;
180 std::vector<char> pm;
183 auto t = prof.scoped_tic(
"reading");
185 string Afile = vm[
"matrix"].as<
string>();
186 bool binary = vm[
"binary"].as<
bool>();
189 io::read_crs(Afile, rows, ptr, col, val);
193 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
194 precondition(rows == cols,
"Non-square system matrix");
197 if (vm.count(
"rhs")) {
198 string bfile = vm[
"rhs"].as<
string>();
203 io::read_dense(bfile, n, m, rhs);
206 std::tie(n, m) = io::mm_reader(bfile)(rhs);
209 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
212 rhs.resize(rows, 1.0);
216#define CALL_BLOCK_SOLVER(z, data, B) \
218 solve_block_cpr<B>(std::tie(rows, ptr, col, val), rhs, prm); \
223 solve_cpr(std::tie(rows, ptr, col, val), rhs, prm);
226 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
229 precondition(
false,
"Unsupported block size");
233 std::cout << prof << std::endl;
Algebraic multigrid method.
Convenience class that bundles together a preconditioner and an iterative solver.
Class to store parameters as a hierarchical key/value tree.
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.
Describes a set of command-line options.
Stores parsed option values.
View of an array of elements of type T.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Runtime-configurable wrappers around iterative solvers.