Dune Core Modules (2.6.0)

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 
4 #ifndef DUNE_PLOCALINDEX_HH
5 #define DUNE_PLOCALINDEX_HH
6 
7 #include "localindex.hh"
8 #include "indexset.hh"
9 #include "mpitraits.hh"
10 
11 #include <iostream>
12 
13 namespace Dune
14 {
15 
16 
27  template<class T> class ParallelLocalIndex;
28 
34  template<class T>
35  std::ostream& operator<<(std::ostream& os, const ParallelLocalIndex<T>& index)
36  {
37  os<<"{local="<<index.localIndex_<<", attr="<<T(index.attribute_)<<", public="
38  <<(index.public_ ? true : false)<<"}";
39  return os;
40  }
41 
45  template<typename T>
47  {
48 #if HAVE_MPI
49  // friend declaration needed for MPITraits
50  friend struct MPITraits<ParallelLocalIndex<T> >;
51 #endif
52  friend std::ostream& operator<<<>(std::ostream& os, const ParallelLocalIndex<T>& index);
53 
54  public:
62  typedef T Attribute;
72 
81  ParallelLocalIndex(size_t localIndex, const Attribute& attribute, bool isPublic=true);
88 
89 #if 0
99  ParallelLocalIndex(const Attribute& attribute, size_t local, bool isPublic);
100 #endif
101 
106  inline const Attribute attribute() const;
107 
112  inline void setAttribute(const Attribute& attribute);
113 
118  inline size_t local() const;
119 
123  inline operator size_t() const;
124 
130  inline ParallelLocalIndex<Attribute>& operator=(size_t index);
131 
136  inline bool isPublic() const;
137 
142  inline LocalIndexState state() const;
143 
148  inline void setState(const LocalIndexState& state);
149 
150  private:
152  size_t localIndex_;
153 
155  char attribute_;
156 
158  char public_;
159 
166  char state_;
167 
168  };
169 
170  template<typename T>
171  bool operator==(const ParallelLocalIndex<T>& p1,
172  const ParallelLocalIndex<T>& p2)
173  {
174  if(p1.local()!=p2.local())
175  return false;
176  if(p1.attribute()!=p2.attribute())
177  return false;
178  if(p1.isPublic()!=p2.isPublic())
179  return false;
180  return true;
181  }
182  template<typename T>
183  bool operator!=(const ParallelLocalIndex<T>& p1,
184  const ParallelLocalIndex<T>& p2)
185  {
186  return !(p1==p2);
187  }
188 
189 
190  template<typename T>
191  struct LocalIndexComparator<ParallelLocalIndex<T> >
192  {
193  static bool compare(const ParallelLocalIndex<T>& t1,
194  const ParallelLocalIndex<T>& t2){
195  return t1.attribute()<t2.attribute();
196  }
197  };
198 
199 
200 #if HAVE_MPI
201 
203  template<typename T>
205  {
206  public:
207  static MPI_Datatype getType();
208  private:
209  static MPI_Datatype type;
210 
211  };
212 
213 #endif
214 
215  template<class T>
216  ParallelLocalIndex<T>::ParallelLocalIndex(const T& attribute, bool isPublic)
217  : localIndex_(0), attribute_(static_cast<char>(attribute)),
218  public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
219  {}
220 
221 
222  template<class T>
223  ParallelLocalIndex<T>::ParallelLocalIndex(size_t local, const T& attribute, bool isPublic)
224  : localIndex_(local), attribute_(static_cast<char>(attribute)),
225  public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
226  {}
227 
228  template<class T>
230  : localIndex_(0), attribute_(), public_(static_cast<char>(false)),
231  state_(static_cast<char>(VALID))
232  {}
233 
234  template<class T>
235  inline const T ParallelLocalIndex<T>::attribute() const
236  {
237  return T(attribute_);
238  }
239 
240  template<class T>
241  inline void
243  {
244  attribute_ = attribute;
245  }
246 
247  template<class T>
248  inline size_t ParallelLocalIndex<T>::local() const
249  {
250  return localIndex_;
251  }
252 
253  template<class T>
254  inline ParallelLocalIndex<T>::operator size_t() const
255  {
256  return localIndex_;
257  }
258 
259  template<class T>
260  inline ParallelLocalIndex<T>&
262  {
263  localIndex_=index;
264  return *this;
265  }
266 
267  template<class T>
269  {
270  return static_cast<bool>(public_);
271  }
272 
273  template<class T>
275  {
276  return LocalIndexState(state_);
277  }
278 
279  template<class T>
281  {
282  state_=static_cast<char>(state);
283  }
284 
285 #if HAVE_MPI
286 
287  template<typename T>
288  MPI_Datatype MPITraits<ParallelLocalIndex<T> >::getType()
289  {
290 
291  if(type==MPI_DATATYPE_NULL) {
292  int length = 1;
293  MPI_Aint base, disp;
294  MPI_Datatype types[1] = {MPITraits<char>::getType()};
295  ParallelLocalIndex<T> rep;
296  MPI_Get_address(&rep, &base);
297  MPI_Get_address(&(rep.attribute_), &disp);
298  disp -= base;
299 
300  MPI_Datatype tmp;
301  MPI_Type_create_struct(1, &length, &disp, types, &tmp);
302 
303  MPI_Type_create_resized(tmp, 0, sizeof(ParallelLocalIndex<T>), &type);
304  MPI_Type_commit(&type);
305 
306  MPI_Type_free(&tmp);
307  }
308  return type;
309  }
310 
311  template<typename T>
312  MPI_Datatype MPITraits<ParallelLocalIndex<T> >::type = MPI_DATATYPE_NULL;
313 
314 #endif
315 
316 
318 } // namespace Dune
319 
320 #endif
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:47
T Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: plocalindex.hh:62
bool isPublic() const
Check whether the index might also be known other processes.
Definition: plocalindex.hh:268
void setAttribute(const Attribute &attribute)
Set the attribute of the index.
Definition: plocalindex.hh:242
size_t local() const
get the local index.
Definition: plocalindex.hh:248
LocalIndexState
The states avaiable for the local indices.
Definition: localindex.hh:26
std::ostream & operator<<(std::ostream &os, const ParallelLocalIndex< T > &index)
Print the local index to a stream.
Definition: plocalindex.hh:35
void setState(const LocalIndexState &state)
Set the state.
Definition: plocalindex.hh:280
ParallelLocalIndex< Attribute > & operator=(size_t index)
Assign a new local index.
Definition: plocalindex.hh:261
LocalIndexState state() const
Get the state.
Definition: plocalindex.hh:274
ParallelLocalIndex()
Parameterless constructor.
Definition: plocalindex.hh:229
const Attribute attribute() const
Get the attribute of the index.
Definition: plocalindex.hh:235
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:255
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:233
Provides a map between global and local indices.
Provides classes for use as the local index in ParallelIndexSet.
Traits classes for mapping types onto MPI_Datatype.
Dune namespace.
Definition: alignedallocator.hh:10
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:38
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)