1#ifndef DUNE_FEM_COMMUNICATION_MANAGER_HH
2#define DUNE_FEM_COMMUNICATION_MANAGER_HH
13#include <dune/fem/misc/mpimanager.hh>
14#include <dune/fem/space/common/commoperations.hh>
15#include <dune/fem/storage/singletonlist.hh>
20#include <dune/alugrid/3d/alugrid.hh>
24#ifndef WANT_CACHED_COMM_MANAGER
25#define WANT_CACHED_COMM_MANAGER 1
28#if ALU3DGRID_PARALLEL && WANT_CACHED_COMM_MANAGER
29#define USE_CACHED_COMM_MANAGER
33 #ifdef DUNE_DEVEL_MODE
34 #warning "HAVE_MPI == 0, therefore default CommunicationManager is used!"
36#elif !ALU3DGRID_PARALLEL
37 #warning "No Parallel ALUGrid found, using default CommunicationManager!"
38#elif ! WANT_CACHED_COMM_MANAGER
39 #warning "CachedCommunication Manager disabled by WANT_CACHED_COMM_MANAGER=0!"
44#undef WANT_CACHED_COMM_MANAGER
46#ifdef USE_CACHED_COMM_MANAGER
47#include "cachedcommmanager.hh"
59 template<
class DiscreteFunctionSpace >
60 class PetscDiscreteFunction;
62 class IsDiscreteFunction;
76 template<
class Space >
80 typedef Space SpaceType;
88 class NonBlockingCommunication
90 const SpaceType& space_;
95 NonBlockingCommunication(
const SpaceType& space,
99 interface_( interface ),
104 template <
class DiscreteFunction >
105 void send(
const DiscreteFunction& discreteFunction )
112 template <
class DiscreteFunctionSpace,
class Operation >
113 double receive( PetscDiscreteFunction< DiscreteFunctionSpace > & discreteFunction,
114 const Operation& operation )
123 discreteFunction.dofVector().communicateNow( operation );
129 template <
class DiscreteFunction,
class Operation >
130 double receive( DiscreteFunction& discreteFunction,
const Operation& operation )
133 if( space_.gridPart().comm().size() <= 1 )
137 typedef typename DiscreteFunction
138 :: template CommDataHandle< Operation > :: Type
145 DataHandleType dataHandle = discreteFunction.dataHandle( operation );
146 space_.gridPart().communicate( dataHandle, interface_ , dir_ );
153 template <
class DiscreteFunction >
154 double receive( DiscreteFunction& discreteFunction )
157 typedef typename DiscreteFunction :: DiscreteFunctionSpaceType
158 :: template CommDataHandle< DiscreteFunction > :: OperationType DefaultOperationType;
159 DefaultOperationType operation;
160 return receive( discreteFunction, operation );
170 mutable double exchangeTime_;
173 typedef NonBlockingCommunication NonBlockingCommunicationType;
177 (
const SpaceType &space,
181 interface_( interface ),
217 return NonBlockingCommunicationType( space_, interface_, dir_ );
224 template<
class DiscreteFunction >
225 inline void exchange ( DiscreteFunction &discreteFunction )
const
228 typedef typename DiscreteFunction :: DiscreteFunctionSpaceType ::
229 template CommDataHandle< DiscreteFunction > :: OperationType DefaultOperationType;
231 DefaultOperationType operation;
232 exchange( discreteFunction, operation );
243 template<
class DiscreteFunction,
class Operation >
244 inline void exchange ( DiscreteFunction &discreteFunction,
245 const Operation &operation )
const
247 NonBlockingCommunicationType nbc( space_, interface_, dir_ );
250 nbc.send( discreteFunction );
252 exchangeTime_ = nbc.receive( discreteFunction, operation );
263 template<
class DiscreteFunction,
class Operation >
265 DiscreteFunction &discreteFunction,
266 const Operation &operation )
const
268#ifndef USE_CACHED_COMM_MANAGER
276#ifndef USE_CACHED_COMM_MANAGER
279 template <
class SpaceImp>
306 class DiscreteFunctionCommunicatorInterface
309 DiscreteFunctionCommunicatorInterface () =
default;
311 virtual ~DiscreteFunctionCommunicatorInterface () =
default;
317 template <
class DiscreteFunctionImp,
class Operation>
318 class DiscreteFunctionCommunicator
319 :
public DiscreteFunctionCommunicatorInterface
327 CommunicationManagerType comm_;
328 const Operation& operation_;
333 : df_(df), comm_(df_.space()), operation_( op )
340 comm_.exchange( df_, operation_ );
346 typedef DiscreteFunctionCommunicatorInterface CommObjIFType;
347 typedef std::list < std::unique_ptr< DiscreteFunctionCommunicatorInterface > > CommObjListType;
348 CommObjListType objList_;
350 CommunicationManagerList(
const CommunicationManagerList&);
352 CommunicationManagerList () =
default;
355 template <
class CombinedObjectType>
358 cObj.addToList(*
this);
362 template <
class DiscreteFunctionImp,
class Operation>
363 void addToList(DiscreteFunctionImp &df,
const Operation& operation )
365 typedef DiscreteFunctionCommunicator<DiscreteFunctionImp, Operation> CommObjType;
366 CommObjType* obj =
new CommObjType( df, operation );
367 objList_.push_back( std::unique_ptr< DiscreteFunctionCommunicatorInterface> (obj) );
371 template <
class DiscreteFunctionImp>
378 template<
class DiscreteFunction >
379 void removeFromList ( DiscreteFunction &df )
381 const auto handles = [ &df ] (
const std::unique_ptr< DiscreteFunctionCommunicatorInterface > &commObj ) {
return commObj->handles( df ); };
382 CommObjListType::reverse_iterator pos = std::find_if( objList_.rbegin(), objList_.rend(), handles );
383 if( pos != objList_.rend() )
384 objList_.erase( --pos.base() );
393 typedef CommObjListType :: const_iterator iterator;
395 iterator end = objList_.end();
396 for(iterator it = objList_.begin(); it != end; ++it)
Proxy class to DependencyCache which is singleton per space.
Definition: communicationmanager.hh:304
use Default CommunicationManager as Communication Manager
Definition: communicationmanager.hh:282
default communication manager using just the grids communicate method
Definition: communicationmanager.hh:78
A vector valued function space.
Definition: functionspace.hh:60
base class for determing whether a class is a discrete function or not
Definition: discretefunction.hh:53
forward declaration
Definition: discretefunction.hh:51
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
Default exception for dummy implementations.
Definition: exceptions.hh:263
Default exception class for range errors.
Definition: exceptions.hh:254
A simple stop watch.
Definition: timer.hh:43
double elapsed() const noexcept
Get elapsed user-time from last reset until now/last stop in seconds.
Definition: timer.hh:77
Different resources needed by all grid implementations.
Describes the parallel communication interface class for MessageBuffers and DataHandles.
double buildTime() const
return time needed for last build
Definition: communicationmanager.hh:203
InterfaceType communicationInterface() const
return communication interface
Definition: communicationmanager.hh:189
double receive(DiscreteFunction &discreteFunction, const Operation &operation)
receive data for discrete function and given operation
Definition: communicationmanager.hh:130
DefaultCommunicationManager(const SpaceType &space, const InterfaceType interface, const CommunicationDirection dir)
constructor taking space and communication interface/direction
Definition: communicationmanager.hh:177
CommunicationManager(const SpaceImp &space)
constructor taking space
Definition: communicationmanager.hh:293
void exchange() const
Definition: communicationmanager.hh:391
void exchange(DiscreteFunction &discreteFunction) const
exchange data for a discrete function using the copy operation
Definition: communicationmanager.hh:225
CommunicationDirection communicationDirection() const
return communication direction
Definition: communicationmanager.hh:194
CommunicationManagerList(CombinedObjectType &cObj)
constructor
Definition: communicationmanager.hh:356
NonBlockingCommunicationType nonBlockingCommunication() const
return object for non-blocking communication
Definition: communicationmanager.hh:215
void send(const DiscreteFunction &discreteFunction)
send data for given discrete function
Definition: communicationmanager.hh:105
void exchange(DiscreteFunction &discreteFunction, const Operation &operation) const
exchange data for a discrete function using the given operation
Definition: communicationmanager.hh:244
void exchange(const Space &space, DiscreteFunction &discreteFunction, const Operation &operation) const
exchange data for a discrete function using the given operation
Definition: communicationmanager.hh:264
DiscreteFunctionCommunicator(DiscreteFunctionType &df, const Operation &op)
constructor taking disctete function
Definition: communicationmanager.hh:332
double exchangeTime() const
return time needed for last exchange of data
Definition: communicationmanager.hh:209
double receive(DiscreteFunction &discreteFunction)
receive method with default operation
Definition: communicationmanager.hh:154
CommunicationManager(const SpaceImp &space, const InterfaceType interface, const CommunicationDirection dir)
constructor taking space and communication interface/direction
Definition: communicationmanager.hh:287
void addToList(DiscreteFunctionImp &df, const Operation &operation)
add discrete function to communication list
Definition: communicationmanager.hh:363
void addToList(DiscreteFunctionImp &df)
add discrete function to communication list
Definition: communicationmanager.hh:372
double receive(PetscDiscreteFunction< DiscreteFunctionSpace > &discreteFunction, const Operation &operation)
receive data for discrete function and given operation
Definition: communicationmanager.hh:113
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
just copy data
Definition: commoperations.hh:127