Nektar++
Loading...
Searching...
No Matches
library
LibUtilities
Communication
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
35
#include <
LibUtilities/BasicUtils/ErrorUtil.hpp
>
36
#include <
LibUtilities/Communication/CommDataType.h
>
37
38
#ifdef NEKTAR_USING_PETSC
39
#include "petscsys.h"
40
#endif
41
42
namespace
Nektar::LibUtilities
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
*/
52
int
CommDataTypeGetSize
(
CommDataType
dt)
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);
91
case
MPI_UNSIGNED_LONG
:
92
return
sizeof
(
unsigned
long);
93
case
MPI_LONG_LONG
:
94
return
sizeof
(
long
long);
95
case
MPI_UNSIGNED_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
110
template
<>
CommDataType
&
CommDataTypeTraits<char>::GetDataType
()
111
{
112
static
CommDataType
type =
MPI_CHAR
;
113
return
type;
114
}
115
116
template
<>
CommDataType
&
CommDataTypeTraits<int>::GetDataType
()
117
{
118
static
CommDataType
type =
MPI_INT
;
119
return
type;
120
}
121
122
template
<>
CommDataType
&
CommDataTypeTraits<unsigned>::GetDataType
()
123
{
124
static
CommDataType
type =
MPI_UNSIGNED
;
125
return
type;
126
}
127
128
template
<>
CommDataType
&
CommDataTypeTraits<long>::GetDataType
()
129
{
130
static
CommDataType
type =
MPI_LONG
;
131
return
type;
132
}
133
134
template
<>
CommDataType
&
CommDataTypeTraits<unsigned long>::GetDataType
()
135
{
136
static
CommDataType
type =
MPI_UNSIGNED_LONG
;
137
return
type;
138
}
139
140
template
<>
CommDataType
&
CommDataTypeTraits<long long>::GetDataType
()
141
{
142
static
CommDataType
type =
MPI_LONG_LONG
;
143
return
type;
144
}
145
146
template
<>
CommDataType
&
CommDataTypeTraits<unsigned long long>::GetDataType
()
147
{
148
static
CommDataType
type =
MPI_UNSIGNED_LONG_LONG
;
149
return
type;
150
}
151
152
template
<>
CommDataType
&
CommDataTypeTraits<float>::GetDataType
()
153
{
154
static
CommDataType
type =
MPI_FLOAT
;
155
return
type;
156
}
157
158
template
<>
CommDataType
&
CommDataTypeTraits<double>::GetDataType
()
159
{
160
static
CommDataType
type =
MPI_DOUBLE
;
161
return
type;
162
}
163
164
template
<>
CommDataType
&
CommDataTypeTraits<long double>::GetDataType
()
165
{
166
static
CommDataType
type =
MPI_LONG_DOUBLE
;
167
return
type;
168
}
169
170
}
// namespace Nektar::LibUtilities
CommDataType.h
MPI_UNSIGNED_LONG_LONG
#define MPI_UNSIGNED_LONG_LONG
Definition
CommDataType.h:92
MPI_INT
#define MPI_INT
Definition
CommDataType.h:72
MPI_FLOAT
#define MPI_FLOAT
Definition
CommDataType.h:96
MPI_UNSIGNED_LONG
#define MPI_UNSIGNED_LONG
Definition
CommDataType.h:84
MPI_DOUBLE
#define MPI_DOUBLE
Definition
CommDataType.h:100
MPI_LONG
#define MPI_LONG
Definition
CommDataType.h:80
MPI_CHAR
#define MPI_CHAR
Definition
CommDataType.h:68
MPI_UNSIGNED
#define MPI_UNSIGNED
Definition
CommDataType.h:76
MPI_LONG_LONG
#define MPI_LONG_LONG
Definition
CommDataType.h:88
MPI_LONG_DOUBLE
#define MPI_LONG_DOUBLE
Definition
CommDataType.h:104
ErrorUtil.hpp
ASSERTL0
#define ASSERTL0(condition, msg)
Definition
ErrorUtil.hpp:216
Nektar::LibUtilities::CommDataTypeTraits::GetDataType
static CommDataType & GetDataType()
Nektar::LibUtilities
Definition
GitRevision.h:54
Nektar::LibUtilities::CommDataType
unsigned int CommDataType
Definition
CommDataType.h:65
Nektar::LibUtilities::CommDataTypeGetSize
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
Definition
CommDataType.cpp:52
Generated on Sun Nov 9 2025 20:16:57 for Nektar++ by
1.9.8