MeDiPack  1.3.0
A Message Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
typePassive.hpp
Go to the documentation of this file.
1/*
2 * MeDiPack, a Message 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 (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of MeDiPack (http://scicomp.rptu.de/software/codi).
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 <mpi.h>
32
33#include <new>
34
35#include "../adToolPassive.hpp"
36#include "../macros.h"
37#include "typeInterface.hpp"
38#include "op.hpp"
39
43namespace medi {
44
45 template<typename T>
46 class MpiTypePassive final
47 : public MpiTypeBase<
48 MpiTypePassive<T>,
49 T,
50 T,
51 ADToolPassive>
52 {
53
54 public:
55
56 typedef T Type;
57 typedef T ModifiedType;
58 typedef void PrimalType;
59 typedef void IndexType;
60
62
63 bool isClone;
64
66
67 MpiTypePassive(MPI_Datatype type) :
69 isClone(false),
70 adTool(type, type) {}
71
72 private:
73 MpiTypePassive(MPI_Datatype type, bool clone) :
76 adTool(type, type) {}
77
78 public:
80 if(isClone) {
81 MPI_Datatype temp = this->getMpiType();
82 MPI_Type_free(&temp);
83 }
84 }
85
86 const Tool& getADTool() const{
87 return adTool;
88 }
89
90 int computeActiveElements(const int count) const {
91 MEDI_UNUSED(count);
92
93 return 0;
94 }
95
97 return false;
98 }
99
100 inline void copyIntoModifiedBuffer(const Type* buf, size_t bufOffset, ModifiedType* bufMod, size_t bufModOffset, int elements) const {
101 for(int i = 0; i < elements; ++i) {
102 bufMod[bufModOffset + i] = buf[bufOffset + i];
103 }
104 }
105
106 inline void copyFromModifiedBuffer(Type* buf, size_t bufOffset, const ModifiedType* bufMod, size_t bufModOffset, int elements) const {
107 for(int i = 0; i < elements; ++i) {
108 buf[bufOffset + i] = bufMod[bufModOffset + i];
109 }
110 }
111
112 inline void getIndices(const Type* buf, size_t bufOffset, IndexType* indices, size_t bufModOffset, int elements) const {
113 MEDI_UNUSED(buf);
114 MEDI_UNUSED(bufOffset);
115 MEDI_UNUSED(indices);
116 MEDI_UNUSED(bufModOffset);
117 MEDI_UNUSED(elements);
118 }
119
120 inline void registerValue(Type* buf, size_t bufOffset, IndexType* indices, PrimalType* oldPrimals, size_t bufModOffset, int elements) const {
121 MEDI_UNUSED(buf);
122 MEDI_UNUSED(bufOffset);
123 MEDI_UNUSED(indices);
124 MEDI_UNUSED(oldPrimals);
125 MEDI_UNUSED(bufModOffset);
126 MEDI_UNUSED(elements);
127 }
128
129 inline void clearIndices(Type* buf, size_t bufOffset, int elements) const {
130 MEDI_UNUSED(buf);
131 MEDI_UNUSED(bufOffset);
132 MEDI_UNUSED(elements);
133 }
134
135 inline void createIndices(Type* buf, size_t bufOffset, IndexType* indices, size_t bufModOffset, int elements) const {
136 MEDI_UNUSED(buf);
137 MEDI_UNUSED(bufOffset);
138 MEDI_UNUSED(indices);
139 MEDI_UNUSED(bufModOffset);
140 MEDI_UNUSED(elements);
141 }
142
143 inline void getValues(const Type* buf, size_t bufOffset, PrimalType* primals, size_t bufModOffset, int elements) const {
144 MEDI_UNUSED(buf);
145 MEDI_UNUSED(bufOffset);
146 MEDI_UNUSED(primals);
147 MEDI_UNUSED(bufModOffset);
148 MEDI_UNUSED(elements);
149 }
150
151 inline void performReduce(Type* buf, Type* target, int count, AMPI_Op op, int ranks) const {
152 MEDI_UNUSED(buf);
153 MEDI_UNUSED(target);
154 MEDI_UNUSED(count);
155 MEDI_UNUSED(op);
156 MEDI_UNUSED(ranks);
157 }
158
159 inline void copy(Type* from, size_t fromOffset, Type* to, size_t toOffset, int count) const {
160 for(int i = 0; i < count; ++i) {
161 to[toOffset + i] = from[fromOffset + i];
162 }
163 }
164
165 void initializeType(Type* buf, size_t bufOffset, int elements) const {
166 for(int i = 0; i < elements; ++i) {
167 new(&buf[bufOffset + i]) Type;
168 }
169 }
170
171 void freeType(Type* buf, size_t bufOffset, int elements) const {
172 for(int i = 0; i < elements; ++i) {
173 buf[bufOffset + elements].~Type();
174 }
175 }
176
177 inline void createTypeBuffer(Type* &buf, size_t size) const {
178 buf = new Type[size];
179 }
180
181 inline void createModifiedTypeBuffer(ModifiedType* &buf, size_t size) const {
182 buf = new ModifiedType[size];
183 }
184
185 inline void deleteTypeBuffer(Type* &buf, size_t size) const {
186 if(NULL != buf) {
187 delete [] buf;
188 buf = NULL;
189 }
190 }
191
192 inline void deleteModifiedTypeBuffer(ModifiedType* &buf) const {
193 if(NULL != buf) {
194 delete [] buf;
195 buf = NULL;
196 }
197 }
198
199 inline MpiTypePassive* clone() const {
200 MPI_Datatype type;
201 MPI_Type_dup(this->getMpiType(), &type);
202
203 return new MpiTypePassive(type, true);
204 }
205 };
206}
Implementation for the AD tool interface of a type that is no AD type.
Definition adToolPassive.hpp:45
Definition typeInterface.hpp:324
MPI_Datatype getMpiType() const
Return the MPI type for the data that this interface represents.
Definition typeInterface.hpp:127
Definition typePassive.hpp:52
void getIndices(const Type *buf, size_t bufOffset, IndexType *indices, size_t bufModOffset, int elements) const
Definition typePassive.hpp:112
void registerValue(Type *buf, size_t bufOffset, IndexType *indices, PrimalType *oldPrimals, size_t bufModOffset, int elements) const
Definition typePassive.hpp:120
void getValues(const Type *buf, size_t bufOffset, PrimalType *primals, size_t bufModOffset, int elements) const
Definition typePassive.hpp:143
MpiTypePassive(MPI_Datatype type)
Definition typePassive.hpp:67
ADToolPassive Tool
Definition typePassive.hpp:61
void deleteTypeBuffer(Type *&buf, size_t size) const
Definition typePassive.hpp:185
void performReduce(Type *buf, Type *target, int count, AMPI_Op op, int ranks) const
Definition typePassive.hpp:151
void createModifiedTypeBuffer(ModifiedType *&buf, size_t size) const
Definition typePassive.hpp:181
void copyIntoModifiedBuffer(const Type *buf, size_t bufOffset, ModifiedType *bufMod, size_t bufModOffset, int elements) const
Definition typePassive.hpp:100
void PrimalType
Definition typePassive.hpp:58
bool isModifiedBufferRequired() const
Tell the functions if the underlying AD tool requires new send/recv buffers or if the original buffer...
Definition typePassive.hpp:96
T ModifiedType
Definition typePassive.hpp:57
void createTypeBuffer(Type *&buf, size_t size) const
Definition typePassive.hpp:177
void createIndices(Type *buf, size_t bufOffset, IndexType *indices, size_t bufModOffset, int elements) const
Definition typePassive.hpp:135
MpiTypePassive * clone() const
Creates a clone of the mpi type also calling MPI_Type_dub.
Definition typePassive.hpp:199
bool isClone
Definition typePassive.hpp:63
const Tool & getADTool() const
Get the AD tool that handled the AD specifics.
Definition typePassive.hpp:86
void deleteModifiedTypeBuffer(ModifiedType *&buf) const
Definition typePassive.hpp:192
Tool adTool
Definition typePassive.hpp:65
T Type
Definition typePassive.hpp:56
void freeType(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:171
void clearIndices(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:129
void initializeType(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:165
int computeActiveElements(const int count) const
Get the number of active elements that are contained in count versions of the type.
Definition typePassive.hpp:90
void IndexType
Definition typePassive.hpp:59
void copy(Type *from, size_t fromOffset, Type *to, size_t toOffset, int count) const
Definition typePassive.hpp:159
~MpiTypePassive()
Definition typePassive.hpp:79
void copyFromModifiedBuffer(Type *buf, size_t bufOffset, const ModifiedType *bufMod, size_t bufModOffset, int elements) const
Definition typePassive.hpp:106
#define MEDI_UNUSED(name)
Definition macros.h:108
Global namespace for MeDiPack - Message Differentiation Package.
Definition adjointInterface.hpp:37
Structure for the special handling of the MPI_Op structure.
Definition op.hpp:50