FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
scale_row_col_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#ifndef KERNEL_LAFEM_ARCH_SCALE_ROW_COL_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_SCALE_ROW_COL_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_SCALE_ROW_COL_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14#include <kernel/util/tiny_algebra.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
20 namespace Arch
21 {
22
23 template <typename DT_, typename IT_>
24 void ScaleRows::csr_generic(DT_ * r, const DT_ * const a, const IT_ * const /*col_ind*/,
25 const IT_ * const row_ptr, const DT_ * const x,
26 const Index rows, const Index, const Index)
27 {
28 FEAT_PRAGMA_OMP(parallel for)
29 for (Index row = 0 ; row < rows ; ++row)
30 {
31 const IT_ end(row_ptr[row + 1]);
32 for (IT_ i = row_ptr[row] ; i < end ; ++i)
33 {
34 r[i] = a[i] * x[row];
35 }
36 }
37 }
38
39 template <int bh_, int bw_, typename DT_, typename IT_>
40 void ScaleRows::bcsr_generic(DT_ * r, const DT_ * const a, const IT_ * const /*col_ind*/,
41 const IT_ * const row_ptr, const DT_ * const x,
42 const Index rows, const Index, const Index)
43 {
44
45 Tiny::Matrix<DT_, bh_, bw_> * const br(reinterpret_cast<Tiny::Matrix<DT_, bh_, bw_> *>(r));
46 const Tiny::Matrix<DT_, bh_, bw_> * const ba(reinterpret_cast<const Tiny::Matrix<DT_, bh_, bw_> *>(a));
47 const Tiny::Vector<DT_, bh_> * const bx(reinterpret_cast<const Tiny::Vector<DT_, bh_> *>(x));
48 FEAT_PRAGMA_OMP(parallel for)
49 for (Index row = 0 ; row < rows ; ++row)
50 {
51 const IT_ end(row_ptr[row + 1]);
52 for (IT_ i = row_ptr[row] ; i < end ; ++i)
53 {
54 for (int irow(0); irow < bh_; ++ irow )
55 {
56 for (int icol(0); icol < bw_; ++icol)
57 {
58 br[i][irow][icol] = ba[i][irow][icol] * bx[row][irow];
59 }
60 }
61 }
62 }
63 }
64
65 // ***********************************************
66
67 template <typename DT_, typename IT_>
68 void ScaleCols::csr_generic(DT_ * r, const DT_ * const a, const IT_ * const col_ind,
69 const IT_ * const row_ptr, const DT_ * const x,
70 const Index rows, const Index, const Index)
71 {
72 FEAT_PRAGMA_OMP(parallel for)
73 for (Index row = 0 ; row < rows ; ++row)
74 {
75 const IT_ end(row_ptr[row + 1]);
76 for (IT_ i = row_ptr[row] ; i < end ; ++i)
77 {
78 r[i] = a[i] * x[col_ind[i]];
79 }
80 }
81 }
82
83 template <int bh_, int bw_, typename DT_, typename IT_>
84 void ScaleCols::bcsr_generic(DT_ * r, const DT_ * const a, const IT_ * const col_ind,
85 const IT_ * const row_ptr, const DT_ * const x,
86 const Index rows, const Index, const Index)
87 {
88
89 Tiny::Matrix<DT_, bh_, bw_> * const br(reinterpret_cast<Tiny::Matrix<DT_, bh_, bw_> *>(r));
90 const Tiny::Matrix<DT_, bh_, bw_> * const ba(reinterpret_cast<const Tiny::Matrix<DT_, bh_, bw_> *>(a));
91 const Tiny::Vector<DT_, bw_> * const bx(reinterpret_cast<const Tiny::Vector<DT_, bw_> *>(x));
92 FEAT_PRAGMA_OMP(parallel for)
93 for (Index row = 0 ; row < rows ; ++row)
94 {
95 const IT_ end(row_ptr[row + 1]);
96 for (IT_ i = row_ptr[row] ; i < end ; ++i)
97 {
98 for (int irow = 0; irow < bh_; ++irow)
99 {
100 for (int icol = 0; icol < bw_; ++icol)
101 {
102 br[i][irow][icol] = ba[i][irow][icol] * bx[col_ind[i]][icol];
103 }
104 }
105 }
106 }
107 }
108
109 } // namespace Arch
110 } // namespace LAFEM
111} // namespace FEAT
112
113#endif // KERNEL_LAFEM_ARCH_SCALE_ROW_COL_GENERIC_HPP
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.