1#ifndef DUNE_FEM_DOMAINTHREADITERATOR_HH
2#define DUNE_FEM_DOMAINTHREADITERATOR_HH
10#include <dune/fem/space/common/dofmanager.hh>
11#include <dune/fem/gridpart/filteredgridpart.hh>
12#include <dune/fem/gridpart/filter/domainfilter.hh>
13#include <dune/fem/misc/threads/threaditeratorstorage.hh>
15#ifdef USE_SMP_PARALLEL
17#define USE_THREADPARTITIONER
18#include <dune/fem/misc/threads/threadpartitioner.hh>
27 template <
class Gr
idPart>
31 typedef GridPart GridPartType;
32 typedef typename GridPartType :: GridType GridType;
33 typedef typename GridPartType :: IndexSetType IndexSetType;
35 typedef DomainFilter<GridPartType> FilterType;
36#ifdef USE_THREADPARTITIONER
39 typedef typename FilteredGridPartType :: template
Codim< 0 > :: IteratorType
42 typedef typename GridPartType :: template
Codim< 0 > :: IteratorType IteratorType ;
45 typedef typename IteratorType :: Entity EntityType ;
51#ifdef USE_THREADPARTITIONER
52 typedef ThreadPartitioner< GridPartType > ThreadPartitionerType;
53 typedef typename ThreadPartitionerType :: Method PartitioningMethodType ;
57 const GridPartType& gridPart_;
59 const IndexSetType& indexSet_;
61#ifdef USE_THREADPARTITIONER
64 std::vector< std::unique_ptr< FilteredGridPartType > > filteredGridParts_;
66 typedef typename FilterType :: DomainArrayType ThreadArrayType;
67 ThreadArrayType threadNum_;
72#ifdef USE_THREADPARTITIONER
73 const PartitioningMethodType method_;
77 const bool communicationThread_;
81#ifdef USE_THREADPARTITIONER
82 static PartitioningMethodType getMethod (
const ParameterReader ¶meter )
85 const std::string methodNames[] = {
"recursive",
"kway",
"sfc" };
86 return (PartitioningMethodType ) parameter.getEnum(
"fem.threads.partitioningmethod", methodNames, 0 );
93 : gridPart_( gridPart ),
95 indexSet_( gridPart_.indexSet() )
96#ifdef USE_THREADPARTITIONER
98 , numThreads_( Fem :: MPIManager :: numThreads() )
99 , filteredGridParts_( Fem :: MPIManager :: maxThreads() )
101 , masterRatio_( 1.0 )
102#ifdef USE_THREADPARTITIONER
103 , method_( getMethod( parameter ) )
105 , communicationThread_( parameter.getValue<bool>(
"fem.threads.communicationthread", false)
106 && Fem :: MPIManager :: maxThreads() > 1 )
108 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
110#ifdef USE_THREADPARTITIONER
114 filteredGridParts_[
thread ].reset(
115 new FilteredGridPartType(
const_cast<GridPartType &
> (gridPart_),
116 FilterType( gridPart_, threadNum_,
thread ) ) );
119 threadNum_.setMemoryFactor( 1.1 );
124#ifdef USE_THREADPARTITIONER
126 const FilterType& filter(
const int thread )
const
128 return filteredGridParts_[
thread ]->filter();
135#ifdef USE_THREADPARTITIONER
136 const int sequence = dofManager_.
sequence() ;
138 if( sequence_ != sequence || numThreads_ != MPIManager :: numThreads() )
140 if( ! MPIManager :: singleThreadMode() )
142 std::cerr <<
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
153 const int commThread = communicationThread_ ? 1 : 0;
155 const size_t partitions = MPIManager :: numThreads() - commThread ;
158 ThreadPartitionerType db( gridPart_, partitions, masterRatio_ );
160 db.serialPartition( method_ );
163 typedef typename GridPartType :: template
Codim< 0 > :: IteratorType GPIteratorType;
164 const GPIteratorType endit = gridPart_.template end< 0 >();
167 const size_t size = indexSet_.size( 0 );
170 threadNum_.resize(
size );
172 for(
size_t i = 0; i<
size; ++i) threadNum_[ i ] = -1;
176 std::vector< int > counter( partitions+commThread , 0 );
178 int numInteriorElems = 0;
179 for(GPIteratorType it = gridPart_.template begin< 0 >();
180 it != endit; ++it, ++numInteriorElems )
182 const EntityType& entity = * it;
183 const int rank = db.getRank( entity ) + commThread ;
186 threadNum_[ indexSet_.index( entity ) ] = rank ;
191 sequence_ = sequence;
194 numThreads_ = MPIManager :: numThreads();
198 std::cout <<
"DomainDecomposedIterator: sequence = " << sequence_ <<
" size = " << numInteriorElems << std::endl;
199 const size_t counterSize = counter.size();
200 for(
size_t i = 0; i<counterSize; ++i )
201 std::cout <<
"DomainDecomposedIterator: T[" << i <<
"] = " << counter[ i ] << std::endl;
206 for(GPIteratorType it = gridPart_.template begin< 0 >(); it != endit; ++it )
208 assert( threadNum_[ indexSet_.index( *it ) ] >= 0 );
223#ifdef USE_THREADPARTITIONER
224 if( ! MPIManager :: singleThreadMode () )
226 const int thread = MPIManager :: thread() ;
227 if( communicationThread_ &&
thread == 0 )
228 return filteredGridParts_[
thread ]->template end< 0 > ();
230 return filteredGridParts_[
thread ]->template begin< 0 > ();
235 return gridPart_.template begin< 0 > ();
242#ifdef USE_THREADPARTITIONER
243 if( ! MPIManager :: singleThreadMode () )
245 return filteredGridParts_[ MPIManager :: thread() ]->template end< 0 > ();
250 return gridPart_.template end< 0 > ();
255 int index(
const EntityType& entity )
const
257 return indexSet_.index( entity );
261 int thread(
const EntityType& entity )
const
263#ifdef USE_THREADPARTITIONER
264 assert( (
int)threadNum_.size() > (
int) indexSet_.index( entity ) );
267 return threadNum_[ indexSet_.index( entity ) ];
273 void setMasterRatio(
const double ratio )
275 masterRatio_ = 0.5 * (ratio + masterRatio_);
281 template <
class Gr
idPart>
Definition: dofmanager.hh:786
Storage of thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:284
Thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:29
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:255
IteratorType begin() const
return begin iterator for current thread
Definition: domainthreaditerator.hh:221
IteratorType end() const
return end iterator for current thread
Definition: domainthreaditerator.hh:240
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:261
DomainDecomposedIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: domainthreaditerator.hh:92
void update()
update internal list of iterators
Definition: domainthreaditerator.hh:133
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: filteredgridpart.hh:221
Container for User Specified Parameters.
Definition: parameter.hh:191
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:22
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
A few common exception classes.
A set of traits classes to store static information about grid implementation.
int sequence() const
return number of sequence, if dofmanagers memory was changed by calling some method like resize,...
Definition: dofmanager.hh:1007
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Specialize with 'true' if the grid implementation is thread safe, while it is not modified....
Definition: capabilities.hh:169