FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_csr_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_CSR_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 MatVecMultCSRDense::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 Index rows, const Index cols, 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) || (alpha != DT_(1)))
29 {
30 const DT_ ba = DT_(1) / alpha;
31 FEAT_PRAGMA_OMP(parallel for)
32 for (Index col = 0 ; col < cols ; ++col)
33 {
34 r[col] = ba * y[col];
35 }
36 }
37
38 for (Index row(0) ; row < rows ; ++row)
39 {
40 for (Index i(row_ptr[row]) ; i < row_ptr[row+1] ; ++i)
41 {
42 r[col_idx[i]] += val[i] * x[row];
43 }
44 }
45
46 if(alpha != DT_(1))
47 {
48 FEAT_PRAGMA_OMP(parallel for)
49 for (Index col = 0 ; col < cols ; ++col)
50 {
51 r[col] = alpha * r[col];
52 }
53 }
54 }
55 else
56 {
57 if(y == nullptr)
58 {
59 FEAT_PRAGMA_OMP(parallel for schedule(static, 2000))
60 for (Index row = 0 ; row < rows ; ++row)
61 {
62 DT_ sum(0);
63 const IT_ end(row_ptr[row + 1]);
64 for (IT_ i = row_ptr[row] ; i < end ; ++i)
65 {
66 sum += val[i] * x[col_idx[i]];
67 }
68 r[row] = sum * alpha;
69 }
70 }
71 else
72 {
73 FEAT_PRAGMA_OMP(parallel for schedule(static, 2000))
74 for (Index row = 0 ; row < rows ; ++row)
75 {
76 DT_ sum(0);
77 const IT_ end(row_ptr[row + 1]);
78 for (IT_ i = row_ptr[row] ; i < end ; ++i)
79 {
80 sum += val[i] * x[col_idx[i]];
81 }
82 r[row] = y[row] + (sum * alpha);
83 }
84 }
85 }
86 }
87} // namespace FEAT::LAFEM::Arch
std::uint64_t Index
Index data type.