20#pragma GCC diagnostic ignored "-Wdeprecated-copy"
21#pragma GCC diagnostic ignored "-Wint-in-bool-context"
26#include <boost/program_options.hpp>
27#include <boost/preprocessor/seq/for_each.hpp>
29#include "arccore/alina/PreconditionedSolver.h"
30#include "arccore/alina/make_block_solver.h"
31#include "arccore/alina/StaticMatrix.h"
32#include "arccore/alina/Adapters.h"
33#include "arccore/alina/AMG.h"
34#include "arccore/alina/SolverRuntime.h"
35#include "arccore/alina/CoarseningRuntime.h"
36#include "arccore/alina/RelaxationRuntime.h"
37#include "arccore/alina/SchurPressureCorrectionPreconditioner.h"
38#include "arccore/alina/PreconditionerRuntime.h"
39#include "arccore/alina/Adapters.h"
41#if defined(SOLVER_BACKEND_VEXCL)
43# ifndef SOLVER_BACKEND_BUILTIN
44# define SOLVER_BACKEND_BUILTIN
46#include "arccore/alina/BuiltinBackend.h"
47#ifdef BLOCK_TYPE_EIGEN
48#include "arccore/alina/ValueTypeEigen.h"
49template <
class T,
int N,
int M>
50using BlockMatrix = Eigen::Matrix<T, N, M>;
52 template <
class T,
int N,
int M>
58#include "arccore/alina/IO.h"
59#include "arccore/alina/Profiler.h"
61#ifndef ARCCORE_ALINA_BLOCK_SIZES
62# define ARCCORE_ALINA_BLOCK_SIZES (3)(4)
67using Alina::precondition;
70template <
class USolver,
class PSolver,
class Matrix>
73 auto& prof = Alina::Profiler::globalProfiler();
74 typedef Backend<double> SBackend;
75 SBackend::params bprm;
77 auto t1 = prof.scoped_tic(
"schur_complement");
85 std::cout << solve << std::endl;
88 auto f = SBackend::copy_vector(rhs, bprm);
89 auto x = SBackend::create_vector(rhs.size(), bprm);
90 Alina::backend::clear(*x);
96 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
97 <<
"Error: " << r.residual() << std::endl;
100#define ARCCORE_ALINA_BLOCK_PSOLVER(z, data, B) \
102 typedef Backend<BlockMatrix<float, B, B>> BBackend; \
103 typedef ::Arcane::Alina::make_block_solver< \
104 ::Arcane::Alina::PreconditionerRuntime<BBackend>, \
105 ::Arcane::Alina::SolverRuntime<BBackend> > \
107 solve_schur<USolver, PSolver>(K, rhs, prm); \
111template <
class USolver,
class Matrix>
118 solve_schur<USolver, PSolver>(K, rhs, prm);
120#if defined(SOLVER_BACKEND_BUILTIN)
121 BOOST_PP_SEQ_FOR_EACH(ARCCORE_ALINA_BLOCK_PSOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
124 precondition(
false,
"Unsupported block size for pressure");
128#define ARCCORE_ALINA_BLOCK_USOLVER(z, data, B) \
130 typedef Backend<BlockMatrix<float, B, B>> BBackend; \
131 typedef ::Arcane::Alina::make_block_solver< \
132 ::Arcane::Alina::PreconditionerRuntime<BBackend>, \
133 ::Arcane::Alina::SolverRuntime<BBackend>> \
135 solve_schur<USolver>(pb, K, rhs, prm); \
139template <
class Matrix>
146 solve_schur<USolver>(pb, K, rhs, prm);
148#if defined(SOLVER_BACKEND_BUILTIN) || defined(SOLVER_BACKEND_VEXCL)
149 BOOST_PP_SEQ_FOR_EACH(ARCCORE_ALINA_BLOCK_USOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
152 precondition(
false,
"Unsupported block size for flow");
157int main(
int argc,
char* argv[])
159 auto& prof = Alina::Profiler::globalProfiler();
163 namespace po = boost::program_options;
164 namespace io = Alina::IO;
166 po::options_description desc(
"Options");
168 desc.add_options()(
"help,h",
"show help")(
170 po::bool_switch()->default_value(
false),
171 "When specified, treat input files as binary instead of as MatrixMarket. "
172 "It is assumed the files were converted to binary format with mm2bin utility. ")(
174 po::bool_switch()->default_value(
false),
175 "Scale the matrix so that the diagonal is unit. ")(
177 po::value<string>()->required(),
178 "The system matrix in MatrixMarket format")(
181 "The right-hand side in MatrixMarket format")(
184 "The pressure mask in MatrixMarket format. Or, if the parameter has "
185 "the form '%n:m', then each (n+i*m)-th variable is treated as pressure.")(
187 po::value<int>()->default_value(1),
188 "Block-size of the 'flow'/'non-pressure' part of the matrix")(
190 po::value<int>()->default_value(1),
191 "Block-size of the 'pressure' part of the matrix")(
194 "parameter file in json format")(
196 po::value<vector<string>>()->multitoken(),
197 "Parameters specified as name=value pairs. "
198 "May be provided multiple times. Examples:\n"
199 " -p solver.tol=1e-3\n"
200 " -p precond.coarse_enough=300");
202 po::variables_map vm;
203 po::store(po::parse_command_line(argc, argv, desc), vm);
205 if (vm.count(
"help")) {
206 std::cout << desc << std::endl;
213 if (vm.count(
"params"))
214 prm.read_json(vm[
"params"].as<string>());
216 if (vm.count(
"prm")) {
217 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
223 vector<ptrdiff_t> ptr, col;
224 vector<double> val, rhs;
225 std::vector<char> pm;
228 auto t = prof.scoped_tic(
"reading");
230 string Afile = vm[
"matrix"].as<
string>();
231 bool binary = vm[
"binary"].as<
bool>();
234 io::read_crs(Afile, rows, ptr, col, val);
238 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
239 precondition(rows == cols,
"Non-square system matrix");
242 if (vm.count(
"rhs")) {
243 string bfile = vm[
"rhs"].as<
string>();
248 io::read_dense(bfile, n, m, rhs);
251 std::tie(n, m) = io::mm_reader(bfile)(rhs);
254 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
257 rhs.resize(rows, 1.0);
260 if (vm.count(
"pmask")) {
261 std::string pmask = vm[
"pmask"].as<
string>();
262 prm.put(
"precond.pmask_size", rows);
268 prm.put(
"precond.pmask_pattern", pmask);
273 precondition(n == rows && m == 1,
"Mask file has wrong size");
274 prm.put(
"precond.pmask",
static_cast<void*
>(&pm[0]));
280 if (vm[
"scale"].as<bool>()) {
281 std::vector<double> dia(rows, 1.0);
283 for (ptrdiff_t i = 0; i < static_cast<ptrdiff_t>(rows); ++i) {
285 for (ptrdiff_t j = ptr[i], e = ptr[i + 1]; j < e; ++j) {
287 d = 1 /
sqrt(val[j]);
294 for (ptrdiff_t i = 0; i < static_cast<ptrdiff_t>(rows); ++i) {
296 for (ptrdiff_t j = ptr[i], e = ptr[i + 1]; j < e; ++j) {
297 val[j] *= dia[i] * dia[col[j]];
302 solve_schur(vm[
"ub"].as<int>(), vm[
"pb"].as<int>(),
303 std::tie(rows, ptr, col, val), rhs, prm);
305 std::cout << prof << std::endl;
Convenience class that bundles together a preconditioner and an iterative solver.
Matrix class, to be used by user.
__host__ __device__ double sqrt(double v)
Racine carrée de v.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Sparse matrix stored in CSR (Compressed Sparse Row) format.
Runtime-configurable wrappers around iterative solvers.