10#include <arccore/collections/Array2.h>
12#include <alien/handlers/scalar/CSRModifierViewT.h>
16namespace Alien::SimpleCSRInternal
21template <
typename ValueT>
23: m_matrix_impl(matrix)
28template <
typename ValueT>
29void SimpleCSRMatrixMultT<ValueT>::synchronize(
VectorType& x)
const
31 if (m_matrix_impl.block()) {
32 if (m_matrix_impl.m_is_parallel)
35 else if (m_matrix_impl.vblock()) {
36 if (m_matrix_impl.m_is_parallel)
37 _synchronizeVariableBlock(x);
40 if (m_matrix_impl.m_is_parallel)
48template <
typename ValueT>
51 if (m_matrix_impl.block()) {
52 if (m_matrix_impl.m_is_parallel)
53 _parallelMultBlock(x, y);
57 else if (m_matrix_impl.vblock()) {
58 if (m_matrix_impl.m_is_parallel)
59 _parallelMultVariableBlock(x, y);
61 _seqMultVariableBlock(x, y);
64 if (m_matrix_impl.m_is_parallel)
71template <
typename ValueT>
74 if (m_matrix_impl.m_is_parallel)
75 lowerUpperSynchronize(x,
const_cast<VectorType&
>(x)) ;
77 _seqAddLMult(alpha, x, y);
79 if (m_matrix_impl.m_is_parallel)
80 _endDistAddLMult(alpha, x, y);
83template <
typename ValueT>
86 if (m_matrix_impl.m_is_parallel)
87 upperLowerSynchronize(x,
const_cast<VectorType&
>(x)) ;
89 _seqAddUMult(alpha, x, y);
91 if (m_matrix_impl.m_is_parallel)
92 _endDistAddUMult(alpha, x, y);
95template <
typename ValueT>
98 if (m_matrix_impl.m_is_parallel)
105template <
typename ValueT>
106void SimpleCSRMatrixMultT<ValueT>::lowerUpperSynchronize(
const VectorType& x_impl, VectorType& y_impl)
const
108 Real* x_ptr =
const_cast<Real*
>(x_impl.getDataPtr());
109 Real* y_ptr = y_impl.getDataPtr();
111 const Integer block_size = m_matrix_impl.blockSize();
114 m_matrix_impl.m_matrix_dist_info.m_send_info,
115 m_matrix_impl.m_send_policy,
117 m_matrix_impl.m_matrix_dist_info.m_recv_info,
118 m_matrix_impl.m_recv_policy,
119 m_matrix_impl.m_parallel_mng,
120 m_matrix_impl.m_trace,
128template <
typename ValueT>
129void SimpleCSRMatrixMultT<ValueT>::upperLowerSynchronize(
const VectorType& x_impl, VectorType& y_impl)
const
131 Real* x_ptr =
const_cast<Real*
>(x_impl.getDataPtr());
132 Real* y_ptr = y_impl.getDataPtr();
133 const Integer block_size = m_matrix_impl.blockSize();
136 m_matrix_impl.m_matrix_dist_info.m_send_info,
137 m_matrix_impl.m_send_policy,
139 m_matrix_impl.m_matrix_dist_info.m_recv_info,
140 m_matrix_impl.m_recv_policy,
141 m_matrix_impl.m_parallel_mng,
142 m_matrix_impl.m_trace,
149template <
typename ValueT>
150void SimpleCSRMatrixMultT<ValueT>::_synchronize(VectorType& x_impl)
const
152 Integer alloc_size = m_matrix_impl.m_local_size + m_matrix_impl.m_ghost_size;
153 x_impl.resize(alloc_size);
154 Real* x_ptr = (Real*)x_impl.getDataPtr();
155 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
156 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
157 ConstArrayView<Integer> row_offset =
158 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
160 m_matrix_impl.m_send_policy, x_ptr, m_matrix_impl.m_matrix_dist_info.m_recv_info,
161 m_matrix_impl.m_recv_policy, m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace);
166template <
typename ValueT>
167void SimpleCSRMatrixMultT<ValueT>::_parallelMult(
168const VectorType& x_impl, VectorType& y_impl)
const
170 Integer alloc_size = m_matrix_impl.m_local_size + m_matrix_impl.m_ghost_size;
171 x_impl.resize(alloc_size);
172 Real* y_ptr = y_impl.getDataPtr();
173 Real* x_ptr = (Real*)x_impl.getDataPtr();
174 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
177 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
178 ConstArrayView<Integer> row_offset =
179 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
181 m_matrix_impl.m_send_policy, x_ptr, m_matrix_impl.m_matrix_dist_info.m_recv_info,
182 m_matrix_impl.m_recv_policy, m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace);
184 ConstArrayView<Integer> local_row_size =
185 m_matrix_impl.m_matrix_dist_info.m_local_row_size;
186 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
187 Integer off = row_offset[irow];
188 Integer off2 = off + local_row_size[irow];
190 for (Integer j = off; j < off2; ++j) {
191 tmpy += matrix[j] * x_ptr[cols[j]];
197 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
198 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
199 for (Integer i = 0; i < interface_nrow; ++i) {
200 Integer irow = row_ids[i];
201 Integer off = row_offset[irow] + local_row_size[irow];
202 Integer off2 = row_offset[irow + 1];
204 for (Integer j = off; j < off2; ++j) {
205 tmpy += matrix[j] * x_ptr[cols[j]];
211template <
typename ValueT>
212void SimpleCSRMatrixMultT<ValueT>::_parallelMult(
213const UniqueArray<Real>& x_impl, UniqueArray<Real>& y_impl)
const
215 Real* y_ptr = dataPtr(y_impl);
216 Real* x_ptr = (Real*)dataPtr(x_impl);
217 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
218 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
219 ConstArrayView<Integer> row_offset =
220 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
222 m_matrix_impl.m_send_policy, x_ptr, m_matrix_impl.m_matrix_dist_info.m_recv_info,
223 m_matrix_impl.m_recv_policy, m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace);
225 ConstArrayView<Integer> local_row_size =
226 m_matrix_impl.m_matrix_dist_info.m_local_row_size;
227 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
228 Integer off = row_offset[irow];
229 Integer off2 = off + local_row_size[irow];
231 for (Integer j = off; j < off2; ++j) {
232 tmpy += matrix[j] * x_ptr[cols[j]];
238 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
239 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
240 for (Integer i = 0; i < interface_nrow; ++i) {
241 Integer irow = row_ids[i];
242 Integer off = row_offset[irow] + local_row_size[irow];
243 Integer off2 = row_offset[irow + 1];
245 for (Integer j = off; j < off2; ++j) {
246 tmpy += matrix[j] * x_ptr[cols[j]];
253template <
typename ValueT>
254void SimpleCSRMatrixMultT<ValueT>::_seqMult(
const VectorType& x_impl, VectorType& y_impl)
const
256#ifdef ALIEN_USE_PERF_TIMER
257 typename MatrixType::SentryType sentry(m_matrix_impl.timer(),
"CSR-SPMV");
259 Real* y_ptr = y_impl.getDataPtr();
260 Real* x_ptr = (Real*)x_impl.getDataPtr();
261 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
262 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
263 ConstArrayView<Integer> row_offset =
264 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
265 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
267 for (Integer j = row_offset[irow]; j < row_offset[irow + 1]; ++j) {
268 tmpy += matrix[j] * x_ptr[cols[j]];
274template <
typename ValueT>
275void SimpleCSRMatrixMultT<ValueT>::_seqAddLMult(Real alpha,
const VectorType& x_impl, VectorType& y_impl)
const
277#ifdef ALIEN_USE_PERF_TIMER
278 typename MatrixType::SentryType sentry(m_matrix_impl.timer(),
"CSR-AddLMult");
280 Real* y_ptr = y_impl.getDataPtr();
281 Real* x_ptr = (Real*)x_impl.getDataPtr();
282 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
283 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
284 ConstArrayView<Integer> row_offset = m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
285 auto diag_offset = m_matrix_impl.m_matrix.getCSRProfile().getUpperDiagOffset();
286 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
287 Real tmpy = y_ptr[irow];
288 for (Integer j = row_offset[irow]; j < diag_offset[irow]; ++j) {
289 tmpy += alpha * matrix[j] * x_ptr[cols[j]];
295template <
typename ValueT>
296void SimpleCSRMatrixMultT<ValueT>::_endDistAddLMult(Real alpha,
297 const VectorType& x_impl, VectorType& y_impl)
const
299 Real* y_ptr = y_impl.getDataPtr();
300 Real* x_ptr = (Real*)x_impl.getDataPtr();
301 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
302 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
303 ConstArrayView<Integer> row_offset = m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
304 ConstArrayView<Integer> local_row_size = m_matrix_impl.m_matrix_dist_info.m_local_row_size;
306 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
307 Integer first_upper_ghost_index = m_matrix_impl.m_matrix_dist_info.m_first_upper_ghost_index;
308 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
310 for (Integer i = 0; i < interface_nrow; ++i) {
311 Integer irow = row_ids[i];
312 Integer off = row_offset[irow] + local_row_size[irow];
313 Integer off2 = row_offset[irow + 1];
315 for (Integer j = off; j < off2; ++j) {
316 if(cols[j] < first_upper_ghost_index)
317 tmpy += matrix[j] * x_ptr[cols[j]];
319 y_ptr[irow] += alpha * tmpy;
323template <
typename ValueT>
324void SimpleCSRMatrixMultT<ValueT>::_seqAddUMult(Real alpha,
const VectorType& x_impl, VectorType& y_impl)
const
326#ifdef ALIEN_USE_PERF_TIMER
327 typename MatrixType::SentryType sentry(m_matrix_impl.timer(),
"CSR-AddUMult");
329 Real* y_ptr = y_impl.getDataPtr();
330 Real* x_ptr = (Real*)x_impl.getDataPtr();
331 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
332 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
333 ConstArrayView<Integer> row_offset = m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
334 auto diag_offset = m_matrix_impl.m_matrix.getCSRProfile().getUpperDiagOffset();
335 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
336 Real tmpy = y_ptr[irow];
337 for (Integer j = diag_offset[irow] + 1; j < row_offset[irow + 1]; ++j) {
338 tmpy += alpha * matrix[j] * x_ptr[cols[j]];
344template <
typename ValueT>
345void SimpleCSRMatrixMultT<ValueT>::_endDistAddUMult(Real alpha,
346 const VectorType& x_impl, VectorType& y_impl)
const
348 Real* y_ptr = y_impl.getDataPtr();
349 Real* x_ptr = (Real*)x_impl.getDataPtr();
350 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
351 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
352 ConstArrayView<Integer> row_offset = m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
353 ConstArrayView<Integer> local_row_size = m_matrix_impl.m_matrix_dist_info.m_local_row_size;
354 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
355 Integer first_upper_ghost_index = m_matrix_impl.m_matrix_dist_info.m_first_upper_ghost_index;
356 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
358 for (Integer i = 0; i < interface_nrow; ++i) {
359 Integer irow = row_ids[i];
360 Integer off = row_offset[irow] + local_row_size[irow];
361 Integer off2 = row_offset[irow + 1];
363 for (Integer j = off; j < off2; ++j) {
364 if(cols[j] >= first_upper_ghost_index)
365 tmpy += matrix[j] * x_ptr[cols[j]];
367 y_ptr[irow] += alpha * tmpy;
371template <
typename ValueT>
372void SimpleCSRMatrixMultT<ValueT>::_seqMult(
373const UniqueArray<Real>& x_impl, UniqueArray<Real>& y_impl)
const
375 Real* y_ptr = dataPtr(y_impl);
376 Real* x_ptr = (Real*)dataPtr(x_impl);
377 ConstArrayView<Real> matrix = m_matrix_impl.m_matrix.getValues();
378 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
379 ConstArrayView<Integer> row_offset =
380 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
381 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
383 for (Integer j = row_offset[irow]; j < row_offset[irow + 1]; ++j) {
384 tmpy += matrix[j] * x_ptr[cols[j]];
392template <
typename ValueT>
393void SimpleCSRMatrixMultT<ValueT>::_synchronizeBlock(VectorType& x)
const
395 Integer alloc_size = m_matrix_impl.m_local_size + m_matrix_impl.m_ghost_size;
396 const Integer block_size = m_matrix_impl.block()->size();
397 x.resize(alloc_size * block_size);
398 ConstArrayView<Real> x_ptr = x.fullValues();
399 Real
const* matrix = m_matrix_impl.m_matrix.getDataPtr();
400 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
401 ConstArrayView<Integer> row_offset =
402 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
403 SimpleCSRInternal::SendRecvOp<Real> op(x.getDataPtr(),
404 m_matrix_impl.m_matrix_dist_info.m_send_info, m_matrix_impl.m_send_policy,
405 (Real*)x.getDataPtr(), m_matrix_impl.m_matrix_dist_info.m_recv_info,
406 m_matrix_impl.m_recv_policy, m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace,
416template <
typename ValueT>
417void SimpleCSRMatrixMultT<ValueT>::_parallelMultBlock(
const VectorType& x, VectorType& y)
const
419 Integer alloc_size = m_matrix_impl.m_local_size + m_matrix_impl.m_ghost_size;
420 const Integer block_size = m_matrix_impl.block()->size();
421 x.resize(alloc_size * block_size);
422 ArrayView<Real> _y = y.fullValues();
423 ConstArrayView<Real> x_ptr = x.fullValues();
424 Real
const* matrix = m_matrix_impl.m_matrix.getDataPtr();
425 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
428 ConstArrayView<Integer> row_offset =
429 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
430 SimpleCSRInternal::SendRecvOp<Real> op(x.getDataPtr(),
431 m_matrix_impl.m_matrix_dist_info.m_send_info, m_matrix_impl.m_send_policy,
432 (Real*)x.getDataPtr(), m_matrix_impl.m_matrix_dist_info.m_recv_info,
433 m_matrix_impl.m_recv_policy, m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace,
436 ConstArrayView<Integer> local_row_size =
437 m_matrix_impl.m_matrix_dist_info.m_local_row_size;
438 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
439 ArrayView<Real> y_ptr = _y.subView(irow * block_size, block_size);
440 Integer off = row_offset[irow];
441 Integer off2 = off + local_row_size[irow];
442 Real
const* m = matrix + off * block_size * block_size;
443 for (Integer ieq = 0; ieq < block_size; ++ieq)
445 for (Integer jcol = off; jcol < off2; ++jcol) {
446 ConstArrayView<Real> ptr = x_ptr.subView(cols[jcol] * block_size, block_size);
447 for (Integer ieq = 0; ieq < block_size; ++ieq)
448 for (Integer iu = 0; iu < block_size; ++iu)
449 y_ptr[ieq] += m[iu + block_size * ieq] * ptr[iu];
450 m += block_size * block_size;
456 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
457 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
458 ArrayView<Real> y_ptr = _y;
459 for (Integer i = 0; i < interface_nrow; ++i) {
460 Integer irow = row_ids[i];
461 ArrayView<Real> yptr = y_ptr.subView(irow * block_size, block_size);
462 Integer off = row_offset[irow] + local_row_size[irow];
463 Integer off2 = row_offset[irow + 1];
464 Real
const* m = matrix + off * block_size * block_size;
465 for (Integer jcol = off; jcol < off2; ++jcol) {
466 ConstArrayView<Real> ptr = x_ptr.subView(cols[jcol] * block_size, block_size);
467 for (Integer ieq = 0; ieq < block_size; ++ieq)
468 for (Integer iu = 0; iu < block_size; ++iu)
469 yptr[ieq] += m[iu + block_size * ieq] * ptr[iu];
470 m += block_size * block_size;
477template <
typename ValueT>
478void SimpleCSRMatrixMultT<ValueT>::_seqMultBlock(
const VectorType& x, VectorType& y)
const
480 Real* y_ptr = y.getDataPtr();
481 Real
const* x_ptr = x.getDataPtr();
482 Real
const* matrix = m_matrix_impl.m_matrix.getDataPtr();
483 const Integer block_size = m_matrix_impl.block()->size();
484 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
485 ConstArrayView<Integer> row_offset = m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
487 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow)
489 Integer off = row_offset[irow];
490 Integer off2 = row_offset[irow + 1];
491 Real
const* m = matrix + off * block_size * block_size;
492 for (Integer ieq = 0; ieq < block_size; ++ieq)
494 for (Integer jcol = off; jcol < off2; ++jcol)
496 Real
const* ptr = x_ptr + cols[jcol] * block_size;
497 for (Integer ieq = 0; ieq < block_size; ++ieq)
498 for (Integer iu = 0; iu < block_size; ++iu)
499 yptr[ieq] += m[iu + block_size * ieq] * ptr[iu];
500 m += block_size * block_size;
542template <
typename ValueT>
543void SimpleCSRMatrixMultT<ValueT>::_synchronizeVariableBlock(VectorType& x_impl)
const
547 ConstArrayView<Integer> block_sizes = m_matrix_impl.getDistStructInfo().m_block_sizes;
548 ConstArrayView<Integer> block_offsets = m_matrix_impl.getDistStructInfo().m_block_offsets;
550 const Integer last = block_offsets.size() - 1;
551 x_impl.resize(block_offsets[last]);
554 const ValueT* x_ptr = x_impl.getDataPtr();
555 const ValueT* matrix_ptr = m_matrix_impl.m_matrix.getDataPtr();
557 ConstArrayView<Integer> row_offset =
558 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
559 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
560 ConstArrayView<Integer> block_cols =
561 m_matrix_impl.m_matrix.getCSRProfile().getBlockCols();
564 m_matrix_impl.m_send_policy, (ValueT*)x_ptr,
565 m_matrix_impl.m_matrix_dist_info.m_recv_info, m_matrix_impl.m_recv_policy,
566 m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace, block_sizes, block_offsets);
576template <
typename ValueT>
577void SimpleCSRMatrixMultT<ValueT>::_parallelMultVariableBlock(
578const VectorType& x_impl, VectorType& y_impl)
const
582 ArrayView<ValueT> y = y_impl.fullValues();
584 ConstArrayView<Integer> block_sizes = m_matrix_impl.getDistStructInfo().m_block_sizes;
585 ConstArrayView<Integer> block_offsets = m_matrix_impl.getDistStructInfo().m_block_offsets;
587 const Integer last = block_offsets.size() - 1;
588 x_impl.resize(block_offsets[last]);
591 const ValueT* x_ptr = x_impl.getDataPtr();
592 const ValueT* matrix_ptr = m_matrix_impl.m_matrix.getDataPtr();
594 ConstArrayView<Integer> row_offset =
595 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
596 ConstArrayView<Integer> cols = m_matrix_impl.getDistStructInfo().m_cols;
597 ConstArrayView<Integer> block_cols =
598 m_matrix_impl.m_matrix.getCSRProfile().getBlockCols();
601 m_matrix_impl.m_send_policy, (ValueT*)x_ptr,
602 m_matrix_impl.m_matrix_dist_info.m_recv_info, m_matrix_impl.m_recv_policy,
603 m_matrix_impl.m_parallel_mng, m_matrix_impl.m_trace, block_sizes, block_offsets);
607 UniqueArray<ValueT> tmpy;
608 tmpy.reserve(m_matrix_impl.vblock()->maxBlockSize());
610 ConstArrayView<Integer> local_row_size =
611 m_matrix_impl.m_matrix_dist_info.m_local_row_size;
612 for (Integer irow = 0; irow < m_matrix_impl.m_local_size; ++irow) {
613 Integer off = row_offset[irow];
614 Integer off2 = off + local_row_size[irow];
615 const Integer block_size_row = block_sizes[irow];
616 tmpy.resize(block_size_row);
618 for (Integer j = off; j < off2; ++j) {
619 const Integer col = cols[j];
620 const Integer block_size_col = block_sizes[col];
621 ConstArrayView<ValueT> x(block_size_col, x_ptr + block_offsets[col]);
622 ConstArray2View<ValueT> matrix(
623 matrix_ptr + block_cols[j], block_size_row, block_size_col);
624 for (Integer krow = 0; krow < block_size_row; ++krow) {
625 for (Integer kcol = 0; kcol < block_size_col; ++kcol) {
626 tmpy[krow] += matrix[krow][kcol] * x[kcol];
630 y.subView(block_offsets[irow], block_size_row).copy(tmpy);
635 Integer interface_nrow = m_matrix_impl.m_matrix_dist_info.m_interface_nrow;
636 ConstArrayView<Integer> row_ids = m_matrix_impl.m_matrix_dist_info.m_interface_rows;
637 for (Integer i = 0; i < interface_nrow; ++i) {
638 Integer irow = row_ids[i];
639 Integer off = row_offset[irow] + local_row_size[irow];
640 Integer off2 = row_offset[irow + 1];
641 const Integer block_size_row = block_sizes[irow];
642 tmpy.resize(block_size_row);
644 for (Integer j = off; j < off2; ++j) {
645 const Integer col = cols[j];
646 const Integer block_size_col = block_sizes[col];
647 ConstArrayView<ValueT> x(block_size_col, x_ptr + block_offsets[col]);
648 ConstArray2View<ValueT> matrix(
649 matrix_ptr + block_cols[j], block_size_row, block_size_col);
650 for (Integer krow = 0; krow < block_size_row; ++krow) {
651 for (Integer kcol = 0; kcol < block_size_col; ++kcol) {
652 tmpy[krow] += matrix[krow][kcol] * x[kcol];
656 ArrayView<ValueT> y_view = y.subView(block_offsets[irow], block_size_row);
657 for (Integer k = 0; k < block_size_row; ++k)
658 y_view[k] += tmpy[k];
664template <
typename ValueT>
665void SimpleCSRMatrixMultT<ValueT>::_seqMultVariableBlock(
666const VectorType& x_impl, VectorType& y_impl)
const
670 ArrayView<ValueT> y = y_impl.fullValues();
672 const ValueT* x_ptr = x_impl.getDataPtr();
673 const ValueT* matrix_ptr = m_matrix_impl.m_matrix.getDataPtr();
675 ConstArrayView<Integer> row_offset =
676 m_matrix_impl.m_matrix.getCSRProfile().getRowOffset();
677 ConstArrayView<Integer> cols = m_matrix_impl.m_matrix.getCSRProfile().getCols();
678 ConstArrayView<Integer> block_cols =
679 m_matrix_impl.m_matrix.getCSRProfile().getBlockCols();
680 const VBlock* block = m_matrix_impl.vblock();
681 const VBlockImpl& block_infos = x_impl.vblockImpl();
683 UniqueArray<ValueT> tmpy;
684 tmpy.reserve(block->maxBlockSize());
685 for (Integer irow = 0; irow < m_matrix_impl.m_local_size;
688 const Integer block_size_row = block->size(irow);
689 tmpy.resize(block_size_row);
691 for (Integer j = row_offset[irow]; j < row_offset[irow + 1]; ++j) {
692 const Integer col = cols[j];
693 const Integer block_size_col = block->size(col);
694 ConstArrayView<ValueT> x(block_size_col, x_ptr + block_infos.offset(col));
695 ConstArray2View<ValueT> matrix(
696 matrix_ptr + block_cols[j], block_size_row, block_size_col);
697 for (Integer krow = 0; krow < block_size_row; ++krow) {
698 for (Integer kcol = 0; kcol < block_size_col; ++kcol) {
699 tmpy[krow] += matrix[krow][kcol] * x[kcol];
703 y.subView(block_infos.offset(irow), block_size_row).copy(tmpy);
708template <
typename ValueT>
709void SimpleCSRMatrixMultT<ValueT>::multDiag(VectorType& y)
const
711 Real* y_ptr = y.getDataPtr();
712 CSRConstViewT<MatrixType> view(m_matrix_impl);
714 auto nrows = view.nrows() ;
715 auto kcol = view.kcol() ;
716 auto dcol = view.dcol() ;
717 auto cols = view.cols() ;
718 auto values = view.data() ;
720 for (std::size_t irow = 0; irow < nrows; ++irow)
721 y_ptr[irow] = y_ptr[irow] * values[dcol[irow]];
724template <
typename ValueT>
725void SimpleCSRMatrixMultT<ValueT>::multInvDiag(VectorType& y)
const
727 Real* y_ptr = y.getDataPtr();
728 CSRConstViewT<MatrixType> view(m_matrix_impl);
730 auto nrows = view.nrows() ;
731 auto kcol = view.kcol() ;
732 auto dcol = view.dcol() ;
733 auto cols = view.cols() ;
734 auto values = view.data() ;
736 for (std::size_t irow = 0; irow < nrows; ++irow)
737 y_ptr[irow] = y_ptr[irow] / values[dcol[irow]];
740template <
typename ValueT>
741void SimpleCSRMatrixMultT<ValueT>::computeDiag(VectorType& y)
const
743 Real* y_ptr = y.getDataPtr();
745 CSRConstViewT<MatrixType> view(m_matrix_impl);
747 auto nrows = view.nrows() ;
748 auto kcol = view.kcol() ;
749 auto dcol = view.dcol() ;
750 auto cols = view.cols() ;
751 auto values = view.data() ;
753 if(m_matrix_impl.blockSize()==1)
755 for (std::size_t irow = 0; irow < nrows; ++irow)
756 y_ptr[irow] = values[dcol[irow]];
760 Integer block_size = m_matrix_impl.blockSize();
761 Integer block2_size = block_size*block_size ;
762 for (std::size_t irow = 0; irow < nrows; ++irow)
764 for(Integer ieq=0;ieq<block_size;++ieq)
765 y_ptr[irow*block_size+ieq] = values[dcol[irow]*block2_size+ieq*block_size+ieq];
770template <
typename ValueT>
771void SimpleCSRMatrixMultT<ValueT>::computeInvDiag(VectorType& y)
const
773 Real* y_ptr = y.getDataPtr();
775 CSRConstViewT<MatrixType> view(m_matrix_impl);
777 auto nrows = view.nrows() ;
778 auto kcol = view.kcol() ;
779 auto dcol = view.dcol() ;
780 auto cols = view.cols() ;
781 auto values = view.data() ;
783 if(m_matrix_impl.blockSize()==1)
785 for (std::size_t irow = 0; irow < nrows; ++irow)
786 y_ptr[irow] = 1. / values[dcol[irow]];
790 Integer block_size = m_matrix_impl.blockSize();
791 Integer block2_size = block_size*block_size ;
792 for (std::size_t irow = 0; irow < nrows; ++irow)
794 for(Integer ieq=0;ieq<block_size;++ieq)
796 y_ptr[irow*block_size+ieq] = 1. / values[dcol[irow]*block2_size+ieq*block_size+ieq];
SimpleCSRMatrixMultT(const MatrixType &matrix)
Constructeur de la classe.
void mult(const VectorType &x, VectorType &y) const
Matrix vector product.