4#ifndef DUNE_INTERFACE_HH
5#define DUNE_INTERFACE_HH
36 class RemotexIndicesStateError :
public Exception
86 template<
class R,
class T1,
class T2,
class Op,
bool send>
88 const T1& sourceFlags,
const T2& destFlags,
135 indices_ =
new std::size_t[
size];
153 void add(std::size_t index)
155 assert(size_<maxSize_);
156 indices_[size_++]=index;
160 : size_(0), maxSize_(0), indices_(0)
163 virtual ~InterfaceInformation()
166 bool operator!=(
const InterfaceInformation& o)
const
168 return !operator==(o);
171 bool operator==(
const InterfaceInformation& o)
const
175 for(std::size_t i=0; i< size_; ++i)
176 if(indices_[i]!=o.indices_[i])
193 std::size_t* indices_;
215 typedef std::map<int,std::pair<InterfaceInformation,InterfaceInformation> >
InformationMap;
233 template<
typename R,
typename T1,
typename T2>
234 void build(
const R& remoteIndices,
const T1& sourceFlags,
235 const T2& destFlags);
270 bool operator!=(
const Interface& o)
const
272 return ! operator==(o);
275 bool operator==(
const Interface& o)
const
279 if(interfaces_.size()!=o.interfaces_.size())
281 typedef InformationMap::const_iterator MIter;
283 for(MIter m=interfaces_.begin(), om=o.interfaces_.begin();
284 m!=interfaces_.end(); ++m, ++om)
286 if(om->first!=m->first)
288 if(om->second.first!=om->second.first)
290 if(om->second.second!=om->second.second)
328 class InformationBuilder
335 void reserve(
int proc,
int size)
338 interfaces_[proc].first.reserve(size);
340 interfaces_[proc].second.reserve(size);
342 void add(
int proc, std::size_t local)
345 interfaces_[proc].first.add(local);
347 interfaces_[proc].second.add(local);
356 template<
class R,
class T1,
class T2,
class Op,
bool send>
360 if(!remoteIndices.isSynced())
361 DUNE_THROW(RemotexIndicesStateError,
"RemoteIndices is not in sync with the index set. Call RemoteIndices::rebuild first!");
364 typedef typename RemoteIndices::RemoteIndexMap::const_iterator const_iterator;
366 const const_iterator end=remoteIndices.
end();
370 MPI_Comm_rank(remoteIndices.communicator(), &rank);
373 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
377 const RemoteIterator remoteEnd = send ? process->second.first->end() :
378 process->second.second->end();
379 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
381 while(remote!=remoteEnd) {
382 if( send ? destFlags.contains(remote->attribute()) :
383 sourceFlags.contains(remote->attribute())) {
386 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
387 destFlags.contains(remote->localIndexPair().local().attribute()))
392 interfaceInformation.reserve(process->first, size);
397 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
399 const RemoteIterator remoteEnd = send ? process->second.first->end() :
400 process->second.second->end();
401 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
403 while(remote!=remoteEnd) {
404 if( send ? destFlags.contains(remote->attribute()) :
405 sourceFlags.contains(remote->attribute())) {
407 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
408 destFlags.contains(remote->localIndexPair().local().attribute()))
409 interfaceInformation.add(process->first,remote->localIndexPair().local().local());
435 typedef InformationMap::const_iterator const_iterator;
436 const const_iterator end=interfaces_.end();
440 for(const_iterator infoPair=interfaces_.begin(); infoPair!=end; ++infoPair) {
442 std::cout<<rank<<
": send for process "<<infoPair->first<<
": ";
444 for(
size_t i=0; i < info.
size(); i++)
445 std::cout<<info[i]<<
" ";
446 std::cout<<std::endl;
449 std::cout<<rank<<
": receive for process "<<infoPair->first<<
": ";
451 for(
size_t i=0; i < info.
size(); i++)
452 std::cout<<info[i]<<
" ";
453 std::cout<<std::endl;
459 template<
typename R,
typename T1,
typename T2>
465 assert(interfaces_.empty());
468 InformationBuilder<true> sendInformation(interfaces_);
469 this->
template buildInterface<R,T1,T2,InformationBuilder<true>,
true>(remoteIndices, sourceFlags,
470 destFlags, sendInformation);
473 InformationBuilder<false> recvInformation(interfaces_);
474 this->
template buildInterface<R,T1,T2,InformationBuilder<false>,
false>(remoteIndices,sourceFlags,
475 destFlags, recvInformation);
478 inline void Interface::strip()
480 typedef InformationMap::iterator const_iterator;
481 for(const_iterator interfacePair = interfaces_.begin(); interfacePair != interfaces_.end();)
482 if(interfacePair->second.first.size()==0 && interfacePair->second.second.size()==0) {
483 interfacePair->second.first.free();
484 interfacePair->second.second.free();
485 const_iterator toerase=interfacePair++;
486 interfaces_.erase(toerase);
493 typedef InformationMap::iterator iterator;
494 typedef InformationMap::const_iterator const_iterator;
495 const const_iterator end = interfaces_.end();
496 for(iterator interfacePair = interfaces_.begin(); interfacePair != end; ++interfacePair) {
497 interfacePair->second.first.free();
498 interfacePair->second.second.free();
512 inline ostream& operator<<(ostream& os,
const Dune::Interface& interface)
515 typedef InfoMap::const_iterator Iter;
519 os<<i->first<<
": [ source=[";
520 for(std::size_t j=0; j < i->second.first.size(); ++j)
521 os<<i->second.first[j]<<
" ";
522 os<<
"] size="<<i->second.first.size()<<
", target=[";
523 for(std::size_t j=0; j < i->second.second.size(); ++j)
524 os<<i->second.second[j]<<
" ";
525 os<<
"] size="<<i->second.second.size()<<
"\n";
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
Base class of all classes representing a communication interface.
Definition: interface.hh:34
InterfaceBuilder()
Not for public use.
Definition: interface.hh:46
Communication interface between remote and local indices.
Definition: interface.hh:208
MPI_Comm communicator_
The MPI communicator we use.
Definition: interface.hh:315
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:215
The indices present on remote processes.
Definition: remoteindices.hh:183
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1525
A constant iterator for the SLList.
Definition: sllist.hh:370
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:357
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
Builds the interface.
Definition: interface.hh:460
void print() const
Print the interface to std::out for debugging.
Definition: interface.hh:433
const InformationMap & interfaces() const
Get information about the interfaces.
Definition: interface.hh:423
MPI_Comm communicator() const
Get the MPI Communicator.
Definition: interface.hh:416
virtual ~Interface()
Destructor.
Definition: interface.hh:503
void free()
Frees memory allocated during the build.
Definition: interface.hh:491
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Classes describing a distributed indexset.