14#include "arccore/alina/RelaxationRuntime.h"
15#include "arccore/alina/CoarseningRuntime.h"
16#include "arccore/alina/SolverRuntime.h"
17#include "arccore/alina/PreconditionedSolver.h"
18#include "arccore/alina/DistributedSolverRuntime.h"
19#include "arccore/alina/DistributedDirectSolverRuntime.h"
20#include "arccore/alina/DistributedSubDomainDeflation.h"
21#include "arccore/alina/AMG.h"
22#include "arccore/alina/BuiltinBackend.h"
23#include "arccore/alina/AlinaLib.h"
55struct AlinaPreconditioner
57 explicit AlinaPreconditioner(PreconditionerType* preconditioner)
58 : m_preconditioner(preconditioner)
60 ~AlinaPreconditioner()
63 delete m_preconditioner;
65 PreconditionerType* m_preconditioner =
nullptr;
71struct AlinaSequentialSolver
73 explicit AlinaSequentialSolver(SequentialSolverType* solver)
76 ~AlinaSequentialSolver()
80 SequentialSolverType* m_solver =
nullptr;
86struct AlinaDistributedSolver
88 explicit AlinaDistributedSolver(DistributedSolverType* solver)
91 ~AlinaDistributedSolver()
95 DistributedSolverType* m_solver =
nullptr;
105 x.iterations = r.nbIteration();
106 x.residual = r.residual();
116 return new AlinaParameters();
125 prm->m_properties.put(name, value);
134 prm->m_properties.put(name, value);
141params_set_string(
AlinaParameters* prm,
const char* name,
const char* value)
143 prm->m_properties.put(name, value);
152 Params& p = prm->m_properties;
169preconditioner_create(
int n,
175 SmallSpan<const int> ptr_range(ptr, n + 1);
176 SmallSpan<const int> col_range(col, ptr[n]);
177 SmallSpan<const double> val_range(val, ptr[n]);
179 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
181 PreconditionerType* amg =
nullptr;
183 amg =
new PreconditionerType(A, prm->m_properties);
185 amg =
new PreconditionerType(A);
186 return new AlinaPreconditioner(amg);
195 PreconditionerType* amg = handle->m_preconditioner;
197 size_t n = Alina::backend::nbRow(amg->system_matrix());
199 SmallSpan<double> x_range(x, n);
200 SmallSpan<const double> rhs_range(rhs, n);
202 amg->apply(rhs_range, x_range);
211 std::cout << *(handle->m_preconditioner) << std::endl;
227solver_create(
int n,
const int* ptr,
232 SmallSpan<const int> ptr_range(ptr, n + 1);
233 SmallSpan<const int> col_range(col, ptr[n]);
234 SmallSpan<const double> val_range(val, ptr[n]);
236 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
238 SequentialSolverType* solver =
new SequentialSolverType(A);
240 solver =
new SequentialSolverType(A, prm->m_properties);
242 solver =
new SequentialSolverType(A);
243 std::cout <<
"Printing solver infos\n";
244 std::cout << (*solver) << std::endl;
245 Alina::PropertyTree ptree;
246 solver->prm.get(ptree);
247 std::cout <<
"SOLVER_PARAMS: " << ptree <<
"\n";
248 return new AlinaSequentialSolver(solver);
257 SequentialSolverType* slv = handle->m_solver;
259 std::cout << slv->
precond() << std::endl;
279 SequentialSolverType* slv = handle->m_solver;
281 size_t n = slv->
size();
283 SmallSpan<double> x_range(x, n);
284 SmallSpan<const double> rhs_range(rhs, n);
286 Alina::SolverResult r = (*slv)(rhs_range, x_range);
288 return _toConvInfo(r);
302 SequentialSolverType* slv = handle->m_solver;
304 size_t n = slv->
size();
306 SmallSpan<double> x_range(x, n);
307 SmallSpan<const double> rhs_range(rhs, n);
309 SmallSpan<const int> ptr_range(A_ptr, n + 1);
310 SmallSpan<const int> col_range(A_col, A_ptr[n]);
311 SmallSpan<const double> val_range(A_val, A_ptr[n]);
313 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
315 Alina::SolverResult r = (*slv)(A, rhs_range, x_range);
317 return _toConvInfo(r);
323struct deflation_vectors
326 AlinaDefVecFunction user_func;
329 deflation_vectors(
int n, AlinaDefVecFunction user_func,
void* user_data)
331 , user_func(user_func)
332 , user_data(user_data)
335 int dim()
const {
return n; }
337 double operator()(
int i, ptrdiff_t j)
const
339 return user_func(i, j, user_data);
345solver_mpi_create(MPI_Comm comm,
347 const ptrdiff_t* ptr,
348 const ptrdiff_t* col,
351 AlinaDefVecFunction def_vec_func,
355 std::function<double(ptrdiff_t,
unsigned)> dv =
deflation_vectors(n_def_vec, def_vec_func, def_vec_data);
357 prm.put(
"num_def_vec", n_def_vec);
358 prm.put(
"def_vec", &dv);
364 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
366 auto* p =
new DistributedSolverType(mpi_comm, A, prm);
379 DistributedSolverType* solver = handle->m_solver;
381 size_t n = solver->size();
383 SmallSpan<double> x_range(x, n);
384 SmallSpan<const double> rhs_range(rhs, n);
386 AlinaConvergenceInfo cnv;
388 std::tie(cnv.iterations, cnv.residual) = (*solver)(rhs_range, x_range);
Algebraic multigrid method.
Runtime wrapper for distributed direct solvers.
Distributed solver based on subdomain deflation.
Convenience class that bundles together a preconditioner and an iterative solver.
const Precond & precond() const
Returns reference to the constructed preconditioner.
size_t size() const
Returns the size of the system matrix.
Vue d'un tableau d'éléments de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Convenience wrapper around MPI_Comm.