CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
reuseIndexManager.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 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 "reuseIndexManagerBase.hpp"
38
40namespace codi {
41
52 template<typename T_Index>
53 struct ReuseIndexManager : public ReuseIndexManagerBase<T_Index, ReuseIndexManager<T_Index>> {
54 public:
55
56 using Index = CODI_DD(T_Index, int);
59
60 friend Base;
61
62 /*******************************************************************************/
65
67 using Base::IsLinear;
69
71
72 private:
73
74 Index globalMaximumIndex;
75
76 public:
77
79 ReuseIndexManager(Index const& reservedIndices) : globalMaximumIndex(reservedIndices) {
80 generateNewIndices();
81 }
82
85
86 /*******************************************************************************/
89
92 void addToTapeValues(TapeValues& values) const {
93 unsigned long maximumGlobalIndex = globalMaximumIndex;
94 unsigned long storedIndices = this->usedIndicesPos + this->unusedIndicesPos;
95 long currentLiveIndices = maximumGlobalIndex - storedIndices;
96
97 TapeValues::LocalReductionOperation constexpr operation =
98 NeedsStaticStorage ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
99
100 values.addUnsignedLongEntry("Max. live indices", maximumGlobalIndex, operation);
101 values.addLongEntry("Cur. live indices", currentLiveIndices, operation);
102
103 Base::addToTapeValues(values);
104 }
105
111 return globalMaximumIndex;
112 }
113
115
116 private:
117
118 CODI_NO_INLINE void generateNewIndices() {
119 // This method is only called when unused indices are empty.
120 // Initially, a number of unused indices is created which
121 // equals the number of indices we generate now, therefore
122 // we do not have to check for size.
123
124 // If used in another context, then the calling method has to ensure that enough space is available.
125
126 codiAssert(this->unusedIndices.size() >= this->indexSizeIncrement);
127
128 for (size_t pos = 0; pos < this->indexSizeIncrement; ++pos) {
129 this->unusedIndices[this->unusedIndicesPos + pos] = globalMaximumIndex + Index(pos) + 1;
130 }
131
132 this->unusedIndicesPos += this->indexSizeIncrement;
133 globalMaximumIndex += this->indexSizeIncrement;
134 }
135 };
136}
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:426
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
static bool constexpr IsLinear
Definition reuseIndexManagerBase.hpp:81
ReuseIndexManagerBase()
Definition reuseIndexManagerBase.hpp:124
std::vector< Index > unusedIndices
Definition reuseIndexManagerBase.hpp:91
static bool constexpr CopyNeedsStatement
Definition reuseIndexManagerBase.hpp:80
void addToTapeValues(TapeValues &values) const
Definition reuseIndexManagerBase.hpp:265
static bool constexpr NeedsStaticStorage
Definition reuseIndexManagerBase.hpp:82
size_t indexSizeIncrement
Definition reuseIndexManagerBase.hpp:94
size_t unusedIndicesPos
Number of remaining unused indices.
Definition reuseIndexManagerBase.hpp:92
size_t usedIndicesPos
Number of remaining used indices.
Definition reuseIndexManagerBase.hpp:89
static bool constexpr NeedsStaticStorage
ReuseIndexManager(Index const &reservedIndices)
Constructor.
Definition reuseIndexManager.hpp:79
inlineIndex getLargestCreatedIndex() const
Returns the largest created index.
Definition reuseIndexManager.hpp:110
~ReuseIndexManager()
Destructor.
Definition reuseIndexManager.hpp:84
ReuseIndexManagerBase< Index, ReuseIndexManager > Base
Definition reuseIndexManager.hpp:58
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition reuseIndexManager.hpp:92
Index ActiveTypeIndexData
Definition reuseIndexManager.hpp:57
Index Index
Definition reuseIndexManager.hpp:56
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addLongEntry(std::string const &name, long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add long entry.
Definition tapeValues.hpp:152
void addUnsignedLongEntry(std::string const &name, unsigned long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add unsigned long entry.
Definition tapeValues.hpp:163