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
43{
44
45/**
46 * @brief Return the size in bytes of a data type @p dt.
47 *
48 * @param dt Data type
49 *
50 * @return Size of @p dt in bytes.
51 */
53{
54#ifdef NEKTAR_USE_MPI
55 int size;
56 MPI_Type_size(dt, &size);
57 return size;
58#elif NEKTAR_USING_PETSC
59 if (dt == MPI_CHAR)
60 return sizeof(char);
61 else if (dt == MPI_INT)
62 return sizeof(int);
63 else if (dt == MPI_UNSIGNED)
64 return sizeof(unsigned);
65 else if (dt == MPI_LONG)
66 return sizeof(long);
67 else if (dt == MPI_UNSIGNED_LONG)
68 return sizeof(unsigned long);
69 else if (dt == MPI_LONG_LONG)
70 return sizeof(long long);
71 else if (dt == MPI_UNSIGNED_LONG_LONG)
72 return sizeof(unsigned long long);
73 else if (dt == MPI_FLOAT)
74 return sizeof(float);
75 else if (dt == MPI_DOUBLE)
76 return sizeof(double);
77 else if (dt == MPI_LONG_DOUBLE)
78 return sizeof(long double);
79 return sizeof(int);
80#else
81 switch (dt)
82 {
83 case MPI_CHAR:
84 return sizeof(char);
85 case MPI_INT:
86 return sizeof(int);
87 case MPI_UNSIGNED:
88 return sizeof(unsigned);
89 case MPI_LONG:
90 return sizeof(long);
92 return sizeof(unsigned long);
93 case MPI_LONG_LONG:
94 return sizeof(long long);
96 return sizeof(unsigned long long);
97 case MPI_FLOAT:
98 return sizeof(float);
99 case MPI_DOUBLE:
100 return sizeof(double);
101 case MPI_LONG_DOUBLE:
102 return sizeof(long double);
103 default:
104 ASSERTL0(false, "Unrecognised datatype!");
105 }
106 return sizeof(int);
107#endif
108}
109
111{
112 static CommDataType type = MPI_CHAR;
113 return type;
114}
115
117{
118 static CommDataType type = MPI_INT;
119 return type;
120}
121
123{
124 static CommDataType type = MPI_UNSIGNED;
125 return type;
126}
127
129{
130 static CommDataType type = MPI_LONG;
131 return type;
132}
133
135{
136 static CommDataType type = MPI_UNSIGNED_LONG;
137 return type;
138}
139
141{
142 static CommDataType type = MPI_LONG_LONG;
143 return type;
144}
145
147{
149 return type;
150}
151
153{
154 static CommDataType type = MPI_FLOAT;
155 return type;
156}
157
159{
160 static CommDataType type = MPI_DOUBLE;
161 return type;
162}
163
165{
166 static CommDataType type = MPI_LONG_DOUBLE;
167 return type;
168}
169
170} // namespace Nektar::LibUtilities
#define MPI_UNSIGNED_LONG_LONG
Definition: CommDataType.h:92
#define MPI_INT
Definition: CommDataType.h:72
#define MPI_FLOAT
Definition: CommDataType.h:96
#define MPI_UNSIGNED_LONG
Definition: CommDataType.h:84
#define MPI_DOUBLE
Definition: CommDataType.h:100
#define MPI_LONG
Definition: CommDataType.h:80
#define MPI_CHAR
Definition: CommDataType.h:68
#define MPI_UNSIGNED
Definition: CommDataType.h:76
#define MPI_LONG_LONG
Definition: CommDataType.h:88
#define MPI_LONG_DOUBLE
Definition: CommDataType.h:104
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
unsigned int CommDataType
Definition: CommDataType.h:65
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.