12#ifndef ARCCORE_ALINA_BLOCKCSRBACKEND_H
13#define ARCCORE_ALINA_BLOCKCSRBACKEND_H
26#include "arccore/alina/AlinaUtils.h"
27#include "arccore/alina/ValueTypeInterface.h"
28#include "arccore/alina/BuiltinBackend.h"
29#include "arccore/alina/SkylineLUSolver.h"
30#include "arccore/alina/BlockCSRMatrix.h"
38namespace Arcane::Alina::backend
49template <
typename real>
53 typedef real value_type;
54 typedef BuiltinBackendType::ptr_type index_type;
55 typedef BuiltinBackendType::col_type col_type;
56 typedef BuiltinBackendType::ptr_type ptr_type;
59 typedef typename BuiltinBackend<real>::vector vector;
60 typedef typename BuiltinBackend<real>::vector matrix_diagonal;
77 : ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p, block_size)
79 p.check_params( {
"block_size" });
83 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path, block_size);
87 static std::string name() {
return "block_crs"; }
90 static std::shared_ptr<matrix>
91 copy_matrix(std::shared_ptr<
typename BuiltinBackend<real>::matrix> A,
94 return std::make_shared<matrix>(*A, prm.
block_size);
98 static std::shared_ptr<vector>
101 return std::make_shared<vector>(x);
104 static std::shared_ptr<vector>
107 return std::make_shared<vector>(x);
111 static std::shared_ptr<vector>
118 static std::shared_ptr<vector>
121 return std::make_shared<vector>(size);
124 static std::shared_ptr<direct_solver>
125 create_solver(std::shared_ptr<
typename BuiltinBackend<real>::matrix> A,
128 return std::make_shared<direct_solver>(*A);
135template <
typename V,
typename C,
typename P>
144template <
typename V,
typename C,
typename P>
153template <
typename V,
typename C,
typename P>
158 return A.ptr.back() * A.block_size * A.block_size;
165template <
typename Alpha,
typename Beta,
typename V,
typename C,
typename P,
class Vec1,
class Vec2>
170 static void apply(Alpha alpha,
const matrix& A,
const Vec1& x, Beta beta, Vec2& y)
172 const size_t nb = A.brows;
173 const size_t na = A.nrows;
174 const size_t ma = A.ncols;
175 const size_t b1 = A.block_size;
176 const size_t b2 = b1 * b1;
178 if (!math::is_zero(beta)) {
181 for (ptrdiff_t i = begin; i < (begin + size); ++i) {
192 for (ptrdiff_t ib = begin; ib < (begin + size); ++ib) {
193 for (P jb = A.ptr[ib], eb = A.ptr[ib + 1]; jb < eb; ++jb) {
194 size_t x0 = A.col[jb] * b1;
196 block_prod(b1, std::min(b1, ma - x0), std::min(b1, na - y0),
197 alpha, &A.val[jb * b2], &x[x0], &y[y0]);
203 static void block_prod(
size_t dim,
size_t nx,
size_t ny,
204 Alpha alpha,
const V* A,
const V* x, V* y)
206 for (
size_t i = 0; i < ny; ++i, ++y) {
209 for (
size_t j = 0; j < dim; ++j, ++A, ++xx)
220template <
typename V,
typename C,
typename P,
class Vec1,
class Vec2,
class Vec3>
225 static void apply(
const Vec1& rhs,
const matrix& A,
const Vec2& x, Vec3& r)
227 typedef typename math::scalar_of<V>::type S;
228 const auto one = math::identity<S>();
229 backend::copy(rhs, r);
230 backend::spmv(-one, A, x, one, r);
Direct solver that uses Skyline LU factorization.
Informations d'exécution d'une boucle.
void arccoreParallelFor(const ComplexForLoopRanges< RankValue > &loop_ranges, const ForLoopRunInfo &run_info, const LambdaType &lambda_function, const ReducerArgs &... reducer_args)
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération donné par loo...
std::int32_t Int32
Type entier signé sur 32 bits.
Sparse matrix in Block CSR format.
Int32 block_size
Block size to use with the created matrices.
BlockCSRBackend backend definition.
static std::shared_ptr< vector > create_vector(size_t size, const params &)
Create vector of the specified size.
static std::shared_ptr< vector > copy_vector(std::shared_ptr< vector > x, const params &)
Copy vector from builtin backend.
static std::shared_ptr< matrix > copy_matrix(std::shared_ptr< typename BuiltinBackend< real >::matrix > A, const params &prm)
Copy matrix from builtin backend.
static std::shared_ptr< vector > copy_vector(const vector &x, const params &)
Copy vector from builtin backend.
Implementation for function returning the number of columns in a matrix.
Implementation for function returning the number of nonzeros in a matrix.
Implementation for residual error compuatation.
Implementation for function returning the number of rows in a matrix.
Implementation for matrix-vector product.