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_;
 
   60      const typename MPIManager::ThreadPoolType& threadPool_;
 
   62#ifdef USE_THREADPARTITIONER 
   65      std::vector< std::unique_ptr< FilteredGridPartType > > filteredGridParts_;
 
   67      typedef typename FilterType :: DomainArrayType ThreadArrayType;
 
   68      ThreadArrayType threadNum_;
 
   73#ifdef USE_THREADPARTITIONER 
   74      const PartitioningMethodType method_;
 
   78      const bool communicationThread_;
 
   82#ifdef USE_THREADPARTITIONER 
   83      static PartitioningMethodType getMethod ( 
const ParameterReader ¶meter )
 
   86        const std::string methodNames[] = { 
"recursive", 
"kway", 
"sfc" };
 
   87        return (PartitioningMethodType ) parameter.getEnum(
"fem.threads.partitioningmethod", methodNames, 0 );
 
   94        : gridPart_( gridPart ),
 
   96          indexSet_( gridPart_.indexSet() ),
 
   97          threadPool_( MPIManager::threadPool() )
 
   98#ifdef USE_THREADPARTITIONER
 
  100        , numThreads_( threadPool_.numThreads() )
 
  101        , filteredGridParts_( threadPool_.maxThreads() )
 
  103        , masterRatio_( 1.0 )
 
  104#ifdef USE_THREADPARTITIONER
 
  105        , method_( getMethod( parameter ) )
 
  107        , communicationThread_( parameter.getValue<bool>(
"fem.threads.communicationthread", false)
 
  108                    &&  threadPool_.maxThreads() > 1 ) 
 
  110                    parameter.getValue<bool>(
"fem.threads.verbose", false ) )
 
  112#ifdef USE_THREADPARTITIONER 
  116          filteredGridParts_[ 
thread ].reset(
 
  117              new FilteredGridPartType( 
const_cast<GridPartType &
> (gridPart_),
 
  118                                        FilterType( gridPart_, threadNum_, 
thread ) ) );
 
  121        threadNum_.setMemoryFactor( 1.1 );
 
  126#ifdef USE_THREADPARTITIONER 
  128      const FilterType& filter( 
const int thread )
 const 
  130        return filteredGridParts_[ 
thread ]->filter();
 
  137#ifdef USE_THREADPARTITIONER 
  138        const int sequence = dofManager_.
sequence() ;
 
  140        if( sequence_ != sequence || numThreads_ != threadPool_.numThreads() )
 
  142          if( ! threadPool_.singleThreadMode() )
 
  144            std::cerr << 
"Don't call ThreadIterator::update in a parallel environment!" << std::endl;
 
  155          const int commThread = communicationThread_ ? 1 : 0;
 
  157          const size_t partitions = threadPool_.numThreads() - commThread ;
 
  160          ThreadPartitionerType db( gridPart_, partitions, masterRatio_ );
 
  162          db.serialPartition( method_ );
 
  165          typedef typename GridPartType :: template 
Codim< 0 > :: IteratorType GPIteratorType;
 
  166          const GPIteratorType endit = gridPart_.template end< 0 >();
 
  169          const size_t size = indexSet_.size( 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 )
 
  184              const EntityType& entity  = * it;
 
  185              const int rank = db.getRank( entity ) + commThread ;
 
  188              threadNum_[ indexSet_.index( entity ) ] = rank ;
 
  193            sequence_ = sequence;
 
  196            numThreads_ = threadPool_.numThreads();
 
  200              std::cout << 
"DomainDecomposedIterator: sequence = " << sequence_ << 
" size = " << numInteriorElems << std::endl;
 
  201              const size_t counterSize = counter.size();
 
  202              for(
size_t i = 0; i<counterSize; ++i )
 
  203                std::cout << 
"DomainDecomposedIterator: T[" << i << 
"] = " << counter[ i ] << std::endl;
 
  208            for(GPIteratorType it = gridPart_.template begin< 0 >(); it != endit; ++it )
 
  210              assert( threadNum_[ indexSet_.index( *it ) ] >= 0 );
 
  225#ifdef USE_THREADPARTITIONER 
  226        if( ! threadPool_.singleThreadMode () )
 
  228          const int thread = threadPool_.thread() ;
 
  229          if( communicationThread_ && 
thread == 0 )
 
  230            return filteredGridParts_[ 
thread ]->template end< 0 > ();
 
  232            return filteredGridParts_[ 
thread ]->template begin< 0 > ();
 
  237          return gridPart_.template begin< 0 > ();
 
  244#ifdef USE_THREADPARTITIONER 
  245        if( ! threadPool_.singleThreadMode () )
 
  247          return filteredGridParts_[ threadPool_.thread() ]->template end< 0 > ();
 
  252          return gridPart_.template end< 0 > ();
 
  257      int index(
const EntityType& entity )
 const 
  259        return indexSet_.index( entity );
 
  263      int thread(
const EntityType& entity )
 const 
  265#ifdef USE_THREADPARTITIONER 
  266        assert( (
int)threadNum_.size() > (
int) indexSet_.index( entity ) );
 
  269        return threadNum_[ indexSet_.index( entity ) ];
 
  275      void setMasterRatio( 
const double ratio )
 
  277        masterRatio_ = 0.5 * (ratio + masterRatio_);
 
  283    template <
class Gr
idPart>
 
Definition: dofmanager.hh:786
 
Storage of thread iterators using domain decomposition.
Definition: domainthreaditerator.hh:286
 
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:257
 
IteratorType begin() const
return begin iterator for current thread
Definition: domainthreaditerator.hh:223
 
IteratorType end() const
return end iterator for current thread
Definition: domainthreaditerator.hh:242
 
int thread(const EntityType &entity) const
return thread number this entity belongs to
Definition: domainthreaditerator.hh:263
 
DomainDecomposedIterator(const GridPartType &gridPart, const ParameterReader ¶meter=Parameter::container())
contructor creating thread iterators
Definition: domainthreaditerator.hh:93
 
void update()
update internal list of iterators
Definition: domainthreaditerator.hh:135
 
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:375
 
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,...)
Definition: exceptions.hh:314
 
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