FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_bcsr_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_BCSR_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_, int bh_, int bw_>
15 void MatVecMultBCSRDense::exec_generic_impl(Tiny::Vector<DT_, bh_> * r, const DT_ alpha, const Tiny::Vector<DT_, bw_> * const x,
16 const Tiny::Vector<DT_, bh_> * const y, const Tiny::Matrix<DT_, bh_, bw_>* const val,
17 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index , const Index)
18 {
19 if(y != nullptr)
20 {
21 FEAT_PRAGMA_OMP(parallel for schedule(static, 2000))
22 for (Index row = 0 ; row < rows ; ++row)
23 {
24 Tiny::Vector<DT_, bh_> bsum(0);
25 const IT_ end(row_ptr[row + 1]);
26 for (IT_ i = row_ptr[row] ; i < end ; ++i)
27 {
28 bsum.add_mat_vec_mult(val[i], x[col_idx[i]]);
29 }
30 r[row] = y[row] + (alpha * bsum);
31 }
32 }
33 else
34 {
35 FEAT_PRAGMA_OMP(parallel for schedule(static, 2000))
36 for (Index row = 0 ; row < rows ; ++row)
37 {
38 Tiny::Vector<DT_, bh_> bsum(0);
39 const IT_ end(row_ptr[row + 1]);
40 for (IT_ i = row_ptr[row] ; i < end ; ++i)
41 {
42 bsum.add_mat_vec_mult(val[i], x[col_idx[i]]);
43 }
44 r[row] = alpha * bsum;
45 }
46 }
47 }
48
49 template <typename DT_, typename IT_, int bh_, int bw_>
50 void MatVecMultBCSRDense::exec_generic_transpose_impl(Tiny::Vector<DT_, bw_> * r, const DT_ alpha, const Tiny::Vector<DT_, bh_> * const x,
51 const Tiny::Vector<DT_, bw_> * const y, const Tiny::Matrix<DT_, bh_, bw_>* const val,
52 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index)
53 {
54 if(y == nullptr)
55 {
56 FEAT_PRAGMA_OMP(parallel for)
57 for (Index col = 0 ; col < cols ; ++col)
58 {
59 r[col] = DT_(0);
60 }
61 }
62 else if((r != y) || (alpha != DT_(1)))
63 {
64 const DT_ ba = DT_(1) / alpha;
65 FEAT_PRAGMA_OMP(parallel for)
66 for (Index col = 0 ; col < cols ; ++col)
67 {
68 r[col] = ba * y[col];
69 }
70 }
71
72 for (Index row = 0 ; row < rows ; ++row)
73 {
74 for (Index i(row_ptr[row]) ; i < row_ptr[row+1] ; ++i)
75 {
76 r[col_idx[i]].add_vec_mat_mult(x[row], val[i]);
77 }
78 }
79
80 if(alpha != DT_(1))
81 {
82 FEAT_PRAGMA_OMP(parallel for)
83 for (Index col = 0 ; col < cols ; ++col)
84 {
85 r[col] = alpha * r[col];
86 }
87 }
88 }
89} // namespace FEAT::LAFEM::Arch
std::uint64_t Index
Index data type.