43 template <
typename Type,
typename ModifiedType,
typename PrimalType,
typename IndexType>
60 template <
typename Type,
typename ModifiedType,
typename PrimalType,
typename IndexType,
typename Adjo
intType, INTERFACE_ARG(Tool)>
74 static void unmodifiedAdd(Type* invec, Type* inoutvec,
int* len, MPI_Datatype* datatype) {
77 for(
int i = 0; i < *len; ++i) {
78 inoutvec[i] += invec[i];
82 static void unmodifiedMul(Type* invec, Type* inoutvec,
int* len, MPI_Datatype* datatype) {
85 for(
int i = 0; i < *len; ++i) {
86 inoutvec[i] *= invec[i];
90 static void unmodifiedMax(Type* invec, Type* inoutvec,
int* len, MPI_Datatype* datatype) {
94 for(
int i = 0; i < *len; ++i) {
95 inoutvec[i] = max(inoutvec[i], invec[i]);
99 static void unmodifiedMin(Type* invec, Type* inoutvec,
int* len, MPI_Datatype* datatype) {
103 for(
int i = 0; i < *len; ++i) {
104 inoutvec[i] = min(inoutvec[i], invec[i]);
112 for(
int i = 0; i < *len; ++i) {
114 if(invec[i].value > inoutvec[i].value) {
116 }
else if(invec[i].value < inoutvec[i].value){
119 inoutvec[i].
index = std::min(invec[i].index, inoutvec[i].index);
123 inoutvec[i].
value = max(inoutvec[i].value, invec[i].value);
131 for(
int i = 0; i < *len; ++i) {
133 if(invec[i].value < inoutvec[i].value) {
135 }
else if(invec[i].value > inoutvec[i].value){
138 inoutvec[i].
index = std::min(invec[i].index, inoutvec[i].index);
142 inoutvec[i].
value = min(inoutvec[i].value, invec[i].value);
146 static void modifiedAdd(ModifiedType* invec, ModifiedType* inoutvec,
int* len, MPI_Datatype* datatype) {
149 for(
int i = 0; i < *len; ++i) {
150 Tool::modifyDependency(invec[i], inoutvec[i]);
151 Tool::setPrimalToMod(inoutvec[i], Tool::getPrimalFromMod(invec[i]) + Tool::getPrimalFromMod(inoutvec[i]));
155 static void modifiedMul(ModifiedType* invec, ModifiedType* inoutvec,
int* len, MPI_Datatype* datatype) {
158 for(
int i = 0; i < *len; ++i) {
159 Tool::modifyDependency(invec[i], inoutvec[i]);
160 Tool::setPrimalToMod(inoutvec[i], Tool::getPrimalFromMod(invec[i]) * Tool::getPrimalFromMod(inoutvec[i]));
164 static void modifiedMax(ModifiedType* invec, ModifiedType* inoutvec,
int* len, MPI_Datatype* datatype) {
168 for(
int i = 0; i < *len; ++i) {
169 Tool::modifyDependency(invec[i], inoutvec[i]);
170 Tool::setPrimalToMod(inoutvec[i], max(Tool::getPrimalFromMod(invec[i]), Tool::getPrimalFromMod(inoutvec[i])));
174 static void modifiedMin(ModifiedType* invec, ModifiedType* inoutvec,
int* len, MPI_Datatype* datatype) {
178 for(
int i = 0; i < *len; ++i) {
179 Tool::modifyDependency(invec[i], inoutvec[i]);
180 Tool::setPrimalToMod(inoutvec[i], min(Tool::getPrimalFromMod(invec[i]), Tool::getPrimalFromMod(inoutvec[i])));
188 for(
int i = 0; i < *len; ++i) {
190 PrimalType inPrimal = Tool::getPrimalFromMod(invec[i].value);
191 PrimalType inoutPrimal = Tool::getPrimalFromMod(inoutvec[i].value);
194 if(inPrimal > inoutPrimal) {
196 }
else if(inPrimal < inoutPrimal){
199 inoutvec[i].
index = std::min(invec[i].index, inoutvec[i].index);
202 Tool::modifyDependency(invec[i].value, inoutvec[i].value);
203 Tool::setPrimalToMod(inoutvec[i].value, max(inPrimal, inoutPrimal));
211 for(
int i = 0; i < *len; ++i) {
212 PrimalType inPrimal = Tool::getPrimalFromMod(invec[i].value);
213 PrimalType inoutPrimal = Tool::getPrimalFromMod(inoutvec[i].value);
216 if(inPrimal < inoutPrimal) {
218 }
else if(inPrimal > inoutPrimal){
221 inoutvec[i].
index = std::min(invec[i].index, inoutvec[i].index);
224 Tool::modifyDependency(invec[i].value, inoutvec[i].value);
225 Tool::setPrimalToMod(inoutvec[i].value, min(inPrimal, inoutPrimal));
248 static void postAdjMinMax(AdjointType* adjoints, PrimalType* primals, PrimalType* rootPrimals,
int count,
int vecSize) {
249 for(
int i = 0; i < count; ++i) {
250 if(rootPrimals[i] != primals[i]) {
251 for(
int dim = 0; dim < vecSize; ++dim) {
252 adjoints[i * vecSize + dim] = AdjointType();
263 template<INTERFACE_ARG(FuncHelp)>
278 (MPI_User_function*)FuncHelp::unmodifiedAdd, 1,
279 (MPI_User_function*)FuncHelp::modifiedAdd, 1,
280 medi::noPreAdjointOperation,
281 medi::noPostAdjointOperation,
326 offsetof(
typename FuncHelp::TypeInt, value),
327 offsetof(
typename FuncHelp::TypeInt, index),
328 offsetof(
typename FuncHelp::TypeInt, index) +
sizeof(int)
330 int blockLength[3] = {1, 1, (int)(
sizeof(
typename FuncHelp::TypeInt) - offsets[2])};
#define AMPI_Aint
Definition ampiDefinitions.h:760
Wrapper interface for MPI types in communications.
Definition typeInterface.hpp:63
#define INTERFACE_DEF(interface, name,...)
Definition macros.h:116
#define MEDI_UNUSED(name)
Definition macros.h:108
Global namespace for MeDiPack - Message Differentiation Package.
Definition adjointInterface.hpp:37
int AMPI_Type_free(MpiTypeInterface **d)
Definition constructedDatatypes.hpp:812
int AMPI_Type_commit(MpiTypeInterface **d)
Definition constructedDatatypes.hpp:800
int AMPI_Type_create_struct(int count, const int *array_of_blocklengths, const MPI_Aint *array_of_displacements, MpiTypeInterface *const *array_of_types, MpiTypeInterface **newtype)
Definition constructedDatatypes.hpp:787
AMPI_BYTE_Type * AMPI_BYTE
Definition ampiDefinitions.cpp:169
int AMPI_Op_create(MPI_User_function *user_fn, int commute, AMPI_Op *op)
Default forward of the operator creation.
Definition operatorFunctions.hpp:53
AMPI_INT_Type * AMPI_INT
Definition ampiDefinitions.cpp:91
Structure for the special handling of the MPI_Op structure.
Definition op.hpp:50
int free()
Definition op.hpp:186
MPI_Op primalFunction
The mpi operator for the unmodified AD types. The AD tool needs to record all operations that are eva...
Definition op.hpp:69
Definition indexTypeHelper.hpp:69
int index
Definition indexTypeHelper.hpp:71
ModifiedType value
Definition indexTypeHelper.hpp:70
Definition indexTypeHelper.hpp:64
int index
Definition indexTypeHelper.hpp:66
Type value
Definition indexTypeHelper.hpp:65
The provides all methods required for the creation of operators for AD types.
Definition indexTypeHelper.hpp:61
static void unmodifiedAdd(Type *invec, Type *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:74
static void modifiedAdd(ModifiedType *invec, ModifiedType *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:146
static void unmodifiedMul(Type *invec, Type *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:82
static void unmodifiedMaxLoc(TypeInt *invec, TypeInt *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:108
static void postAdjMinMax(AdjointType *adjoints, PrimalType *primals, PrimalType *rootPrimals, int count, int vecSize)
Definition indexTypeHelper.hpp:248
static void unmodifiedMinLoc(TypeInt *invec, TypeInt *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:127
static void modifiedMin(ModifiedType *invec, ModifiedType *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:174
static void unmodifiedMax(Type *invec, Type *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:90
static void modifiedMaxLoc(ModTypeInt *invec, ModTypeInt *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:184
static void modifiedMinLoc(ModTypeInt *invec, ModTypeInt *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:207
static void modifiedMax(ModifiedType *invec, ModifiedType *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:164
static void unmodifiedMin(Type *invec, Type *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:99
static void modifiedMul(ModifiedType *invec, ModifiedType *inoutvec, int *len, MPI_Datatype *datatype)
Definition indexTypeHelper.hpp:155
Definition indexTypeHelper.hpp:264
AMPI_Op OP_SUM
Definition indexTypeHelper.hpp:269
AMPI_Op OP_MIN
Definition indexTypeHelper.hpp:271
void init()
Definition indexTypeHelper.hpp:309
static void freeIntType(AMPI_Datatype &type)
Definition indexTypeHelper.hpp:339
AMPI_Op OP_MAX
Definition indexTypeHelper.hpp:272
AMPI_Op OP_MAXLOC
Definition indexTypeHelper.hpp:274
AMPI_Op OP_MINLOC
Definition indexTypeHelper.hpp:273
AMPI_Op OP_PROD
Definition indexTypeHelper.hpp:270
void createOperators()
Definition indexTypeHelper.hpp:276
static AMPI_Datatype createIntType(const AMPI_Datatype type)
Definition indexTypeHelper.hpp:322
void finalize()
Definition indexTypeHelper.hpp:313
AMPI_Op convertOperator(AMPI_Op op) const
Definition indexTypeHelper.hpp:290