1#ifndef DUNE_FEM_DOMAINTHREADITERATOR_HH
2#define DUNE_FEM_DOMAINTHREADITERATOR_HH
6#include <dune/common/exceptions.hh>
14#ifdef USE_SMP_PARALLEL
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 ;
60#ifdef USE_THREADPARTITIONER
62 std::vector< FilteredGridPartType* > filteredGridParts_;
65 ThreadArrayType threadNum_;
70#ifdef USE_THREADPARTITIONER
71 const PartitioningMethodType method_;
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 );
94#ifdef USE_THREADPARTITIONER
99#ifdef USE_THREADPARTITIONER
100 , method_( getMethod( parameter ) )
105 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
107#ifdef USE_THREADPARTITIONER
111 filteredGridParts_[
thread ]
116 threadNum_.setMemoryFactor( 1.1 );
121#ifdef USE_THREADPARTITIONER
128 delete filteredGridParts_[
thread ] ;
129 filteredGridParts_[
thread ] = 0 ;
136 return filteredGridParts_[
thread ]->filter();
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;
162 db.serialPartition( method_ );
165 typedef typename GridPartType :: template Codim< 0 >
:: IteratorType GPIteratorType;
166 const GPIteratorType endit =
gridPart_.template end< 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 )
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
225 return filteredGridParts_[
thread ]->template end< 0 > ();
227 return filteredGridParts_[
thread ]->template begin< 0 > ();
236#ifdef USE_THREADPARTITIONER
252#ifdef USE_THREADPARTITIONER
253 assert( (
int)threadNum_.size() > (
int)
indexSet_.index( entity ) );
256 return threadNum_[
indexSet_.index( entity ) ];
270 template <
class Gr
idPart>
Definition: bindguard.hh:11
Definition: domainfilter.hh:55
DomainArrayImp DomainArrayType
type of array
Definition: domainfilter.hh:61
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: filteredgridpart.hh:228
Container for User Specified Parameters.
Definition: io/parameter.hh:191
static ParameterContainer & container()
Definition: io/parameter.hh:193
int getEnum(const std::string &key, const std::string(&values)[n]) const
Definition: reader.hh:225
Thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:28
void setMasterRatio(const double ratio)
Definition: domainthreaditerator.hh:262
const bool communicationThread_
Definition: domainthreaditerator.hh:75
static const PartitionIteratorType pitype
Definition: domainthreaditerator.hh:48
GridPart GridPartType
Definition: domainthreaditerator.hh:30
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:244
const IndexSetType & indexSet_
Definition: domainthreaditerator.hh:58
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition: domainthreaditerator.hh:41
const bool verbose_
Definition: domainthreaditerator.hh:76
IteratorType begin() const
return begin iterator for current thread
Definition: domainthreaditerator.hh:220
IteratorType end() const
return end iterator for current thread
Definition: domainthreaditerator.hh:234
DomainFilter< GridPartType > FilterType
Definition: domainthreaditerator.hh:34
GridPartType::IndexSetType IndexSetType
Definition: domainthreaditerator.hh:32
const DofManagerType & dofManager_
Definition: domainthreaditerator.hh:57
DofManager< GridType > DofManagerType
Definition: domainthreaditerator.hh:46
GridPartType::GridType GridType
Definition: domainthreaditerator.hh:31
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:250
const GridPartType & gridPart_
Definition: domainthreaditerator.hh:56
IteratorType::Entity EntityType
Definition: domainthreaditerator.hh:44
DomainDecomposedIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: domainthreaditerator.hh:90
void update()
update internal list of iterators
Definition: domainthreaditerator.hh:141
double masterRatio_
Definition: domainthreaditerator.hh:68
Storage of thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:273
DomainDecomposedIteratorStorage(const GridPart &gridPart)
Definition: domainthreaditerator.hh:276
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:23
Definition: threadmanager.hh:45
static int maxThreads()
return maximal number of threads possbile in the current run
Definition: threadmanager.hh:59
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:74
static int thread()
return thread number
Definition: threadmanager.hh:65
Definition: dofmanager.hh:762