dune-fem  2.4.1-rc
threaditeratorstorage.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_THREADITERATORSTORAGE_HH
2 #define DUNE_FEM_THREADITERATORSTORAGE_HH
3 
4 #include <vector>
5 
6 #include <dune/common/exceptions.hh>
7 
12 
13 #ifdef USE_SMP_PARALLEL
15 #endif
16 
17 namespace Dune {
18 
19  namespace Fem {
20 
22  template < class ThreadIterator >
24  {
25  public:
28  typedef typename GridPartType :: IndexSetType IndexSetType;
29 
32 
33  typedef typename IteratorType :: Entity EntityType ;
34 
35  static const PartitionIteratorType pitype = ThreadIteratorType :: pitype ;
36 
37  private:
38  struct IteratorFactory
39  {
40  struct Key
41  {
42  const GridPartType& gridPart_;
43  const IndexSetType& indexSet_;
44  static const PartitionIteratorType ptype = pitype ;
45  Key(const GridPartType& gridPart)
46  : gridPart_( gridPart ),
47  indexSet_( gridPart_.indexSet() )
48  {}
49 
50  bool operator ==( const Key& other ) const
51  {
52  // compare grid pointers
53  return (&indexSet_) == (& other.indexSet_ ) && ( ptype == other.ptype );
54  }
55  const GridPartType& gridPart() const { return gridPart_; }
56  };
57 
58  typedef ThreadIteratorType ObjectType;
59  typedef Key KeyType;
60 
61  inline static ObjectType *createObject ( const KeyType &key )
62  {
63  return new ObjectType( key.gridPart() );
64  }
65 
66  inline static void deleteObject ( ObjectType *object )
67  {
68  delete object;
69  }
70  };
71 
72 
73  typedef typename IteratorFactory :: KeyType KeyType;
74  typedef SingletonList< KeyType,
75  ThreadIteratorType, IteratorFactory > IteratorProviderType;
76 
77  protected:
78  ThreadIteratorType& iterators_;
79 
80  public:
82  explicit ThreadIteratorStorageBase( const GridPartType& gridPart )
83  : iterators_( IteratorProviderType::getObject( KeyType( gridPart ) ) )
84  {
85  update();
86  }
87 
90  {
92  }
93 
95  const FilterType& filter( const int thread ) const
96  {
97  return iterators_.filter( thread );
98  }
99 
101  void update()
102  {
103  iterators_.update();
104  }
105 
107  void setMasterRatio( const double ratio )
108  {
109  iterators_.setMasterRatio( ratio );
110  }
111 
113  IteratorType begin() const
114  {
115  return iterators_.begin();
116  }
117 
119  IteratorType end() const
120  {
121  return iterators_.end();
122  }
123 
125  int index(const EntityType& entity ) const
126  {
127  return iterators_.index( entity );
128  }
129 
131  int thread(const EntityType& entity ) const
132  {
133  return iterators_.thread( entity );
134  }
135  };
136  } // end namespace Fem
137 } // end namespace Dune
138 
139 #endif // #ifndef DUNE_FEM_DG_DOMAINTHREADITERATOR_HH
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:227
ThreadIteratorType::FilterType FilterType
Definition: threaditeratorstorage.hh:30
GridPartType::IndexSetType IndexSetType
Definition: threaditeratorstorage.hh:28
const FilterType & filter(const int thread) const
return filter for given thread
Definition: threaditeratorstorage.hh:95
IteratorType end() const
return end iterator for current thread
Definition: threaditeratorstorage.hh:119
Thread iterators.
Definition: threaditerator.hh:22
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:221
static const PartitionIteratorType pitype
Definition: threaditerator.hh:28
void update()
update internal list of iterators
Definition: threaditeratorstorage.hh:101
ThreadIteratorType & iterators_
Definition: threaditeratorstorage.hh:78
ThreadIterator::GridPartType GridPartType
Definition: threaditeratorstorage.hh:27
ThreadIteratorType::IteratorType IteratorType
Definition: threaditeratorstorage.hh:31
IteratorType begin() const
return begin iterator for current thread
Definition: threaditeratorstorage.hh:113
Singleton list for key/object pairs.
Definition: singletonlist.hh:49
static const PartitionIteratorType ptype
Definition: threaditeratorstorage.hh:44
IteratorType end() const
return end iterator for current thread
Definition: threaditerator.hh:211
bool operator==(const Key &other) const
Definition: threaditeratorstorage.hh:50
IteratorType::Entity EntityType
Definition: threaditeratorstorage.hh:33
static const PartitionIteratorType pitype
Definition: threaditeratorstorage.hh:35
ThreadIteratorStorageBase(const GridPartType &gridPart)
contructor creating thread iterators
Definition: threaditeratorstorage.hh:82
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditeratorstorage.hh:125
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditeratorstorage.hh:131
Definition: threaditeratorstorage.hh:40
Definition: coordinate.hh:4
IteratorType begin() const
return begin iterator for current thread
Definition: threaditerator.hh:201
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:23
static void removeObject(const ObjectType &object)
Definition: singletonlist.hh:114
~ThreadIteratorStorageBase()
destructor removing instance of thread iterators
Definition: threaditeratorstorage.hh:89
void update()
update internal list of iterators
Definition: threaditerator.hh:102
GridPartType::template Codim< 0 >::template Partition< pitype >::IteratorType IteratorType
Definition: threaditerator.hh:32
const GridPartType & gridPart_
Definition: threaditeratorstorage.hh:42
Key(const GridPartType &gridPart)
Definition: threaditeratorstorage.hh:45
ThreadIterator ThreadIteratorType
Definition: threaditeratorstorage.hh:26
Definition: threadfilter.hh:20
void setMasterRatio(const double ratio)
set ratio between master thread and other threads in comp time
Definition: threaditerator.hh:240
const GridPartType & gridPart() const
Definition: threaditeratorstorage.hh:55
const IndexSetType & indexSet_
Definition: threaditeratorstorage.hh:43
void setMasterRatio(const double ratio)
set ratio between master thread and other threads in comp time
Definition: threaditeratorstorage.hh:107
GridPart GridPartType
Definition: threaditerator.hh:30