Dune Core Modules (2.3.1)

plocalindex.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// $Id$
4
5#ifndef DUNE_PLOCALINDEX_HH
6#define DUNE_PLOCALINDEX_HH
7
8#include "localindex.hh"
9#include "indexset.hh"
10#include "mpitraits.hh"
11
12#include <iostream>
13
14namespace Dune
15{
16
17
28 template<class T> class ParallelLocalIndex;
29
35 template<class T>
36 std::ostream& operator<<(std::ostream& os, const ParallelLocalIndex<T>& index)
37 {
38 os<<"{local="<<index.localIndex_<<", attr="<<T(index.attribute_)<<", public="
39 <<(index.public_ ? true : false)<<"}";
40 return os;
41 }
42
46 template<typename T>
48 {
49#if HAVE_MPI
50 // friend declaration needed for MPITraits
51 friend struct MPITraits<ParallelLocalIndex<T> >;
52#endif
53 friend std::ostream& operator<<<>(std::ostream& os, const ParallelLocalIndex<T>& index);
54
55 public:
63 typedef T Attribute;
73
82 ParallelLocalIndex(size_t localIndex, const Attribute& attribute, bool isPublic=true);
89
90#if 0
101#endif
102
107 inline const Attribute attribute() const;
108
113 inline void setAttribute(const Attribute& attribute);
114
119 inline size_t local() const;
120
124 inline operator size_t() const;
125
131 inline ParallelLocalIndex<Attribute>& operator=(size_t index);
132
137 inline bool isPublic() const;
138
143 inline LocalIndexState state() const;
144
149 inline void setState(const LocalIndexState& state);
150
151 private:
153 size_t localIndex_;
154
156 char attribute_;
157
159 char public_;
160
167 char state_;
168
169 };
170
171 template<typename T>
172 bool operator==(const ParallelLocalIndex<T>& p1,
173 const ParallelLocalIndex<T>& p2)
174 {
175 if(p1.local()!=p2.local())
176 return false;
177 if(p1.attribute()!=p2.attribute())
178 return false;
179 if(p1.isPublic()!=p2.isPublic())
180 return false;
181 return true;
182 }
183 template<typename T>
184 bool operator!=(const ParallelLocalIndex<T>& p1,
185 const ParallelLocalIndex<T>& p2)
186 {
187 return !(p1==p2);
188 }
189
190
191 template<typename T>
192 struct LocalIndexComparator<ParallelLocalIndex<T> >
193 {
194 static bool compare(const ParallelLocalIndex<T>& t1,
195 const ParallelLocalIndex<T>& t2){
196 return t1.attribute()<t2.attribute();
197 }
198 };
199
200
201#if HAVE_MPI
202
204 template<typename T>
206 {
207 public:
208 static MPI_Datatype getType();
209 private:
210 static MPI_Datatype type;
211
212 };
213
214#endif
215
216 template<class T>
217 ParallelLocalIndex<T>::ParallelLocalIndex(const T& attribute, bool isPublic)
218 : localIndex_(0), attribute_(static_cast<char>(attribute)),
219 public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
220 {}
221
222
223 template<class T>
224 ParallelLocalIndex<T>::ParallelLocalIndex(size_t local, const T& attribute, bool isPublic)
225 : localIndex_(local), attribute_(static_cast<char>(attribute)),
226 public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
227 {}
228
229 template<class T>
231 : localIndex_(0), attribute_(), public_(static_cast<char>(false)),
232 state_(static_cast<char>(VALID))
233 {}
234
235 template<class T>
236 inline const T ParallelLocalIndex<T>::attribute() const
237 {
238 return T(attribute_);
239 }
240
241 template<class T>
242 inline void
244 {
245 attribute_ = attribute;
246 }
247
248 template<class T>
249 inline size_t ParallelLocalIndex<T>::local() const
250 {
251 return localIndex_;
252 }
253
254 template<class T>
256 {
257 return localIndex_;
258 }
259
260 template<class T>
263 {
264 localIndex_=index;
265 return *this;
266 }
267
268 template<class T>
270 {
271 return static_cast<bool>(public_);
272 }
273
274 template<class T>
276 {
277 return LocalIndexState(state_);
278 }
279
280 template<class T>
282 {
283 state_=static_cast<char>(state);
284 }
285
286#if HAVE_MPI
287
288 template<typename T>
289 MPI_Datatype MPITraits<ParallelLocalIndex<T> >::getType()
290 {
291
292 if(type==MPI_DATATYPE_NULL) {
293 int length[3];
294 MPI_Aint disp[3];
295 MPI_Datatype types[3] = {MPI_LB, MPITraits<char>::getType(), MPI_UB};
296 ParallelLocalIndex<T> rep[2];
297 length[0]=length[1]=length[2]=1;
298 MPI_Address(rep, disp); // lower bound of the datatype
299 MPI_Address(&(rep[0].attribute_), disp+1);
300 MPI_Address(rep+1, disp+2); // upper bound of the datatype
301 for(int i=2; i >= 0; --i)
302 disp[i] -= disp[0];
303 MPI_Type_struct(3, length, disp, types, &type);
304 MPI_Type_commit(&type);
305 }
306 return type;
307 }
308
309 template<typename T>
310 MPI_Datatype MPITraits<ParallelLocalIndex<T> >::type = MPI_DATATYPE_NULL;
311
312#endif
313
314
316} // namespace Dune
317
318#endif
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:48
T Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: plocalindex.hh:63
bool isPublic() const
Check whether the index might also be known other processes.
Definition: plocalindex.hh:269
void setAttribute(const Attribute &attribute)
Set the attribute of the index.
Definition: plocalindex.hh:243
size_t local() const
get the local index.
Definition: plocalindex.hh:249
LocalIndexState
The states avaiable for the local indices.
Definition: localindex.hh:27
void setState(const LocalIndexState &state)
Set the state.
Definition: plocalindex.hh:281
ParallelLocalIndex< Attribute > & operator=(size_t index)
Assign a new local index.
Definition: plocalindex.hh:262
LocalIndexState state() const
Get the state.
Definition: plocalindex.hh:275
ParallelLocalIndex()
Parameterless constructor.
Definition: plocalindex.hh:230
const Attribute attribute() const
Get the attribute of the index.
Definition: plocalindex.hh:236
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:253
Provides a map between global and local indices.
Provides classes for use as the local index in ParallelIndexSet.
Dune namespace.
Definition: alignment.hh:14
Traits classes for mapping types onto MPI_Datatype.
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:37
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)