24struct is_integral_constant : std::false_type
27template <std::
integral U, U N>
28struct is_integral_constant<std::integral_constant<U, N>> : std::true_type
36concept BlockSizeArg = std::integral<std::remove_cvref_t<T>>
37 or is_integral_constant<std::remove_cvref_t<T>>::value;
69template <
int BS0,
int BS1,
typename OP,
typename U,
typename V,
typename W,
70 typename X,
typename Y>
71void insert_csr(U&& data,
const V& cols,
const W& row_ptr,
const X& x,
72 const Y& xrows,
const Y& xcols, OP op,
73 [[maybe_unused]]
typename Y::value_type num_rows)
75 const std::size_t nc = xcols.size();
76 assert(x.size() == xrows.size() * xcols.size() * BS0 * BS1);
77 for (std::size_t r = 0; r < xrows.size(); ++r)
81 using T =
typename X::value_type;
82 const T* xr = x.data() + r * nc * BS0 * BS1;
86 throw std::out_of_range(
"Local row out of range");
89 auto cit0 = std::next(cols.begin(), row_ptr[row]);
90 auto cit1 = std::next(cols.begin(), row_ptr[row + 1]);
91 for (std::size_t c = 0; c < nc; ++c)
94 auto it = std::lower_bound(cit0, cit1, xcols[c]);
95 if (it == cit1 or *it != xcols[c])
96 throw std::out_of_range(
"Entry not in sparsity");
98 std::size_t d = std::ranges::distance(cols.begin(), it);
99 std::size_t di = d * BS0 * BS1;
100 std::size_t xi = c * BS1;
101 assert(di < data.size());
102 for (
int i = 0; i < BS0; ++i)
104 for (
int j = 0; j < BS1; ++j)
105 op(data[di + j], xr[xi + j]);
134template <
int BS0,
int BS1,
typename OP,
typename U,
typename V,
typename W,
135 typename X,
typename Y>
137 const Y& xrows,
const Y& xcols, OP op,
138 [[maybe_unused]]
typename Y::value_type num_rows)
140 const std::size_t nc = xcols.size();
141 assert(x.size() == xrows.size() * xcols.size() * BS0 * BS1);
142 for (std::size_t r = 0; r < xrows.size(); ++r)
145 auto row = xrows[r] * BS0;
148 throw std::out_of_range(
"Local row out of range");
151 for (
int i = 0; i < BS0; ++i)
153 using T =
typename X::value_type;
154 const T* xr = x.data() + (r * BS0 + i) * nc * BS1;
157 auto cit0 = std::next(cols.begin(), row_ptr[row + i]);
158 auto cit1 = std::next(cols.begin(), row_ptr[row + i + 1]);
159 for (std::size_t c = 0; c < nc; ++c)
162 auto it = std::lower_bound(cit0, cit1, xcols[c] * BS1);
163 if (it == cit1 or *it != xcols[c] * BS1)
164 throw std::out_of_range(
"Entry not in sparsity");
166 std::size_t d = std::ranges::distance(cols.begin(), it);
167 assert(d < data.size());
168 std::size_t xi = c * BS1;
169 for (
int j = 0; j < BS1; ++j)
170 op(data[d + j], xr[xi + j]);
195template <
typename OP,
typename U,
typename V,
typename W,
typename X,
198 const X& x,
const Y& xrows,
const Y& xcols, OP op,
199 [[maybe_unused]]
typename Y::value_type num_rows,
202 const std::size_t nc = xcols.size();
203 const int nbs = bs0 * bs1;
205 assert(x.size() == xrows.size() * xcols.size());
206 for (std::size_t r = 0; r < xrows.size(); ++r)
209 auto rdiv = std::div(xrows[r], bs0);
210 using T =
typename X::value_type;
211 const T* xr = x.data() + r * nc;
214 if (rdiv.quot >= num_rows)
215 throw std::out_of_range(
"Local row out of range");
218 auto cit0 = std::next(cols.begin(), row_ptr[rdiv.quot]);
219 auto cit1 = std::next(cols.begin(), row_ptr[rdiv.quot + 1]);
220 for (std::size_t c = 0; c < nc; ++c)
223 auto cdiv = std::div(xcols[c], bs1);
224 auto it = std::lower_bound(cit0, cit1, cdiv.quot);
225 if (it == cit1 or *it != cdiv.quot)
226 throw std::out_of_range(
"Entry not in sparsity");
228 std::size_t d = std::ranges::distance(cols.begin(), it);
229 std::size_t di = d * nbs + rdiv.rem * bs1 + cdiv.rem;
230 assert(di < data.size());
262void spmv(std::span<const T> values, std::span<const std::int64_t> row_begin,
263 std::span<const std::int64_t> row_end,
264 std::span<const std::int32_t> indices, std::span<const T> x,
265 std::span<T> y, BlockSizeArg
auto bs0, BlockSizeArg
auto bs1)
267 assert(row_begin.size() == row_end.size());
271 for (
decltype(+bs0) k0 = 0; k0 < bs0; ++k0)
273 for (std::size_t i = 0; i < row_begin.size(); i++)
276 for (std::int64_t j = row_begin[i]; j < row_end[i]; j++)
278 for (
decltype(+bs1) k1 = 0; k1 < bs1; ++k1)
280 vi += values[j * bs0 * bs1 + k0 * bs1 + k1]
281 * x[indices[j] * bs1 + k1];
285 y[i * bs0 + k0] += vi;
322void spmvT(std::span<const T> values, std::span<const std::int64_t> row_begin,
323 std::span<const std::int64_t> row_end,
324 std::span<const std::int32_t> indices, std::span<const T> x,
325 std::span<T> y, BlockSizeArg
auto bs0, BlockSizeArg
auto bs1)
327 assert(row_begin.size() == row_end.size());
330 for (
decltype(+bs0) k0 = 0; k0 < bs0; ++k0)
332 for (std::size_t i = 0; i < row_begin.size(); i++)
334 const T xval = x[i * bs0 + k0];
335 for (std::int64_t j = row_begin[i]; j < row_end[i]; j++)
337 for (
decltype(+bs1) k1 = 0; k1 < bs1; ++k1)
339 y[indices[j] * bs1 + k1]
340 += values[j * bs0 * bs1 + k0 * bs1 + k1] * xval;
Fetch the rows of B that correspond to the ghost columns of A.
Definition matmul.h:39
void insert_csr(U &&data, const V &cols, const W &row_ptr, const X &x, const Y &xrows, const Y &xcols, OP op, typename Y::value_type num_rows)
Incorporate data into a CSR matrix.
Definition matrix_csr_impl.h:71
void spmv(std::span< const T > values, std::span< const std::int64_t > row_begin, std::span< const std::int64_t > row_end, std::span< const std::int32_t > indices, std::span< const T > x, std::span< T > y, BlockSizeArg auto bs0, BlockSizeArg auto bs1)
Sparse matrix-vector product implementation.
Definition matrix_csr_impl.h:262
void insert_blocked_csr(U &&data, const V &cols, const W &row_ptr, const X &x, const Y &xrows, const Y &xcols, OP op, typename Y::value_type num_rows)
Incorporate blocked data with given block sizes into a non-blocked MatrixCSR.
Definition matrix_csr_impl.h:136
void insert_nonblocked_csr(U &&data, const V &cols, const W &row_ptr, const X &x, const Y &xrows, const Y &xcols, OP op, typename Y::value_type num_rows, int bs0, int bs1)
Incorporate non-blocked data into a blocked matrix (data block size=1).
Definition matrix_csr_impl.h:197
void spmvT(std::span< const T > values, std::span< const std::int64_t > row_begin, std::span< const std::int64_t > row_end, std::span< const std::int32_t > indices, std::span< const T > x, std::span< T > y, BlockSizeArg auto bs0, BlockSizeArg auto bs1)
Sparse matrix-vector transpose product implementation.
Definition matrix_csr_impl.h:322
Linear algebra interface.
Definition dolfinx_la.h:7