Nektar++
CommDataType.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CommDataType.cpp
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: Define static members for the different data types
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
38#ifdef NEKTAR_USING_PETSC
39#include "petscsys.h"
40#endif
41
42namespace Nektar
43{
44namespace LibUtilities
45{
46
47/**
48 * @brief Return the size in bytes of a data type @p dt.
49 *
50 * @param dt Data type
51 *
52 * @return Size of @p dt in bytes.
53 */
55{
56#ifdef NEKTAR_USE_MPI
57 int size;
58 MPI_Type_size(dt, &size);
59 return size;
60#elif NEKTAR_USING_PETSC
61 if (dt == MPI_CHAR)
62 return sizeof(char);
63 else if (dt == MPI_INT)
64 return sizeof(int);
65 else if (dt == MPI_UNSIGNED)
66 return sizeof(unsigned);
67 else if (dt == MPI_LONG)
68 return sizeof(long);
69 else if (dt == MPI_UNSIGNED_LONG)
70 return sizeof(unsigned long);
71 else if (dt == MPI_LONG_LONG)
72 return sizeof(long long);
73 else if (dt == MPI_UNSIGNED_LONG_LONG)
74 return sizeof(unsigned long long);
75 else if (dt == MPI_FLOAT)
76 return sizeof(float);
77 else if (dt == MPI_DOUBLE)
78 return sizeof(double);
79 else if (dt == MPI_LONG_DOUBLE)
80 return sizeof(long double);
81 return sizeof(int);
82#else
83 switch (dt)
84 {
85 case MPI_CHAR:
86 return sizeof(char);
87 case MPI_INT:
88 return sizeof(int);
89 case MPI_UNSIGNED:
90 return sizeof(unsigned);
91 case MPI_LONG:
92 return sizeof(long);
94 return sizeof(unsigned long);
95 case MPI_LONG_LONG:
96 return sizeof(long long);
98 return sizeof(unsigned long long);
99 case MPI_FLOAT:
100 return sizeof(float);
101 case MPI_DOUBLE:
102 return sizeof(double);
103 case MPI_LONG_DOUBLE:
104 return sizeof(long double);
105 default:
106 ASSERTL0(false, "Unrecognised datatype!");
107 }
108 return sizeof(int);
109#endif
110}
111
113{
114 static CommDataType type = MPI_CHAR;
115 return type;
116}
117
119{
120 static CommDataType type = MPI_INT;
121 return type;
122}
123
125{
126 static CommDataType type = MPI_UNSIGNED;
127 return type;
128}
129
131{
132 static CommDataType type = MPI_LONG;
133 return type;
134}
135
137{
138 static CommDataType type = MPI_UNSIGNED_LONG;
139 return type;
140}
141
143{
144 static CommDataType type = MPI_LONG_LONG;
145 return type;
146}
147
149{
151 return type;
152}
153
155{
156 static CommDataType type = MPI_FLOAT;
157 return type;
158}
159
161{
162 static CommDataType type = MPI_DOUBLE;
163 return type;
164}
165
167{
168 static CommDataType type = MPI_LONG_DOUBLE;
169 return type;
170}
171
172} // namespace LibUtilities
173} // namespace Nektar
#define MPI_UNSIGNED_LONG_LONG
Definition: CommDataType.h:97
#define MPI_INT
Definition: CommDataType.h:77
#define MPI_FLOAT
Definition: CommDataType.h:101
#define MPI_UNSIGNED_LONG
Definition: CommDataType.h:89
#define MPI_DOUBLE
Definition: CommDataType.h:105
#define MPI_LONG
Definition: CommDataType.h:85
#define MPI_CHAR
Definition: CommDataType.h:73
#define MPI_UNSIGNED
Definition: CommDataType.h:81
#define MPI_LONG_LONG
Definition: CommDataType.h:93
#define MPI_LONG_DOUBLE
Definition: CommDataType.h:109
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
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