22#include <boost/program_options.hpp>
23#include <boost/preprocessor/seq/for_each.hpp>
25#if defined(SOLVER_BACKEND_CUDA)
26# include "arccore/alina/CudaBackend.h"
27# include "arccore/alina/relaxation_cusparse_ilu0.h"
30# ifndef SOLVER_BACKEND_BUILTIN
31# define SOLVER_BACKEND_BUILTIN
33#include "arccore/alina/BuiltinBackend.h"
37#if defined(SOLVER_BACKEND_BUILTIN)
38#include "arccore/alina/StaticMatrix.h"
39#include "arccore/alina/Adapters.h"
42#include "arccore/alina/PreconditionedSolver.h"
43#include "arccore/alina/AMG.h"
44#include "arccore/alina/SolverRuntime.h"
45#include "arccore/alina/CoarseningRuntime.h"
46#include "arccore/alina/RelaxationRuntime.h"
47#include "arccore/alina/Relaxation.h"
48#include "arccore/alina/CPRDynamicRowSumPreconditioner.h"
49#include "arccore/alina/Adapters.h"
50#include "arccore/alina/IO.h"
51#include "arccore/alina/Profiler.h"
55using Alina::precondition;
58template <
class Matrix>
61 auto& prof = Alina::Profiler::globalProfiler();
64#if defined(SOLVER_BACKEND_VEXCL)
65 vex::Context ctx(vex::Filter::Env);
66 std::cout << ctx << std::endl;
68#elif defined(SOLVER_BACKEND_VIENNACL)
70 << viennacl::ocl::current_device().name()
71 <<
" (" << viennacl::ocl::current_device().vendor() <<
")\n\n";
72#elif defined(SOLVER_BACKEND_CUDA)
73 cusparseCreate(&bprm.cusparse_handle);
79 cudaGetDeviceProperties(&prop, dev);
80 std::cout << prop.name << std::endl
85 auto t1 = prof.scoped_tic(
"CPR");
99 std::cout << solve.precond() << std::endl;
101 auto f = Backend::copy_vector(rhs, bprm);
102 auto x = Backend::create_vector(rhs.size(), bprm);
103 Alina::backend::clear(*x);
109 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
110 <<
"Error: " << r.residual() << std::endl;
113#if defined(SOLVER_BACKEND_BUILTIN)
115template <
int B,
class Matrix>
118 auto& prof = Alina::Profiler::globalProfiler();
119 auto t1 = prof.scoped_tic(
"CPR");
130 typename SBackend::params bprm;
136 solve(Alina::adapter::block_matrix<val_type>(K), prm, bprm);
139 std::cout << solve.precond() << std::endl;
141 size_t n = Alina::backend::nbRow(K) / B;
142 auto rhs_ptr =
reinterpret_cast<const rhs_type*
>(rhs.data());
146 auto x = SBackend::create_vector(n, bprm);
147 Alina::backend::clear(*x);
153 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
154 <<
"Error: " << r.residual() << std::endl;
159int main(
int argc,
char* argv[])
161 auto& prof = Alina::Profiler::globalProfiler();
162 using Alina::precondition;
166 namespace po = boost::program_options;
167 namespace io = Alina::IO;
169 po::options_description desc(
"Options");
171 desc.add_options()(
"help,h",
"show help")(
173 po::bool_switch()->default_value(
false),
174 "When specified, treat input files as binary instead of as MatrixMarket. "
175 "It is assumed the files were converted to binary format with mm2bin utility. ")(
177 po::value<string>()->required(),
178 "The system matrix in MatrixMarket format")(
181 "The right-hand side in MatrixMarket format")(
184 "Equation weights in MatrixMarket format")(
185 "runtime-block-size,b",
187 "The block size of the system matrix set at runtime")(
188 "static-block-size,c",
189 po::value<int>()->default_value(1),
190 "The block size of the system matrix set at compiletime")(
193 "parameter file in json format")(
195 po::value<vector<string>>()->multitoken(),
196 "Parameters specified as name=value pairs. "
197 "May be provided multiple times. Examples:\n"
198 " -p solver.tol=1e-3\n"
199 " -p precond.coarse_enough=300");
201 po::variables_map vm;
202 po::store(po::parse_command_line(argc, argv, desc), vm);
204 if (vm.count(
"help")) {
205 std::cout << desc << std::endl;
212 if (vm.count(
"params"))
213 prm.read_json(vm[
"params"].as<string>());
215 if (vm.count(
"prm")) {
216 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
221 int cb = vm[
"static-block-size"].as<
int>();
223 if (vm.count(
"runtime-block-size"))
224 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
226 prm.put(
"precond.block_size", cb);
229 vector<ptrdiff_t> ptr, col;
230 vector<double> val, rhs, wgt;
231 std::vector<char> pm;
234 auto t = prof.scoped_tic(
"reading");
236 string Afile = vm[
"matrix"].as<
string>();
237 bool binary = vm[
"binary"].as<
bool>();
240 io::read_crs(Afile, rows, ptr, col, val);
244 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
245 precondition(rows == cols,
"Non-square system matrix");
248 if (vm.count(
"rhs")) {
249 string bfile = vm[
"rhs"].as<
string>();
254 io::read_dense(bfile, n, m, rhs);
257 std::tie(n, m) = io::mm_reader(bfile)(rhs);
260 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
263 rhs.resize(rows, 1.0);
266 if (vm.count(
"weights")) {
267 string wfile = vm[
"weights"].as<
string>();
272 io::read_dense(wfile, n, m, wgt);
275 std::tie(n, m) = io::mm_reader(wfile)(wgt);
278 prm.put(
"precond.weights", &wgt[0]);
279 prm.put(
"precond.weights_size", wgt.size());
283#define CALL_BLOCK_SOLVER(z, data, B) \
285 solve_block_cpr<B>(std::tie(rows, ptr, col, val), rhs, prm); \
290 solve_cpr(std::tie(rows, ptr, col, val), rhs, prm);
293#if defined(SOLVER_BACKEND_BUILTIN) || defined(SOLVER_BACKEND_VEXCL)
294 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
298 precondition(
false,
"Unsupported block size");
302 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.
CPR preconditioner with Dynamic Row Sum modification.
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 -*-
Alina::detail::empty_params params
Runtime-configurable wrappers around iterative solvers.