-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.h
144 lines (118 loc) · 3.7 KB
/
Types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Types.h
* This file is part of Generic Runtime Support for Parallel Divide and Conquer
*
* Copyright (C) 2010 - Lorenzo Anardu, Emanuele Vespa
*
* Generic Runtime Support for Parallel Divide and Conquer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Generic Runtime Support for Parallel Divide and Conquer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Generic Runtime Support for Parallel Divide and Conquer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include <cstddef>
#include "mpi.h"
#include "./Exception.h"
#include "./UserClasses.h"
#ifndef DAC_TYPES
#define DAC_TYPES
namespace dac {
template <bool v>
struct Bool2Type {
enum {value = v};
};
/*****************************************
* Structure used for mapping base types on MPI::Datatype
* For user-defined classes/structs returns MPI::BYTE
*****************************************/
template <class T>
struct MpiType {
inline static const MPI::Datatype &get() { return MPI::BYTE; }
};
/*****************************************
* Mapping of base types on MPI::Datatype struct
*****************************************/
template<>
struct MpiType<char> {
inline static const MPI::Datatype &get() { return MPI::CHAR; }
};
template<>
struct MpiType<signed char> {
inline static const MPI::Datatype &get() { return MPI::SIGNED_CHAR; }
};
template<>
struct MpiType<unsigned char> {
inline static const MPI::Datatype &get() { return MPI::UNSIGNED_CHAR; }
};
template<>
struct MpiType<short> {
inline static const MPI::Datatype &get() { return MPI::SHORT; }
};
template<>
struct MpiType<unsigned short> {
inline static const MPI::Datatype &get() { return MPI::UNSIGNED_SHORT; }
};
template<>
struct MpiType<int> {
inline static const MPI::Datatype &get() { return MPI::INT; }
};
template<>
struct MpiType<unsigned> {
inline static const MPI::Datatype &get() { return MPI::UNSIGNED; }
};
template<>
struct MpiType<long> {
inline static const MPI::Datatype &get() { return MPI::LONG; }
};
template<>
struct MpiType<unsigned long> {
inline static const MPI::Datatype &get() { return MPI::UNSIGNED_LONG; }
};
template<>
struct MpiType<float> {
inline static const MPI::Datatype &get() { return MPI::FLOAT; }
};
template<>
struct MpiType<double> {
inline static const MPI::Datatype &get() { return MPI::DOUBLE; }
};
template<>
struct MpiType<long double> {
inline static const MPI::Datatype &get() { return MPI::LONG_DOUBLE; }
};
/*****************************************
* Function used for test if a type is serializable
*
* A type is serializable iff it extends SerializableData class (defined in UserClasses.h)
* base types are not serializable.
*****************************************/
#define IS_SERIALIZABLE(U) \
(Conversion<const U*, const SerializableData*>::exists && \
!Conversion<const SerializableData*, const void*>::sameType)
template <class T, class U>
struct Conversion {
private:
typedef char Small;
class Big { char dummy[2]; };
static Small Test(U);
static Big Test(...);
static T MakeT();
public:
enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
enum { sameType = false };
};
template<class T>
struct Conversion<T, T> {
enum {exists = true, sameType = true};
};
}
#endif