1#ifndef DUNE_FEM_DOMAINTHREADITERATOR_HH
2#define DUNE_FEM_DOMAINTHREADITERATOR_HH
6#include <dune/common/exceptions.hh>
13#ifdef USE_SMP_PARALLEL
15#define USE_THREADPARTITIONER
25 template <
class Gr
idPart>
30 typedef typename GridPartType :: GridType
GridType;
34#ifdef USE_THREADPARTITIONER
37 typedef typename FilteredGridPartType :: template Codim< 0 >
:: IteratorType
47 static const PartitionIteratorType
pitype = GridPartType :: indexSetPartitionType ;
49#ifdef USE_THREADPARTITIONER
50 typedef ThreadPartitioner< GridPartType > ThreadPartitionerType;
51 typedef typename ThreadPartitionerType :: Method PartitioningMethodType ;
59#ifdef USE_THREADPARTITIONER
62 std::vector< std::unique_ptr< FilteredGridPartType > > filteredGridParts_;
64 typedef typename FilterType :: DomainArrayType ThreadArrayType;
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
96 , numThreads_( Fem ::
MPIManager :: numThreads() )
97 , filteredGridParts_( Fem ::
MPIManager :: maxThreads() )
100#ifdef USE_THREADPARTITIONER
101 , method_( getMethod( parameter ) )
106 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
108#ifdef USE_THREADPARTITIONER
112 filteredGridParts_[
thread ].reset(
117 threadNum_.setMemoryFactor( 1.1 );
122#ifdef USE_THREADPARTITIONER
126 return filteredGridParts_[
thread ]->filter();
133#ifdef USE_THREADPARTITIONER
134 const int sequence =
gridPart_.sequence() ;
136 if( sequence_ != sequence || numThreads_ != MPIManager :: numThreads() )
138 if( ! MPIManager :: singleThreadMode() )
140 std::cerr <<
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
147 const size_t partitions = MPIManager :: numThreads() - commThread ;
152 db.serialPartition( method_ );
155 typedef typename GridPartType :: template Codim< 0 >
:: IteratorType GPIteratorType;
156 const GPIteratorType endit =
gridPart_.template end< 0 >();
162 threadNum_.resize( size );
164 for(
size_t i = 0; i<size; ++i) threadNum_[ i ] = -1;
168 std::vector< int > counter( partitions+commThread , 0 );
170 int numInteriorElems = 0;
171 for(GPIteratorType it =
gridPart_.template begin< 0 >();
172 it != endit; ++it, ++numInteriorElems )
175 const int rank = db.getRank( entity ) + commThread ;
178 threadNum_[
indexSet_.index( entity ) ] = rank ;
183 sequence_ = sequence;
186 numThreads_ = MPIManager :: numThreads();
190 std::cout <<
"DomainDecomposedIterator: sequence = " << sequence_ <<
" size = " << numInteriorElems << std::endl;
191 const size_t counterSize = counter.size();
192 for(
size_t i = 0; i<counterSize; ++i )
193 std::cout <<
"DomainDecomposedIterator: T[" << i <<
"] = " << counter[ i ] << std::endl;
198 for(GPIteratorType it =
gridPart_.template begin< 0 >(); it != endit; ++it )
200 assert( threadNum_[
indexSet_.index( *it ) ] >= 0 );
215#ifdef USE_THREADPARTITIONER
216 if( ! MPIManager :: singleThreadMode () )
218 const int thread = MPIManager :: thread() ;
220 return filteredGridParts_[
thread ]->template end< 0 > ();
222 return filteredGridParts_[
thread ]->template begin< 0 > ();
234#ifdef USE_THREADPARTITIONER
235 if( ! MPIManager :: singleThreadMode () )
237 return filteredGridParts_[ MPIManager :: thread() ]->template end< 0 > ();
255#ifdef USE_THREADPARTITIONER
256 assert( (
int)threadNum_.size() > (
int)
indexSet_.index( entity ) );
259 return threadNum_[
indexSet_.index( entity ) ];
273 template <
class Gr
idPart>
Definition: bindguard.hh:11
Definition: domainfilter.hh:55
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
Definition: mpimanager.hh:337
Thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:27
void setMasterRatio(const double ratio)
Definition: domainthreaditerator.hh:265
const bool communicationThread_
Definition: domainthreaditerator.hh:75
static const PartitionIteratorType pitype
Definition: domainthreaditerator.hh:47
GridPart GridPartType
Definition: domainthreaditerator.hh:29
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:247
const IndexSetType & indexSet_
Definition: domainthreaditerator.hh:57
GridPartType::template Codim< 0 >::IteratorType IteratorType
Definition: domainthreaditerator.hh:40
const bool verbose_
Definition: domainthreaditerator.hh:76
IteratorType begin() const
return begin iterator for current thread
Definition: domainthreaditerator.hh:213
IteratorType end() const
return end iterator for current thread
Definition: domainthreaditerator.hh:232
DomainFilter< GridPartType > FilterType
Definition: domainthreaditerator.hh:33
GridPartType::IndexSetType IndexSetType
Definition: domainthreaditerator.hh:31
const DofManagerType & dofManager_
Definition: domainthreaditerator.hh:56
DofManager< GridType > DofManagerType
Definition: domainthreaditerator.hh:45
GridPartType::GridType GridType
Definition: domainthreaditerator.hh:30
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:253
const GridPartType & gridPart_
Definition: domainthreaditerator.hh:55
IteratorType::Entity EntityType
Definition: domainthreaditerator.hh:43
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:131
double masterRatio_
Definition: domainthreaditerator.hh:68
Storage of thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:276
DomainDecomposedIteratorStorage(const GridPart &gridPart)
Definition: domainthreaditerator.hh:279
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:22
Definition: dofmanager.hh:761