rheolef
6.3
Main Page
Namespaces
Classes
Files
Examples
File List
File Members
skit
plib2
distributor.h
Go to the documentation of this file.
1
#ifndef _RHEO_DISTRIBUTOR_H
2
#define _RHEO_DISTRIBUTOR_H
3
4
# include "rheolef/distributed.h"
5
# include "rheolef/dis_macros.h"
6
# include "rheolef/Vector.h"
7
8
namespace
rheolef {
9
19
class
distributor
:
public
Vector
<std::allocator<int>::size_type> {
20
public
:
21
22
23
typedef
std::allocator<int>::size_type
size_type
;
24
typedef
Vector<size_type>
_base
;
25
typedef
_base::iterator
iterator
;
26
typedef
_base::const_iterator
const_iterator
;
27
typedef
int
tag_type
;
28
typedef
communicator
communicator_type
;
29
30
31
static
const
size_type
decide
=
size_type
(-1);
32
33
// allocators/deallocators:
34
35
distributor
(
36
size_type
dis_size
= 0,
37
const
communicator_type
& c =
communicator_type
(),
38
size_type
loc_size =
decide
);
39
40
distributor
(
const
distributor
&);
41
~distributor
();
42
43
void
resize
(
44
size_type
dis_size
= 0,
45
const
communicator_type
& c =
communicator_type
(),
46
size_type
loc_size =
decide
);
47
48
49
const
communicator_type
&
comm
()
const
;
50
52
size_type
dis_size
()
const
;
53
55
size_type
process
()
const
;
56
58
size_type
n_process
()
const
;
59
61
size_type
find_owner
(
size_type
dis_i)
const
;
62
64
size_type
first_index
(
size_type
ip)
const
;
65
size_type
last_index
(
size_type
ip)
const
;
66
size_type
size
(
size_type
ip)
const
;
67
69
size_type
first_index
()
const
;
70
size_type
last_index
()
const
;
71
size_type
size
()
const
;
72
74
bool
is_owned
(
size_type
dis_i,
size_type
ip)
const
;
75
76
bool
is_owned
(
size_type
dis_i)
const
;
77
78
80
static
tag_type
get_new_tag
();
81
82
83
bool
operator==
(
const
distributor
&)
const
;
84
bool
operator!=
(
const
distributor
&)
const
;
85
protected
:
86
communicator_type
_comm
;
87
};
88
@end
code
89
90
inline
91
const
distributor::communicator_type
&
92
distributor::comm
()
const
93
{
94
return
_comm
;
95
}
96
inline
97
distributor::size_type
98
distributor::first_index
(
size_type
j)
const
99
{
100
return
at
(j);
101
}
102
inline
103
distributor::size_type
104
distributor::last_index
(
size_type
j)
const
105
{
106
return
at
(j+1);
107
}
108
inline
109
distributor::size_type
110
distributor::size
(
size_type
j)
const
111
{
112
return
last_index
(j) -
first_index
(j);
113
}
114
inline
115
distributor::size_type
116
distributor::n_process
()
const
117
{
118
#ifdef _RHEOLEF_HAVE_MPI
119
return
_comm
.size();
120
#else // _RHEOLEF_HAVE_MPI
121
return
1;
122
#endif // _RHEOLEF_HAVE_MPI
123
}
124
inline
125
distributor::size_type
126
distributor::process
()
const
127
{
128
#ifdef _RHEOLEF_HAVE_MPI
129
return
_comm
.rank();
130
#else // _RHEOLEF_HAVE_MPI
131
return
0;
132
#endif // _RHEOLEF_HAVE_MPI
133
}
134
inline
135
distributor::size_type
136
distributor::first_index
()
const
137
{
138
return
first_index
(
process
());
139
}
140
inline
141
distributor::size_type
142
distributor::last_index
()
const
143
{
144
return
last_index
(
process
());
145
}
146
inline
147
distributor::size_type
148
distributor::size
()
const
149
{
150
return
size
(
process
());
151
}
152
inline
153
distributor::size_type
154
distributor::dis_size
()
const
155
{
156
return
at
(
n_process
());
157
}
158
inline
159
bool
160
distributor::is_owned
(
size_type
dis_i,
size_type
ip)
const
161
{
162
return
dis_i >=
first_index
(ip) && dis_i <
last_index
(ip);
163
}
164
inline
165
bool
166
distributor::is_owned
(
size_type
dis_i)
const
167
{
168
return
is_owned
(dis_i,
process
());
169
}
170
inline
171
bool
172
distributor::operator!=
(
const
distributor
& x)
const
173
{
174
return
!
operator==
(x);
175
}
176
inline
177
bool
178
distributor::operator==
(
const
distributor
& x)
const
179
{
180
return
(x.
n_process
() ==
n_process
()) && (x.
size
() ==
size
()) && (x.
dis_size
() ==
dis_size
());
181
}
182
183
}
// namespace rheolef
184
#endif // _RHEO_DISTRIBUTOR_H
185