5#ifndef DUNE_INTERFACE_HH
6#define DUNE_INTERFACE_HH
87 template<
class R,
class T1,
class T2,
class Op,
bool send>
89 const T1& sourceFlags,
const T2& destFlags,
136 indices_ =
new std::size_t[
size];
154 void add(std::size_t index)
156 assert(size_<maxSize_);
157 indices_[size_++]=index;
161 : size_(0), maxSize_(0), indices_(0)
164 virtual ~InterfaceInformation()
167 bool operator!=(
const InterfaceInformation& o)
const
169 return !operator==(o);
172 bool operator==(
const InterfaceInformation& o)
const
176 for(std::size_t i=0; i< size_; ++i)
177 if(indices_[i]!=o.indices_[i])
194 std::size_t* indices_;
216 typedef std::map<int,std::pair<InterfaceInformation,InterfaceInformation> >
InformationMap;
234 template<
typename R,
typename T1,
typename T2>
235 void build(
const R& remoteIndices,
const T1& sourceFlags,
236 const T2& destFlags);
271 bool operator!=(
const Interface& o)
const
273 return ! operator==(o);
276 bool operator==(
const Interface& o)
const
280 if(interfaces_.size()!=o.interfaces_.size())
282 typedef InformationMap::const_iterator MIter;
284 for(MIter m=interfaces_.begin(), om=o.interfaces_.begin();
285 m!=interfaces_.end(); ++m, ++om)
287 if(om->first!=m->first)
289 if(om->second.first!=om->second.first)
291 if(om->second.second!=om->second.second)
329 class InformationBuilder
336 void reserve(
int proc,
int size)
339 interfaces_[proc].first.reserve(size);
341 interfaces_[proc].second.reserve(size);
343 void add(
int proc, std::size_t local)
346 interfaces_[proc].first.add(local);
348 interfaces_[proc].second.add(local);
357 template<
class R,
class T1,
class T2,
class Op,
bool send>
361 if(!remoteIndices.isSynced())
362 DUNE_THROW(RemoteIndicesStateError,
"RemoteIndices is not in sync with the index set. Call RemoteIndices::rebuild first!");
365 typedef typename RemoteIndices::RemoteIndexMap::const_iterator const_iterator;
367 const const_iterator end=remoteIndices.
end();
371 MPI_Comm_rank(remoteIndices.communicator(), &rank);
374 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
378 const RemoteIterator remoteEnd = send ? process->second.first->end() :
379 process->second.second->end();
380 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
382 while(remote!=remoteEnd) {
383 if( send ? destFlags.contains(remote->attribute()) :
384 sourceFlags.contains(remote->attribute())) {
387 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
388 destFlags.contains(remote->localIndexPair().local().attribute()))
393 interfaceInformation.reserve(process->first, size);
398 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
400 const RemoteIterator remoteEnd = send ? process->second.first->end() :
401 process->second.second->end();
402 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
404 while(remote!=remoteEnd) {
405 if( send ? destFlags.contains(remote->attribute()) :
406 sourceFlags.contains(remote->attribute())) {
408 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
409 destFlags.contains(remote->localIndexPair().local().attribute()))
410 interfaceInformation.add(process->first,remote->localIndexPair().local().local());
436 typedef InformationMap::const_iterator const_iterator;
437 const const_iterator end=interfaces_.end();
441 for(const_iterator infoPair=interfaces_.begin(); infoPair!=end; ++infoPair) {
443 std::cout<<rank<<
": send for process "<<infoPair->first<<
": ";
445 for(
size_t i=0; i < info.
size(); i++)
446 std::cout<<info[i]<<
" ";
447 std::cout<<std::endl;
450 std::cout<<rank<<
": receive for process "<<infoPair->first<<
": ";
452 for(
size_t i=0; i < info.
size(); i++)
453 std::cout<<info[i]<<
" ";
454 std::cout<<std::endl;
460 template<
typename R,
typename T1,
typename T2>
466 assert(interfaces_.empty());
469 InformationBuilder<true> sendInformation(interfaces_);
470 this->
template buildInterface<R,T1,T2,InformationBuilder<true>,
true>(remoteIndices, sourceFlags,
471 destFlags, sendInformation);
474 InformationBuilder<false> recvInformation(interfaces_);
475 this->
template buildInterface<R,T1,T2,InformationBuilder<false>,
false>(remoteIndices,sourceFlags,
476 destFlags, recvInformation);
479 inline void Interface::strip()
481 typedef InformationMap::iterator const_iterator;
482 for(const_iterator interfacePair = interfaces_.begin(); interfacePair != interfaces_.end();)
483 if(interfacePair->second.first.size()==0 && interfacePair->second.second.size()==0) {
484 interfacePair->second.first.free();
485 interfacePair->second.second.free();
486 const_iterator toerase=interfacePair++;
487 interfaces_.erase(toerase);
494 typedef InformationMap::iterator iterator;
495 typedef InformationMap::const_iterator const_iterator;
496 const const_iterator end = interfaces_.end();
497 for(iterator interfacePair = interfaces_.begin(); interfacePair != end; ++interfacePair) {
498 interfacePair->second.first.free();
499 interfacePair->second.second.free();
510 inline std::ostream& operator<<(std::ostream& os,
const Interface& interface)
513 typedef InfoMap::const_iterator Iter;
517 os<<i->first<<
": [ source=[";
518 for(std::size_t j=0; j < i->second.first.size(); ++j)
519 os<<i->second.first[j]<<
" ";
520 os<<
"] size="<<i->second.first.size()<<
", target=[";
521 for(std::size_t j=0; j < i->second.second.size(); ++j)
522 os<<i->second.second[j]<<
" ";
523 os<<
"] size="<<i->second.second.size()<<
"\n";
Base class of all classes representing a communication interface.
Definition: interface.hh:35
InterfaceBuilder()
Not for public use.
Definition: interface.hh:47
Communication interface between remote and local indices.
Definition: interface.hh:209
MPI_Comm communicator_
The MPI communicator we use.
Definition: interface.hh:316
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:216
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
The indices present on remote processes.
Definition: remoteindices.hh:189
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1529
A constant iterator for the SLList.
Definition: sllist.hh:371
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:358
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
Builds the interface.
Definition: interface.hh:461
void print() const
Print the interface to std::out for debugging.
Definition: interface.hh:434
const InformationMap & interfaces() const
Get information about the interfaces.
Definition: interface.hh:424
MPI_Comm communicator() const
Get the MPI Communicator.
Definition: interface.hh:417
virtual ~Interface()
Destructor.
Definition: interface.hh:504
void free()
Frees memory allocated during the build.
Definition: interface.hh:492
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Classes describing a distributed indexset.