FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
row_norm_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_ROW_NORM_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_ROW_NORM_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_ROW_NORM_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14#include <kernel/util/math.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
20 namespace Arch
21 {
22 template <typename DT_, typename IT_>
23 void RowNorm::csr_generic_norm2(DT_* row_norms, const DT_* const val, const IT_* const /*col_ind*/,
24 const IT_* const row_ptr, const Index rows)
25 {
26 FEAT_PRAGMA_OMP(parallel for)
27 for (Index row = 0; row < rows; row++)
28 {
29 Index end = row_ptr[row + 1];
30 DT_ norm(0);
31
32 // Manually compute norm2 of row
33 for (Index col = row_ptr[row]; col < end; col++)
34 {
35 norm += Math::sqr(val[col]);
36 }
37
38 // Take the square root
39 row_norms[row] = Math::sqrt(norm);
40 }
41 }
42
43 template <typename DT_, typename IT_>
44 void RowNorm::csr_generic_norm2sqr(DT_* row_norms, const DT_* const val,
45 const IT_* const /*col_ind*/, const IT_* const row_ptr, const Index rows)
46 {
47 FEAT_PRAGMA_OMP(parallel for)
48 for (Index row = 0; row < rows; row++)
49 {
50 Index end = row_ptr[row + 1];
51 DT_ norm(0);
52
53 // Manually compute norm2 of row
54 for (Index col = row_ptr[row]; col < end; col++)
55 {
56 norm += Math::sqr(val[col]);
57 }
58 // Do not take the square root
59 row_norms[row] = norm;
60 }
61 }
62
63 template <typename DT_, typename IT_>
64 void RowNorm::csr_generic_scaled_norm2sqr(DT_* row_norms, const DT_* const scal,
65 const DT_* const val, const IT_* const /*col_ind*/, const IT_* const row_ptr, const Index rows)
66 {
67 FEAT_PRAGMA_OMP(parallel for)
68 for (Index row = 0; row < rows; row++)
69 {
70 Index end = row_ptr[row + 1];
71 DT_ norm(0);
72
73 // Manually compute norm2 of row
74 for (Index col = row_ptr[row]; col < end; col++)
75 {
76 norm += scal[row]*Math::sqr(val[col]);
77 }
78 // Do not take the square root
79 row_norms[row] = norm;
80 }
81 }
82
83 template <typename DT_, typename IT_>
84 void RowNorm::bcsr_generic_norm2(DT_* row_norms, const DT_* const val, const IT_* const /*col_ind*/,
85 const IT_* const row_ptr, const Index rows, const int BlockHeight, const int BlockWidth)
86 {
87 Index block_height = Index(BlockHeight);
88 Index block_width = Index(BlockWidth);
89
90 FEAT_PRAGMA_OMP(parallel for)
91 for (Index row = 0; row < rows; row++)
92 {
93 Index end = row_ptr[row + 1];
94
95 for(Index i = 0; i < block_height; ++i)
96 {
97 row_norms[block_height*row + i] = DT_(0);
98 }
99
100 for (Index col = row_ptr[row]; col < end; col++)
101 {
102 // Manually compute norm2 of row
103 for(Index i = 0; i < block_height; ++i)
104 {
105 for(Index j = 0; j < block_width; ++j)
106 {
107 row_norms[block_height*row + i] += Math::sqr(val[block_height*block_width*col + i*block_width + j]);
108 }
109 // Take the square root
110 row_norms[block_height*row + i] = Math::sqrt(row_norms[block_height*row + i]);
111 }
112 }
113 }
114 }
115
116 template <typename DT_, typename IT_>
117 void RowNorm::bcsr_generic_norm2sqr(DT_* row_norms, const DT_* const val,
118 const IT_* const /*col_ind*/, const IT_* const row_ptr, const Index rows,
119 const int BlockHeight, const int BlockWidth)
120 {
121 Index block_height = Index(BlockHeight);
122 Index block_width = Index(BlockWidth);
123
124 FEAT_PRAGMA_OMP(parallel for)
125 for (Index row = 0; row < rows; row++)
126 {
127 Index end = row_ptr[row + 1];
128
129 for(Index i = 0; i < block_height; ++i)
130 {
131 row_norms[block_height*row + i] = DT_(0);
132 }
133
134 for (Index col = row_ptr[row]; col < end; col++)
135 {
136 // Manually compute norm2 of row
137 for(Index i = 0; i < block_height; ++i)
138 {
139 for(Index j = 0; j < block_width; ++j)
140 {
141 row_norms[block_height*row + i] += Math::sqr(val[block_height*block_width*col + i*block_width + j]);
142 }
143 // Do not take the square root
144 }
145 }
146 }
147 }
148
149 template <typename DT_, typename IT_>
150 void RowNorm::bcsr_generic_scaled_norm2sqr(DT_* row_norms, const DT_* const scal,
151 const DT_* const val, const IT_* const col_ind, const IT_* const row_ptr, const Index rows,
152 const int BlockHeight, const int BlockWidth)
153 {
154 Index block_height = Index(BlockHeight);
155 Index block_width = Index(BlockWidth);
156
157 FEAT_PRAGMA_OMP(parallel for)
158 for (Index row = 0; row < rows; row++)
159 {
160 Index end = row_ptr[row + 1];
161
162 for(Index i = 0; i < block_height; ++i)
163 {
164 row_norms[block_height*row + i] = DT_(0);
165 }
166
167 for (Index col = row_ptr[row]; col < end; col++)
168 {
169 // Manually compute norm2 of row
170 for(Index i = 0; i < block_height; ++i)
171 {
172 for(Index j = 0; j < block_width; ++j)
173 {
174 row_norms[block_height*row + i] += scal[block_width*col_ind[col] + j]
175 *Math::sqr(val[block_height*block_width*col + i*block_width + j]);
176 }
177 }
178 }
179 }
180 }
181 } // namespace Arch
182 } // namespace LAFEM
183} // namespace FEAT
184
185#endif // KERNEL_LAFEM_ARCH_ROW_NORM_GENERIC_HPP
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.