Nektar++
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
43
{
44
namespace
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
*/
54
int
CommDataTypeGetSize
(
CommDataType
dt)
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);
93
case
MPI_UNSIGNED_LONG
:
94
return
sizeof
(
unsigned
long);
95
case
MPI_LONG_LONG
:
96
return
sizeof
(
long
long);
97
case
MPI_UNSIGNED_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
112
template
<>
CommDataType
&
CommDataTypeTraits<char>::GetDataType
()
113
{
114
static
CommDataType
type =
MPI_CHAR
;
115
return
type;
116
}
117
118
template
<>
CommDataType
&
CommDataTypeTraits<int>::GetDataType
()
119
{
120
static
CommDataType
type =
MPI_INT
;
121
return
type;
122
}
123
124
template
<>
CommDataType
&
CommDataTypeTraits<unsigned>::GetDataType
()
125
{
126
static
CommDataType
type =
MPI_UNSIGNED
;
127
return
type;
128
}
129
130
template
<>
CommDataType
&
CommDataTypeTraits<long>::GetDataType
()
131
{
132
static
CommDataType
type =
MPI_LONG
;
133
return
type;
134
}
135
136
template
<>
CommDataType
&
CommDataTypeTraits<unsigned long>::GetDataType
()
137
{
138
static
CommDataType
type =
MPI_UNSIGNED_LONG
;
139
return
type;
140
}
141
142
template
<>
CommDataType
&
CommDataTypeTraits<long long>::GetDataType
()
143
{
144
static
CommDataType
type =
MPI_LONG_LONG
;
145
return
type;
146
}
147
148
template
<>
CommDataType
&
CommDataTypeTraits<unsigned long long>::GetDataType
()
149
{
150
static
CommDataType
type =
MPI_UNSIGNED_LONG_LONG
;
151
return
type;
152
}
153
154
template
<>
CommDataType
&
CommDataTypeTraits<float>::GetDataType
()
155
{
156
static
CommDataType
type =
MPI_FLOAT
;
157
return
type;
158
}
159
160
template
<>
CommDataType
&
CommDataTypeTraits<double>::GetDataType
()
161
{
162
static
CommDataType
type =
MPI_DOUBLE
;
163
return
type;
164
}
165
166
template
<>
CommDataType
&
CommDataTypeTraits<long double>::GetDataType
()
167
{
168
static
CommDataType
type =
MPI_LONG_DOUBLE
;
169
return
type;
170
}
171
172
}
173
}
ASSERTL0
#define ASSERTL0(condition, msg)
Definition:
ErrorUtil.hpp:216
ErrorUtil.hpp
Nektar::LibUtilities::MPI_UNSIGNED
Definition:
CommDataType.h:74
Nektar
Definition:
CoupledSolver.h:1
Nektar::LibUtilities::CommDataTypeGetSize
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
Definition:
CommDataType.cpp:54
Nektar::LibUtilities::MPI_DOUBLE
Definition:
CommDataType.h:80
Nektar::LibUtilities::MPI_INT
Definition:
CommDataType.h:73
CommDataType.h
Nektar::LibUtilities::MPI_LONG
Definition:
CommDataType.h:75
Nektar::LibUtilities::MPI_CHAR
Definition:
CommDataType.h:72
Nektar::LibUtilities::MPI_FLOAT
Definition:
CommDataType.h:79
Nektar::LibUtilities::CommDataTypeTraits::GetDataType
static CommDataType & GetDataType()
Nektar::LibUtilities::MPI_UNSIGNED_LONG_LONG
Definition:
CommDataType.h:78
Nektar::LibUtilities::MPI_LONG_DOUBLE
Definition:
CommDataType.h:81
Nektar::LibUtilities::MPI_UNSIGNED_LONG
Definition:
CommDataType.h:76
Nektar::LibUtilities::CommDataType
CommDataType
Definition:
CommDataType.h:70
Nektar::LibUtilities::MPI_LONG_LONG
Definition:
CommDataType.h:77
Generated on Wed Jan 20 2021 03:33:31 for Nektar++ by
1.8.13