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
38#include <boost/core/ignore_unused.hpp>
39
41#include <vector>
42
43#ifdef NEKTAR_USE_MPI
44#include <mpi.h>
45
46namespace Nektar
47{
48namespace LibUtilities
49{
50typedef MPI_Datatype CommDataType;
51}
52} // namespace Nektar
53
54#elif NEKTAR_USING_PETSC
55
56namespace Nektar
57{
58namespace LibUtilities
59{
60typedef unsigned int CommDataType;
61}
62} // namespace Nektar
63
64#else
65
66namespace Nektar
67{
68namespace LibUtilities
69{
70typedef unsigned int CommDataType;
71
72#ifndef MPI_CHAR
73#define MPI_CHAR ((CommDataType)0x4c000101)
74#endif
75
76#ifndef MPI_INT
77#define MPI_INT ((CommDataType)0x4c000405)
78#endif
79
80#ifndef MPI_UNSIGNED
81#define MPI_UNSIGNED ((CommDataType)0x4c000406)
82#endif
83
84#ifndef MPI_LONG
85#define MPI_LONG ((CommDataType)0x4c000807)
86#endif
87
88#ifndef MPI_UNSIGNED_LONG
89#define MPI_UNSIGNED_LONG ((CommDataType)0x4c000808)
90#endif
91
92#ifndef MPI_LONG_LONG
93#define MPI_LONG_LONG ((CommDataType)0x4c000809)
94#endif
95
96#ifndef MPI_UNSIGNED_LONG_LONG
97#define MPI_UNSIGNED_LONG_LONG ((CommDataType)0x4c000819)
98#endif
99
100#ifndef MPI_FLOAT
101#define MPI_FLOAT ((CommDataType)0x4c00040a)
102#endif
103
104#ifndef MPI_DOUBLE
105#define MPI_DOUBLE ((CommDataType)0x4c00080b)
106#endif
107
108#ifndef MPI_LONG_DOUBLE
109#define MPI_LONG_DOUBLE ((CommDataType)0x4c00100c)
110#endif
111} // namespace LibUtilities
112} // namespace Nektar
113#endif
114
115namespace Nektar
116{
117template <typename Dim, typename DataType> class Array;
118
119namespace LibUtilities
120{
122
123template <class T> class CommDataTypeTraits
124{
125public:
127
128 static void *GetPointer(T &val)
129 {
130 return &val;
131 }
132 static const void *GetPointer(const T &val)
133 {
134 return &val;
135 }
136 static int GetCount(const T &val)
137 {
138 boost::ignore_unused(val);
139 return 1;
140 }
141
142 const static bool IsVector = false;
143};
144
145/**
146 * Partial specialisation for vectors
147 */
148template <class elemT> class CommDataTypeTraits<std::vector<elemT>>
149{
150public:
152 {
154 }
155 static void *GetPointer(std::vector<elemT> &val)
156 {
157 ASSERTL1(!val.empty(),
158 "Vector cannot be empty when trying to use GetPointer to "
159 "access a pointer to the first element.");
160 return &val[0];
161 }
162 static const void *GetPointer(const std::vector<elemT> &val)
163 {
164 ASSERTL1(!val.empty(),
165 "Vector cannot be empty when trying to use GetPointer to "
166 "access a pointer to the first element.");
167 return &val[0];
168 }
169 static size_t GetCount(const std::vector<elemT> &val)
170 {
171 return val.size();
172 }
173 const static bool IsVector = true;
174};
175
176/**
177 * Partial specialisation for vectors
178 */
179template <class elemT> class CommDataTypeTraits<Array<OneD, elemT>>
180{
181public:
183 {
185 }
187 {
188 return val.get();
189 }
190 static const void *GetPointer(const Array<OneD, elemT> &val)
191 {
192 return val.get();
193 }
194 static size_t GetCount(const Array<OneD, elemT> &val)
195 {
196 return val.size();
197 }
198 const static bool IsVector = true;
199};
200} // namespace LibUtilities
201} // namespace Nektar
202
203#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
#define LIB_UTILITIES_EXPORT
static void * GetPointer(Array< OneD, elemT > &val)
Definition: CommDataType.h:186
static const void * GetPointer(const Array< OneD, elemT > &val)
Definition: CommDataType.h:190
static size_t GetCount(const Array< OneD, elemT > &val)
Definition: CommDataType.h:194
static size_t GetCount(const std::vector< elemT > &val)
Definition: CommDataType.h:169
static const void * GetPointer(const std::vector< elemT > &val)
Definition: CommDataType.h:162
static void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:155
static const void * GetPointer(const T &val)
Definition: CommDataType.h:132
unsigned int CommDataType
Definition: CommDataType.h:70
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2