CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codiMpiTypes.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://www.scicomp.uni-kl.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://www.scicomp.uni-kl.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 <medi/medi.hpp>
38
39#include "../../config.h"
40#include "../../misc/macros.hpp"
41#include "../../traits/tapeTraits.hpp"
42#include "codiForwardMeDiPackTool.hpp"
43#include "codiReverseMeDiPackTool.hpp"
44
46namespace codi {
47
59 template<typename T_Type,
60 typename T_Tool = typename std::conditional<codi::TapeTraits::IsForwardTape<typename T_Type::Tape>::value,
61 CoDiPackForwardTool<T_Type>, CoDiPackReverseTool<T_Type> >::type>
62 struct CoDiMpiTypes {
63 public:
64
66 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
67 using Tool = CODI_DD(T_Tool, medi::ADToolInterface);
68
69 using MPIType = medi::MpiTypeDefault<Tool>;
70
71 private:
72
73 MPI_Datatype codiMpiType;
74 MPI_Datatype modifiedMpiType;
75 MPI_Datatype primalMpiType;
76 MPI_Datatype adjointMpiType;
77
78 Tool adTool;
79
80 public:
81
83 medi::AMPI_Datatype MPI_INT_TYPE;
84
87 : codiMpiType(createByteType(sizeof(Type))),
88 modifiedMpiType(codiMpiType),
89 primalMpiType(createByteType(sizeof(typename Type::Real))),
90 adjointMpiType(primalMpiType),
91 adTool(primalMpiType, adjointMpiType),
92 MPI_TYPE(nullptr),
93 MPI_INT_TYPE() {
94 MPI_TYPE = new MPIType(&adTool, codiMpiType, modifiedMpiType);
95 MPI_INT_TYPE = Tool::OpHelper::createIntType(MPI_TYPE);
96 }
97
100 Tool::OpHelper::freeIntType(MPI_INT_TYPE);
101
102 if (nullptr != MPI_TYPE) {
103 delete MPI_TYPE;
104 MPI_TYPE = nullptr;
105 }
106
107 MPI_Type_free(&codiMpiType);
108 MPI_Type_free(&primalMpiType);
109 }
110
111 private:
112
113 static MPI_Datatype createByteType(size_t size) {
114 MPI_Datatype type;
115 MPI_Type_contiguous(size, MPI_BYTE, &type);
116 MPI_Type_commit(&type);
117
118 return type;
119 }
120 };
121}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition: macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition: codi.hpp:90
Represents a concrete lvalue in the CoDiPack expression tree.
Definition: activeType.hpp:52
MPI datatype implementation for CoDipack types in the type wrapper of MeDiPack.
Definition: codiMpiTypes.hpp:62
medi::MpiTypeDefault< Tool > MPIType
MeDiPack default implementation.
Definition: codiMpiTypes.hpp:69
medi::AMPI_Datatype MPI_INT_TYPE
MPI_Datatype for the specified CoDiPack type and an int.
Definition: codiMpiTypes.hpp:83
T_Type Type
See CoDiMpiTypes.
Definition: codiMpiTypes.hpp:66
CoDiMpiTypes()
Constructor.
Definition: codiMpiTypes.hpp:86
MPIType * MPI_TYPE
MPI_Datatype for the specified CoDiPack type.
Definition: codiMpiTypes.hpp:82
T_Tool Tool
See CoDiMpiTypes.
Definition: codiMpiTypes.hpp:67
~CoDiMpiTypes()
Destructor.
Definition: codiMpiTypes.hpp:99