CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
parallelActiveType.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 "../misc/macros.hpp"
38#include "../tapes/interfaces/editingTapeInterface.hpp"
39#include "../tools/parallel/parallelToolbox.hpp"
40#include "activeTypeBase.hpp"
41
43namespace codi {
44
53 template<typename T_Tape, typename T_ParallelToolbox>
54 struct ParallelActiveType : public ActiveTypeBase<T_Tape, ParallelActiveType<T_Tape, T_ParallelToolbox>> {
55 public:
56
58 using Tape = CODI_DD(T_Tape, CODI_DEFAULT_PARALLEL_TAPE);
60 using ParallelToolbox = CODI_DD(T_ParallelToolbox, CODI_DEFAULT_PARALLEL_TOOLBOX);
61
63
64 using typename Base::Gradient;
65 using typename Base::Identifier;
66 using typename Base::PassiveReal;
67 using typename Base::Real;
68
69 using typename Base::ActiveResult;
70 using typename Base::StoreAs;
71
74 typename ParallelToolbox::template StaticThreadLocalPointer<Tape, ParallelActiveType>;
75
76 private:
77
78 static ThreadLocalTapePointer tape;
79
80 public:
81
83 CODI_INLINE ParallelActiveType(ParallelActiveType const& v) : Base(static_cast<Base const&>(v)) {}
84
85 using Base::Base; // Use constructors from base class.
86
89
90 /*******************************************************************************/
93
96 static_cast<Base&>(*this) = static_cast<Base const&>(v);
97 return *this;
98 }
99
100 using Base::operator=;
101
103 /*******************************************************************************/
106
109 return *(tape.get());
110 }
111
113 /*******************************************************************************/
116
119 return tape.get();
120 }
121
123 static CODI_INLINE void setTapePtr(Tape* other) {
124 tape.set(other);
125 }
126
128 };
129
130 template<typename Tape, typename ParallelToolbox>
132 ParallelActiveType<Tape, ParallelToolbox>::tape;
133
134#if CODI_IDE
136 using CODI_DEFAULT_PARALLEL_ACTIVE_TYPE =
137 ParallelActiveType<CODI_DEFAULT_PARALLEL_TAPE, CODI_DEFAULT_PARALLEL_TOOLBOX>;
138#endif
139}
#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
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Represents the base implementation concrete lvalue in the CoDiPack expression tree.
Definition activeTypeBase.hpp:64
Impl const & StoreAs
Defines how this expression is stored in an expression tree.
Definition activeTypeBase.hpp:147
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition activeTypeBase.hpp:77
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition activeTypeBase.hpp:78
Impl ActiveResult
Type into which the expression can be converted. Usually also the type from which it is constructed.
Definition activeTypeBase.hpp:148
typename Tape::Gradient Gradient
See LhsExpressionInterface.
Definition activeTypeBase.hpp:79
LhsExpressionInterface< Real, Gradient, T_Tape, T_Impl > Base
Base class abbreviation.
Definition activeTypeBase.hpp:81
typename Tape::Real Real
See LhsExpressionInterface.
Definition activeTypeBase.hpp:76
Represents a concrete lvalue in the CoDiPack expression tree.
Definition parallelActiveType.hpp:54
static Tape & getTape()
Get a reference to the tape which manages this expression.
Definition parallelActiveType.hpp:108
typename ParallelToolbox::template StaticThreadLocalPointer< Tape, ParallelActiveType > ThreadLocalTapePointer
< See ActiveTypeBase.
Definition parallelActiveType.hpp:73
ParallelActiveType & operator=(ParallelActiveType const &v)
See ActiveTypeBase::operator=(ActiveTypeBase const&).
Definition parallelActiveType.hpp:95
T_ParallelToolbox ParallelToolbox
See ParallelActiveType.
Definition parallelActiveType.hpp:60
~ParallelActiveType()
Destructor.
Definition parallelActiveType.hpp:88
T_Tape Tape
See ParallelActiveType.
Definition parallelActiveType.hpp:58
ParallelActiveType(ParallelActiveType const &v)
Constructor.
Definition parallelActiveType.hpp:83
static void setTapePtr(Tape *other)
Set the thread-local tape pointer.
Definition parallelActiveType.hpp:123
static Tape * getTapePtr()
Get the thread-local tape pointer.
Definition parallelActiveType.hpp:118