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 {
85 public:
87 
88  static void *GetPointer(T &val)
89  {
90  return &val;
91  }
92  static const void *GetPointer(const T &val)
93  {
94  return &val;
95  }
96  static int GetCount(const T &val)
97  {
98  return 1;
99  }
100 
101  const static bool IsVector = false;
102 };
103 
104 /**
105  * Partial specialisation for vectors
106  */
107 template <class elemT> class CommDataTypeTraits<std::vector<elemT> >
108 {
109 public:
111  {
113  }
114  static void *GetPointer(std::vector<elemT> &val)
115  {
116  return &val[0];
117  }
118  static const void *GetPointer(const std::vector<elemT> &val)
119  {
120  return &val[0];
121  }
122  static int GetCount(const std::vector<elemT> &val)
123  {
124  return val.size();
125  }
126  const static bool IsVector = true;
127 };
128 
129 /**
130  * Partial specialisation for vectors
131  */
132 template <class elemT> class CommDataTypeTraits<Array<OneD, elemT> >
133 {
134 public:
136  {
138  }
139  static void *GetPointer(Array<OneD, elemT> &val)
140  {
141  return val.get();
142  }
143  static const void *GetPointer(const Array<OneD, elemT> &val)
144  {
145  return val.get();
146  }
147  static int GetCount(const Array<OneD, elemT> &val)
148  {
149  return val.num_elements();
150  }
151  const static bool IsVector = true;
152 };
153 }
154 }
155 
156 #endif
static int GetCount(const Array< OneD, elemT > &val)
Definition: CommDataType.h:147
static void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:114
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
static int GetCount(const T &val)
Definition: CommDataType.h:96
STL namespace.
static const void * GetPointer(const std::vector< elemT > &val)
Definition: CommDataType.h:118
static int GetCount(const std::vector< elemT > &val)
Definition: CommDataType.h:122
static const void * GetPointer(const Array< OneD, elemT > &val)
Definition: CommDataType.h:143
static const void * GetPointer(const T &val)
Definition: CommDataType.h:92
#define LIB_UTILITIES_EXPORT
static void * GetPointer(Array< OneD, elemT > &val)
Definition: CommDataType.h:139