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 
46 namespace Nektar
47 {
48 namespace LibUtilities
49 {
50 typedef MPI_Datatype CommDataType;
51 }
52 }
53 
54 #elif NEKTAR_USING_PETSC
55 
56 namespace Nektar
57 {
58 namespace LibUtilities
59 {
60 typedef unsigned int CommDataType;
61 }
62 }
63 
64 #else
65 
66 namespace Nektar
67 {
68 namespace LibUtilities
69 {
70 typedef 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 }
112 }
113 #endif
114 
115 namespace Nektar
116 {
117 template <typename Dim, typename DataType> class Array;
118 
119 namespace LibUtilities
120 {
122 
123 template <class T> class CommDataTypeTraits
124 {
125 public:
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  */
148 template <class elemT> class CommDataTypeTraits<std::vector<elemT> >
149 {
150 public:
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  */
179 template <class elemT> class CommDataTypeTraits<Array<OneD, elemT> >
180 {
181 public:
183  {
185  }
186  static void *GetPointer(Array<OneD, elemT> &val)
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 }
201 }
202 
203 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
#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 void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:155
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 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:1