1#ifndef DUNE_FEM_THREADITERATOR_HH
2#define DUNE_FEM_THREADITERATOR_HH
6#include <dune/common/exceptions.hh>
21 template <
class Gr
idPart, PartitionIteratorType ptype = InteriorBorder_Partition >
28 static const PartitionIteratorType
pitype = ptype ;
31 typedef typename GridPartType :: GridType
GridType;
45#ifdef USE_SMP_PARALLEL
47 std::vector< IteratorType > iterators_;
49 std::vector< std::vector< int > > threadId_;
50 std::vector< FilterType* > filters_;
63#ifdef USE_SMP_PARALLEL
71 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
73#ifdef USE_SMP_PARALLEL
75 filters_.resize( Fem :: ThreadManager :: maxThreads(), (
FilterType *) 0 );
84#ifdef USE_SMP_PARALLEL
87 for(
size_t i = 0; i<filters_.size(); ++i )
96 assert(
thread < filters_.size() );
97 return *(filters_[
thread ]);
104#ifdef USE_SMP_PARALLEL
105 const int sequence =
gridPart_.sequence();
107 if( sequence_ != sequence )
111 std::cerr <<
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
125 iterators_[
thread ] = endit ;
131 sequence_ = sequence;
136 iterators_[ 0 ] = it ;
144 threadNum_.
resize( size );
146 for(
size_t i = 0; i<size; ++i) threadNum_[ i ] = -1;
149 size_t checkSize = 0;
150 const size_t roundOff = (iterSize % maxThreads);
151 const size_t counterBase = ((size_t) iterSize / maxThreads );
154 std::vector< int > nElems( maxThreads, 0 );
159 const size_t counter = counterBase + (( (
thread-1) < roundOff ) ? 1 : 0);
160 nElems[
thread-1 ] = counter ;
161 checkSize += counter ;
163 while( (i < counter) && (it != endit) )
166 assert( std::size_t(
indexSet_.index( entity ) ) < std::size_t( threadNum_.
size() ) );
171 iterators_[
thread ] = it ;
173 iterators_[ maxThreads ] = endit ;
175 if( checkSize != iterSize )
177 assert( checkSize == iterSize );
178 DUNE_THROW(InvalidStateException,
"Partitioning inconsistent!");
182 sequence_ = sequence;
186 std::cout <<
"ThreadIterator: sequence = " << sequence_ <<
" size = " << checkSize << std::endl;
187 const size_t counterSize = nElems.size();
188 for(
size_t i = 0; i<counterSize; ++i )
189 std::cout <<
"ThreadIterator: T[" << i <<
"] = " << nElems[ i ] << std::endl;
192 checkConsistency( iterSize );
203#ifdef USE_SMP_PARALLEL
206 return gridPart_.template begin< 0, pitype >();
213#ifdef USE_SMP_PARALLEL
216 return gridPart_.template end< 0, pitype >();
229#ifdef USE_SMP_PARALLEL
230 assert( std::size_t( threadNum_.
size() ) > std::size_t(
indexSet_.index( entity ) ) );
233 return threadNum_[
indexSet_.index( entity ) ];
245 template <
class Iterator >
249 for( Iterator it =
begin; it !=
end; ++ it )
254#ifdef USE_SMP_PARALLEL
256 void checkConsistency(
const size_t totalElements )
260 std::set< int > indices ;
266 const int idx =
gridPart_.indexSet().index( *it );
267 assert( indices.find( idx ) == indices.end() ) ;
268 indices.insert( idx );
271 assert( indices.size() == totalElements );
278 template <
class Gr
idPart, PartitionIteratorType pitype = InteriorBorder_Partition >
Definition: bindguard.hh:11
Definition: domainfilter.hh:55
Container for User Specified Parameters.
Definition: io/parameter.hh:191
static ParameterContainer & container()
Definition: io/parameter.hh:193
Thread iterators.
Definition: threaditerator.hh:23
DofManager< GridType > DofManagerType
Definition: threaditerator.hh:35
GridPartType::template Codim< 0 >::EntityType EntityType
Definition: threaditerator.hh:33
const bool verbose_
Definition: threaditerator.hh:55
GridPartType::GridType GridType
Definition: threaditerator.hh:31
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
GridPartType::IndexSetType IndexSetType
Definition: threaditerator.hh:34
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
const IndexSetType & indexSet_
Definition: threaditerator.hh:43
GridPartType::template Codim< 0 >::template Partition< pitype >::IteratorType IteratorType
Definition: threaditerator.hh:32
const bool communicationThread_
Definition: threaditerator.hh:54
size_t countElements(const Iterator &begin, const Iterator &end) const
Definition: threaditerator.hh:246
GridPart GridPartType
Definition: threaditerator.hh:30
IteratorType begin() const
return begin iterator for current thread
Definition: threaditerator.hh:201
const GridPartType & gridPart_
Definition: threaditerator.hh:41
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:221
const DofManagerType & dofManager_
Definition: threaditerator.hh:42
ThreadIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: threaditerator.hh:59
Storage of thread iterators.
Definition: threaditerator.hh:281
ThreadIteratorStorage(const GridPart &gridPart)
Definition: threaditerator.hh:284
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
size_type size() const
return size of array
Definition: dynamicarray.hh:170
An implementation of DenseVector which uses a C-array of dynamic size as storage.
Definition: dynamicarray.hh:244
void setMemoryFactor(double memFactor)
set memory factor
Definition: dynamicarray.hh:296
void resize(size_type nsize)
Definition: dynamicarray.hh:334