dune-fem 2.8-git
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
11
12#ifdef USE_SMP_PARALLEL
14#endif
15
16namespace Dune {
17
18 namespace Fem {
19
21 template < class ThreadIterator >
23 {
24 public:
27 typedef typename GridPartType :: IndexSetType IndexSetType;
28
31
32 typedef typename IteratorType :: Entity EntityType ;
33
34 static const PartitionIteratorType pitype = ThreadIteratorType :: pitype ;
35
36 private:
37 struct IteratorFactory
38 {
39 struct Key
40 {
43 static const PartitionIteratorType ptype = pitype ;
46 indexSet_( gridPart_.indexSet() )
47 {}
48
49 bool operator ==( const Key& other ) const
50 {
51 // compare grid pointers
52 return (&indexSet_) == (& other.indexSet_ ) && ( ptype == other.ptype );
53 }
54 const GridPartType& gridPart() const { return gridPart_; }
55 };
56
57 typedef ThreadIteratorType ObjectType;
58 typedef Key KeyType;
59
60 inline static ObjectType *createObject ( const KeyType &key )
61 {
62 return new ObjectType( key.gridPart() );
63 }
64
65 inline static void deleteObject ( ObjectType *object )
66 {
67 delete object;
68 }
69 };
70
71
72 typedef typename IteratorFactory :: KeyType KeyType;
73 typedef SingletonList< KeyType,
74 ThreadIteratorType, IteratorFactory > IteratorProviderType;
75
76 protected:
77 std::unique_ptr< ThreadIteratorType, typename IteratorProviderType::Deleter> iterators_;
78
79 public:
81 explicit ThreadIteratorStorageBase( const GridPartType& gridPart )
82 : iterators_( &IteratorProviderType::getObject( KeyType( gridPart ) ) )
83 {
84 update();
85 }
86
87 ThreadIteratorType& iterators () const { assert( iterators_ ); return *iterators_; }
88
90 const FilterType& filter( const int thread ) const
91 {
92 return iterators().filter( thread );
93 }
94
96 void update()
97 {
98 iterators().update();
99 }
100
102 void setMasterRatio( const double ratio )
103 {
104 iterators().setMasterRatio( ratio );
105 }
106
109 {
110 return iterators().begin();
111 }
112
115 {
116 return iterators().end();
117 }
118
120 int index(const EntityType& entity ) const
121 {
122 return iterators().index( entity );
123 }
124
126 int thread(const EntityType& entity ) const
127 {
128 return iterators().thread( entity );
129 }
130 };
131 } // end namespace Fem
132} // end namespace Dune
133
134#endif // #ifndef DUNE_FEM_DG_DOMAINTHREADITERATOR_HH
Definition: bindguard.hh:11
Definition: domainfilter.hh:55
Thread iterators.
Definition: threaditerator.hh:23
static const PartitionIteratorType pitype
Definition: threaditerator.hh:28
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:227
IteratorType end() const
return end iterator for current thread
Definition: threaditerator.hh:211
void update()
update internal list of iterators
Definition: threaditerator.hh:102
void setMasterRatio(const double ratio)
set ratio between master thread and other threads in comp time
Definition: threaditerator.hh:240
DomainFilter< GridPartType > FilterType
Definition: threaditerator.hh:37
GridPartType::template Codim< 0 >::template Partition< pitype >::IteratorType IteratorType
Definition: threaditerator.hh:32
GridPart GridPartType
Definition: threaditerator.hh:30
IteratorType begin() const
return begin iterator for current thread
Definition: threaditerator.hh:201
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:221
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:23
ThreadIteratorType & iterators() const
Definition: threaditeratorstorage.hh:87
static const PartitionIteratorType pitype
Definition: threaditeratorstorage.hh:34
void setMasterRatio(const double ratio)
set ratio between master thread and other threads in comp time
Definition: threaditeratorstorage.hh:102
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditeratorstorage.hh:126
IteratorType end() const
return end iterator for current thread
Definition: threaditeratorstorage.hh:114
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditeratorstorage.hh:120
const FilterType & filter(const int thread) const
return filter for given thread
Definition: threaditeratorstorage.hh:90
ThreadIteratorType::FilterType FilterType
Definition: threaditeratorstorage.hh:29
ThreadIteratorType::IteratorType IteratorType
Definition: threaditeratorstorage.hh:30
void update()
update internal list of iterators
Definition: threaditeratorstorage.hh:96
std::unique_ptr< ThreadIteratorType, typename IteratorProviderType::Deleter > iterators_
Definition: threaditeratorstorage.hh:77
ThreadIteratorStorageBase(const GridPartType &gridPart)
contructor creating thread iterators
Definition: threaditeratorstorage.hh:81
IteratorType begin() const
return begin iterator for current thread
Definition: threaditeratorstorage.hh:108
IteratorType::Entity EntityType
Definition: threaditeratorstorage.hh:32
ThreadIterator ThreadIteratorType
Definition: threaditeratorstorage.hh:25
ThreadIterator::GridPartType GridPartType
Definition: threaditeratorstorage.hh:26
GridPartType::IndexSetType IndexSetType
Definition: threaditeratorstorage.hh:27
Definition: threaditeratorstorage.hh:40
const GridPartType & gridPart_
Definition: threaditeratorstorage.hh:41
bool operator==(const Key &other) const
Definition: threaditeratorstorage.hh:49
static const PartitionIteratorType ptype
Definition: threaditeratorstorage.hh:43
const GridPartType & gridPart() const
Definition: threaditeratorstorage.hh:54
const IndexSetType & indexSet_
Definition: threaditeratorstorage.hh:42
Key(const GridPartType &gridPart)
Definition: threaditeratorstorage.hh:44
Singleton list for key/object pairs.
Definition: singletonlist.hh:53