5#ifndef DUNE_REMOTEINDICES_HH
6#define DUNE_REMOTEINDICES_HH
40 template<
typename TG,
typename TA>
50 template<
typename T,
typename A>
53 template<
typename T1,
typename T2>
60 template<
typename T1,
typename T2>
64 template<
typename T,
typename A,
bool mode>
71 template<
typename T1,
typename T2>
77 template<
typename T,
typename A,
typename A1>
82 template<
typename T,
typename A,
bool mode>
153 template<
class T,
class A>
158 template<
class T,
class A>
166 template<
typename T1,
typename T2>
186 template<
class T,
class A=std::allocator<
RemoteIndex<
typename T::GlobalIndex,
187 typename T::LocalIndex::Attribute> > >
192 template<
typename T1,
typename A2,
typename A1>
197 template<
class G,
class T1,
class T2>
244 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
302 neighbourIds.clear();
326 template<
bool ignorePublic>
359 template<
bool mode,
bool send>
420 std::set<int> neighbourIds;
423 const static int commTag_=333;
477 template<
bool ignorePublic>
478 inline void buildRemote(
bool includeSelf);
498 template<
bool ignorePublic>
501 int* position,
int n);
549 template<
class T,
class A,
bool mode>
553 template<
typename T1,
typename A1>
696 GlobalModifyIterator giter_;
706 template<
class T,
class A>
713 typedef T ParallelIndexSet;
728 typedef typename LocalIndex::Attribute Attribute;
747 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
765 inline void advance(
const GlobalIndex& global);
776 inline void advance(
const GlobalIndex& global,
const Attribute& attribute);
783 inline bool empty()
const;
800 : iter_(
iter), end_(
end), index_(index), hasAttribute(
false)
803 while(iter_!=end_ && iter_->second.first->localIndexPair().global()!=index_)
809 : iter_(
iter), end_(
end), index_(index), attribute_(attribute), hasAttribute(
true)
812 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_
813 || iter_->second.first->localIndexPair().local().attribute()!=attribute))
818 : iter_(other.iter_), end_(other.end_), index_(other.index_)
826 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_ ||
828 iter_->second.first->localIndexPair().local().attribute()!=attribute_)))
831 (iter_->second.first->localIndexPair().global()==index_));
832 assert(iter_==end_ || !hasAttribute ||
833 (iter_->second.first->localIndexPair().local().attribute()==attribute_));
840 return *(iter_->second.first);
852 return iter_->second.first.operator->();
858 return other.iter_==iter_;
864 return other.iter_!=iter_;
873 Attribute attribute_;
885 Attribute attribute_;
889 template<
typename TG,
typename TA>
916 template<
typename TG,
typename TA>
919 template<
typename T1,
typename T2>
924 template<
typename T1,
typename T2>
929 template<
typename T1,
typename T2>
931 : localIndex_(0), attribute_()
933 template<
typename T1,
typename T2>
936 return localIndex_==
ri.localIndex_ && attribute_==
ri.attribute;
939 template<
typename T1,
typename T2>
942 return localIndex_!=
ri.localIndex_ || attribute_!=
ri.attribute_;
945 template<
typename T1,
typename T2>
948 return T2(attribute_);
951 template<
typename T1,
typename T2>
957 template<
typename T,
typename A>
961 const std::vector<int>& neighbours,
964 sourceSeqNo_(-1), destSeqNo_(-1), publicIgnored(
false), firstBuild(
true),
970 template<
typename T,
typename A>
976 template<
typename T,
typename A>
978 : source_(0), target_(0), sourceSeqNo_(-1),
979 destSeqNo_(-1), publicIgnored(
false), firstBuild(
true),
983 template<
class T,
typename A>
987 const std::vector<int>& neighbours)
994 setNeighbours(neighbours);
997 template<
typename T,
typename A>
1005 template<
typename T,
typename A>
1013 template<
typename T,
typename A>
1019 template<
typename T,
typename A>
1020 template<
bool ignorePublic>
1039 pairs[
i++] =
const_cast<PairType*
>(&(*index));
1045 template<
typename T,
typename A>
1053 if(index->local().isPublic())
1061 template<
typename T,
typename A>
1062 inline void RemoteIndices<T,A>::unpackCreateRemote(
char* p_in, PairType** sourcePairs,
1063 PairType** destPairs,
int remoteProc,
1064 int sourcePublish,
int destPublish,
1065 int bufferSize,
bool sendTwo,
1082 RemoteIndexList*
receive=
new RemoteIndexList();
1084 RemoteIndexList* send=0;
1090 send =
new RemoteIndexList();
1110 send =
new RemoteIndexList();
1115 if(
receive->empty() && send->empty()) {
1123 remoteIndices_.insert(std::make_pair(
remoteProc,
1124 std::make_pair(send,
receive)));
1129 template<
typename T,
typename A>
1130 template<
bool ignorePublic>
1131 inline void RemoteIndices<T,A>::buildRemote(
bool includeSelf_)
1143 char sendTwo = (source_ != target_);
1171 char**
buffer =
new char*[2];
1222 neighbourIds.erase(rank);
1224 if(neighbourIds.size()==0)
1226 Dune::dvverb<<rank<<
": Sending messages in a ring"<<std::endl;
1238 commTag_, comm_, &
status);
1241 commTag_, comm_, &
status);
1261 typedef typename std::set<int>::size_type
size_type;
1265 for(std::set<int>::iterator
neighbour=neighbourIds.begin();
1283 commTag_, comm_, &
status);
1294 std::cerr<<rank<<
": MPI_Error occurred while receiving message."<<std::endl;
1313 template<
typename T,
typename A>
1314 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& remote,
1335 if(local[
localIndex]->global()==index.global()) {
1339 local[
localIndex]->global()==index.global()) {
1343 remote.push_back(RemoteIndex(index.local().attribute(),
1364 if (local[
localIndex]->global()<index.global()) {
1386 template<
typename T,
typename A>
1387 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& send,
1388 RemoteIndexList& receive,
1390 PairType** localSource,
1391 int localSourceEntries,
1392 PairType** localDest,
1393 int localDestEntries,
1418 send.push_back(RemoteIndex(index.local().attribute(),
1422 receive.push_back(RemoteIndex(index.local().attribute(),
1428 template<
typename T,
typename A>
1431 auto lend = remoteIndices_.
end();
1433 if(
lists->second.first==
lists->second.second) {
1435 delete lists->second.first;
1437 delete lists->second.first;
1438 delete lists->second.second;
1441 remoteIndices_.
clear();
1445 template<
typename T,
typename A>
1448 return remoteIndices_.
size();
1451 template<
typename T,
typename A>
1452 template<
bool ignorePublic>
1463 sourceSeqNo_ = source_->seqNo();
1464 destSeqNo_ = target_->seqNo();
1472 template<
typename T,
typename A>
1475 return sourceSeqNo_==source_->seqNo() && destSeqNo_ ==target_->seqNo();
1478 template<
typename T,
typename A>
1479 template<
bool mode,
bool send>
1486 sourceSeqNo_ = source_->seqNo();
1487 destSeqNo_ = target_->seqNo();
1489 typename RemoteIndexMap::iterator
found = remoteIndices_.find(process);
1493 if(source_ != target_)
1494 found = remoteIndices_.insert(
found, std::make_pair(process,
1500 std::make_pair(process,
1513 template<
typename T,
typename A>
1517 return remoteIndices_.find(
proc);
1520 template<
typename T,
typename A>
1524 return remoteIndices_.begin();
1527 template<
typename T,
typename A>
1531 return remoteIndices_.end();
1535 template<
typename T,
typename A>
1538 if(neighbours()!=
ri.neighbours())
1541 const auto rend = remoteIndices_.
end();
1554 template<
class T,
class A,
bool mode>
1556 RemoteIndexList&
rList)
1559 if(MODIFYINDEXSET) {
1562 glist_.push_back(
iter->localIndexPair().global());
1563 giter_ = glist_.beginModify();
1567 template<
typename T,
typename A,
bool mode>
1569 : rList_(other.rList_), indexSet_(other.indexSet_),
1570 glist_(other.glist_), iter_(other.iter_), giter_(other.giter_), end_(other.end_),
1571 first_(other.first_), last_(other.last_)
1574 template<
typename T,
typename A,
bool mode>
1577 if(MODIFYINDEXSET) {
1579#ifdef DUNE_ISTL_WITH_CHECKING
1580 if(indexSet_->state()!=
GROUND)
1584 auto index = indexSet_->begin();
1587 while(index->global()<*
giter) {
1589#ifdef DUNE_ISTL_WITH_CHECKING
1590 if(index == indexSet_->end())
1595#ifdef DUNE_ISTL_WITH_CHECKING
1596 if(index->global() != *
giter)
1599 iter->localIndex_ = &(*index);
1604 template<
typename T,
typename A,
bool mode>
1607 static_assert(!
mode,
"Not allowed if the mode indicates that new indices"
1608 "might be added to the underlying index set. Use "
1609 "insert(const RemoteIndex&, const GlobalIndex&) instead");
1611#ifdef DUNE_ISTL_WITH_CHECKING
1616 while(iter_ != end_ && iter_->localIndexPair().global() < index.
localIndexPair().global()) {
1622 iter_.insert(index);
1627 template<
typename T,
typename A,
bool mode>
1630 static_assert(
mode,
"Not allowed if the mode indicates that no new indices"
1631 "might be added to the underlying index set. Use "
1632 "insert(const RemoteIndex&) instead");
1633#ifdef DUNE_ISTL_WITH_CHECKING
1634 if(!first_ && global<last_)
1638 while(iter_ != end_ && *giter_ < global) {
1644 assert(iter_->localIndexPair().global() != global);
1645 iter_.insert(index);
1646 giter_.insert(global);
1652 template<
typename T,
typename A,
bool mode>
1655#ifdef DUNE_ISTL_WITH_CHECKING
1656 if(!first_ && global<last_)
1662 if(MODIFYINDEXSET) {
1664 while(iter_!=end_ && *giter_< global) {
1668 if(*giter_ == global) {
1674 while(iter_!=end_ && iter_->localIndexPair().global() < global)
1677 if(iter_->localIndexPair().global()==global) {
1688 template<
typename T,
typename A>
1695 template<
typename T,
typename A>
1702 template<
typename T,
typename A>
1707 for(
auto process =
pmap.
begin(); process !=
end; ++process) {
1708 const RemoteIndexList* list = send ? process->second.first : process->second.second;
1710 map_.insert(std::make_pair(process->first,
1711 std::pair<ri_iterator, const ri_iterator>(list->
begin(), list->
end())));
1715 template<
typename T,
typename A>
1718 const auto end = map_.end();
1726 remoteIndex = *current;
1728 while(
iter->second.first!=
iter->second.second &&
iter->second.first->localIndexPair().global()<index)
1729 ++(
iter->second.first);
1732 if(
iter->second.first ==
iter->second.second)
1742 template<
typename T,
typename A>
1744 const Attribute& attribute)
1746 const auto end = map_.end();
1754 remoteIndex = *current;
1757 while(
iter->second.first!=
iter->second.second &&
iter->second.first->localIndexPair().global()<index)
1758 ++(
iter->second.first);
1761 while(
iter->second.first!=
iter->second.second
1762 &&
iter->second.first->localIndexPair().global()==index
1763 &&
iter->second.first->localIndexPair().local().attribute()<attribute)
1764 ++(
iter->second.first);
1767 if(
iter->second.first ==
iter->second.second)
1774 attribute_=attribute;
1778 template<
typename T,
typename A>
1781 const auto end = map_.end();
1785 auto current =
iter->second.first;
1786 auto rend =
iter->second.second;
1789 if(
iter->second.first->localIndexPair().global()==index_ &&
1790 (noattribute ||
iter->second.first->localIndexPair().local().attribute() == attribute_))
1791 ++(
iter->second.first);
1794 if(
iter->second.first ==
iter->second.second)
1803 template<
typename T,
typename A>
1806 return map_.empty();
1809 template<
typename T,
typename A>
1814 return iterator(map_.begin(), map_.end(), index_);
1816 return iterator(map_.begin(), map_.end(), index_,
1820 template<
typename T,
typename A>
1824 return iterator(map_.end(), map_.end(), index_);
1827 template<
typename TG,
typename TA>
1830 os<<
"[global="<<index.localIndexPair().global()<<
", remote attribute="<<index.attribute()<<
" local attribute="<<index.localIndexPair().local().attribute()<<
"]";
1834 template<
typename T,
typename A>
1839 const auto rend =
indices.remoteIndices_.
end();
1842 os<<rank<<
": Process "<<
rindex->first<<
":";
1844 if(!
rindex->second.first->empty()) {
1847 const auto send=
rindex->second.first->
end();
1850 index != send; ++index)
1854 if(!
rindex->second.second->empty()) {
1855 os<<rank<<
": Process "<<
rindex->first<<
": "<<
"receive: ";
1857 for(
const auto& index : *(
rindex->second.second))
1860 os<<std::endl<<std::flush;
A few common exception classes.
Standard Dune debug streams.
Provides classes for use as the local index in ParallelIndexSet for distributed computing.
Traits classes for mapping types onto MPI_Datatype.
Provides a map between global and local indices.
Implements a singly linked list together with the necessary iterators.
iterator begin()
Get an iterator that is positioned at the first element.
Definition arraylist.hh:517
size_type size() const
Get the number of elements in the list.
Definition arraylist.hh:472
ArrayList()
Constructs an Array list with one chunk.
Definition arraylist.hh:457
iterator end()
Get a random access iterator positioned after the last element.
Definition arraylist.hh:529
iterator end()
Get an iterator pointing to the end of the list.
Definition sllist.hh:774
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition sllist.hh:74
SLListModifyIterator< GlobalIndex, Allocator > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition sllist.hh:103
void clear()
Delete all entries from the list.
Definition arraylist.hh:464
iterator begin()
Get an iterator pointing to the first element in the list.
Definition sllist.hh:762
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:278
#define DUNE_THROW(E, m)
Definition exceptions.hh:218
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition indexset.hh:239
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition indexset.hh:226
@ GROUND
The default mode. Indicates that the index set is ready to be used.
Definition indexset.hh:186
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition stdstreams.hh:95
Dune namespace.
Definition alignedallocator.hh:13
A dynamically growing random access list.
Definition arraylist.hh:62
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition arraylist.hh:105
std::size_t size_type
The size type.
Definition arraylist.hh:115
A traits class describing the mapping of types onto MPI_Datatypes.
Definition mpitraits.hh:41
static MPI_Datatype getType()
Definition mpitraits.hh:48
Default exception class for range errors.
Definition exceptions.hh:254
A pair consisting of a global and local index.
Definition indexset.hh:85
Exception indicating that the index set is not in the expected state.
Definition indexset.hh:205
Manager class for the mapping between local indices and globally unique indices.
Definition indexset.hh:218
Class for recomputing missing indices of a distributed index set.
Definition indicessyncer.hh:41
Base class of all classes representing a communication interface.
Definition parallel/interface.hh:35
An index present on the local process with an additional attribute flag.
Definition plocalindex.hh:49
The indices present on remote processes.
Definition remoteindices.hh:189
const std::set< int > & getNeighbours() const
Definition remoteindices.hh:307
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition remoteindices.hh:231
RemoteIndices()
Definition remoteindices.hh:977
friend void fillIndexSetHoles(const G &graph, Dune::OwnerOverlapCopyCommunication< T1, T2 > &oocomm)
void setIndexSets(const ParallelIndexSet &source, const ParallelIndexSet &destination, const MPI_Comm &comm, const std::vector< int > &neighbours=std::vector< int >())
Set the index sets and communicator we work with.
Definition remoteindices.hh:984
void free()
Free the index lists.
Definition remoteindices.hh:1429
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T1::GlobalIndex, typename T1::LocalIndex::Attribute >, A2 > > &, RemoteIndices< T1, A1 > &, const T1 &)
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition remoteindices.hh:215
void rebuild()
Rebuilds the set of remote indices.
Definition remoteindices.hh:1453
T ParallelIndexSet
Type of the index set we use, e.g. ParallelLocalIndexSet.
Definition remoteindices.hh:206
MPI_Comm communicator() const
Get the mpi communicator used.
Definition remoteindices.hh:1696
LocalIndex::Attribute Attribute
The type of the attribute.
Definition remoteindices.hh:226
CollectiveIteratorT iterator() const
Get an iterator for colletively iterating over the remote indices of all remote processes.
Definition remoteindices.hh:1690
void setIncludeSelf(bool includeSelf)
Tell whether sending from indices of the processor to other indices on the same processor is enabled ...
Definition remoteindices.hh:971
const_iterator end() const
Get an iterator over all remote index lists.
Definition remoteindices.hh:1529
bool operator==(const RemoteIndices &ri) const
Definition remoteindices.hh:1536
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition remoteindices.hh:245
void setNeighbours(const C &neighbours)
Definition remoteindices.hh:300
RemoteIndexListModifier< T, A, mode > getModifier(int process)
Get a modifier for a remote index list.
Definition remoteindices.hh:1480
const ParallelIndexSet & sourceIndexSet() const
Get the index set at the source.
Definition remoteindices.hh:999
~RemoteIndices()
Destructor.
Definition remoteindices.hh:1014
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition remoteindices.hh:241
int neighbours() const
Get the number of processors we share indices with.
Definition remoteindices.hh:1446
CollectiveIterator< T, A > CollectiveIteratorT
The type of the collective iterator over all remote indices.
Definition remoteindices.hh:210
const ParallelIndexSet & destinationIndexSet() const
Get the index set at destination.
Definition remoteindices.hh:1007
typename std::allocator_traits< A >::template rebind_alloc< RemoteIndex > Allocator
The type of the allocator for the remote index list.
Definition remoteindices.hh:237
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition remoteindices.hh:1515
bool isSynced() const
Checks whether the remote indices are synced with the indexsets.
Definition remoteindices.hh:1473
const_iterator begin() const
Get an iterator over all remote index lists.
Definition remoteindices.hh:1522
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition remoteindices.hh:221
RemoteIndexMap::const_iterator const_iterator
Definition remoteindices.hh:247
Information about an index residing on another processor.
Definition remoteindices.hh:73
const Attribute attribute() const
Get the attribute of the index on the remote process.
Definition remoteindices.hh:946
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T::GlobalIndex, typename T::LocalIndex::Attribute >, A > > &, RemoteIndices< T, A1 > &, const T &)
Repair the pointers to the local indices in the remote indices.
Definition indicessyncer.hh:487
bool operator==(const RemoteIndex &ri) const
Definition remoteindices.hh:934
T1 GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition remoteindices.hh:90
T2 Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition remoteindices.hh:99
IndexPair< GlobalIndex, ParallelLocalIndex< Attribute > > PairType
The type of the index pair.
Definition remoteindices.hh:105
const PairType & localIndexPair() const
Get the corresponding local index pair.
Definition remoteindices.hh:952
RemoteIndex()
Parameterless Constructor.
Definition remoteindices.hh:930
bool operator!=(const RemoteIndex &ri) const
Definition remoteindices.hh:940
Modifier for adding and/or deleting remote indices from the remote index list.
Definition remoteindices.hh:551
void repairLocalIndexPointers()
Repair the pointers to the local index pairs.
Definition remoteindices.hh:1575
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition remoteindices.hh:602
A Allocator
The type of the allocator for the remote index list.
Definition remoteindices.hh:598
void insert(const RemoteIndex &index)
Insert an index to the list.
Definition remoteindices.hh:1605
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition remoteindices.hh:578
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition remoteindices.hh:583
RemoteIndexList::const_iterator ConstIterator
The type of the remote index list iterator.
Definition remoteindices.hh:612
SLListModifyIterator< RemoteIndex, Allocator > ModifyIterator
The type of the modifying iterator of the remote index list.
Definition remoteindices.hh:607
bool remove(const GlobalIndex &global)
Remove a remote index.
Definition remoteindices.hh:1653
T ParallelIndexSet
Type of the index set we use.
Definition remoteindices.hh:573
RemoteIndexListModifier()
Default constructor.
Definition remoteindices.hh:676
LocalIndex::Attribute Attribute
The type of the attribute.
Definition remoteindices.hh:588
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition remoteindices.hh:593
static constexpr bool MODIFYINDEXSET
If true the index set corresponding to the remote indices might get modified.
Definition remoteindices.hh:568
A collective iterator for moving over the remote indices for all processes collectively.
Definition remoteindices.hh:708
CollectiveIterator & operator++()
Definition remoteindices.hh:1779
iterator end()
Definition remoteindices.hh:1822
CollectiveIterator(const RemoteIndexMap &map_, bool send)
Constructor.
Definition remoteindices.hh:1703
bool empty() const
Checks whether there are still iterators in the map.
Definition remoteindices.hh:1804
void advance(const GlobalIndex &global)
Advances all underlying iterators.
Definition remoteindices.hh:1716
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition remoteindices.hh:748
iterator begin()
Definition remoteindices.hh:1811
Definition remoteindices.hh:167
Definition remoteindices.hh:558
Iterator over the valid underlying iterators.
Definition remoteindices.hh:792
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex &index)
Definition remoteindices.hh:799
iterator(const iterator &other)
Definition remoteindices.hh:817
const RemoteIndex & operator*() const
Definition remoteindices.hh:838
Map::iterator ConstRealIterator
Definition remoteindices.hh:795
iterator & operator++()
Definition remoteindices.hh:822
const RemoteIndex * operator->() const
Definition remoteindices.hh:850
bool operator==(const iterator &other) const
Definition remoteindices.hh:856
int process() const
Definition remoteindices.hh:844
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex index, Attribute attribute)
Definition remoteindices.hh:807
bool operator!=(const iterator &other) const
Definition remoteindices.hh:862
Map::iterator RealIterator
Definition remoteindices.hh:794
A single linked list.
Definition sllist.hh:44