FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dot_product_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_DOT_PRODUCT_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_DOT_PRODUCT_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_DOT_PRODUCT_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14namespace FEAT
15{
16 namespace LAFEM
17 {
18 namespace Arch
19 {
20 template <typename DT_>
21 DT_ DotProduct::value_generic(const DT_ * const x, const DT_ * const y, const Index size)
22 {
23 DT_ r(0);
24
25 if(x == y)
26 {
27 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
28 for (Index i = 0 ; i < size ; ++i)
29 {
30 r += x[i] * x[i];
31 }
32 }
33 else
34 {
35 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
36 for (Index i = 0 ; i < size ; ++i)
37 {
38 r += x[i] * y[i];
39 }
40 }
41
42 return r;
43 }
44
45 template <typename ValueType_>
46 ValueType_ DotProduct::value_blocked_generic(const ValueType_ * const x, const ValueType_ * const y, const Index size)
47 {
48 ValueType_ r(0);
49
50 if(x == y)
51 {
52
53 for (Index i(0) ; i < size ; ++i)
54 {
55 for(int j(0); j < ValueType_::n; ++j) {
56 r[j] += x[i][j] * x[i][j];
57 }
58 }
59 }
60 else
61 {
62
63 for (Index i(0) ; i < size ; ++i)
64 {
65 for(int j(0); j < ValueType_::n; ++j) {
66 r[j] += x[i][j] * y[i][j];
67 }
68 }
69 }
70
71 return r;
72 }
73
74 template <typename DT_>
75 DT_ TripleDotProduct::value_generic(const DT_ * const x, const DT_ * const y, const DT_ * const z, const Index size)
76 {
77 DT_ r(0);
78
79 if (x == y)
80 {
81 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
82 for (Index i = 0 ; i < size ; ++i)
83 r += x[i] * x[i] * z[i];
84 }
85 else if (x == z)
86 {
87 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
88 for (Index i = 0 ; i < size ; ++i)
89 r += x[i] * x[i] * y[i];
90 }
91 else if (y == z)
92 {
93 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
94 for (Index i = 0 ; i < size ; ++i)
95 r += x[i] * y[i] * y[i];
96 }
97 else
98 {
99 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
100 for (Index i = 0 ; i < size ; ++i)
101 r += x[i] * y[i] * z[i];
102 }
103
104 return r;
105 }
106
107 template <typename ValueType_>
108 ValueType_ TripleDotProduct::value_blocked_generic(const ValueType_ * const x, const ValueType_ * const y, const ValueType_ * const z, const Index size)
109 {
110 ValueType_ r(0);
111
112 if (x == y)
113 {
114
115 for(Index i(0); i < size; ++i)
116 {
117 for(int j(0); j < ValueType_::n; ++j)
118 {
119 r[j] += x[i][j] * x[i][j] * z[i][j];
120 }
121 }
122 }
123 else if (x == z)
124 {
125
126 for (Index i(0) ; i < size ; ++i)
127 {
128 for(int j(0); j < ValueType_::n; ++j)
129 {
130 r[j] += x[i][j] * x[i][j] * y[i][j];
131 }
132 }
133 }
134 else if (y == z)
135 {
136
137 for (Index i(0) ; i < size ; ++i)
138 {
139 for(int j(0); j < ValueType_::n; ++j)
140 {
141 r[j] += x[i][j] * y[i][j] * y[i][j];
142 }
143 }
144 }
145 else
146 {
147
148 for(Index i(0); i < size; ++i)
149 {
150 for(int j(0); j < ValueType_::n; ++j)
151 {
152 r[j] += x[i][j] * y[i][j] * z[i][j];
153 }
154 }
155 }
156
157 return r;
158 }
159 } // namespace Arch
160 } // namespace LAFEM
161} // namespace FEAT
162
163#endif // KERNEL_LAFEM_ARCH_DOT_PRODUCT_GENERIC_HPP
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.