FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mirror_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_MIRROR_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_MIRROR_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_MIRROR_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
15namespace FEAT
16{
17 namespace LAFEM
18 {
19 namespace Arch
20 {
21 template<typename DT_, typename IT_>
22 void Mirror::gather_dv_generic(const Index boff, const Index nidx, const IT_* idx, DT_* buf, const DT_* vec)
23 {
24 FEAT_PRAGMA_OMP(parallel for)
25 for(Index i = 0; i < nidx; ++i)
26 {
27 buf[boff+i] = vec[idx[i]];
28 }
29 }
30
31 template<typename DT_, typename IT_>
32 void Mirror::scatter_dv_generic(const Index boff, const Index nidx, const IT_* idx, const DT_* buf, DT_* vec, const DT_ alpha)
33 {
34 FEAT_PRAGMA_OMP(parallel for)
35 for(Index i = 0; i < nidx; ++i)
36 {
37 vec[idx[i]] += alpha*buf[boff+i];
38 }
39 }
40
41 template<typename DT_, typename IT_>
42 void Mirror::gather_dvb_generic(const Index bs, const Index boff, const Index nidx, const IT_* idx, DT_* buf, const DT_* vec)
43 {
44 FEAT_PRAGMA_OMP(parallel for)
45 for(Index i = 0; i < nidx; ++i)
46 {
47 for(Index k(0); k < bs; ++k)
48 {
49 buf[boff+i*bs+k] = vec[idx[i]*bs+k];
50 }
51 }
52 }
53
54 template<typename DT_, typename IT_>
55 void Mirror::scatter_dvb_generic(const Index bs, const Index boff, const Index nidx, const IT_* idx, const DT_* buf, DT_* vec, const DT_ alpha)
56 {
57 FEAT_PRAGMA_OMP(parallel for)
58 for(Index i = 0; i < nidx; ++i)
59 {
60 for(Index k(0); k < bs; ++k)
61 {
62 vec[idx[i]*bs+k] += alpha*buf[boff+i*bs+k];
63 }
64 }
65 }
66
67 template<typename DT_, typename IT_>
68 void Mirror::gather_sv_generic(const Index boff, const Index nidx, const IT_* idx, DT_* buf, const Index nvec, const DT_* vval, const IT_* vidx)
69 {
70 // loop over all mirror indices
71 FEAT_PRAGMA_OMP(parallel for)
72 for(Index i = 0; i < nidx; ++i)
73 {
74 buf[boff+i] = DT_(0);
75
76 // loop over all vector indices and try to find the match
77 for(Index j = 0; j < nvec; ++j)
78 {
79 if(idx[i] == vidx[j])
80 {
81 buf[boff+i] = vval[j];
82 break;
83 }
84 }
85 }
86 }
87
88 template<typename DT_, typename IT_>
89 void Mirror::scatter_sv_generic(const Index boff, const Index nidx, const IT_* idx, const DT_* buf, const Index nvec, DT_* vval, const IT_* vidx, const DT_ alpha)
90 {
91 // loop over all mirror indices
92 FEAT_PRAGMA_OMP(parallel for)
93 for(Index i = 0; i < nidx; ++i)
94 {
95 // loop over all vector indices and try to find the match
96 for(Index j(0); j < nvec; ++j)
97 {
98 if(idx[i] == vidx[j])
99 {
100 vval[j] += alpha*buf[boff+i];
101 break;
102 }
103 }
104 }
105 }
106
107 template<typename DT_, typename IT_>
108 void Mirror::gather_svb_generic(const Index bs, const Index boff, const Index nidx, const IT_* idx, DT_* buf, const Index nvec, const DT_* vval, const IT_* vidx)
109 {
110 FEAT_PRAGMA_OMP(parallel for)
111 for(Index i = 0; i < nidx; ++i)
112 {
113 for(Index k(0); k < bs; ++k)
114 buf[boff+i*bs+k] = DT_(0);
115
116 for(Index j(0); j < nvec; ++j)
117 {
118 if(idx[i] == vidx[j])
119 {
120 for(Index k(0); k < bs; ++k)
121 buf[boff+i*bs+k] = vval[j*bs+k];
122 break;
123 }
124 }
125 }
126 }
127
128 template<typename DT_, typename IT_>
129 void Mirror::scatter_svb_generic(const Index bs, const Index boff, const Index nidx, const IT_* idx, const DT_* buf, const Index nvec, DT_* vval, const IT_* vidx, const DT_ alpha)
130 {
131 FEAT_PRAGMA_OMP(parallel for)
132 for(Index i = 0; i < nidx; ++i)
133 {
134 for(Index j(0); j < nvec; ++j)
135 {
136 if(idx[i] == vidx[j])
137 {
138 for(Index k(0); k < bs; ++k)
139 vval[j*bs+k] += alpha*buf[boff+i*bs+k];
140 break;
141 }
142 }
143 }
144 }
145 } // namespace Arch
146 } // namespace LAFEM
147} // namespace FEAT
149
150#endif // KERNEL_LAFEM_ARCH_MIRROR_GENERIC_HPP
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.