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 {
71 {
82 };
83 }
84 }
85 #endif
86 
87 namespace Nektar
88 {
89 template <typename Dim, typename DataType> class Array;
90 
91 namespace LibUtilities
92 {
94 
95 template <class T> class CommDataTypeTraits
96 {
97 public:
98  LIB_UTILITIES_EXPORT static CommDataType &GetDataType();
99 
100  static void *GetPointer(T &val)
101  {
102  return &val;
103  }
104  static const void *GetPointer(const T &val)
105  {
106  return &val;
107  }
108  static int GetCount(const T &val)
109  {
110  boost::ignore_unused(val);
111  return 1;
112  }
113 
114  const static bool IsVector = false;
115 };
116 
117 /**
118  * Partial specialisation for vectors
119  */
120 template <class elemT> class CommDataTypeTraits<std::vector<elemT> >
121 {
122 public:
124  {
126  }
127  static void *GetPointer(std::vector<elemT> &val)
128  {
129  return &val[0];
130  }
131  static const void *GetPointer(const std::vector<elemT> &val)
132  {
133  return &val[0];
134  }
135  static size_t GetCount(const std::vector<elemT> &val)
136  {
137  return val.size();
138  }
139  const static bool IsVector = true;
140 };
141 
142 /**
143  * Partial specialisation for vectors
144  */
145 template <class elemT> class CommDataTypeTraits<Array<OneD, elemT> >
146 {
147 public:
149  {
151  }
152  static void *GetPointer(Array<OneD, elemT> &val)
153  {
154  return val.get();
155  }
156  static const void *GetPointer(const Array<OneD, elemT> &val)
157  {
158  return val.get();
159  }
160  static size_t GetCount(const Array<OneD, elemT> &val)
161  {
162  return val.num_elements();
163  }
164  const static bool IsVector = true;
165 };
166 }
167 }
168 
169 #endif
static void * GetPointer(std::vector< elemT > &val)
Definition: CommDataType.h:127
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:131
static size_t GetCount(const std::vector< elemT > &val)
Definition: CommDataType.h:135
static const void * GetPointer(const Array< OneD, elemT > &val)
Definition: CommDataType.h:156
static const void * GetPointer(const T &val)
Definition: CommDataType.h:104
#define LIB_UTILITIES_EXPORT
static void * GetPointer(Array< OneD, elemT > &val)
Definition: CommDataType.h:152
static size_t GetCount(const Array< OneD, elemT > &val)
Definition: CommDataType.h:160