FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_cscr_dense_generic.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#ifndef KERNEL_LAFEM_ARCH_MATVECMULT_CSCR_DENSE_HPP
9#error "Do not include this implementation-only header file directly!"
10#endif
11
12namespace FEAT::LAFEM::Arch
13{
14 template <typename DT_, typename IT_>
15 void MatVecMultCSCRDense::exec_generic_impl(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val,
16 const IT_ * const col_idx, const IT_ * const row_ptr, const IT_ * const row_idx, const Index rows, const Index cols, const Index nonzero_rows, const Index, const bool transposed)
17 {
18 if (transposed)
19 {
20 if(y == nullptr)
21 {
22 FEAT_PRAGMA_OMP(parallel for)
23 for (Index col = 0 ; col < cols ; ++col)
24 {
25 r[col] = DT_(0);
26 }
27 }
28 else if(r != y)
29 {
30 FEAT_PRAGMA_OMP(parallel for)
31 for (Index col = 0 ; col < cols ; ++col)
32 {
33 r[col] = y[col];
34 }
35 }
36
37 for (Index nzrow(0) ; nzrow < nonzero_rows ; ++nzrow)
38 {
39 const Index row(row_idx[nzrow]);
40 for (Index i(row_ptr[nzrow]) ; i < row_ptr[nzrow+1] ; ++i)
41 {
42 r[col_idx[i]] += alpha * val[i] * x[row];
43 }
44 }
45 }
46 else
47 {
48 if(y == nullptr)
49 {
50 FEAT_PRAGMA_OMP(parallel for)
51 for (Index row = 0 ; row < rows ; ++row)
52 {
53 r[row] = DT_(0);
54 }
55 }
56 else if(r != y)
57 {
58 FEAT_PRAGMA_OMP(parallel for)
59 for (Index row = 0 ; row < rows ; ++row)
60 {
61 r[row] = y[row];
62 }
63 }
64
65 FEAT_PRAGMA_OMP(parallel for schedule(static, 2000))
66 for (Index nzrow = 0 ; nzrow < nonzero_rows ; ++nzrow)
67 {
68 const Index row(row_idx[nzrow]);
69 DT_ sum(0);
70 const IT_ end(row_ptr[nzrow + 1]);
71 for (IT_ i = row_ptr[nzrow] ; i < end ; ++i)
72 {
73 sum += val[i] * x[col_idx[i]];
74 }
75 r[row] += sum * alpha;
76 }
77 }
78 }
79} // namespace FEAT::LAFEM::Arch
std::uint64_t Index
Index data type.