MeDiPack  1.3.3
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-2025 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 <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
64
65 bool isClone;
66
68
69 MpiTypePassive(MPI_Datatype type) :
70 Base(type, type),
71 isClone(false),
72 adTool(type, type) {}
73
74 private:
75 MpiTypePassive(MPI_Datatype type, bool clone) :
76 Base(type, type),
78 adTool(type, type) {}
79
80 public:
82 if(isClone) {
83 MPI_Datatype temp = this->getMpiType();
84 MPI_Type_free(&temp);
85 }
86 }
87
88 const Tool& getADTool() const{
89 return adTool;
90 }
91
92 int computeActiveElements(const int count) const {
93 MEDI_UNUSED(count);
94
95 return 0;
96 }
97
99 return false;
100 }
101
102 inline void copyIntoModifiedBuffer(const Type* buf, size_t bufOffset, ModifiedType* bufMod, size_t bufModOffset, int elements) const {
103 for(int i = 0; i < elements; ++i) {
104 bufMod[bufModOffset + i] = buf[bufOffset + i];
105 }
106 }
107
108 inline void copyFromModifiedBuffer(Type* buf, size_t bufOffset, const ModifiedType* bufMod, size_t bufModOffset, int elements) const {
109 for(int i = 0; i < elements; ++i) {
110 buf[bufOffset + i] = bufMod[bufModOffset + i];
111 }
112 }
113
114 inline void getIndices(const Type* buf, size_t bufOffset, IndexType* indices, size_t bufModOffset, int elements) const {
115 MEDI_UNUSED(buf);
116 MEDI_UNUSED(bufOffset);
117 MEDI_UNUSED(indices);
118 MEDI_UNUSED(bufModOffset);
119 MEDI_UNUSED(elements);
120 }
121
122 inline void registerValue(Type* buf, size_t bufOffset, IndexType* indices, PrimalType* oldPrimals, size_t bufModOffset, int elements) const {
123 MEDI_UNUSED(buf);
124 MEDI_UNUSED(bufOffset);
125 MEDI_UNUSED(indices);
126 MEDI_UNUSED(oldPrimals);
127 MEDI_UNUSED(bufModOffset);
128 MEDI_UNUSED(elements);
129 }
130
131 inline void clearIndices(Type* buf, size_t bufOffset, int elements) const {
132 MEDI_UNUSED(buf);
133 MEDI_UNUSED(bufOffset);
134 MEDI_UNUSED(elements);
135 }
136
137 inline void createIndices(Type* buf, size_t bufOffset, IndexType* indices, size_t bufModOffset, int elements) const {
138 MEDI_UNUSED(buf);
139 MEDI_UNUSED(bufOffset);
140 MEDI_UNUSED(indices);
141 MEDI_UNUSED(bufModOffset);
142 MEDI_UNUSED(elements);
143 }
144
145 inline void getValues(const Type* buf, size_t bufOffset, PrimalType* primals, size_t bufModOffset, int elements) const {
146 MEDI_UNUSED(buf);
147 MEDI_UNUSED(bufOffset);
148 MEDI_UNUSED(primals);
149 MEDI_UNUSED(bufModOffset);
150 MEDI_UNUSED(elements);
151 }
152
153 inline void performReduce(Type* buf, Type* target, int count, AMPI_Op op, int ranks) const {
154 MEDI_UNUSED(buf);
155 MEDI_UNUSED(target);
156 MEDI_UNUSED(count);
157 MEDI_UNUSED(op);
158 MEDI_UNUSED(ranks);
159 }
160
161 using Base::copy;
162 inline void copy(Type* from, size_t fromOffset, Type* to, size_t toOffset, int count) const {
163 for(int i = 0; i < count; ++i) {
164 to[toOffset + i] = from[fromOffset + i];
165 }
166 }
167
168 void initializeType(Type* buf, size_t bufOffset, int elements) const {
169 for(int i = 0; i < elements; ++i) {
170 new(&buf[bufOffset + i]) Type;
171 }
172 }
173
174 void freeType(Type* buf, size_t bufOffset, int elements) const {
175 for(int i = 0; i < elements; ++i) {
176 buf[bufOffset + elements].~Type();
177 }
178 }
179
180 inline void createTypeBuffer(Type* &buf, size_t size) const {
181 buf = new Type[size];
182 }
183
184 inline void createModifiedTypeBuffer(ModifiedType* &buf, size_t size) const {
185 buf = new ModifiedType[size];
186 }
187
188 inline void deleteTypeBuffer(Type* &buf, size_t size) const {
189 if(NULL != buf) {
190 delete [] buf;
191 buf = NULL;
192 }
193 }
194
195 inline void deleteModifiedTypeBuffer(ModifiedType* &buf) const {
196 if(NULL != buf) {
197 delete [] buf;
198 buf = NULL;
199 }
200 }
201
202 inline MpiTypePassive* clone() const {
203 MPI_Datatype type;
204 MPI_Type_dup(this->getMpiType(), &type);
205
206 return new MpiTypePassive(type, true);
207 }
208 };
209}
Implementation for the AD tool interface of a type that is no AD type.
Definition adToolPassive.hpp:45
void copy(void *from, size_t fromOffset, void *to, size_t toOffset, int count) const
Definition typeInterface.hpp:369
MpiTypeBase(MPI_Datatype mpiType, MPI_Datatype modifiedMpiType)
Definition typeInterface.hpp:330
MPI_Datatype getMpiType() const
Return the MPI type for the data that this interface represents.
Definition typeInterface.hpp:127
void getIndices(const Type *buf, size_t bufOffset, IndexType *indices, size_t bufModOffset, int elements) const
Definition typePassive.hpp:114
void registerValue(Type *buf, size_t bufOffset, IndexType *indices, PrimalType *oldPrimals, size_t bufModOffset, int elements) const
Definition typePassive.hpp:122
void getValues(const Type *buf, size_t bufOffset, PrimalType *primals, size_t bufModOffset, int elements) const
Definition typePassive.hpp:145
MpiTypePassive(MPI_Datatype type)
Definition typePassive.hpp:69
ADToolPassive Tool
Definition typePassive.hpp:61
void deleteTypeBuffer(Type *&buf, size_t size) const
Definition typePassive.hpp:188
void performReduce(Type *buf, Type *target, int count, AMPI_Op op, int ranks) const
Definition typePassive.hpp:153
void createModifiedTypeBuffer(ModifiedType *&buf, size_t size) const
Definition typePassive.hpp:184
void copyIntoModifiedBuffer(const Type *buf, size_t bufOffset, ModifiedType *bufMod, size_t bufModOffset, int elements) const
Definition typePassive.hpp:102
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:98
T ModifiedType
Definition typePassive.hpp:57
void createTypeBuffer(Type *&buf, size_t size) const
Definition typePassive.hpp:180
void createIndices(Type *buf, size_t bufOffset, IndexType *indices, size_t bufModOffset, int elements) const
Definition typePassive.hpp:137
MpiTypePassive * clone() const
Creates a clone of the mpi type also calling MPI_Type_dub.
Definition typePassive.hpp:202
bool isClone
Definition typePassive.hpp:65
const Tool & getADTool() const
Get the AD tool that handled the AD specifics.
Definition typePassive.hpp:88
void deleteModifiedTypeBuffer(ModifiedType *&buf) const
Definition typePassive.hpp:195
Tool adTool
Definition typePassive.hpp:67
T Type
Definition typePassive.hpp:56
void freeType(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:174
void clearIndices(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:131
MpiTypeBase< MpiTypePassive< T >, Type, ModifiedType, ADToolPassive > Base
Definition typePassive.hpp:63
void initializeType(Type *buf, size_t bufOffset, int elements) const
Definition typePassive.hpp:168
int computeActiveElements(const int count) const
Get the number of active elements that are contained in count versions of the type.
Definition typePassive.hpp:92
void IndexType
Definition typePassive.hpp:59
void copy(Type *from, size_t fromOffset, Type *to, size_t toOffset, int count) const
Definition typePassive.hpp:162
~MpiTypePassive()
Definition typePassive.hpp:81
void copyFromModifiedBuffer(Type *buf, size_t bufOffset, const ModifiedType *bufMod, size_t bufModOffset, int elements) const
Definition typePassive.hpp:108
#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