FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
min_max_value_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_MIN_MAX_VALUE_DENSE_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_>
17 DT_ MinMaxValueDense::exec_generic_impl(const DT_ * const x, const Index size, const bool min_, const bool abs_)
18 {
19 DT_ result(abs_ ? Math::abs(x[0]) : x[0]);
20 if(min_)
21 {
22 if(abs_)
23 {
24 FEAT_PRAGMA_OMP(parallel for reduction(min:result))
25 for (Index i = 0 ; i < size ; ++i)
26 {
27 result = Math::min(result, Math::abs(x[i]));
28 }
29 }
30 else
31 {
32 FEAT_PRAGMA_OMP(parallel for reduction(min:result))
33 for (Index i = 0 ; i < size ; ++i)
34 {
35 result = Math::min(result, x[i]);
36 }
37 }
38 }
39 else // max
40 {
41 if(abs_)
42 {
43 FEAT_PRAGMA_OMP(parallel for reduction(max:result))
44 for (Index i = 0 ; i < size ; ++i)
45 {
46 result = Math::max(result, Math::abs(x[i]));
47 }
48 }
49 else
50 {
51 FEAT_PRAGMA_OMP(parallel for reduction(max:result))
52 for (Index i = 0 ; i < size ; ++i)
53 {
54 result = Math::max(result, x[i]);
55 }
56 }
57 }
58
59 return result;
60 }
61} // namespace FEAT::LAFEM::Arch
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ min(T_ a, T_ b)
Returns the minimum of two values.
Definition: math.hpp:123
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
std::uint64_t Index
Index data type.