Nektar++
CommDataType.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CommDataType.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Describes data types (using MPI_Datatype if available)
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIB_UTILITIES_COMMDATATYPE_H
36#define NEKTAR_LIB_UTILITIES_COMMDATATYPE_H
37
39#include <vector>
40
41#ifdef NEKTAR_USE_MPI
42#include <mpi.h>
43
45{
46typedef MPI_Datatype CommDataType;
47} // namespace Nektar::LibUtilities
48
49#elif NEKTAR_USING_PETSC
50
51namespace Nektar
52{
53namespace LibUtilities
54{
55typedef unsigned int CommDataType;
56}
57} // namespace Nektar
58
59#else
60
61namespace Nektar
62{
63namespace LibUtilities
64{
65typedef unsigned int CommDataType;
66
67#ifndef MPI_CHAR
68#define MPI_CHAR ((CommDataType)0x4c000101)
69#endif
70
71#ifndef MPI_INT
72#define MPI_INT ((CommDataType)0x4c000405)
73#endif
74
75#ifndef MPI_UNSIGNED
76#define MPI_UNSIGNED ((CommDataType)0x4c000406)
77#endif
78
79#ifndef MPI_LONG
80#define MPI_LONG ((CommDataType)0x4c000807)
81#endif
82
83#ifndef MPI_UNSIGNED_LONG
84#define MPI_UNSIGNED_LONG ((CommDataType)0x4c000808)
85#endif
86
87#ifndef MPI_LONG_LONG
88#define MPI_LONG_LONG ((CommDataType)0x4c000809)
89#endif
90
91#ifndef MPI_UNSIGNED_LONG_LONG
92#define MPI_UNSIGNED_LONG_LONG ((CommDataType)0x4c000819)
93#endif
94
95#ifndef MPI_FLOAT
96#define MPI_FLOAT ((CommDataType)0x4c00040a)
97#endif
98
99#ifndef MPI_DOUBLE
100#define MPI_DOUBLE ((CommDataType)0x4c00080b)
101#endif
102
103#ifndef MPI_LONG_DOUBLE
104#define MPI_LONG_DOUBLE ((CommDataType)0x4c00100c)
105#endif
106} // namespace LibUtilities
107} // namespace Nektar
108#endif
109
110namespace Nektar
111{
112template <typename Dim, typename DataType> class Array;
113
114namespace LibUtilities
115{
117
118template <class T> class CommDataTypeTraits
119{
120public:
122
123 static void *GetPointer(T &val)
124 {
125 return &val;
126 }
127 static const void *GetPointer(const T &val)
128 {
129 return &val;
130 }
131 static int GetCount([[maybe_unused]] const T &val)
132 {
133 return 1;
134 }
135
136 const static bool IsVector = false;
137};
138
139/**
140 * Partial specialisation for vectors
141 */
142template <class elemT> class CommDataTypeTraits<std::vector<elemT>>
143{
144public:
146 {
148 }
149 static void *GetPointer(std::vector<elemT> &val)
150 {
151 ASSERTL1(!val.empty(),
152 "Vector cannot be empty when trying to use GetPointer to "
153 "access a pointer to the first element.");
154 return &val[0];
155 }
156 static const void *GetPointer(const std::vector<elemT> &val)
157 {
158 ASSERTL1(!val.empty(),
159 "Vector cannot be empty when trying to use GetPointer to "
160 "access a pointer to the first element.");
161 return &val[0];
162 }
163 static size_t GetCount(const std::vector<elemT> &val)
164 {
165 return val.size();
166 }
167 const static bool IsVector = true;
168};
169
170/**
171 * Partial specialisation for vectors
172 */
173template <class elemT> class CommDataTypeTraits<Array<OneD, elemT>>
174{
175public:
177 {
179 }
181 {
182 return val.get();
183 }
184 static const void *GetPointer(const Array<OneD, elemT> &val)
185 {
186 return val.get();
187 }
188 static size_t GetCount(const Array<OneD, elemT> &val)
189 {
190 return val.size();
191 }
192 const static bool IsVector = true;
193};
194} // namespace LibUtilities
195} // namespace Nektar
196
197#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
#define LIB_UTILITIES_EXPORT
static void * GetPointer(Array< OneD, elemT > &val)
Definition: CommDataType.h:180
static const void * GetPointer(const Array< OneD, elemT > &val)
Definition: CommDataType.h:184
static size_t GetCount(const Array< OneD, elemT > &val)
Definition: CommDataType.h:188
static size_t GetCount(const std::vector< elemT > &val)
Definition: CommDataType.h:163
static const void * GetPointer(const std::vector< elemT > &val)
Definition: CommDataType.h:156
static void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:149
static const void * GetPointer(const T &val)
Definition: CommDataType.h:127
unsigned int CommDataType
Definition: CommDataType.h:65
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
STL namespace.