Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Describes data types (using MPI_Datatype if available)
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_COMMDATATYPE_H
37 #define NEKTAR_LIB_UTILITIES_COMMDATATYPE_H
38 
40 #include <vector>
41 
42 #ifdef NEKTAR_USE_MPI
43 #include <mpi.h>
44 
45 namespace Nektar
46 {
47 namespace LibUtilities
48 {
49 typedef MPI_Datatype CommDataType;
50 }
51 }
52 
53 #else
54 
55 namespace Nektar
56 {
57 namespace LibUtilities
58 {
60 {
70 };
71 }
72 }
73 #endif
74 
75 namespace Nektar
76 {
77 template <typename Dim, typename DataType> class Array;
78 
79 namespace LibUtilities
80 {
82 
83 template <class T> class CommDataTypeTraits
84 {
86 
87 public:
89  {
90  return type;
91  }
92  static void *GetPointer(T &val)
93  {
94  return &val;
95  }
96  static const void *GetPointer(const T &val)
97  {
98  return &val;
99  }
100  static int GetCount(const T &val)
101  {
102  return 1;
103  }
104 
105  const static bool IsVector = false;
106 };
107 
108 /**
109  * Partial specialisation for vectors
110  */
111 template <class elemT> class CommDataTypeTraits<std::vector<elemT> >
112 {
113 public:
115  {
117  }
118  static void *GetPointer(std::vector<elemT> &val)
119  {
120  return &val[0];
121  }
122  static const void *GetPointer(const std::vector<elemT> &val)
123  {
124  return &val[0];
125  }
126  static int GetCount(const std::vector<elemT> &val)
127  {
128  return val.size();
129  }
130  const static bool IsVector = true;
131 };
132 
133 /**
134  * Partial specialisation for vectors
135  */
136 template <class elemT> class CommDataTypeTraits<Array<OneD, elemT> >
137 {
138 public:
140  {
142  }
143  static void *GetPointer(Array<OneD, elemT> &val)
144  {
145  return val.get();
146  }
147  static const void *GetPointer(const Array<OneD, elemT> &val)
148  {
149  return val.get();
150  }
151  static int GetCount(const Array<OneD, elemT> &val)
152  {
153  return val.num_elements();
154  }
155  const static bool IsVector = true;
156 };
157 }
158 }
159 
160 #endif
static int GetCount(const Array< OneD, elemT > &val)
Definition: CommDataType.h:151
static void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:118
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
STL namespace.
static const void * GetPointer(const std::vector< elemT > &val)
Definition: CommDataType.h:122
static int GetCount(const std::vector< elemT > &val)
Definition: CommDataType.h:126
static const void * GetPointer(const Array< OneD, elemT > &val)
Definition: CommDataType.h:147
static const void * GetPointer(const T &val)
Definition: CommDataType.h:96
#define LIB_UTILITIES_EXPORT
static CommDataType & GetDataType()
Definition: CommDataType.h:88
static void * GetPointer(Array< OneD, elemT > &val)
Definition: CommDataType.h:143