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>
62 auto& prof = Alina::Profiler::globalProfiler();
65#if defined(SOLVER_BACKEND_VEXCL)
66 vex::Context ctx(vex::Filter::Env);
67 std::cout << ctx << std::endl;
69#elif defined(SOLVER_BACKEND_VIENNACL)
71 << viennacl::ocl::current_device().name()
72 <<
" (" << viennacl::ocl::current_device().vendor() <<
")\n\n";
73#elif defined(SOLVER_BACKEND_CUDA)
74 cusparseCreate(&bprm.cusparse_handle);
80 cudaGetDeviceProperties(&prop, dev);
81 std::cout << prop.name << std::endl
86 auto t1 = prof.scoped_tic(
"CPR");
100 std::cout << solve.precond() << std::endl;
102 auto f = Backend::copy_vector(rhs, bprm);
103 auto x = Backend::create_vector(rhs.size(), bprm);
104 Alina::backend::clear(*x);
110 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
111 <<
"Error: " << r.residual() << std::endl;
114#if defined(SOLVER_BACKEND_BUILTIN)
116template <
int B,
class Matrix>
119 auto& prof = Alina::Profiler::globalProfiler();
120 auto t1 = prof.scoped_tic(
"CPR");
131 typename SBackend::params bprm;
137 solve(Alina::adapter::block_matrix<val_type>(K), prm, bprm);
140 std::cout << solve.precond() << std::endl;
142 size_t n = Alina::backend::nbRow(K) / B;
143 auto rhs_ptr =
reinterpret_cast<const rhs_type*
>(rhs.data());
147 auto x = SBackend::create_vector(n, bprm);
148 Alina::backend::clear(*x);
154 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
155 <<
"Error: " << r.residual() << std::endl;
160int main(
int argc,
char* argv[])
162 auto& prof = Alina::Profiler::globalProfiler();
163 using Alina::precondition;
167 namespace po = Arcane::ProgramOptions;
168 namespace io = Alina::IO;
172 desc.add_options()(
"help,h",
"show help")(
174 po::bool_switch()->default_value(
false),
175 "When specified, treat input files as binary instead of as MatrixMarket. "
176 "It is assumed the files were converted to binary format with mm2bin utility. ")(
178 po::value<string>()->required(),
179 "The system matrix in MatrixMarket format")(
182 "The right-hand side in MatrixMarket format")(
185 "Equation weights in MatrixMarket format")(
186 "runtime-block-size,b",
188 "The block size of the system matrix set at runtime")(
189 "static-block-size,c",
190 po::value<int>()->default_value(1),
191 "The block size of the system matrix set at compiletime")(
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");
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>>()) {
222 int cb = vm[
"static-block-size"].as<
int>();
224 if (vm.count(
"runtime-block-size"))
225 prm.put(
"precond.block_size", vm[
"runtime-block-size"].as<int>());
227 prm.put(
"precond.block_size", cb);
230 vector<ptrdiff_t> ptr, col;
231 vector<double> val, rhs, wgt;
232 std::vector<char> pm;
235 auto t = prof.scoped_tic(
"reading");
237 string Afile = vm[
"matrix"].as<
string>();
238 bool binary = vm[
"binary"].as<
bool>();
241 io::read_crs(Afile, rows, ptr, col, val);
245 std::tie(rows, cols) = io::mm_reader(Afile)(ptr, col, val);
246 precondition(rows == cols,
"Non-square system matrix");
249 if (vm.count(
"rhs")) {
250 string bfile = vm[
"rhs"].as<
string>();
255 io::read_dense(bfile, n, m, rhs);
258 std::tie(n, m) = io::mm_reader(bfile)(rhs);
261 precondition(n == rows && m == 1,
"The RHS vector has wrong size");
264 rhs.resize(rows, 1.0);
267 if (vm.count(
"weights")) {
268 string wfile = vm[
"weights"].as<
string>();
273 io::read_dense(wfile, n, m, wgt);
276 std::tie(n, m) = io::mm_reader(wfile)(wgt);
279 prm.put(
"precond.weights", &wgt[0]);
280 prm.put(
"precond.weights_size", wgt.size());
284#define CALL_BLOCK_SOLVER(z, data, B) \
286 solve_block_cpr<B>(std::tie(rows, ptr, col, val), rhs, prm); \
291 solve_cpr(std::tie(rows, ptr, col, val), rhs, prm);
294#if defined(SOLVER_BACKEND_BUILTIN) || defined(SOLVER_BACKEND_VEXCL)
295 BOOST_PP_SEQ_FOR_EACH(CALL_BLOCK_SOLVER, ~, ARCCORE_ALINA_BLOCK_SIZES)
299 precondition(
false,
"Unsupported block size");
303 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.
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 --
Alina::detail::empty_params params
Runtime-configurable wrappers around iterative solvers.