3#ifndef DUNE_INTERFACE_HH
4#define DUNE_INTERFACE_HH
85 template<
class R,
class T1,
class T2,
class Op,
bool send>
87 const T1& sourceFlags,
const T2& destFlags,
134 indices_ =
new std::size_t[
size];
152 void add(std::size_t index)
154 assert(size_<maxSize_);
155 indices_[size_++]=index;
159 : size_(0), maxSize_(0), indices_(0)
162 virtual ~InterfaceInformation()
165 bool operator!=(
const InterfaceInformation& o)
const
167 return !operator==(o);
170 bool operator==(
const InterfaceInformation& o)
const
174 for(std::size_t i=0; i< size_; ++i)
175 if(indices_[i]!=o.indices_[i])
192 std::size_t* indices_;
214 typedef std::map<int,std::pair<InterfaceInformation,InterfaceInformation> >
InformationMap;
232 template<
typename R,
typename T1,
typename T2>
233 void build(
const R& remoteIndices,
const T1& sourceFlags,
234 const T2& destFlags);
269 bool operator!=(
const Interface& o)
const
271 return ! operator==(o);
274 bool operator==(
const Interface& o)
const
278 if(interfaces_.size()!=o.interfaces_.size())
280 typedef InformationMap::const_iterator MIter;
282 for(MIter m=interfaces_.begin(), om=o.interfaces_.begin();
283 m!=interfaces_.end(); ++m, ++om)
285 if(om->first!=m->first)
287 if(om->second.first!=om->second.first)
289 if(om->second.second!=om->second.second)
327 class InformationBuilder
334 void reserve(
int proc,
int size)
337 interfaces_[proc].first.reserve(size);
339 interfaces_[proc].second.reserve(size);
341 void add(
int proc, std::size_t local)
344 interfaces_[proc].first.add(local);
346 interfaces_[proc].second.add(local);
355 template<
class R,
class T1,
class T2,
class Op,
bool send>
359 if(!remoteIndices.isSynced())
360 DUNE_THROW(RemoteIndicesStateError,
"RemoteIndices is not in sync with the index set. Call RemoteIndices::rebuild first!");
363 typedef typename RemoteIndices::RemoteIndexMap::const_iterator const_iterator;
365 const const_iterator end=remoteIndices.
end();
369 MPI_Comm_rank(remoteIndices.communicator(), &rank);
372 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
376 const RemoteIterator remoteEnd = send ? process->second.first->end() :
377 process->second.second->end();
378 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
380 while(remote!=remoteEnd) {
381 if( send ? destFlags.contains(remote->attribute()) :
382 sourceFlags.contains(remote->attribute())) {
385 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
386 destFlags.contains(remote->localIndexPair().local().attribute()))
391 interfaceInformation.reserve(process->first, size);
396 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
398 const RemoteIterator remoteEnd = send ? process->second.first->end() :
399 process->second.second->end();
400 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
402 while(remote!=remoteEnd) {
403 if( send ? destFlags.contains(remote->attribute()) :
404 sourceFlags.contains(remote->attribute())) {
406 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
407 destFlags.contains(remote->localIndexPair().local().attribute()))
408 interfaceInformation.add(process->first,remote->localIndexPair().local().local());
434 typedef InformationMap::const_iterator const_iterator;
435 const const_iterator end=interfaces_.end();
439 for(const_iterator infoPair=interfaces_.begin(); infoPair!=end; ++infoPair) {
441 std::cout<<rank<<
": send for process "<<infoPair->first<<
": ";
443 for(
size_t i=0; i < info.
size(); i++)
444 std::cout<<info[i]<<
" ";
445 std::cout<<std::endl;
448 std::cout<<rank<<
": receive for process "<<infoPair->first<<
": ";
450 for(
size_t i=0; i < info.
size(); i++)
451 std::cout<<info[i]<<
" ";
452 std::cout<<std::endl;
458 template<
typename R,
typename T1,
typename T2>
464 assert(interfaces_.empty());
467 InformationBuilder<true> sendInformation(interfaces_);
468 this->
template buildInterface<R,T1,T2,InformationBuilder<true>,
true>(remoteIndices, sourceFlags,
469 destFlags, sendInformation);
472 InformationBuilder<false> recvInformation(interfaces_);
473 this->
template buildInterface<R,T1,T2,InformationBuilder<false>,
false>(remoteIndices,sourceFlags,
474 destFlags, recvInformation);
477 inline void Interface::strip()
479 typedef InformationMap::iterator const_iterator;
480 for(const_iterator interfacePair = interfaces_.begin(); interfacePair != interfaces_.end();)
481 if(interfacePair->second.first.size()==0 && interfacePair->second.second.size()==0) {
482 interfacePair->second.first.free();
483 interfacePair->second.second.free();
484 const_iterator toerase=interfacePair++;
485 interfaces_.erase(toerase);
492 typedef InformationMap::iterator iterator;
493 typedef InformationMap::const_iterator const_iterator;
494 const const_iterator end = interfaces_.end();
495 for(iterator interfacePair = interfaces_.begin(); interfacePair != end; ++interfacePair) {
496 interfacePair->second.first.free();
497 interfacePair->second.second.free();
508 inline std::ostream& operator<<(std::ostream& os,
const Interface& interface)
511 typedef InfoMap::const_iterator Iter;
515 os<<i->first<<
": [ source=[";
516 for(std::size_t j=0; j < i->second.first.size(); ++j)
517 os<<i->second.first[j]<<
" ";
518 os<<
"] size="<<i->second.first.size()<<
", target=[";
519 for(std::size_t j=0; j < i->second.second.size(); ++j)
520 os<<i->second.second[j]<<
" ";
521 os<<
"] size="<<i->second.second.size()<<
"\n";
Base class of all classes representing a communication interface.
Definition: interface.hh:33
InterfaceBuilder()
Not for public use.
Definition: interface.hh:45
Communication interface between remote and local indices.
Definition: interface.hh:207
MPI_Comm communicator_
The MPI communicator we use.
Definition: interface.hh:314
std::map< int, std::pair< InterfaceInformation, InterfaceInformation > > InformationMap
The type of the map form process number to InterfaceInformation for sending and receiving to and from...
Definition: interface.hh:214
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
The indices present on remote processes.
Definition: remoteindices.hh:187
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1535
A constant iterator for the SLList.
Definition: sllist.hh:369
Classes for building sets out of enumeration values.
void buildInterface(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags, Op &functor) const
Builds the interface between remote processes.
Definition: interface.hh:356
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
Builds the interface.
Definition: interface.hh:459
void print() const
Print the interface to std::out for debugging.
Definition: interface.hh:432
const InformationMap & interfaces() const
Get information about the interfaces.
Definition: interface.hh:422
MPI_Comm communicator() const
Get the MPI Communicator.
Definition: interface.hh:415
virtual ~Interface()
Destructor.
Definition: interface.hh:502
void free()
Frees memory allocated during the build.
Definition: interface.hh:490
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:14
Classes describing a distributed indexset.