1 #ifndef DUNE_FEM_DOMAINTHREADITERATOR_HH 2 #define DUNE_FEM_DOMAINTHREADITERATOR_HH 6 #include <dune/common/exceptions.hh> 14 #ifdef USE_SMP_PARALLEL 15 #ifdef HAVE_DUNE_ALUGRID 16 #define USE_THREADPARTITIONER 26 template <
class Gr
idPart>
31 typedef typename GridPartType :: GridType
GridType;
35 #ifdef USE_THREADPARTITIONER 38 typedef typename FilteredGridPartType :: template Codim< 0 >
:: IteratorType 48 static const PartitionIteratorType
pitype = GridPartType :: indexSetPartitionType ;
50 #ifdef USE_THREADPARTITIONER 51 typedef ThreadPartitioner< GridPartType > ThreadPartitionerType;
52 typedef typename ThreadPartitionerType :: Method PartitioningMethodType ;
53 #endif // #ifdef USE_SMP_PARALLEL 60 #ifdef USE_THREADPARTITIONER 62 std::vector< FilteredGridPartType* > filteredGridParts_;
65 ThreadArrayType threadNum_;
70 #ifdef USE_THREADPARTITIONER 71 const PartitioningMethodType method_;
72 #endif // #ifdef USE_SMP_PARALLEL 79 #ifdef USE_THREADPARTITIONER 80 static PartitioningMethodType getMethod (
const ParameterReader ¶meter )
83 const std::string methodNames[] = {
"recursive",
"kway",
"sfc" };
84 return (PartitioningMethodType ) parameter.
getEnum(
"fem.threads.partitioningmethod", methodNames, 0 );
86 #endif // #ifdef USE_SMP_PARALLEL 91 : gridPart_( gridPart ),
92 dofManager_( DofManagerType :: instance( gridPart_.grid() ) ),
93 indexSet_( gridPart_.indexSet() )
94 #ifdef USE_THREADPARTITIONER
99 #ifdef USE_THREADPARTITIONER
100 , method_( getMethod( parameter ) )
102 , communicationThread_( parameter.getValue<bool>(
"fem.threads.communicationthread", false)
105 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
107 #ifdef USE_THREADPARTITIONER 111 filteredGridParts_[
thread ]
112 =
new FilteredGridPartType( const_cast<GridPartType &> (gridPart_),
116 threadNum_.setMemoryFactor( 1.1 );
121 #ifdef USE_THREADPARTITIONER 128 delete filteredGridParts_[
thread ] ;
129 filteredGridParts_[
thread ] = 0 ;
134 const FilterType& filter(
const int thread )
const 136 return filteredGridParts_[
thread ]->filter();
138 #endif // USE_SMP_PARALLEL 143 #ifdef USE_THREADPARTITIONER 144 const int sequence = gridPart_.sequence() ;
146 if( sequence_ != sequence )
150 std::cerr <<
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
155 const int commThread = communicationThread_ ? 1 : 0;
160 ThreadPartitionerType db( gridPart_, partitions, masterRatio_ );
162 db.serialPartition( method_ );
165 typedef typename GridPartType :: template Codim< 0 >
:: IteratorType GPIteratorType;
166 const GPIteratorType endit = gridPart_.template end< 0 >();
169 const size_t size = indexSet_.size( 0 );
172 threadNum_.resize( size );
174 for(
size_t i = 0; i<size; ++i) threadNum_[ i ] = -1;
178 std::vector< int > counter( partitions+commThread , 0 );
180 int numInteriorElems = 0;
181 for(GPIteratorType it = gridPart_.template begin< 0 >();
182 it != endit; ++it, ++numInteriorElems )
184 const EntityType& entity = * it;
185 const int rank = db.getRank( entity ) + commThread ;
188 threadNum_[ indexSet_.index( entity ) ] = rank ;
193 sequence_ = sequence;
197 std::cout <<
"DomainDecomposedIterator: sequence = " << sequence_ <<
" size = " << numInteriorElems << std::endl;
198 const size_t counterSize = counter.size();
199 for(
size_t i = 0; i<counterSize; ++i )
200 std::cout <<
"DomainDecomposedIterator: T[" << i <<
"] = " << counter[ i ] << std::endl;
205 for(GPIteratorType it = gridPart_.template begin< 0 >(); it != endit; ++it )
207 assert( threadNum_[ indexSet_.index( *it ) ] >= 0 );
222 #ifdef USE_THREADPARTITIONER 224 if( communicationThread_ && thread == 0 )
225 return filteredGridParts_[
thread ]->template end< 0 > ();
227 return filteredGridParts_[
thread ]->template begin< 0 > ();
229 return gridPart_.template begin< 0 > ();
236 #ifdef USE_THREADPARTITIONER 239 return gridPart_.template end< 0 > ();
244 int index(
const EntityType& entity )
const 246 return indexSet_.index( entity );
250 int thread(
const EntityType& entity )
const 252 #ifdef USE_THREADPARTITIONER 253 assert( (
int)threadNum_.size() > (int) indexSet_.index( entity ) );
256 return threadNum_[ indexSet_.index( entity ) ];
270 template <
class Gr
idPart>
277 : BaseType( gridPart )
285 #endif // #ifndef DUNE_FEM_DG_DOMAINTHREADITERATOR_HH
GridPartType::IndexSetType IndexSetType
Definition: domainthreaditerator.hh:32
const DofManagerType & dofManager_
Definition: domainthreaditerator.hh:57
Container for User Specified Parameters.
Definition: io/parameter.hh:187
const IndexSetType & indexSet_
Definition: domainthreaditerator.hh:58
The ThreadManager wrapps basic shared memory functionality provided by OpenMP or pthreads such as thr...
Definition: threadmanager.hh:199
int getEnum(const std::string &key, const std::string(&values)[n]) const
Definition: reader.hh:215
double masterRatio_
Definition: domainthreaditerator.hh:68
GridPart GridPartType
Definition: domainthreaditerator.hh:30
DomainDecomposedIteratorStorage(const GridPart &gridPart)
Definition: domainthreaditerator.hh:276
Definition: datacollector.hh:45
DomainDecomposedIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: domainthreaditerator.hh:90
GridPartType::GridType GridType
Definition: domainthreaditerator.hh:31
ThreadFilter< GridPartType > FilterType
Definition: domainthreaditerator.hh:34
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: gridpart/filteredgridpart/capabilities.hh:23
static int thread()
return thread number
Definition: threadmanager.hh:208
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:250
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition: domainthreaditerator.hh:41
void update()
update internal list of iterators
Definition: domainthreaditerator.hh:141
Definition: coordinate.hh:4
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:23
static const PartitionIteratorType pitype
Definition: domainthreaditerator.hh:48
static ParameterContainer & container()
Definition: io/parameter.hh:190
void setMasterRatio(const double ratio)
Definition: domainthreaditerator.hh:262
IteratorType end() const
return end iterator for current thread
Definition: domainthreaditerator.hh:234
const bool communicationThread_
Definition: domainthreaditerator.hh:75
Definition: threadfilter.hh:20
static int maxThreads()
return maximal number of threads possbile in the current run
Definition: threadmanager.hh:202
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:244
Storage of thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:271
DofManager< GridType > DofManagerType
Definition: domainthreaditerator.hh:46
IteratorType::Entity EntityType
Definition: domainthreaditerator.hh:44
const bool verbose_
Definition: domainthreaditerator.hh:76
IteratorType begin() const
return begin iterator for current thread
Definition: domainthreaditerator.hh:220
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:217
const GridPartType & gridPart_
Definition: domainthreaditerator.hh:56
Thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:27