12#ifndef ARCCORE_ALINA_BACKENDINTERFACE_H
13#define ARCCORE_ALINA_BACKENDINTERFACE_H
30#include "arccore/alina/ValueTypeInterface.h"
31#include "arccore/alina/AlinaUtils.h"
36namespace Arcane::Alina::backend
71template <
class SBackend,
class PBackend>
76template <
class T,
class Enable =
void>
79 typedef typename T::value_type type;
83template <
class T,
class Enable =
void>
86 typedef typename T::col_type type;
90template <
class T,
class Enable =
void>
93 typedef typename T::ptr_type type;
103template <
class Matrix,
class Enable =
void>
106 static size_t get(
const Matrix& A)
118template <
class Matrix,
class Enable =
void>
121 static size_t get(
const Matrix& A)
134template <
class T,
class Enable =
void>
140 static auto get_impl(
const U& t,
int) ->
decltype(t.bytes())
147 static size_t get_impl(
const U&, ...)
152 static size_t get(
const T& t)
154 return get_impl(t, 0);
161template <
class Matrix,
class Enable =
void>
164 typedef typename Matrix::PTR_DATA_NOT_IMPLEMENTED type;
167template <
class Matrix,
class Enable =
void>
170 typedef typename Matrix::COL_DATA_NOT_IMPLEMENTED type;
173template <
class Matrix,
class Enable =
void>
176 typedef typename Matrix::VAL_DATA_NOT_IMPLEMENTED type;
186template <
class Matrix,
class Enable =
void>
189 static size_t get(
const Matrix& A)
202template <
class Matrix,
class Enable =
void>
205 typedef typename Matrix::ROW_NONZEROS_NOT_IMPLEMENTED type;
216template <
class Matrix,
class Enable =
void>
219 typedef typename Matrix::row_iterator type;
231template <
class Matrix,
class Enable =
void>
234 static typename row_iterator<Matrix>::type
235 get(
const Matrix& A,
size_t row)
237 return A.row_begin(row);
248template <
class Alpha,
class Matrix,
class Vector1,
class Beta,
class Vector2,
class Enable =
void>
251 typedef typename Matrix::SPMV_NOT_IMPLEMENTED type;
261template <
class Matrix,
class Vector1,
class Vector2,
class Vector3,
class Enable =
void>
264 typedef typename Matrix::RESIDUAL_NOT_IMPLEMENTED type;
272template <
class Vector,
class Enable =
void>
275 typedef typename Vector::CLEAR_NOT_IMPLEMENTED type;
283template <
class Vector1,
class Vector2,
class Enable =
void>
286 typedef typename Vector1::COPY_NOT_IMPLEMENTED type;
294template <
class Vector1,
class Vector2,
class Enable =
void>
297 typedef typename Vector1::INNER_PRODUCT_NOT_IMPLEMENTED type;
305template <
class A,
class Vector1,
class B,
class Vector2,
class Enable =
void>
308 typedef typename Vector1::AXPBY_NOT_IMPLEMENTED type;
316template <
class A,
class Vector1,
class B,
class Vector2,
class C,
class Vector3,
class Enable =
void>
319 typedef typename Vector1::AXPBYPCZ_NOT_IMPLEMENTED type;
327template <
class Alpha,
class Vector1,
class Vector2,
class Beta,
class Vector3,
class Enable =
void>
330 typedef typename Vector1::VMUL_NOT_IMPLEMENTED type;
336template <
class MatrixValue,
class Vector,
bool IsConst,
class Enable =
void>
339 typedef typename MatrixValue::REINTERPRET_AS_RHS_NOT_IMPLEMENTED type;
348template <
class Matrix>
351 return rows_impl<Matrix>::get(
matrix);
358template <
class Matrix>
361 return cols_impl<Matrix>::get(
matrix);
369size_t bytes(
const T& t)
371 return bytes_impl<T>::get(t);
377template <
class Matrix>
378typename ptr_data_impl<Matrix>::type
379ptr_data(
const Matrix& matrix)
381 return ptr_data_impl<Matrix>::get(matrix);
384template <
class Matrix>
385typename col_data_impl<Matrix>::type
386col_data(
const Matrix& matrix)
391template <
class Matrix>
392typename val_data_impl<Matrix>::type
393val_data(
const Matrix& matrix)
399template <
class Matrix>
400size_t nonzeros(
const Matrix& matrix)
402 return nonzeros_impl<Matrix>::get(matrix);
406template <
class Matrix>
407typename row_iterator<Matrix>::type
408row_begin(
const Matrix& matrix,
size_t row)
410 return row_begin_impl<Matrix>::get(matrix, row);
414template <
class Matrix>
415size_t row_nonzeros(
const Matrix& A,
size_t row)
427template <
class Alpha,
class Matrix,
class Vector1,
class Beta,
class Vector2>
428void spmv(Alpha alpha,
const Matrix& A,
const Vector1& x,
429 Beta beta, Vector2& y)
431 ARCCORE_ALINA_TIC(
"spmv");
433 ARCCORE_ALINA_TOC(
"spmv");
443template <
class Matrix,
class Vector1,
class Vector2,
class Vector3>
444void residual(
const Vector1& rhs,
const Matrix& A,
const Vector2& x, Vector3& r)
446 ARCCORE_ALINA_TIC(
"residual");
448 ARCCORE_ALINA_TOC(
"residual");
454template <
class Vector>
457 ARCCORE_ALINA_TIC(
"clear");
459 ARCCORE_ALINA_TOC(
"clear");
466template <
class Vector1,
class Vector2>
467void copy(
const Vector1& x, Vector2& y)
469 ARCCORE_ALINA_TIC(
"copy");
471 ARCCORE_ALINA_TOC(
"copy");
478template <
class Vector1,
class Vector2>
479typename math::inner_product_impl<typename value_type<Vector1>::type>::return_type
480inner_product(
const Vector1& x,
const Vector2& y)
482 typedef typename math::inner_product_impl<
483 typename value_type<Vector1>::type>::return_type result_type;
485 ARCCORE_ALINA_TIC(
"inner_product");
487 ARCCORE_ALINA_TOC(
"inner_product");
498template <
class A,
class Vector1,
class B,
class Vector2>
499void axpby(A a, Vector1
const& x, B b, Vector2& y)
501 ARCCORE_ALINA_TIC(
"axpby");
503 ARCCORE_ALINA_TOC(
"axpby");
513template <
class A,
class Vector1,
class B,
class Vector2,
class C,
class Vector3>
514void axpbypcz(A a, Vector1
const& x, B b, Vector2
const& y, C c, Vector3& z)
516 ARCCORE_ALINA_TIC(
"axpbypcz");
517 axpbypcz_impl<A, Vector1, B, Vector2, C, Vector3>::apply(a, x, b, y, c, z);
518 ARCCORE_ALINA_TOC(
"axpbypcz");
528template <
class Alpha,
class Vector1,
class Vector2,
class Beta,
class Vector3>
529void vmul(Alpha alpha,
const Vector1& x,
const Vector2& y, Beta beta, Vector3& z)
531 ARCCORE_ALINA_TIC(
"vmul");
533 ARCCORE_ALINA_TOC(
"vmul");
540template <
class MatrixValue,
class Vector>
542 typename std::decay<Vector>::type,
543 std::is_const<typename std::remove_reference<Vector>::type>::value>::return_type
544reinterpret_as_rhs(Vector&& x)
547 typename std::decay<Vector>::type,
548 std::is_const<typename std::remove_reference<Vector>::type>::value>::get(std::forward<Vector>(x));
555template <
class Backend,
template <
class>
class Relaxation,
class Enable =
void>
560template <
class Backend,
template <
class>
class Coarsening,
class Enable =
void>
571template <
class Coefs,
class Vecs,
class Coef,
class Vec>
572void lin_comb(
size_t n,
const Coefs& c,
const Vecs& v,
const Coef& alpha, Vec& y)
574 axpby(c[0], *v[0], alpha, y);
576 for (; i + 1 < n; i += 2)
577 axpbypcz(c[i], *v[i], c[i + 1], *v[i + 1], math::identity<Coef>(), y);
580 axpby(c[i], *v[i], math::identity<Coef>(), y);
588namespace Arcane::Alina::detail
593struct common_scalar_backend<B, B, typename std::enable_if<math::static_rows<typename B::value_type>::value == 1>::type>
Matrix class, to be used by user.
Implementation for linear combination of two vectors.
Implementation for linear combination of three vectors.
Metafunction that checks if two backends are compatible.
Implementation for function returning number of bytes allocated for a matrix/vector.
Implementation for zeroing out a vector.
Is the coarsening supported by the backend?
Metafunction that returns column type of a matrix.
Implementation for function returning the number of columns in a matrix.
Implementation for vector copy.
Implementation for inner product.
Implementation for function returning the number of nonzeros in a matrix.
Metafunction that returns pointer type of a matrix.
Reinterpret the vector to be compatible with the matrix value type.
Is the relaxation supported by the backend?
Implementation for residual error compuatation.
Implementation for function returning row iterator for a matrix.
Metafunction returning the row iterator type for a matrix type.
Implementation for function returning the number of nonzeros in a matrix row.
Implementation for function returning the number of rows in a matrix.
Implementation for matrix-vector product.
Metafunction that returns value type of a matrix or a vector type.
Implementation for element-wize vector product.