3#ifndef DUNE_REMOTEINDICES_HH
4#define DUNE_REMOTEINDICES_HH
38 template<
typename TG,
typename TA>
42 inline static MPI_Datatype getType();
44 static MPI_Datatype type;
48 template<
typename T,
typename A>
51 template<
typename T1,
typename T2>
58 template<
typename T1,
typename T2>
62 template<
typename T,
typename A,
bool mode>
69 template<
typename T1,
typename T2>
75 template<
typename T,
typename A,
typename A1>
80 template<
typename T,
typename A,
bool mode>
151 template<
class T,
class A>
156 template<
class T,
class A>
164 template<
typename T1,
typename T2>
184 template<
class T,
class A=std::allocator<
RemoteIndex<
typename T::GlobalIndex,
185 typename T::LocalIndex::Attribute> > >
190 template<
typename T1,
typename A2,
typename A1>
195 template<
class G,
class T1,
class T2>
235 using Allocator =
typename std::allocator_traits<A>::template rebind_alloc<RemoteIndex>;
242 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
245 typedef typename RemoteIndexMap::const_iterator const_iterator;
265 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>(),
bool includeSelf=
false);
295 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>());
300 neighbourIds.clear();
305 const std::set<int>& getNeighbours()
const
324 template<
bool ignorePublic>
357 template<
bool mode,
bool send>
366 inline const_iterator
find(
int proc)
const;
372 inline const_iterator
begin()
const;
378 inline const_iterator
end()
const;
418 std::set<int> neighbourIds;
421 const static int commTag_=333;
475 template<
bool ignorePublic>
476 inline void buildRemote(
bool includeSelf);
496 template<
bool ignorePublic>
498 char* p_out, MPI_Datatype type,
int bufferSize,
499 int* position,
int n);
515 PairType** local,
int localEntries,
char* p_in,
516 MPI_Datatype type,
int* position,
int bufferSize,
520 int remoteEntries,
PairType** localSource,
521 int localSourceEntries,
PairType** localDest,
522 int localDestEntries,
char* p_in,
523 MPI_Datatype type,
int* position,
int bufferSize);
525 void unpackCreateRemote(
char* p_in,
PairType** sourcePairs,
PairType** DestPairs,
526 int remoteProc,
int sourcePublish,
int destPublish,
527 int bufferSize,
bool sendTwo,
bool fromOurSelf=
false);
547 template<
class T,
class A,
bool mode>
551 template<
typename T1,
typename A1>
696 GlobalModifyIterator giter_;
706 template<
class T,
class A>
713 typedef T ParallelIndexSet;
728 typedef typename LocalIndex::Attribute Attribute;
734 using Allocator =
typename std::allocator_traits<A>::template rebind_alloc<RemoteIndex>;
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);
794 typedef typename Map::iterator RealIterator;
795 typedef typename Map::iterator ConstRealIterator;
799 iterator(
const RealIterator& iter,
const ConstRealIterator& end, GlobalIndex& index)
800 : iter_(iter), end_(end), index_(index), hasAttribute(false)
803 while(iter_!=end_ && iter_->second.first->localIndexPair().global()!=index_)
807 iterator(
const RealIterator& iter,
const ConstRealIterator& end, GlobalIndex 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_)))
830 assert(iter_==end_ ||
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>
890 MPI_Datatype MPITraits<IndexPair<TG,ParallelLocalIndex<TA> > >::getType()
892 if(type==MPI_DATATYPE_NULL) {
893 int length[2] = {1, 1};
896 MPI_Datatype types[2] = {MPITraits<TG>::getType(),
897 MPITraits<ParallelLocalIndex<TA> >::getType()};
898 IndexPair<TG,ParallelLocalIndex<TA> > rep;
899 MPI_Get_address(&rep, &base);
900 MPI_Get_address(&(rep.global_), &disp[0]);
901 MPI_Get_address(&(rep.local_), &disp[1]);
902 for (MPI_Aint& d : disp)
906 MPI_Type_create_struct(2, length, disp, types, &tmp);
908 MPI_Type_create_resized(tmp, 0,
sizeof(IndexPair<TG,ParallelLocalIndex<TA> >), &type);
909 MPI_Type_commit(&type);
916 template<
typename TG,
typename TA>
917 MPI_Datatype MPITraits<IndexPair<TG,ParallelLocalIndex<TA> > >::type=MPI_DATATYPE_NULL;
919 template<
typename T1,
typename T2>
921 : localIndex_(local), attribute_(attribute)
924 template<
typename T1,
typename T2>
926 : localIndex_(0), attribute_(attribute)
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>
940 inline bool RemoteIndex<T1,T2>::operator!=(
const RemoteIndex& ri)
const
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>
960 const MPI_Comm& comm,
961 const std::vector<int>& neighbours,
963 : source_(&source), target_(&destination), comm_(comm),
964 sourceSeqNo_(-1), destSeqNo_(-1), publicIgnored(false), firstBuild(true),
965 includeSelf(includeSelf_)
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>
986 const MPI_Comm& comm,
987 const std::vector<int>& neighbours)
991 target_ = &destination;
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>
1023 char* p_out, MPI_Datatype type,
1025 int *position,
int n)
1031 const const_iterator end = indexSet.
end();
1035 for(const_iterator index = indexSet.
begin(); index != end; ++index)
1036 if(ignorePublic || index->local().isPublic()) {
1038 MPI_Pack(
const_cast<PairType*
>(&(*index)), 1,
1040 p_out, bufferSize, position, comm_);
1041 pairs[i++] =
const_cast<PairType*
>(&(*index));
1047 template<
typename T,
typename A>
1048 inline int RemoteIndices<T,A>::noPublic(
const ParallelIndexSet& indexSet)
1054 const const_iterator end=indexSet.end();
1055 for(const_iterator index=indexSet.begin(); index!=end; ++index)
1056 if(index->local().isPublic())
1064 template<
typename T,
typename A>
1065 inline void RemoteIndices<T,A>::unpackCreateRemote(
char* p_in, PairType** sourcePairs,
1066 PairType** destPairs,
int remoteProc,
1067 int sourcePublish,
int destPublish,
1068 int bufferSize,
bool sendTwo,
1073 int noRemoteSource=-1, noRemoteDest=-1;
1074 char twoIndexSets=0;
1077 MPI_Unpack(p_in, bufferSize, &position, &twoIndexSets, 1, MPI_CHAR, comm_);
1079 MPI_Unpack(p_in, bufferSize, &position, &noRemoteSource, 1, MPI_INT, comm_);
1081 MPI_Unpack(p_in, bufferSize, &position, &noRemoteDest, 1, MPI_INT, comm_);
1085 RemoteIndexList* receive=
new RemoteIndexList();
1087 RemoteIndexList* send=0;
1089 MPI_Datatype type= MPITraits<PairType>::getType();
1093 send =
new RemoteIndexList();
1095 unpackIndices(*send, *receive, noRemoteSource, sourcePairs, sourcePublish,
1096 destPairs, destPublish, p_in, type, &position, bufferSize);
1099 unpackIndices(*receive, noRemoteSource, sourcePairs, sourcePublish,
1100 p_in, type, &position, bufferSize, fromOurSelf);
1105 int oldPos=position;
1107 unpackIndices(*receive, noRemoteSource, destPairs, destPublish,
1108 p_in, type, &position, bufferSize, fromOurSelf);
1113 send =
new RemoteIndexList();
1114 unpackIndices(*send, noRemoteDest, sourcePairs, sourcePublish,
1115 p_in, type, &position, bufferSize, fromOurSelf);
1118 if(receive->empty() && send->empty()) {
1126 remoteIndices_.insert(std::make_pair(remoteProc,
1127 std::make_pair(send,receive)));
1132 template<
typename T,
typename A>
1133 template<
bool ignorePublic>
1134 inline void RemoteIndices<T,A>::buildRemote(
bool includeSelf_)
1138 MPI_Comm_rank(comm_, &rank);
1139 MPI_Comm_size(comm_, &procs);
1143 int sourcePublish, destPublish;
1146 char sendTwo = (source_ != target_);
1148 if(procs==1 && !(sendTwo || includeSelf_))
1152 sourcePublish = (ignorePublic) ? source_->size() : noPublic(*source_);
1155 destPublish = (ignorePublic) ? target_->size() : noPublic(*target_);
1160 int maxPublish, publish=sourcePublish+destPublish;
1163 MPI_Allreduce(&publish, &maxPublish, 1, MPI_INT, MPI_MAX, comm_);
1166 typedef IndexPair<GlobalIndex,LocalIndex> PairType;
1168 PairType** destPairs;
1169 PairType** sourcePairs =
new PairType*[sourcePublish>0 ? sourcePublish : 1];
1172 destPairs =
new PairType*[destPublish>0 ? destPublish : 1];
1174 destPairs=sourcePairs;
1176 char** buffer =
new char*[2];
1183 MPI_Datatype type = MPITraits<PairType>::getType();
1185 MPI_Pack_size(maxPublish, type, comm_,
1187 MPI_Pack_size(1, MPI_INT, comm_,
1189 MPI_Pack_size(1, MPI_CHAR, comm_,
1195 bufferSize += 2 * intSize + charSize;
1197 if(bufferSize<=0) bufferSize=1;
1199 buffer[0] =
new char[bufferSize];
1200 buffer[1] =
new char[bufferSize];
1204 MPI_Pack(&sendTwo, 1, MPI_CHAR, buffer[0], bufferSize, &position,
1208 MPI_Pack(&sourcePublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1210 MPI_Pack(&destPublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1214 packEntries<ignorePublic>(sourcePairs, *source_, buffer[0], type,
1215 bufferSize, &position, sourcePublish);
1218 packEntries<ignorePublic>(destPairs, *target_, buffer[0], type,
1219 bufferSize, &position, destPublish);
1223 if(sendTwo|| includeSelf_)
1224 unpackCreateRemote(buffer[0], sourcePairs, destPairs, rank, sourcePublish,
1225 destPublish, bufferSize, sendTwo, includeSelf_);
1227 neighbourIds.erase(rank);
1229 if(neighbourIds.size()==0)
1231 Dune::dvverb<<rank<<
": Sending messages in a ring"<<std::endl;
1233 for(
int proc=1; proc<procs; proc++) {
1235 char* p_out = buffer[1-(proc%2)];
1236 char* p_in = buffer[proc%2];
1240 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1242 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1243 commTag_, comm_, &status);
1245 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1246 commTag_, comm_, &status);
1247 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1253 int remoteProc = (rank+procs-proc)%procs;
1255 unpackCreateRemote(p_in, sourcePairs, destPairs, remoteProc, sourcePublish,
1256 destPublish, bufferSize, sendTwo);
1263 MPI_Request* requests=
new MPI_Request[neighbourIds.size()];
1264 MPI_Request* req=requests;
1266 typedef typename std::set<int>::size_type size_type;
1267 size_type noNeighbours=neighbourIds.size();
1270 for(std::set<int>::iterator neighbour=neighbourIds.begin();
1271 neighbour!= neighbourIds.end(); ++neighbour) {
1273 MPI_Issend(buffer[0], position , MPI_PACKED, *neighbour, commTag_, comm_, req++);
1278 for(size_type received=0; received <noNeighbours; ++received)
1282 MPI_Probe(MPI_ANY_SOURCE, commTag_, comm_, &status);
1283 int remoteProc=status.MPI_SOURCE;
1285 MPI_Get_count(&status, MPI_PACKED, &size);
1287 MPI_Recv(buffer[1], size, MPI_PACKED, remoteProc,
1288 commTag_, comm_, &status);
1290 unpackCreateRemote(buffer[1], sourcePairs, destPairs, remoteProc, sourcePublish,
1291 destPublish, bufferSize, sendTwo);
1294 MPI_Status* statuses =
new MPI_Status[neighbourIds.size()];
1296 if(MPI_ERR_IN_STATUS==MPI_Waitall(neighbourIds.size(), requests, statuses)) {
1297 for(size_type i=0; i < neighbourIds.size(); ++i)
1298 if(statuses[i].MPI_ERROR!=MPI_SUCCESS) {
1299 std::cerr<<rank<<
": MPI_Error occurred while receiving message."<<std::endl;
1300 MPI_Abort(comm_, 999);
1309 if(destPairs!=sourcePairs)
1312 delete[] sourcePairs;
1318 template<
typename T,
typename A>
1319 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& remote,
1329 if(remoteEntries==0)
1333 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1335 GlobalIndex oldGlobal=index.global();
1336 int n_in=0, localIndex=0;
1339 while(localIndex<localEntries) {
1340 if(local[localIndex]->global()==index.global()) {
1341 int oldLocalIndex=localIndex;
1343 while(localIndex<localEntries &&
1344 local[localIndex]->global()==index.global()) {
1345 if(!fromOurSelf || index.local().attribute() !=
1346 local[localIndex]->local().attribute())
1348 remote.push_back(RemoteIndex(index.local().attribute(),
1349 local[localIndex]));
1354 if((++n_in) < remoteEntries) {
1355 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1357 if(index.global()==oldGlobal)
1359 localIndex=oldLocalIndex;
1361 oldGlobal=index.global();
1369 if (local[localIndex]->global()<index.global()) {
1374 if((++n_in) < remoteEntries) {
1375 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1377 oldGlobal=index.global();
1385 while(++n_in < remoteEntries)
1386 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1391 template<
typename T,
typename A>
1392 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& send,
1393 RemoteIndexList& receive,
1395 PairType** localSource,
1396 int localSourceEntries,
1397 PairType** localDest,
1398 int localDestEntries,
1404 int n_in=0, sourceIndex=0, destIndex=0;
1407 while(n_in<remoteEntries && (sourceIndex<localSourceEntries || destIndex<localDestEntries)) {
1410 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1415 while(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()<index.global())
1418 while(destIndex<localDestEntries && localDest[destIndex]->global()<index.global())
1422 if(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()==index.global())
1423 send.push_back(RemoteIndex(index.local().attribute(),
1424 localSource[sourceIndex]));
1426 if(destIndex < localDestEntries && localDest[destIndex]->global() == index.global())
1427 receive.push_back(RemoteIndex(index.local().attribute(),
1428 localDest[sourceIndex]));
1433 template<
typename T,
typename A>
1436 typedef typename RemoteIndexMap::iterator Iterator;
1437 Iterator lend = remoteIndices_.end();
1438 for(Iterator lists=remoteIndices_.begin(); lists != lend; ++lists) {
1439 if(lists->second.first==lists->second.second) {
1441 delete lists->second.first;
1443 delete lists->second.first;
1444 delete lists->second.second;
1447 remoteIndices_.clear();
1451 template<
typename T,
typename A>
1454 return remoteIndices_.size();
1457 template<
typename T,
typename A>
1458 template<
bool ignorePublic>
1463 ignorePublic!=publicIgnored || !
1467 buildRemote<ignorePublic>(includeSelf);
1469 sourceSeqNo_ = source_->seqNo();
1470 destSeqNo_ = target_->seqNo();
1472 publicIgnored=ignorePublic;
1478 template<
typename T,
typename A>
1481 return sourceSeqNo_==source_->seqNo() && destSeqNo_ ==target_->seqNo();
1484 template<
typename T,
typename A>
1485 template<
bool mode,
bool send>
1492 sourceSeqNo_ = source_->seqNo();
1493 destSeqNo_ = target_->seqNo();
1495 typename RemoteIndexMap::iterator found = remoteIndices_.find(process);
1497 if(found == remoteIndices_.end())
1499 if(source_ != target_)
1500 found = remoteIndices_.insert(found, std::make_pair(process,
1505 found = remoteIndices_.insert(found,
1506 std::make_pair(process,
1507 std::make_pair(rlist, rlist)));
1519 template<
typename T,
typename A>
1520 inline typename RemoteIndices<T,A>::const_iterator
1523 return remoteIndices_.find(proc);
1526 template<
typename T,
typename A>
1527 inline typename RemoteIndices<T,A>::const_iterator
1530 return remoteIndices_.begin();
1533 template<
typename T,
typename A>
1534 inline typename RemoteIndices<T,A>::const_iterator
1537 return remoteIndices_.end();
1541 template<
typename T,
typename A>
1547 typedef RemoteIndexList RList;
1548 typedef typename std::map<int,std::pair<RList*,RList*> >::const_iterator const_iterator;
1550 const const_iterator rend = remoteIndices_.
end();
1552 for(const_iterator rindex = remoteIndices_.begin(), rindex1=ri.remoteIndices_.begin(); rindex!=rend; ++rindex, ++rindex1) {
1553 if(rindex->first != rindex1->first)
1555 if(*(rindex->second.first) != *(rindex1->second.first))
1557 if(*(rindex->second.second) != *(rindex1->second.second))
1563 template<
class T,
class A,
bool mode>
1565 RemoteIndexList& rList)
1566 : rList_(&rList), indexSet_(&indexSet), iter_(rList.beginModify()), end_(rList.end()), first_(true)
1568 if(MODIFYINDEXSET) {
1570 for(ConstIterator iter=iter_; iter != end_; ++iter)
1571 glist_.push_back(iter->localIndexPair().global());
1572 giter_ = glist_.beginModify();
1576 template<
typename T,
typename A,
bool mode>
1578 : rList_(other.rList_), indexSet_(other.indexSet_),
1579 glist_(other.glist_), iter_(other.iter_), giter_(other.giter_), end_(other.end_),
1580 first_(other.first_), last_(other.last_)
1583 template<
typename T,
typename A,
bool mode>
1586 if(MODIFYINDEXSET) {
1588#ifdef DUNE_ISTL_WITH_CHECKING
1589 if(indexSet_->state()!=
GROUND)
1595 GlobalIterator giter = glist_.begin();
1596 IndexIterator index = indexSet_->begin();
1598 for(Iterator iter=rList_->begin(); iter != end_; ++iter) {
1599 while(index->global()<*giter) {
1601#ifdef DUNE_ISTL_WITH_CHECKING
1602 if(index == indexSet_->end())
1603 DUNE_THROW(InvalidPosition,
"No such global index in set!");
1607#ifdef DUNE_ISTL_WITH_CHECKING
1608 if(index->global() != *giter)
1609 DUNE_THROW(InvalidPosition,
"No such global index in set!");
1611 iter->localIndex_ = &(*index);
1616 template<
typename T,
typename A,
bool mode>
1619 static_assert(!mode,
"Not allowed if the mode indicates that new indices"
1620 "might be added to the underlying index set. Use "
1621 "insert(const RemoteIndex&, const GlobalIndex&) instead");
1623#ifdef DUNE_ISTL_WITH_CHECKING
1625 DUNE_THROW(InvalidPosition,
"Modifcation of remote indices have to occur with ascending global index.");
1634 iter_.insert(index);
1639 template<
typename T,
typename A,
bool mode>
1642 static_assert(mode,
"Not allowed if the mode indicates that no new indices"
1643 "might be added to the underlying index set. Use "
1644 "insert(const RemoteIndex&) instead");
1645#ifdef DUNE_ISTL_WITH_CHECKING
1646 if(!first_ && global<last_)
1647 DUNE_THROW(InvalidPosition,
"Modification of remote indices have to occur with ascending global index.");
1650 while(iter_ != end_ && *giter_ < global) {
1656 assert(iter_->localIndexPair().global() != global);
1657 iter_.insert(index);
1658 giter_.insert(global);
1664 template<
typename T,
typename A,
bool mode>
1667#ifdef DUNE_ISTL_WITH_CHECKING
1668 if(!first_ && global<last_)
1669 DUNE_THROW(InvalidPosition,
"Modifcation of remote indices have to occur with ascending global index.");
1674 if(MODIFYINDEXSET) {
1676 while(iter_!=end_ && *giter_< global) {
1680 if(*giter_ == global) {
1686 while(iter_!=end_ && iter_->localIndexPair().global() < global)
1689 if(iter_->localIndexPair().global()==global) {
1700 template<
typename T,
typename A>
1707 template<
typename T,
typename A>
1714 template<
typename T,
typename A>
1717 typedef typename RemoteIndexMap::const_iterator const_iterator;
1719 const const_iterator end=pmap.end();
1720 for(const_iterator process=pmap.begin(); process != end; ++process) {
1721 const RemoteIndexList* list = send ? process->second.first : process->second.second;
1723 map_.insert(std::make_pair(process->first,
1724 std::pair<iterator, const iterator>(list->
begin(), list->
end())));
1728 template<
typename T,
typename A>
1731 typedef typename Map::iterator
iterator;
1732 typedef typename Map::const_iterator const_iterator;
1733 const const_iterator end = map_.end();
1735 for(
iterator iter = map_.begin(); iter != end;) {
1741 remoteIndex = *current;
1743 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1744 ++(iter->second.first);
1747 if(iter->second.first == iter->second.second)
1757 template<
typename T,
typename A>
1759 const Attribute& attribute)
1761 typedef typename Map::iterator
iterator;
1762 typedef typename Map::const_iterator const_iterator;
1763 const const_iterator end = map_.end();
1765 for(
iterator iter = map_.begin(); iter != end;) {
1771 remoteIndex = *current;
1774 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1775 ++(iter->second.first);
1778 while(iter->second.first!=iter->second.second
1779 && iter->second.first->localIndexPair().global()==index
1780 && iter->second.first->localIndexPair().local().attribute()<attribute)
1781 ++(iter->second.first);
1784 if(iter->second.first == iter->second.second)
1791 attribute_=attribute;
1795 template<
typename T,
typename A>
1798 typedef typename Map::iterator iterator;
1799 typedef typename Map::const_iterator const_iterator;
1800 const const_iterator end = map_.end();
1802 for(iterator iter = map_.begin(); iter != end;) {
1804 typename RemoteIndexList::const_iterator current = iter->second.first;
1805 typename RemoteIndexList::const_iterator rend = iter->second.second;
1808 if(iter->second.first->localIndexPair().global()==index_ &&
1809 (noattribute || iter->second.first->localIndexPair().local().attribute() == attribute_))
1810 ++(iter->second.first);
1813 if(iter->second.first == iter->second.second)
1822 template<
typename T,
typename A>
1825 return map_.empty();
1828 template<
typename T,
typename A>
1833 return iterator(map_.begin(), map_.end(), index_);
1835 return iterator(map_.begin(), map_.end(), index_,
1839 template<
typename T,
typename A>
1840 inline typename CollectiveIterator<T,A>::iterator
1841 CollectiveIterator<T,A>::end()
1843 return iterator(map_.end(), map_.end(), index_);
1846 template<
typename TG,
typename TA>
1847 inline std::ostream& operator<<(std::ostream& os,
const RemoteIndex<TG,TA>& index)
1849 os<<
"[global="<<index.localIndexPair().global()<<
", remote attribute="<<index.attribute()<<
" local attribute="<<index.localIndexPair().local().attribute()<<
"]";
1853 template<
typename T,
typename A>
1854 inline std::ostream& operator<<(std::ostream& os,
const RemoteIndices<T,A>& indices)
1857 MPI_Comm_rank(indices.comm_, &rank);
1860 typedef typename std::map<int,std::pair<RList*,RList*> >::const_iterator const_iterator;
1862 const const_iterator rend = indices.remoteIndices_.
end();
1864 for(const_iterator rindex = indices.remoteIndices_.begin(); rindex!=rend; ++rindex) {
1865 os<<rank<<
": Prozess "<<rindex->first<<
":";
1867 if(!rindex->second.first->empty()) {
1870 const typename RList::const_iterator send= rindex->second.first->end();
1872 for(
typename RList::const_iterator index = rindex->second.first->begin();
1873 index != send; ++index)
1877 if(!rindex->second.second->empty()) {
1878 os<<rank<<
": Prozess "<<rindex->first<<
": "<<
"receive: ";
1880 for(
const auto& index : *(rindex->second.second))
1883 os<<std::endl<<std::flush;
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
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
bool operator!=(const iterator &other) const
Definition: remoteindices.hh:862
A collective iterator for moving over the remote indices for all processes collectively.
Definition: remoteindices.hh:708
CollectiveIterator(const RemoteIndexMap &map_, bool send)
Constructor.
Definition: remoteindices.hh:1715
bool empty()
Checks whether there are still iterators in the map.
Definition: remoteindices.hh:1823
void advance(const GlobalIndex &global)
Advances all underlying iterators.
Definition: remoteindices.hh:1729
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:748
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:377
A pair consisting of a global and local index.
Definition: indexset.hh:84
Class for recomputing missing indices of a distributed index set.
Definition: indicessyncer.hh:40
Base class of all classes representing a communication interface.
Definition: interface.hh:33
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:204
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:217
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:47
Default exception class for range errors.
Definition: exceptions.hh:252
Modifier for adding and/or deleting remote indices from the remote index list.
Definition: remoteindices.hh:549
void repairLocalIndexPointers()
Repair the pointers to the local index pairs.
Definition: remoteindices.hh:1584
@ MODIFYINDEXSET
If true the index set corresponding to the remote indices might get modified.
Definition: remoteindices.hh:567
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:1617
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:1665
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
Information about an index residing on another processor.
Definition: remoteindices.hh:71
const Attribute attribute() const
Get the attribute of the index on the remote process.
Definition: remoteindices.hh:946
T1 GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: remoteindices.hh:88
T2 Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: remoteindices.hh:97
IndexPair< GlobalIndex, ParallelLocalIndex< Attribute > > PairType
The type of the index pair.
Definition: remoteindices.hh:103
const PairType & localIndexPair() const
Get the corresponding local index pair.
Definition: remoteindices.hh:952
RemoteIndex()
Parameterless Constructor.
Definition: remoteindices.hh:930
The indices present on remote processes.
Definition: remoteindices.hh:187
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:229
friend void fillIndexSetHoles(const G &graph, Dune::OwnerOverlapCopyCommunication< T1, T2 > &oocomm)
Fills the holes in an index set.
Definition: repartition.hh:82
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:1434
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:213
void rebuild()
Rebuilds the set of remote indices.
Definition: remoteindices.hh:1459
T ParallelIndexSet
Type of the index set we use, e.g. ParallelLocalIndexSet.
Definition: remoteindices.hh:204
MPI_Comm communicator() const
Get the mpi communicator used.
Definition: remoteindices.hh:1708
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:224
CollectiveIteratorT iterator() const
Get an iterator for colletively iterating over the remote indices of all remote processes.
Definition: remoteindices.hh:1702
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:1535
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:243
RemoteIndexListModifier< T, A, mode > getModifier(int process)
Get a modifier for a remote index list.
Definition: remoteindices.hh:1486
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:239
int neighbours() const
Get the number of processors we share indices with.
Definition: remoteindices.hh:1452
CollectiveIterator< T, A > CollectiveIteratorT
The type of the collective iterator over all remote indices.
Definition: remoteindices.hh:208
const ParallelIndexSet & destinationIndexSet() const
Get the index set at destination.
Definition: remoteindices.hh:1007
RemoteIndices(const ParallelIndexSet &source, const ParallelIndexSet &destination, const MPI_Comm &comm, const std::vector< int > &neighbours=std::vector< int >(), bool includeSelf=false)
Constructor.
Definition: remoteindices.hh:958
typename std::allocator_traits< A >::template rebind_alloc< RemoteIndex > Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:235
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1521
bool isSynced() const
Checks whether the remote indices are synced with the indexsets.
Definition: remoteindices.hh:1479
const_iterator begin() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1528
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:219
A constant iterator for the SLList.
Definition: sllist.hh:369
A single linked list.
Definition: sllist.hh:42
A few common exception classes.
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:297
void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T::GlobalIndex, typename T::LocalIndex::Attribute >, A > > &globalMap, RemoteIndices< T, A1 > &remoteIndices, const T &indexSet)
Repair the pointers to the local indices in the remote indices.
Definition: indicessyncer.hh:490
iterator begin()
Get an iterator over the indices positioned at the first index.
iterator end()
Get an iterator over the indices positioned after the last index.
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:238
const GlobalIndex & global() const
Get the global index.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:225
@ GROUND
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:185
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:780
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition: sllist.hh:72
SLListModifyIterator< GlobalIndex, Allocator > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:101
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:768
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:235
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:257
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:93
Provides a map between global and local indices.
Traits classes for mapping types onto MPI_Datatype.
Dune namespace.
Definition: alignedallocator.hh:14
Provides classes for use as the local index in ParallelIndexSet for distributed computing.
Implements a singly linked list together with the necessary iterators.
Standard Dune debug streams.
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:38