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"
25#include "arccore/concurrency/Mutex.h"
55 x.iterations = r.nbIteration();
56 x.residual = r.residual();
85 m_p->m_properties.put(name, value);
91 m_p->m_properties.put(name, value);
97 m_p->m_properties.put(name, value);
101setString(
const char* name,
const char* value)
103 m_p->m_properties.put(name, value);
109 Params& p = m_p->m_properties;
119 Int32 nb_row = nbRow();
120 Int32 n1 = m_row_indexes.size();
121 if (n1 != (nb_row + 1))
122 ARCCORE_FATAL(
"Bad size '{0}' for rowIndexes() (expected value = {1})",n1, nb_row+1);
123 Int32 nb_value = m_row_indexes[nb_row];
124 Int32 n2 = m_columns.size();
125 Int32 n3 = m_values.size();
127 ARCCORE_FATAL(
"Bad size '{0}' for columns() (expected value = {1})",n2, nb_value);
129 ARCCORE_FATAL(
"Bad size '{0}' for values() (expected value = {1})",n3, nb_value);
135class AlinaPreconditionerImpl
139 explicit AlinaPreconditionerImpl(PreconditionerType* preconditioner)
140 : m_preconditioner(preconditioner)
142 ~AlinaPreconditionerImpl()
144 delete m_preconditioner;
147 PreconditionerType* m_preconditioner =
nullptr;
154AlinaPreconditioner(
int n,
164 auto A = std::make_tuple(n, ptr_range, col_range, val_range);
166 PreconditionerType* amg =
nullptr;
168 amg =
new PreconditionerType(A, prm->m_p->m_properties);
170 amg =
new PreconditionerType(A);
171 m_p = std::make_shared<AlinaPreconditionerImpl>(amg);
178apply(
const double* rhs,
double* x)
180 PreconditionerType* amg = m_p->m_preconditioner;
182 size_t n = Alina::backend::nbRow(amg->system_matrix());
187 amg->apply(rhs_range, x_range);
196 std::cout << *(m_p->m_preconditioner) << std::endl;
205struct AlinaSequentialSolverImpl
207 explicit AlinaSequentialSolverImpl(SequentialSolverType* solver)
210 ~AlinaSequentialSolverImpl()
214 SequentialSolverType* m_solver =
nullptr;
225 auto A = std::make_tuple(matrix_view.nbRow(), matrix_view.rowIndexes(),
226 matrix_view.columns(), matrix_view.values());
228 auto* solver =
new SequentialSolverType(A);
230 solver =
new SequentialSolverType(A, prm->m_p->m_properties);
232 solver =
new SequentialSolverType(A);
233 std::cout <<
"Printing solver infos\n";
234 std::cout << (*solver) << std::endl;
236 solver->prm.get(ptree);
237 std::cout <<
"SOLVER_PARAMS: " << ptree <<
"\n";
238 m_p = std::make_shared<AlinaSequentialSolverImpl>(solver);
247 SequentialSolverType* slv = m_p->m_solver;
249 std::cout << slv->
precond() << std::endl;
258 SequentialSolverType* slv = m_p->m_solver;
262 return _toConvInfo(r);
273 SequentialSolverType* slv = m_p->m_solver;
275 Int32 n = slv->
size();
278 if (n != matrix_view.nbRow())
279 ARCCORE_FATAL(
"Bad number of rows v={0} expected={1}", matrix_view.nbRow(), n);
281 auto A = std::make_tuple(matrix_view.nbRow(), matrix_view.rowIndexes(),
282 matrix_view.columns(), matrix_view.values());
286 return _toConvInfo(r);
292struct deflation_vectors
295 AlinaDefVecFunction user_func;
298 deflation_vectors(
int n, AlinaDefVecFunction user_func,
void* user_data)
300 , user_func(user_func)
301 , user_data(user_data)
304 int dim()
const {
return n; }
306 double operator()(
int i, ptrdiff_t j)
const
308 return user_func(i, j, user_data);
316class AlinaDistributedSolverImpl
320 explicit AlinaDistributedSolverImpl(DistributedSolverType* solver)
323 ~AlinaDistributedSolverImpl()
327 DistributedSolverType* m_solver =
nullptr;
341 AlinaDefVecFunction def_vec_func,
345 std::function<double(ptrdiff_t,
unsigned)> dv =
deflation_vectors(n_def_vec, def_vec_func, def_vec_data);
347 prm.put(
"num_def_vec", n_def_vec);
348 prm.put(
"def_vec", &dv);
351 auto A = std::make_tuple(matrix_view.nbRow(), matrix_view.rowIndexes(),
352 matrix_view.columns(), matrix_view.values());
355 auto* p =
new DistributedSolverType(mpi_comm, A, prm);
357 m_p = std::make_shared<AlinaDistributedSolverImpl>(p);
366 DistributedSolverType* solver = m_p->m_solver;
368 size_t n = solver->size();
374 return _toConvInfo(r);
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
CSR Matrix view used in AlinaLib.
void checkSizes() const
Check that sizes are valid:
AlinaConvergenceInfo solve(Arcane::SmallSpan< const double > rhs, Arcane::SmallSpan< double > x)
Find solution for the given RHS.
AlinaDistributedSolver(MPI_Comm comm, const AlinaCSRMatrixView &matrix_view, int n_def_vec, AlinaDefVecFunction def_vec_func, void *def_vec_data, const AlinaParameters ¶ms)
Create distributed solver.
Handle parameters for Alina.
void setInt64(const char *name, Arcane::Int64 value)
Set Int64 parameter in the parameter list.
void setInt32(const char *name, Arcane::Int32 value)
Set Int32 parameter in the parameter list.
void setReal(const char *name, Arcane::Real value)
Set floating point parameter in the parameter list.
void readFromJSON(const char *fname)
Read parameters from a JSON file.
void setString(const char *name, const char *value)
Set floating point parameter in the parameter list.
void report()
Printout preconditioner structure.
void apply(const double *rhs, double *x)
Apply AMG preconditioner (x = M^(-1) * rhs).
void report()
Printout solver structure.
AlinaConvergenceInfo solve(Arcane::SmallSpan< const double > rhs, Arcane::SmallSpan< double > x)
Solve the problem for the given right-hand side.
AlinaSequentialSolver(const AlinaCSRMatrixView &matrix_view, const AlinaParameters *parameters)
Build a solver for matrix matrix.
AlinaConvergenceInfo solveMatrix(const AlinaCSRMatrixView &matrix_view, Arcane::SmallSpan< const double > rhs, Arcane::SmallSpan< double > x)
Solve the problem for the given matrix and the right-hand side.
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.
Class to store parameters as a hierarchical key/value tree.
View of an array of elements of type T.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.
Convenience wrapper around MPI_Comm.