CoDiPack  2.2.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-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 "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);
58
59 friend Base;
60
61 /*******************************************************************************/
64
66 using Base::IsLinear;
68
70
71 private:
72
73 Index globalMaximumIndex;
74
75 public:
76
78 ReuseIndexManager(Index const& reservedIndices) : globalMaximumIndex(reservedIndices) {
79 generateNewIndices();
80 }
81
84
85 /*******************************************************************************/
88
91 void addToTapeValues(TapeValues& values) const {
92 unsigned long maximumGlobalIndex = globalMaximumIndex;
93 unsigned long storedIndices = this->usedIndicesPos + this->unusedIndicesPos;
94 long currentLiveIndices = maximumGlobalIndex - storedIndices;
95
96 values.addUnsignedLongEntry("Max. live indices", maximumGlobalIndex);
97 values.addLongEntry("Cur. live indices", currentLiveIndices);
98
100 }
101
107 return globalMaximumIndex;
108 }
109
111
112 private:
113
114 CODI_NO_INLINE void generateNewIndices() {
115 // This method is only called when unused indices are empty.
116 // Initially, a number of unused indices is created which
117 // equals the number of indices we generate now, therefore
118 // we do not have to check for size.
119
120 codiAssert(this->unusedIndices.size() >= this->indexSizeIncrement);
121
122 for (size_t pos = 0; pos < this->indexSizeIncrement; ++pos) {
123 this->unusedIndices[this->unusedIndicesPos + pos] = globalMaximumIndex + Index(pos) + 1;
124 }
125
127 globalMaximumIndex += this->indexSizeIncrement;
128 }
129 };
130}
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:417
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Identifiers are reused. Freed identifiers are assigned to new variables. Variables keep their indices...
Definition reuseIndexManagerBase.hpp:66
static bool constexpr IsLinear
Identifiers are not coupled to statements.
Definition reuseIndexManagerBase.hpp:80
std::vector< Index > unusedIndices
Pool of indices that have not been used in this recording yet.
Definition reuseIndexManagerBase.hpp:90
static bool constexpr CopyNeedsStatement
No copy optimization is implemented.
Definition reuseIndexManagerBase.hpp:79
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition reuseIndexManagerBase.hpp:233
static bool constexpr NeedsStaticStorage
Identifiers are managed globally.
Definition reuseIndexManagerBase.hpp:81
size_t indexSizeIncrement
Block size for index pool enlargement.
Definition reuseIndexManagerBase.hpp:93
size_t unusedIndicesPos
Number of remaining unused indices.
Definition reuseIndexManagerBase.hpp:91
size_t usedIndicesPos
Number of remaining used indices.
Definition reuseIndexManagerBase.hpp:88
Reuse index manager with a many-to-one relation between tapes and index manager.
Definition reuseIndexManager.hpp:53
ReuseIndexManager(Index const &reservedIndices)
Constructor.
Definition reuseIndexManager.hpp:78
friend Base
Allow the base class to call protected and private methods.
Definition reuseIndexManager.hpp:59
Index getLargestCreatedIndex() const
Returns the largest created index.
Definition reuseIndexManager.hpp:106
~ReuseIndexManager()
Destructor.
Definition reuseIndexManager.hpp:83
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition reuseIndexManager.hpp:91
T_Index Index
See ReuseIndexManager.
Definition reuseIndexManager.hpp:56
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:73
void addUnsignedLongEntry(std::string const &name, unsigned long const &value)
Add unsigned long entry.
Definition tapeValues.hpp:150
void addLongEntry(std::string const &name, long const &value)
Add long entry.
Definition tapeValues.hpp:140