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
Number of elements in the vector.
Distributed Matrix using message passing.
const T * data() const
Access to the root of the array without any protection.
Constant view of an array of type T.
Matrix class, to be used by user.
Interface of the message passing manager.
View of an array of elements of type T.
1D data vector with value semantics (STL style).
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)
allGather() message for serialization
Namespace for mathematical functions.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Sparse matrix stored in CSR (Compressed Sparse Row) format.
Convenience wrapper around MPI_Comm.