FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
row_norm2_bcsr_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_ROW_NORM2_BCSR_HPP
9#error "Do not include this implementation-only header file directly!"
10#endif
11
12#include <kernel/util/math.hpp>
13
14namespace FEAT::LAFEM::Arch
15{
16 template <typename DT_, typename IT_>
17 void RowNorm2BCSR::exec_generic_impl(DT_* row_norms, const DT_* const val, const IT_* const /*col_idx*/,
18 const IT_* const row_ptr, const Index rows, const int bh, const int bw, const bool squared)
19 {
20 Index block_height = Index(bh);
21 Index block_width = Index(bw);
22
23 FEAT_PRAGMA_OMP(parallel for)
24 for (Index row = 0; row < rows; row++)
25 {
26 Index end = row_ptr[row + 1];
27
28 for(Index i = 0; i < block_height; ++i)
29 {
30 row_norms[block_height*row + i] = DT_(0);
31 }
32
33 for (Index k = row_ptr[row]; k < end; ++k)
34 {
35 // Manually compute norm2 of row
36 for(Index i = 0; i < block_height; ++i)
37 {
38 for(Index j = 0; j < block_width; ++j)
39 {
40 row_norms[block_height*row + i] += Math::sqr(val[block_height*block_width*k + i*block_width + j]);
41 }
42 // Take the square root
43 if(!squared)
44 row_norms[block_height*row + i] = Math::sqrt(row_norms[block_height*row + i]);
45 }
46 }
47 }
48 }
49} // namespace FEAT::LAFEM::Arch
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
std::uint64_t Index
Index data type.