19#include "arccore/alina/BuiltinBackend.h"
20#include "arccore/alina/StaticMatrix.h"
21#include "arccore/alina/Adapters.h"
22#include "arccore/alina/DistributedMatrix.h"
23#include "arccore/alina/IO.h"
25#include "arccore/alina/Profiler.h"
32namespace math = Alina::math;
35void assemble(
int n,
int beg,
int end,
36 std::vector<int>& ptr,
37 std::vector<int>& col,
38 std::vector<Val>& val)
40 int chunk = end - beg;
43 ptr.reserve(chunk + 1);
46 col.reserve(chunk * 4);
48 val.reserve(chunk * 4);
50 for (
int j = beg, i = 0; j < end; ++j, ++i) {
53 val.push_back(-math::identity<Val>());
57 val.push_back(2 * math::identity<Val>());
61 val.push_back(-math::identity<Val>());
66 val.push_back(-0.1 * math::identity<Val>());
69 ptr.push_back(col.size());
77 using Rhs = math::rhs_of<Val>::type;
78 using ScalarRhs = math::scalar_of<Rhs>::type;
79 int nb_scalar_for_rhs =
sizeof(Rhs) /
sizeof(ScalarRhs);
85 int chunk_len = (n + comm.size - 1) / comm.size;
86 int chunk_beg = std::min(n, chunk_len * comm.rank);
87 int chunk_end = std::min(n, chunk_len * (comm.rank + 1));
88 int chunk = chunk_end - chunk_beg;
97 std::vector<Rhs> x(chunk);
98 std::vector<Rhs> y(chunk);
100 assemble(n, chunk_beg, chunk_end, ptr, col, val);
102 for (
int i = 0; i < chunk; ++i)
103 x[i] = math::constant<Rhs>(drand48());
108 Matrix A(comm, std::tie(chunk, ptr, col, val), chunk);
110 auto B = Alina::product(A, A);
111 B->move_to_backend();
113 Alina::backend::spmv(1, *B, x, 0, y);
119 Span<const ScalarRhs> scalar_x_view(
reinterpret_cast<ScalarRhs*
>(x.data()), x.size() * nb_scalar_for_rhs);
120 Span<const ScalarRhs> scalar_r_view(
reinterpret_cast<ScalarRhs*
>(y.data()), y.size() * nb_scalar_for_rhs);
124 if (comm.rank == 0) {
125 std::cout <<
"Doing verification size=" << scalarX.
size() <<
"\n";
126 Rhs* scalar_x_begin =
reinterpret_cast<Rhs*
>(scalarX.
data());
127 std::vector<Rhs> X(scalar_x_begin, scalar_x_begin + n);
129 Rhs* scalar_r_begin =
reinterpret_cast<Rhs*
>(scalarR.
data());
130 std::vector<Rhs> R(scalar_r_begin, scalar_r_begin + n);
132 std::vector<Rhs> Y(n);
133 assemble(n, 0, n, ptr, col, val);
136 Alina::backend::spmv(1, *product(A, A), X, 0, Y);
139 for (
int i = 0; i < n; ++i) {
140 double d = math::norm(R[i] - Y[i]);
143 std::cout <<
"Error: " << s << std::endl;
147int main(
int argc,
char* argv[])
149 MPI_Init(&argc, &argv);
152 test<Alina::StaticMatrix<double, 2, 2>>();
Integer size() const
Nombre d'éléments du vecteur.
Distributed Matrix using message passing.
const T * data() const
Accès à la racine du tableau hors toute protection.
Vue constante d'un tableau de type T.
Matrix class, to be used by user.
Interface du gestionnaire des échanges de messages.
Vue d'un tableau d'éléments de type T.
Vecteur 1D de données avec sémantique par valeur (style STL).
C void mpGatherVariable(IMessagePassingMng *pm, Span< const char > send_buf, Array< char > &recv_buf, Int32 rank)
void mpAllGather(IMessagePassingMng *pm, const ISerializer *send_serializer, ISerializer *receive_serialize)
Message allGather() pour une sérialisation.
Espace de nom pour les fonctions mathématiques.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Matrice creuse stockée au format CSR (Compressed Sparse Row).
Wrapper de commodité autour de MPI_Comm.