5#ifndef DUNE_COMMON_PARALLEL_INTERFACE_HH
6#define DUNE_COMMON_PARALLEL_INTERFACE_HH
96 template<
class R,
class T1,
class T2,
class Op,
bool send>
98 const T1& sourceFlags,
const T2& destFlags,
145 indices_ =
new std::size_t[
size];
163 void add(std::size_t index)
165 assert(size_<maxSize_);
166 indices_[size_++]=index;
170 : size_(0), maxSize_(0), indices_(0)
185 for(std::size_t i=0; i< size_; ++i)
186 if(indices_[i]!=o.indices_[i])
203 std::size_t* indices_;
225 typedef std::map<int,std::pair<InterfaceInformation,InterfaceInformation> >
InformationMap;
243 template<
typename R,
typename T1,
typename T2>
244 void build(
const R& remoteIndices,
const T1& sourceFlags,
245 const T2& destFlags);
289 if(interfaces_.size()!=o.interfaces_.size())
291 typedef InformationMap::const_iterator MIter;
293 for(MIter m=interfaces_.begin(), om=o.interfaces_.begin();
294 m!=interfaces_.end(); ++m, ++om)
296 if(om->first!=m->first)
298 if(om->second.first!=om->second.first)
300 if(om->second.second!=om->second.second)
338 class InformationBuilder
345 void reserve(
int proc,
int size)
348 interfaces_[proc].first.reserve(
size);
350 interfaces_[proc].second.reserve(
size);
352 void add(
int proc, std::size_t local)
355 interfaces_[proc].first.add(local);
357 interfaces_[proc].second.add(local);
366 template<
class R,
class T1,
class T2,
class Op,
bool send>
370 if(!remoteIndices.isSynced())
374 typedef typename RemoteIndices::RemoteIndexMap::const_iterator const_iterator;
376 const const_iterator end=remoteIndices.
end();
380 MPI_Comm_rank(remoteIndices.communicator(), &rank);
383 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
387 const RemoteIterator remoteEnd = send ? process->second.first->end() :
388 process->second.second->end();
389 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
391 while(remote!=remoteEnd) {
392 if( send ? destFlags.contains(remote->attribute()) :
393 sourceFlags.contains(remote->attribute())) {
396 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
397 destFlags.contains(remote->localIndexPair().local().attribute()))
402 interfaceInformation.reserve(process->first,
size);
407 for(const_iterator process=remoteIndices.begin(); process != end; ++process) {
409 const RemoteIterator remoteEnd = send ? process->second.first->end() :
410 process->second.second->end();
411 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
413 while(remote!=remoteEnd) {
414 if( send ? destFlags.contains(remote->attribute()) :
415 sourceFlags.contains(remote->attribute())) {
417 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
418 destFlags.contains(remote->localIndexPair().local().attribute()))
419 interfaceInformation.add(process->first,remote->localIndexPair().local().local());
445 typedef InformationMap::const_iterator const_iterator;
446 const const_iterator end=interfaces_.end();
450 for(const_iterator infoPair=interfaces_.begin(); infoPair!=end; ++infoPair) {
452 std::cout<<rank<<
": send for process "<<infoPair->first<<
": ";
454 for(
size_t i=0; i < info.
size(); i++)
455 std::cout<<info[i]<<
" ";
456 std::cout<<std::endl;
459 std::cout<<rank<<
": receive for process "<<infoPair->first<<
": ";
461 for(
size_t i=0; i < info.
size(); i++)
462 std::cout<<info[i]<<
" ";
463 std::cout<<std::endl;
469 template<
typename R,
typename T1,
typename T2>
475 assert(interfaces_.empty());
478 InformationBuilder<true> sendInformation(interfaces_);
479 this->
template buildInterface<R,T1,T2,InformationBuilder<true>,
true>(remoteIndices, sourceFlags,
480 destFlags, sendInformation);
483 InformationBuilder<false> recvInformation(interfaces_);
484 this->
template buildInterface<R,T1,T2,InformationBuilder<false>,
false>(remoteIndices,sourceFlags,
485 destFlags, recvInformation);
490 typedef InformationMap::iterator const_iterator;
491 for(const_iterator interfacePair = interfaces_.begin(); interfacePair != interfaces_.end();)
492 if(interfacePair->second.first.size()==0 && interfacePair->second.second.size()==0) {
493 interfacePair->second.first.free();
494 interfacePair->second.second.free();
495 const_iterator toerase=interfacePair++;
496 interfaces_.erase(toerase);
503 typedef InformationMap::iterator iterator;
504 typedef InformationMap::const_iterator const_iterator;
505 const const_iterator end = interfaces_.end();
506 for(iterator interfacePair = interfaces_.begin(); interfacePair != end; ++interfacePair) {
507 interfacePair->second.first.free();
508 interfacePair->second.second.free();
522 typedef InfoMap::const_iterator Iter;
526 os<<i->first<<
": [ source=[";
527 for(std::size_t j=0; j < i->second.first.size(); ++j)
528 os<<i->second.first[j]<<
" ";
529 os<<
"] size="<<i->second.first.size()<<
", target=[";
530 for(std::size_t j=0; j < i->second.second.size(); ++j)
531 os<<i->second.second[j]<<
" ";
532 os<<
"] size="<<i->second.second.size()<<
"\n";
A few common exception classes.
Classes for building sets out of enumeration values.
Classes describing a distributed indexset.
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:278
#define DUNE_THROW(E, m)
Definition exceptions.hh:218
void buildInterface(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags, Op &functor) const
Builds the interface between remote processes.
Definition parallel/interface.hh:367
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
Builds the interface.
Definition parallel/interface.hh:470
void print() const
Print the interface to std::out for debugging.
Definition parallel/interface.hh:443
const_iterator end() const
Get an iterator over all remote index lists.
Definition remoteindices.hh:1528
const InformationMap & interfaces() const
Get information about the interfaces.
Definition parallel/interface.hh:433
MPI_Comm communicator() const
Get the MPI Communicator.
Definition parallel/interface.hh:426
void strip()
Definition parallel/interface.hh:488
virtual ~Interface()
Destructor.
Definition parallel/interface.hh:513
void free()
Frees memory allocated during the build.
Definition parallel/interface.hh:501
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
Default exception if a function was called while the object is not in a valid state for that function...
Definition exceptions.hh:281
Base class of all classes representing a communication interface.
Definition parallel/interface.hh:44
virtual ~InterfaceBuilder()
Definition parallel/interface.hh:49
InterfaceBuilder()
Not for public use.
Definition parallel/interface.hh:56
Definition parallel/interface.hh:47
Information describing an interface.
Definition parallel/interface.hh:110
bool operator!=(const InterfaceInformation &o) const
Definition parallel/interface.hh:176
void free()
Definition parallel/interface.hh:152
void add(std::size_t index)
Add a new index to the interface.
Definition parallel/interface.hh:163
virtual ~InterfaceInformation()
Definition parallel/interface.hh:173
std::size_t & operator[](size_t i)
Get the local index for an entry.
Definition parallel/interface.hh:125
bool operator==(const InterfaceInformation &o) const
Definition parallel/interface.hh:181
InterfaceInformation()
Definition parallel/interface.hh:169
size_t size() const
Get the number of entries in the interface.
Definition parallel/interface.hh:117
void reserve(size_t size)
Reserve space for a number of entries.
Definition parallel/interface.hh:143
std::size_t operator[](size_t i) const
Get the local index for an entry.
Definition parallel/interface.hh:134
Communication interface between remote and local indices.
Definition parallel/interface.hh:218
bool operator!=(const Interface &o) const
Definition parallel/interface.hh:280
MPI_Comm communicator_
The MPI communicator we use.
Definition parallel/interface.hh:325
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 parallel/interface.hh:225
Interface()
Definition parallel/interface.hh:271
bool operator==(const Interface &o) const
Definition parallel/interface.hh:285
Interface(MPI_Comm comm)
Definition parallel/interface.hh:267
The indices present on remote processes.
Definition remoteindices.hh:190
A constant iterator for the SLList.
Definition sllist.hh:371