-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmpi_util.cpp
116 lines (88 loc) · 2.41 KB
/
mpi_util.cpp
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
#include "mpi_util.h"
#include "options.h"
#include "hybrid_sig.h"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////
// Specialization for std::string
/////////////////////////////////////////////////////////////////////////////////////////
template<>
size_t mpi_size<string>(const string &m_str)
{
return sizeof(size_t) + m_str.size();
}
template<>
unsigned char* mpi_pack<string>(unsigned char* m_ptr, const string &m_str)
{
size_t len = m_str.size();
memcpy( m_ptr, &len, sizeof(size_t) );
m_ptr += sizeof(size_t);
memcpy(m_ptr, m_str.c_str(), len);
m_ptr += len;
return m_ptr;
}
template<>
unsigned char* mpi_unpack<string>(unsigned char* m_ptr, string &m_str)
{
size_t len;
memcpy( &len, m_ptr, sizeof(size_t) );
m_ptr += sizeof(size_t);
m_str.assign( (char*)m_ptr, len );
m_ptr += len;
return m_ptr;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Specialization for Options
/////////////////////////////////////////////////////////////////////////////////////////
template<>
size_t mpi_size(const Options &m_obj)
{
size_t ret = 0;
#define VARIABLE(A, B) ret += mpi_size(m_obj.B);
OPTIONS_MEMBERS
#undef VARIABLE
return ret;
};
template<>
unsigned char* mpi_unpack(unsigned char* m_ptr, Options &m_obj)
{
#define VARIABLE(A, B) m_ptr = mpi_unpack(m_ptr, m_obj.B);
OPTIONS_MEMBERS
#undef VARIABLE
return m_ptr;
}
template<>
unsigned char* mpi_pack(unsigned char* m_ptr, const Options &m_obj)
{
#define VARIABLE(A, B) m_ptr = mpi_pack(m_ptr, m_obj.B);
OPTIONS_MEMBERS
#undef VARIABLE
return m_ptr;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Specialization for hybrid_sig
/////////////////////////////////////////////////////////////////////////////////////////
template<>
size_t mpi_size(const hybrid_sig &m_obj)
{
size_t ret = 0;
#define VARIABLE(A, B) ret += mpi_size(m_obj.B);
HYBRID_SIG_MEMBERS
#undef VARIABLE
return ret;
};
template<>
unsigned char* mpi_unpack(unsigned char* m_ptr, hybrid_sig &m_obj)
{
#define VARIABLE(A, B) m_ptr = mpi_unpack(m_ptr, m_obj.B);
HYBRID_SIG_MEMBERS
#undef VARIABLE
return m_ptr;
}
template<>
unsigned char* mpi_pack(unsigned char* m_ptr, const hybrid_sig &m_obj)
{
#define VARIABLE(A, B) m_ptr = mpi_pack(m_ptr, m_obj.B);
HYBRID_SIG_MEMBERS
#undef VARIABLE
return m_ptr;
}