CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
pointerStore.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include "../../config.h"
38#include "../../misc/macros.hpp"
39#include "chunk.hpp"
40
42namespace codi {
43
71 template<typename T_ChunkData>
72 struct PointerStore {
73 public:
74
75 using ChunkData = CODI_DD(T_ChunkData, ChunkBase);
76
78 template<typename FuncObj, typename... Args>
79 void call(FuncObj& func, Args&&... args);
80
82 template<typename FuncObj, typename... Args>
83 void callAndAppend(FuncObj& func, Args&&... args);
84
86 template<int selectedDepth, typename Nested, typename... Args>
87 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, Args&&... args);
88
90 template<int selectedDepth, typename Nested, typename... Args>
91 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, Args&&... args);
92
94 void setPointers(const size_t& dataPos, ChunkData* chunk);
95 };
96
102 template<typename T_Data1>
103 struct PointerStore<Chunk1<T_Data1>> {
104 public:
105
106 using Data1 = CODI_DD(T_Data1, int);
107
109
110 private:
111
112 Data1* p1;
113
114 public:
115
117 template<typename FuncObj, typename... Args>
118 void call(FuncObj& func, Args&&... args) {
119 func(p1, std::forward<Args>(args)...);
120 }
121
123 template<typename FuncObj, typename... Args>
124 void callAndAppend(FuncObj& func, Args&&... args) {
125 func(std::forward<Args>(args)..., p1);
126 }
127
129 template<int selectedDepth, typename Nested, typename... Args>
130 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
131 nested->template evaluateForward<selectedDepth>(std::forward<Args>(args)..., start, end, p1);
132 }
133
135 template<int selectedDepth, typename Nested, typename... Args>
136 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
137 nested->template evaluateReverse<selectedDepth>(std::forward<Args>(args)..., start, end, p1);
138 }
139
141 void setPointers(size_t const& dataPos, Chunk* chunk) {
142 chunk->dataPointer(dataPos, p1);
143 }
144 };
145
151 template<typename T_Data1, typename T_Data2>
152 struct PointerStore<Chunk2<T_Data1, T_Data2>> {
153 public:
154
155 using Data1 = CODI_DD(T_Data1, int);
156 using Data2 = CODI_DD(T_Data2, int);
157
159
160 private:
161 Data1* p1;
162 Data2* p2;
163
164 public:
165
167 template<typename FuncObj, typename... Args>
168 void call(FuncObj& func, Args&&... args) {
169 func(p1, p2, std::forward<Args>(args)...);
170 }
171
173 template<typename FuncObj, typename... Args>
174 void callAndAppend(FuncObj& func, Args&&... args) {
175 func(std::forward<Args>(args)..., p1, p2);
176 }
177
179 template<int selectedDepth, typename Nested, typename... Args>
180 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
181 nested->template evaluateForward<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2);
182 }
183
185 template<int selectedDepth, typename Nested, typename... Args>
186 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
187 nested->template evaluateReverse<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2);
188 }
189
191 void setPointers(size_t const& dataPos, Chunk* chunk) {
192 chunk->dataPointer(dataPos, p1, p2);
193 }
194 };
195
201 template<typename T_Data1, typename T_Data2, typename T_Data3>
202 struct PointerStore<Chunk3<T_Data1, T_Data2, T_Data3>> {
203 public:
204
205 using Data1 = CODI_DD(T_Data1, int);
206 using Data2 = CODI_DD(T_Data2, int);
207 using Data3 = CODI_DD(T_Data3, int);
208
210
211 private:
212 Data1* p1;
213 Data2* p2;
214 Data3* p3;
215
216 public:
217
219 template<typename FuncObj, typename... Args>
220 void call(FuncObj& func, Args&&... args) {
221 func(p1, p2, p3, std::forward<Args>(args)...);
222 }
223
225 template<typename FuncObj, typename... Args>
226 void callAndAppend(FuncObj& func, Args&&... args) {
227 func(std::forward<Args>(args)..., p1, p2, p3);
228 }
229
231 template<int selectedDepth, typename Nested, typename... Args>
232 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
233 nested->template evaluateForward<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2, p3);
234 }
235
237 template<int selectedDepth, typename Nested, typename... Args>
238 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
239 nested->template evaluateReverse<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2, p3);
240 }
241
243 void setPointers(size_t const& dataPos, Chunk* chunk) {
244 chunk->dataPointer(dataPos, p1, p2, p3);
245 }
246 };
247
253 template<typename T_Data1, typename T_Data2, typename T_Data3, typename T_Data4>
254 struct PointerStore<Chunk4<T_Data1, T_Data2, T_Data3, T_Data4>> {
255 public:
256
257 using Data1 = CODI_DD(T_Data1, int);
258 using Data2 = CODI_DD(T_Data2, int);
259 using Data3 = CODI_DD(T_Data3, int);
260 using Data4 = CODI_DD(T_Data4, int);
261
263
264 private:
265 Data1* p1;
266 Data2* p2;
267 Data3* p3;
268 Data4* p4;
269
270 public:
271
273 template<typename FuncObj, typename... Args>
274 void call(FuncObj& func, Args&&... args) {
275 func(p1, p2, p3, p4, std::forward<Args>(args)...);
276 }
277
279 template<typename FuncObj, typename... Args>
280 void callAndAppend(FuncObj& func, Args&&... args) {
281 func(std::forward<Args>(args)..., p1, p2, p3, p4);
282 }
283
285 template<int selectedDepth, typename Nested, typename... Args>
286 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
287 nested->template evaluateForward<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2, p3, p4);
288 }
289
291 template<int selectedDepth, typename Nested, typename... Args>
292 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, Args&&... args) {
293 nested->template evaluateReverse<selectedDepth>(std::forward<Args>(args)..., start, end, p1, p2, p3, p4);
294 }
295
297 void setPointers(size_t const& dataPos, Chunk* chunk) {
298 chunk->dataPointer(dataPos, p1, p2, p3, p4);
299 }
300 };
301
308 template<typename T_Base>
309 struct TerminatingPointerStore : public T_Base {
310 public:
311
313
315 template<int selectedDepth, typename Nested, typename InnerPos, typename FunctionObject, typename... Args>
316 CODI_INLINE void callNestedForward(Nested* nested, size_t& start, size_t const& end, InnerPos const&,
317 InnerPos const&, FunctionObject function, Args&&... args) {
318 CODI_UNUSED(nested);
319
320 Base::callAndAppend(function, std::forward<Args>(args)..., start, end);
321 }
322
324 template<int selectedDepth, typename Nested, typename InnerPos, typename FunctionObject, typename... Args>
325 CODI_INLINE void callNestedReverse(Nested* nested, size_t& start, size_t const& end, InnerPos const&,
326 InnerPos const&, FunctionObject function, Args&&... args) {
327 CODI_UNUSED(nested);
328
329 Base::callAndAppend(function, std::forward<Args>(args)..., start, end);
330 }
331 };
332}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Definition chunk.hpp:185
void dataPointer(size_t const &index, Data1 *&pointer1)
Definition chunk.hpp:220
Definition chunk.hpp:283
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2)
Definition chunk.hpp:323
Definition chunk.hpp:400
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2, Data3 *&pointer3)
Definition chunk.hpp:446
Definition chunk.hpp:537
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2, Data3 *&pointer3, Data4 *&pointer4)
Definition chunk.hpp:589
A chunk stores a contiguous block of data in CoDiPack.
Definition chunk.hpp:76
T_Data1 Data1
Data entry 1.
Definition pointerStore.hpp:106
void setPointers(size_t const &dataPos, Chunk *chunk)
Sets the internal pointers to the data of the chunk. Afterwards on of the call functions can be calle...
Definition pointerStore.hpp:141
void callNestedForward(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateForward<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:130
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateReverse<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:136
void callAndAppend(FuncObj &func, Args &&... args)
Calls func(args..., pointers);.
Definition pointerStore.hpp:124
void call(FuncObj &func, Args &&... args)
Calls func(pointers, args...);.
Definition pointerStore.hpp:118
void setPointers(size_t const &dataPos, Chunk *chunk)
Sets the internal pointers to the data of the chunk. Afterwards on of the call functions can be calle...
Definition pointerStore.hpp:191
void call(FuncObj &func, Args &&... args)
Calls func(pointers, args...);.
Definition pointerStore.hpp:168
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateReverse<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:186
void callNestedForward(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateForward<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:180
void callAndAppend(FuncObj &func, Args &&... args)
Calls func(args..., pointers);.
Definition pointerStore.hpp:174
T_Data2 Data2
Data entry 2.
Definition pointerStore.hpp:156
T_Data1 Data1
Data entry 1.
Definition pointerStore.hpp:155
void setPointers(size_t const &dataPos, Chunk *chunk)
Sets the internal pointers to the data of the chunk. Afterwards on of the call functions can be calle...
Definition pointerStore.hpp:243
T_Data3 Data3
Data entry 3.
Definition pointerStore.hpp:207
void callNestedForward(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateForward<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:232
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateReverse<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:238
T_Data1 Data1
Data entry 1.
Definition pointerStore.hpp:205
void call(FuncObj &func, Args &&... args)
Calls func(pointers, args...);.
Definition pointerStore.hpp:220
void callAndAppend(FuncObj &func, Args &&... args)
Calls func(args..., pointers);.
Definition pointerStore.hpp:226
T_Data2 Data2
Data entry 2.
Definition pointerStore.hpp:206
T_Data2 Data2
Data entry 2.
Definition pointerStore.hpp:258
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateReverse<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:292
void callNestedForward(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateForward<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:286
T_Data1 Data1
Data entry 1.
Definition pointerStore.hpp:257
void call(FuncObj &func, Args &&... args)
Calls func(pointers, args...);.
Definition pointerStore.hpp:274
T_Data4 Data4
Data entry 4.
Definition pointerStore.hpp:260
void callAndAppend(FuncObj &func, Args &&... args)
Calls func(args..., pointers);.
Definition pointerStore.hpp:280
void setPointers(size_t const &dataPos, Chunk *chunk)
Sets the internal pointers to the data of the chunk. Afterwards on of the call functions can be calle...
Definition pointerStore.hpp:297
T_Data3 Data3
Data entry 3.
Definition pointerStore.hpp:259
Inserts data pointers at the back of all arguments in the nested call hierarchy.
Definition pointerStore.hpp:72
void call(FuncObj &func, Args &&... args)
Calls func(pointers, args...);.
T_ChunkData ChunkData
See PointerStore.
Definition pointerStore.hpp:75
void callAndAppend(FuncObj &func, Args &&... args)
Calls func(args..., pointers);.
void setPointers(const size_t &dataPos, ChunkData *chunk)
Sets the internal pointers to the data of the chunk. Afterwards on of the call functions can be calle...
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateReverse<selectedDepth>(args..., start, end, pointers);.
void callNestedForward(Nested *nested, size_t &start, size_t const &end, Args &&... args)
Calls nested->template evaluateForward<selectedDepth>(args..., start, end, pointers);.
Definition pointerStore.hpp:309
T_Base Base
See TerminatingPointerStore.
Definition pointerStore.hpp:312
void callNestedReverse(Nested *nested, size_t &start, size_t const &end, InnerPos const &, InnerPos const &, FunctionObject function, Args &&... args)
Calls Base::callAndAppend. See PointerStore::callAndAppend.
Definition pointerStore.hpp:325
void callNestedForward(Nested *nested, size_t &start, size_t const &end, InnerPos const &, InnerPos const &, FunctionObject function, Args &&... args)
Calls Base::callAndAppend. See PointerStore::callAndAppend.
Definition pointerStore.hpp:316