MeDiPack  1.4.0
A Message Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
adToolImplCommon.hpp
Go to the documentation of this file.
1/*
2 * MeDiPack, a Message 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 (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of MeDiPack (http://scicomp.rptu.de/software/medi).
11 *
12 * MeDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation, either
15 * version 3 of the License, or (at your option) any later version.
16 *
17 * MeDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU
23 * Lesser General Public License along with MeDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Authors: Max Sagebaum, Tim Albring (SciComp, University of Kaiserslautern-Landau)
27 */
28
29#pragma once
30
31#include "typeDefinitions.h"
32#include "adToolInterface.h"
33
37namespace medi {
38
39 template <typename Impl, bool restorePrimal, bool modifiedBuffer, typename Type, typename AdjointType, typename PrimalType, typename IndexType>
40 class ADToolImplCommon : public ADToolBase<Impl, AdjointType, PrimalType, IndexType> {
41 public:
42
44
46
47 ADToolImplCommon(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType) :
48 Base(primalMpiType, adjointMpiType) {}
49
50 inline bool isActiveType() const {
51 return true;
52 }
53
54 inline bool isModifiedBufferRequired() const {
55 return modifiedBuffer;
56 }
57
58 inline bool isOldPrimalsRequired() const {
59 return restorePrimal;
60 }
61
62 inline void createPrimalTypeBuffer(PrimalType* &buf, size_t size) const {
63 buf = new PrimalType[size];
64 }
65
67 inline void createIndexTypeBuffer(IndexType* &buf, size_t size) const {
68 buf = new IndexType[size];
69 }
70
71 inline void deletePrimalTypeBuffer(PrimalType* &buf) const {
72 if(NULL != buf) {
73 delete [] buf;
74 buf = NULL;
75 }
76 }
77
79 inline void deleteIndexTypeBuffer(IndexType* &buf) const {
80 if(NULL != buf) {
81 delete [] buf;
82 buf = NULL;
83 }
84 }
85
87 void iterateIdentifiers(IndexType* indices, int elements, CallbackFuncTyped func, void* userData) const {
88 for(int i = 0; i < elements; i += 1) {
89 func(&indices[i], userData);
90 }
91 }
92 };
93}
ADToolBase(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType)
Definition adToolInterface.h:318
void iterateIdentifiers(void *indices, int elements, CallbackFunc func, void *userData) const
Definition adToolInterface.h:337
void(*)(IndexType *id, void *userData) CallbackFuncTyped
Definition adToolInterface.h:311
void deleteIndexTypeBuffer(void *&buf) const
Definition adToolInterface.h:333
void createIndexTypeBuffer(void *&buf, size_t size) const
Definition adToolInterface.h:325
ADToolImplCommon(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType)
Definition adToolImplCommon.hpp:47
typename Base::CallbackFuncTyped CallbackFuncTyped
Definition adToolImplCommon.hpp:45
void deleteIndexTypeBuffer(IndexType *&buf) const
Delete the array of the index variables.
Definition adToolImplCommon.hpp:79
bool isModifiedBufferRequired() const
Indicates if the AD tool needs to modify the buffer in order to send the correct data.
Definition adToolImplCommon.hpp:54
void createIndexTypeBuffer(IndexType *&buf, size_t size) const
Create an array for the index variables.
Definition adToolImplCommon.hpp:67
void deletePrimalTypeBuffer(PrimalType *&buf) const
Delete the array of the passive variables.
Definition adToolImplCommon.hpp:71
ADToolBase< Impl, AdjointType, PrimalType, IndexType > Base
Definition adToolImplCommon.hpp:43
void iterateIdentifiers(IndexType *indices, int elements, CallbackFuncTyped func, void *userData) const
Iterate of the identifiers of the AD tool. That is the AD tool should perform the operation:
Definition adToolImplCommon.hpp:87
bool isOldPrimalsRequired() const
Indicates if MeDiPack needs store the overwritten primal values for the AD tool.
Definition adToolImplCommon.hpp:58
void createPrimalTypeBuffer(PrimalType *&buf, size_t size) const
Create an array for the passive variables.
Definition adToolImplCommon.hpp:62
bool isActiveType() const
If this AD interface represents an AD type.
Definition adToolImplCommon.hpp:50
void PrimalType
The data type used for the floating point data.
Definition adToolInterface.h:67
void IndexType
The data type from the AD tool for the identification of AD variables.
Definition adToolInterface.h:72
Global namespace for MeDiPack - Message Differentiation Package.
Definition adjointInterface.hpp:37