22#include <boost/preprocessor/seq/for_each.hpp>
24#if defined(SOLVER_BACKEND_CUDA)
25# include "arccore/alina/CudaBackend.h"
26# include "arccore/alina/relaxation_cusparse_ilu0.h"
29# ifndef SOLVER_BACKEND_BUILTIN
30# define SOLVER_BACKEND_BUILTIN
32#include "arccore/alina/BuiltinBackend.h"
36#if defined(SOLVER_BACKEND_BUILTIN)
37#include "arccore/alina/StaticMatrix.h"
38#include "arccore/alina/Adapters.h"
41#include "arccore/alina/PreconditionedSolver.h"
42#include "arccore/alina/AMG.h"
43#include "arccore/alina/SolverRuntime.h"
44#include "arccore/alina/CoarseningRuntime.h"
45#include "arccore/alina/RelaxationRuntime.h"
46#include "arccore/alina/Relaxation.h"
47#include "arccore/alina/CPRDynamicRowSumPreconditioner.h"
48#include "arccore/alina/Adapters.h"
49#include "arccore/alina/IO.h"
50#include "arccore/alina/Profiler.h"
52#include "arccore/common/internal/ProgramOptions.h"
56using Alina::precondition;
59template <
class Matrix>
63 auto& prof = Alina::Profiler::globalProfiler();
66#if defined(SOLVER_BACKEND_VEXCL)
67 vex::Context ctx(vex::Filter::Env);
68 std::cout << ctx << std::endl;
70#elif defined(SOLVER_BACKEND_VIENNACL)
72 << viennacl::ocl::current_device().name()
73 <<
" (" << viennacl::ocl::current_device().vendor() <<
")\n\n";
74#elif defined(SOLVER_BACKEND_CUDA)
75 cusparseCreate(&bprm.cusparse_handle);
81 cudaGetDeviceProperties(&prop, dev);
82 std::cout << prop.name << std::endl
87 auto t1 = prof.scoped_tic(
"CPR");
98 solve(context, K, prm, bprm);
101 std::cout << solve.precond() << std::endl;
103 auto f = Backend::copy_vector(rhs, bprm);
104 auto x = Backend::create_vector(rhs.size(), bprm);
105 Alina::backend::clear(*x);
111 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
112 <<
"Error: " << r.residual() << std::endl;
115#if defined(SOLVER_BACKEND_BUILTIN)
117template <
int B,
class Matrix>
120 auto& prof = Alina::Profiler::globalProfiler();
121 auto t1 = prof.scoped_tic(
"CPR");
132 typename SBackend::params bprm;
138 solve(context, Alina::adapter::block_matrix<val_type>(K), prm, bprm);
141 std::cout << solve.precond() << std::endl;
143 size_t n = Alina::backend::nbRow(K) / B;
144 auto rhs_ptr =
reinterpret_cast<const rhs_type*
>(rhs.data());
148 auto x = SBackend::create_vector(n, bprm);
149 Alina::backend::clear(*x);
155 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
156 <<
"Error: " << r.residual() << std::endl;
161int main(
int argc,
char* argv[])
163 auto& prof = Alina::Profiler::globalProfiler();
164 using Alina::precondition;
170 namespace po = Arcane::ProgramOptions;
171 namespace io = Alina::IO;
175 desc.add_options()(
"help,h",
"show help");
176 desc.add_options()(
"binary,B",
177 po::bool_switch()->default_value(
false),
178 "Lorsque spécifié, traite les fichiers d'entrée en binaire au lieu de MatrixMarket. "
179 "Il est supposé que les fichiers ont été convertis au format binaire avec l'utilitaire mm2bin. ");
180 desc.add_options()(
"matrix,A",
181 po::value<string>()->required(),
182 "La matrice système au format MatrixMarket");
183 desc.add_options()(
"rhs,f",
185 "Le côté droit en format MatrixMarket");
186 desc.add_options()(
"weights,w",
188 "Poids des équations au format MatrixMarket");
189 desc.add_options()(
"runtime-block-size,b",
191 "La taille de bloc de la matrice système définie à l'exécution");
192 desc.add_options()(
"static-block-size,c",
193 po::value<int>()->default_value(1),
194 "La taille de bloc de la matrice système définie à la compilation");
195 desc.add_options()(
"params,P",
197 "fichier de paramètres au format json");
198 desc.add_options()(
"prm,p",
199 po::value<vector<string>>()->multitoken(),
200 "Paramètres spécifiés sous forme de paires nom=valeur. "
201 "Peut être fourni plusieurs fois. Exemples :\n"
202 " -p solver.tol=1e-3\n"
203 " -p precond.coarse_enough=300");
206 po::store(po::parse_command_line(argc, argv, desc), vm);
208 if (vm.count(
"help")) {
209 std::cout << desc << std::endl;
216 if (vm.count(
"params"))
217 prm.read_json(vm[
"params"].as<string>());
219 if (vm.count(
"prm")) {
220 for (
const string& v : vm[
"prm"].as<vector<string>>()) {
225 int cb = vm[
"static-block-size"].as<
int>();
227 if (vm.count(
"runtime-block-size"))
228 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
230 prm.put(
"precond.block_size", cb);
233 vector<ptrdiff_t> ptr, col;
234 vector<double> val, rhs, wgt;
235 std::vector<char> pm;
238 auto t = prof.scoped_tic(
"reading");
240 string Afile = vm[
"matrix"].as<
string>();
241 bool binary = vm[
"binary"].as<
bool>();
244 io::read_crs(Afile, rows, ptr, col, val);
248 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
249 precondition(rows == cols,
"Matrice système non carrée");
252 if (vm.count(
"rhs")) {
253 string bfile = vm[
"rhs"].as<
string>();
258 io::read_dense(bfile, n, m, rhs);
261 std::tie(n, m) = io::mm_reader(bfile)(rhs);
264 precondition(n == rows && m == 1,
"Le vecteur RHS a une taille incorrecte");
267 rhs.resize(rows, 1.0);
270 if (vm.count(
"weights")) {
271 string wfile = vm[
"weights"].as<
string>();
276 io::read_dense(wfile, n, m, wgt);
279 std::tie(n, m) = io::mm_reader(wfile)(wgt);
282 prm.put(
"precond.weights", &wgt[0]);
283 prm.put(
"precond.weights_size", wgt.size());
287#define CALL_BLOCK_SOLVER(z, data, B) \
289 solve_block_cpr<B>(context, std::tie(rows, ptr, col, val), rhs, prm); \
294 solve_cpr(context, std::tie(rows, ptr, col, val), rhs, prm);
297#if defined(SOLVER_BACKEND_BUILTIN) || defined(SOLVER_BACKEND_VEXCL)
298 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
302 precondition(
false,
"Taille de bloc non prise en charge");
306 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.
CPR preconditioner with Dynamic Row Sum modification.
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 --
Alina::detail::empty_params params
Runtime-configurable wrappers around iterative solvers.