1#ifndef DUNE_FEM_THREADITERATOR_HH
2#define DUNE_FEM_THREADITERATOR_HH
6#include <dune/common/exceptions.hh>
20 template <
class Gr
idPart, PartitionIteratorType ptype = InteriorBorder_Partition >
27 static const PartitionIteratorType
pitype = ptype ;
30 typedef typename GridPartType :: GridType
GridType;
50 std::vector< std::unique_ptr< FilterType > >
filters_;
70 parameter.getValue<bool>(
"fem.threads.verbose", false ) )
90 const int sequence =
gridPart_.sequence();
94 if( ! MPIManager :: singleThreadMode() )
96 std::cerr <<
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
137 for(
size_t i = 0; i<size; ++i)
threadNum_[ i ] = -1;
140 size_t checkSize = 0;
141 const size_t roundOff = (iterSize % numThreads);
142 const size_t counterBase = ((size_t) iterSize / numThreads );
145 std::vector< int > nElems( numThreads, 0 );
150 const size_t counter = counterBase + (( (
thread-1) < roundOff ) ? 1 : 0);
151 nElems[
thread-1 ] = counter ;
152 checkSize += counter ;
154 while( (i < counter) && (it != endit) )
166 if( checkSize != iterSize )
168 assert( checkSize == iterSize );
169 DUNE_THROW(InvalidStateException,
"Partitioning inconsistent!");
177 std::cout <<
"ThreadIterator: sequence = " <<
sequence_ <<
" size = " << checkSize << std::endl;
178 const size_t counterSize = nElems.size();
179 for(
size_t i = 0; i<counterSize; ++i )
180 std::cout <<
"ThreadIterator: T[" << i <<
"] = " << nElems[ i ] << std::endl;
193 if( MPIManager :: singleThreadMode() )
195 return gridPart_.template begin< 0, pitype >();
212 if( MPIManager :: singleThreadMode() )
214 return gridPart_.template end< 0, pitype >();
220 return iterators_[ MPIManager :: thread() + 1 ];
256 template <
class Iterator >
260 for( Iterator it =
begin; it !=
end; ++ it )
269 const int numThreads = MPIManager :: numThreads() ;
270 std::set< int > indices ;
276 const int idx =
gridPart_.indexSet().index( *it );
277 assert( indices.find( idx ) == indices.end() ) ;
278 indices.insert( idx );
281 assert( indices.size() == totalElements );
287 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
Definition: mpimanager.hh:337
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: mpimanager.hh:436
Thread iterators.
Definition: threaditerator.hh:22
DynamicArray< int > threadNum_
Definition: threaditerator.hh:48
DofManager< GridType > DofManagerType
Definition: threaditerator.hh:34
GridPartType::template Codim< 0 >::EntityType EntityType
Definition: threaditerator.hh:32
int sequence_
Definition: threaditerator.hh:44
const bool verbose_
Definition: threaditerator.hh:54
GridPartType::GridType GridType
Definition: threaditerator.hh:30
void checkConsistency(const size_t totalElements)
Definition: threaditerator.hh:266
static const PartitionIteratorType pitype
Definition: threaditerator.hh:27
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:242
IteratorType begin(int thread) const
Definition: threaditerator.hh:204
GridPartType::IndexSetType IndexSetType
Definition: threaditerator.hh:33
int numThreads_
Definition: threaditerator.hh:45
IteratorType end() const
return end iterator for current thread
Definition: threaditerator.hh:210
std::vector< std::vector< int > > threadId_
Definition: threaditerator.hh:49
std::vector< std::unique_ptr< FilterType > > filters_
Definition: threaditerator.hh:50
void update()
update internal list of iterators
Definition: threaditerator.hh:88
void setMasterRatio(const double ratio)
set ratio between master thread and other threads in comp time
Definition: threaditerator.hh:251
DomainFilter< GridPartType > FilterType
Definition: threaditerator.hh:36
const IndexSetType & indexSet_
Definition: threaditerator.hh:42
GridPartType::template Codim< 0 >::template Partition< pitype >::IteratorType IteratorType
Definition: threaditerator.hh:31
const bool communicationThread_
Definition: threaditerator.hh:53
size_t countElements(const Iterator &begin, const Iterator &end) const
Definition: threaditerator.hh:257
GridPart GridPartType
Definition: threaditerator.hh:29
IteratorType end(int thread) const
Definition: threaditerator.hh:223
IteratorType begin() const
return begin iterator for current thread
Definition: threaditerator.hh:191
const GridPartType & gridPart_
Definition: threaditerator.hh:40
const FilterType & filter(const unsigned int thread) const
return filter for given thread
Definition: threaditerator.hh:81
int index(const EntityType &entity) const
return thread number this entity belongs to
Definition: threaditerator.hh:229
int threadParallel(const EntityType &entity) const
Definition: threaditerator.hh:234
const DofManagerType & dofManager_
Definition: threaditerator.hh:41
std::vector< IteratorType > iterators_
Definition: threaditerator.hh:47
ThreadIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: threaditerator.hh:58
Storage of thread iterators.
Definition: threaditerator.hh:290
ThreadIteratorStorage(const GridPart &gridPart)
Definition: threaditerator.hh:293
Storage of thread iterators using domain decomposition.
Definition: threaditeratorstorage.hh:22
Definition: dofmanager.hh:761
size_type size() const
return size of array
Definition: dynamicarray.hh:170
void setMemoryFactor(double memFactor)
set memory factor
Definition: dynamicarray.hh:296
void resize(size_type nsize)
Definition: dynamicarray.hh:334