3 #ifndef DUNE_REMOTEINDICES_HH
4 #define DUNE_REMOTEINDICES_HH
33 template<
typename TG,
typename TA>
38 inline static MPI_Datatype
getType();
40 static MPI_Datatype type;
44 template<
typename T,
typename A>
47 template<
typename T1,
typename T2>
53 template<
typename T1,
typename T2>
54 std::ostream& operator<<(std::ostream& os, const RemoteIndex<T1,T2>& index);
57 template<
typename T,
typename A,
bool mode>
64 template<
typename T1,
typename T2>
70 template<
typename T,
typename A,
typename A1>
75 template<
typename T,
typename A,
bool mode>
146 template<
class T,
class A>
147 std::ostream& operator<<(std::ostream& os, const RemoteIndices<T,A>& indices);
151 template<
class T,
class A>
158 template<
typename T1,
typename T2>
178 template<
class T,
class A=std::allocator<
RemoteIndex<
typename T::GlobalIndex,
179 typename T::LocalIndex::Attribute> > >
184 template<
typename T1,
typename A2,
typename A1>
189 template<
class G,
class T1,
class T2>
229 typedef typename A::template rebind<RemoteIndex>::other
Allocator;
236 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
258 inline RemoteIndices(
const ParallelIndexSet& source,
const ParallelIndexSet& destination,
259 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>(),
bool includeSelf=
false);
288 void setIndexSets(
const ParallelIndexSet& source,
const ParallelIndexSet& destination,
289 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>());
294 neighbourIds.clear();
295 neighbourIds.insert(neighbours.begin(), neighbours.end());
318 template<
bool ignorePublic>
351 template<
bool mode,
bool send>
360 inline const_iterator
find(
int proc)
const;
366 inline const_iterator
begin()
const;
372 inline const_iterator
end()
const;
378 inline CollectiveIteratorT
iterator()
const;
403 const ParallelIndexSet* source_;
406 const ParallelIndexSet* target_;
413 std::set<int> neighbourIds;
416 const static int commTag_=333;
449 typedef IndexPair<GlobalIndex, LocalIndex>
470 template<
bool ignorePublic>
471 inline void buildRemote(
bool includeSelf);
478 inline int noPublic(
const ParallelIndexSet& indexSet);
491 template<
bool ignorePublic>
492 inline void packEntries(PairType** myPairs,
const ParallelIndexSet& indexSet,
493 char* p_out, MPI_Datatype type,
int bufferSize,
494 int* position,
int n);
510 PairType** local,
int localEntries,
char* p_in,
511 MPI_Datatype type,
int* positon,
int bufferSize,
515 int remoteEntries, PairType** localSource,
516 int localSourceEntries, PairType** localDest,
517 int localDestEntries,
char* p_in,
518 MPI_Datatype type,
int* position,
int bufferSize);
520 void unpackCreateRemote(
char* p_in, PairType** sourcePairs, PairType** DestPairs,
521 int remoteProc,
int sourcePublish,
int destPublish,
522 int bufferSize,
bool sendTwo,
bool fromOurSelf=
false);
542 template<
class T,
class A,
bool mode>
543 class RemoteIndexListModifier
546 template<
typename T1,
typename A1>
671 RemoteIndexListModifier()
688 const ParallelIndexSet* indexSet_;
690 ModifyIterator iter_;
691 GlobalModifyIterator giter_;
701 template<
class T,
class A>
702 class CollectiveIterator
708 typedef T ParallelIndexSet;
723 typedef typename LocalIndex::Attribute Attribute;
729 typedef typename A::template rebind<RemoteIndex>::other Allocator;
736 const typename RemoteIndexList::const_iterator> >
742 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
760 inline void advance(
const GlobalIndex& global);
771 inline void advance(
const GlobalIndex& global,
const Attribute& attribute);
794 iterator(
const RealIterator& iter,
const ConstRealIterator&
end, GlobalIndex& index)
795 : iter_(iter), end_(end), index_(index), hasAttribute(false)
798 while(iter_!=end_ && iter_->second.first->localIndexPair().global()!=index_)
802 iterator(
const RealIterator& iter,
const ConstRealIterator&
end, GlobalIndex index,
804 : iter_(iter), end_(end), index_(index), attribute_(attribute), hasAttribute(true)
807 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_
808 || iter_->second.first->localIndexPair().local().attribute()!=attribute))
813 : iter_(other.iter_), end_(other.end_), index_(other.index_)
821 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_ ||
823 iter_->second.first->localIndexPair().local().attribute()!=attribute_)))
825 assert(iter_==end_ ||
826 (iter_->second.first->localIndexPair().global()==index_));
827 assert(iter_==end_ || !hasAttribute ||
828 (iter_->second.first->localIndexPair().local().attribute()==attribute_));
835 return *(iter_->second.first);
847 return iter_->second.first.operator->();
853 return other.iter_==iter_;
859 return other.iter_!=iter_;
868 Attribute attribute_;
880 Attribute attribute_;
884 template<
typename TG,
typename TA>
887 if(type==MPI_DATATYPE_NULL) {
893 length[0]=length[1]=length[2]=length[3]=1;
894 MPI_Address(rep, disp);
895 MPI_Address(&(rep[0].global_), disp+1);
896 MPI_Address(&(rep[0].local_), disp+2);
897 MPI_Address(rep+1, disp+3);
898 for(
int i=3; i >= 0; --i)
900 MPI_Type_struct(4, length, disp, types, &type);
901 MPI_Type_commit(&type);
906 template<
typename TG,
typename TA>
909 template<
typename T1,
typename T2>
911 : localIndex_(local), attribute_(attribute)
914 template<
typename T1,
typename T2>
916 : localIndex_(0), attribute_(attribute)
919 template<
typename T1,
typename T2>
921 : localIndex_(0), attribute_()
923 template<
typename T1,
typename T2>
926 return localIndex_==ri.localIndex_ && attribute_==ri.
attribute;
929 template<
typename T1,
typename T2>
932 return localIndex_!=ri.localIndex_ || attribute_!=ri.attribute_;
935 template<
typename T1,
typename T2>
938 return T2(attribute_);
941 template<
typename T1,
typename T2>
947 template<
typename T,
typename A>
949 const ParallelIndexSet& destination,
950 const MPI_Comm& comm,
951 const std::vector<int>& neighbours,
953 : source_(&source), target_(&destination), comm_(comm),
954 sourceSeqNo_(-1), destSeqNo_(-1), publicIgnored(false), firstBuild(true),
955 includeSelf(includeSelf_)
960 template<
typename T,
typename A>
966 template<
typename T,
typename A>
968 : source_(0), target_(0), sourceSeqNo_(-1),
969 destSeqNo_(-1), publicIgnored(false), firstBuild(true)
972 template<
class T,
typename A>
974 const ParallelIndexSet& destination,
975 const MPI_Comm& comm,
976 const std::vector<int>& neighbours)
980 target_ = &destination;
983 setNeighbours(neighbours);
986 template<
typename T,
typename A>
994 template<
typename T,
typename A>
1002 template<
typename T,
typename A>
1008 template<
typename T,
typename A>
1009 template<
bool ignorePublic>
1011 const ParallelIndexSet& indexSet,
1012 char* p_out, MPI_Datatype type,
1014 int *position,
int n)
1020 const const_iterator end = indexSet.end();
1024 for(const_iterator index = indexSet.begin(); index != end; ++index)
1025 if(ignorePublic || index->local().isPublic()) {
1027 MPI_Pack(const_cast<PairType*>(&(*index)), 1,
1029 p_out, bufferSize, position, comm_);
1030 pairs[i++] =
const_cast<PairType*
>(&(*index));
1036 template<
typename T,
typename A>
1043 const const_iterator end=indexSet.
end();
1044 for(const_iterator index=indexSet.
begin(); index!=end; ++index)
1045 if(index->local().isPublic())
1053 template<
typename T,
typename A>
1054 inline void RemoteIndices<T,A>::unpackCreateRemote(
char* p_in, PairType** sourcePairs,
1055 PairType** destPairs,
int remoteProc,
1056 int sourcePublish,
int destPublish,
1057 int bufferSize,
bool sendTwo,
1062 int noRemoteSource=-1, noRemoteDest=-1;
1063 char twoIndexSets=0;
1066 MPI_Unpack(p_in, bufferSize, &position, &twoIndexSets, 1, MPI_CHAR, comm_);
1068 MPI_Unpack(p_in, bufferSize, &position, &noRemoteSource, 1, MPI_INT, comm_);
1070 MPI_Unpack(p_in, bufferSize, &position, &noRemoteDest, 1, MPI_INT, comm_);
1074 RemoteIndexList* receive=
new RemoteIndexList();
1076 RemoteIndexList* send=0;
1082 send =
new RemoteIndexList();
1084 unpackIndices(*send, *receive, noRemoteSource, sourcePairs, sourcePublish,
1085 destPairs, destPublish, p_in, type, &position, bufferSize);
1088 unpackIndices(*receive, noRemoteSource, sourcePairs, sourcePublish,
1089 p_in, type, &position, bufferSize, fromOurSelf);
1094 int oldPos=position;
1096 unpackIndices(*receive, noRemoteSource, destPairs, destPublish,
1097 p_in, type, &position, bufferSize, fromOurSelf);
1102 send =
new RemoteIndexList();
1103 unpackIndices(*send, noRemoteDest, sourcePairs, sourcePublish,
1104 p_in, type, &position, bufferSize, fromOurSelf);
1107 if(receive->empty() && send->empty()) {
1115 remoteIndices_.insert(std::make_pair(remoteProc,
1116 std::make_pair(send,receive)));
1121 template<
typename T,
typename A>
1122 template<
bool ignorePublic>
1123 inline void RemoteIndices<T,A>::buildRemote(
bool includeSelf)
1127 MPI_Comm_rank(comm_, &rank);
1128 MPI_Comm_size(comm_, &procs);
1132 int sourcePublish, destPublish;
1135 char sendTwo = (source_ != target_);
1137 if(procs==1 && !(sendTwo || includeSelf))
1141 sourcePublish = (ignorePublic) ? source_->size() : noPublic(*source_);
1144 destPublish = (ignorePublic) ? target_->size() : noPublic(*target_);
1149 int maxPublish, publish=sourcePublish+destPublish;
1152 MPI_Allreduce(&publish, &maxPublish, 1, MPI_INT, MPI_MAX, comm_);
1155 typedef IndexPair<GlobalIndex,LocalIndex> PairType;
1157 PairType** destPairs;
1158 PairType** sourcePairs =
new PairType*[sourcePublish>0 ? sourcePublish : 1];
1161 destPairs =
new PairType*[destPublish>0 ? destPublish : 1];
1163 destPairs=sourcePairs;
1165 char** buffer =
new char*[2];
1174 MPI_Pack_size(maxPublish, type, comm_,
1176 MPI_Pack_size(1, MPI_INT, comm_,
1178 MPI_Pack_size(1, MPI_CHAR, comm_,
1184 bufferSize += 2 * intSize + charSize;
1186 if(bufferSize<=0) bufferSize=1;
1188 buffer[0] =
new char[bufferSize];
1189 buffer[1] =
new char[bufferSize];
1193 MPI_Pack(&sendTwo, 1, MPI_CHAR, buffer[0], bufferSize, &position,
1197 MPI_Pack(&sourcePublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1199 MPI_Pack(&destPublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1203 packEntries<ignorePublic>(sourcePairs, *source_, buffer[0], type,
1204 bufferSize, &position, sourcePublish);
1207 packEntries<ignorePublic>(destPairs, *target_, buffer[0], type,
1208 bufferSize, &position, destPublish);
1212 if(sendTwo|| includeSelf)
1213 unpackCreateRemote(buffer[0], sourcePairs, destPairs, rank, sourcePublish,
1214 destPublish, bufferSize, sendTwo, includeSelf);
1216 neighbourIds.erase(rank);
1218 if(neighbourIds.size()==0)
1220 Dune::dvverb<<rank<<
": Sending messages in a ring"<<std::endl;
1222 for(
int proc=1; proc<procs; proc++) {
1224 char* p_out = buffer[1-(proc%2)];
1225 char* p_in = buffer[proc%2];
1229 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1231 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1232 commTag_, comm_, &status);
1234 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1235 commTag_, comm_, &status);
1236 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1242 int remoteProc = (rank+procs-proc)%procs;
1244 unpackCreateRemote(p_in, sourcePairs, destPairs, remoteProc, sourcePublish,
1245 destPublish, bufferSize, sendTwo);
1252 MPI_Request* requests=
new MPI_Request[neighbourIds.size()];
1253 MPI_Request* req=requests;
1255 typedef typename std::set<int>::size_type size_type;
1256 size_type noNeighbours=neighbourIds.size();
1259 for(std::set<int>::iterator neighbour=neighbourIds.begin();
1260 neighbour!= neighbourIds.end(); ++neighbour) {
1262 MPI_Issend(buffer[0], position , MPI_PACKED, *neighbour, commTag_, comm_, req++);
1267 for(size_type received=0; received <noNeighbours; ++received)
1271 MPI_Probe(MPI_ANY_SOURCE, commTag_, comm_, &status);
1272 int remoteProc=status.MPI_SOURCE;
1274 MPI_Get_count(&status, MPI_PACKED, &size);
1276 MPI_Recv(buffer[1], size, MPI_PACKED, remoteProc,
1277 commTag_, comm_, &status);
1279 unpackCreateRemote(buffer[1], sourcePairs, destPairs, remoteProc, sourcePublish,
1280 destPublish, bufferSize, sendTwo);
1283 MPI_Status* statuses =
new MPI_Status[neighbourIds.size()];
1285 if(MPI_ERR_IN_STATUS==MPI_Waitall(neighbourIds.size(), requests, statuses)) {
1286 for(size_type i=0; i < neighbourIds.size(); ++i)
1287 if(statuses[i].MPI_ERROR!=MPI_SUCCESS) {
1288 std::cerr<<rank<<
": MPI_Error occurred while receiving message."<<std::endl;
1289 MPI_Abort(comm_, 999);
1298 if(destPairs!=sourcePairs)
1301 delete[] sourcePairs;
1307 template<
typename T,
typename A>
1308 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& remote,
1318 if(remoteEntries==0)
1322 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1324 GlobalIndex oldGlobal=index.global();
1325 int n_in=0, localIndex=0;
1328 while(localIndex<localEntries) {
1329 if(local[localIndex]->global()==index.global()) {
1330 int oldLocalIndex=localIndex;
1332 while(localIndex<localEntries &&
1333 local[localIndex]->global()==index.global()) {
1334 if(!fromOurSelf || index.local().attribute() !=
1335 local[localIndex]->local().attribute())
1337 remote.push_back(RemoteIndex(index.local().attribute(),
1338 local[localIndex]));
1343 if((++n_in) < remoteEntries) {
1344 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1346 if(index.global()==oldGlobal)
1348 localIndex=oldLocalIndex;
1350 oldGlobal=index.global();
1358 if (local[localIndex]->global()<index.global()) {
1363 if((++n_in) < remoteEntries) {
1364 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1366 oldGlobal=index.global();
1374 while(++n_in < remoteEntries)
1375 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1380 template<
typename T,
typename A>
1381 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& send,
1382 RemoteIndexList& receive,
1384 PairType** localSource,
1385 int localSourceEntries,
1386 PairType** localDest,
1387 int localDestEntries,
1393 int n_in=0, sourceIndex=0, destIndex=0;
1396 while(n_in<remoteEntries && (sourceIndex<localSourceEntries || destIndex<localDestEntries)) {
1399 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1404 while(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()<index.global())
1407 while(destIndex<localDestEntries && localDest[destIndex]->global()<index.global())
1411 if(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()==index.global())
1412 send.push_back(RemoteIndex(index.local().attribute(),
1413 localSource[sourceIndex]));
1415 if(destIndex < localDestEntries && localDest[destIndex]->global() == index.global())
1416 receive.push_back(RemoteIndex(index.local().attribute(),
1417 localDest[sourceIndex]));
1422 template<
typename T,
typename A>
1425 typedef typename RemoteIndexMap::iterator Iterator;
1426 Iterator lend = remoteIndices_.end();
1427 for(Iterator lists=remoteIndices_.begin(); lists != lend; ++lists) {
1428 if(lists->second.first==lists->second.second) {
1430 delete lists->second.first;
1432 delete lists->second.first;
1433 delete lists->second.second;
1436 remoteIndices_.clear();
1440 template<
typename T,
typename A>
1443 return remoteIndices_.size();
1446 template<
typename T,
typename A>
1447 template<
bool ignorePublic>
1452 ignorePublic!=publicIgnored || !
1456 buildRemote<ignorePublic>(includeSelf);
1458 sourceSeqNo_ = source_->seqNo();
1459 destSeqNo_ = target_->seqNo();
1461 publicIgnored=ignorePublic;
1467 template<
typename T,
typename A>
1470 return sourceSeqNo_==source_->seqNo() && destSeqNo_ ==target_->seqNo();
1473 template<
typename T,
typename A>
1474 template<
bool mode,
bool send>
1481 sourceSeqNo_ = source_->seqNo();
1482 destSeqNo_ = target_->seqNo();
1484 typename RemoteIndexMap::iterator found = remoteIndices_.find(process);
1486 if(found == remoteIndices_.end())
1488 if(source_ != target_)
1489 found = remoteIndices_.insert(found, std::make_pair(process,
1494 found = remoteIndices_.insert(found,
1495 std::make_pair(process,
1496 std::make_pair(rlist, rlist)));
1508 template<
typename T,
typename A>
1512 return remoteIndices_.find(proc);
1515 template<
typename T,
typename A>
1519 return remoteIndices_.begin();
1522 template<
typename T,
typename A>
1526 return remoteIndices_.end();
1530 template<
typename T,
typename A>
1537 typedef typename std::map<int,std::pair<RList*,RList*> >
::const_iterator const_iterator;
1539 const const_iterator rend = remoteIndices_.
end();
1541 for(const_iterator rindex = remoteIndices_.begin(), rindex1=ri.remoteIndices_.begin(); rindex!=rend; ++rindex, ++rindex1) {
1542 if(rindex->first != rindex1->first)
1544 if(*(rindex->second.first) != *(rindex1->second.first))
1546 if(*(rindex->second.second) != *(rindex1->second.second))
1552 template<
class T,
class A,
bool mode>
1554 RemoteIndexList& rList)
1555 : rList_(&rList), indexSet_(&indexSet), iter_(rList.beginModify()), end_(rList.end()), first_(true)
1557 if(MODIFYINDEXSET) {
1559 for(ConstIterator iter=iter_; iter != end_; ++iter)
1560 glist_.push_back(iter->localIndexPair().global());
1561 giter_ = glist_.beginModify();
1565 template<
typename T,
typename A,
bool mode>
1567 : rList_(other.rList_), indexSet_(other.indexSet_),
1568 glist_(other.glist_), iter_(other.iter_), giter_(other.giter_), end_(other.end_),
1569 first_(other.first_), last_(other.last_)
1572 template<
typename T,
typename A,
bool mode>
1575 if(MODIFYINDEXSET) {
1577 #ifdef DUNE_ISTL_WITH_CHECKING
1578 if(indexSet_->state()!=
GROUND)
1579 DUNE_THROW(InvalidIndexSetState,
"Index has to be in ground mode for repairing pointers to indices");
1584 GlobalIterator giter = glist_.begin();
1585 IndexIterator index = indexSet_->begin();
1587 for(Iterator iter=rList_->begin(); iter != end_; ++iter) {
1588 while(index->global()<*giter) {
1590 #ifdef DUNE_ISTL_WITH_CHECKING
1591 if(index == indexSet_->end())
1596 #ifdef DUNE_ISTL_WITH_CHECKING
1597 if(index->global() != *giter)
1600 iter->localIndex_ = &(*index);
1605 template<
typename T,
typename A,
bool mode>
1608 static_assert(!mode,
"Not allowed if the mode indicates that new indices"
1609 "might be added to the underlying index set. Use "
1610 "insert(const RemoteIndex&, const GlobalIndex&) instead");
1612 #ifdef DUNE_ISTL_WITH_CHECKING
1613 if(!first_ && index.localIndexPair().global()<last_)
1617 while(iter_ != end_ && iter_->localIndexPair().global() < index.localIndexPair().global()) {
1622 assert(iter_==end_ || iter_->localIndexPair().global() != index.localIndexPair().global());
1623 iter_.insert(index);
1624 last_ = index.localIndexPair().global();
1628 template<
typename T,
typename A,
bool mode>
1631 static_assert(mode,
"Not allowed if the mode indicates that no new indices"
1632 "might be added to the underlying index set. Use "
1633 "insert(const RemoteIndex&) instead");
1634 #ifdef DUNE_ISTL_WITH_CHECKING
1635 if(!first_ && global<last_)
1639 while(iter_ != end_ && *giter_ < global) {
1645 assert(iter_->localIndexPair().global() != global);
1646 iter_.insert(index);
1647 giter_.insert(global);
1653 template<
typename T,
typename A,
bool mode>
1656 #ifdef DUNE_ISTL_WITH_CHECKING
1657 if(!first_ && global<last_)
1663 if(MODIFYINDEXSET) {
1665 while(iter_!=end_ && *giter_< global) {
1669 if(*giter_ == global) {
1675 while(iter_!=end_ && iter_->localIndexPair().global() < global)
1678 if(iter_->localIndexPair().global()==global) {
1689 template<
typename T,
typename A>
1696 template<
typename T,
typename A>
1703 template<
typename T,
typename A>
1706 typedef typename RemoteIndexMap::const_iterator const_iterator;
1708 const const_iterator end=pmap.end();
1709 for(const_iterator process=pmap.begin(); process != end; ++process) {
1710 const RemoteIndexList* list = send ? process->second.first : process->second.second;
1712 map_.insert(std::make_pair(process->first,
1713 std::pair<iterator, const iterator>(list->
begin(), list->
end())));
1717 template<
typename T,
typename A>
1720 typedef typename Map::iterator
iterator;
1721 typedef typename Map::const_iterator const_iterator;
1722 const const_iterator end = map_.end();
1724 for(iterator iter = map_.begin(); iter != end;) {
1728 RemoteIndex remoteIndex;
1730 remoteIndex = *current;
1732 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1733 ++(iter->second.first);
1736 if(iter->second.first == iter->second.second)
1746 template<
typename T,
typename A>
1748 const Attribute& attribute)
1750 typedef typename Map::iterator
iterator;
1751 typedef typename Map::const_iterator const_iterator;
1752 const const_iterator end = map_.end();
1754 for(iterator iter = map_.begin(); iter != end;) {
1758 RemoteIndex remoteIndex;
1760 remoteIndex = *current;
1763 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1764 ++(iter->second.first);
1767 while(iter->second.first!=iter->second.second
1768 && iter->second.first->localIndexPair().global()==index
1769 && iter->second.first->localIndexPair().local().attribute()<attribute)
1770 ++(iter->second.first);
1773 if(iter->second.first == iter->second.second)
1780 attribute_=attribute;
1784 template<
typename T,
typename A>
1787 typedef typename Map::iterator
iterator;
1788 typedef typename Map::const_iterator const_iterator;
1789 const const_iterator end = map_.end();
1791 for(iterator iter = map_.begin(); iter != end;) {
1797 if(iter->second.first->localIndexPair().global()==
index_ &&
1798 (noattribute || iter->second.first->localIndexPair().local().attribute() == attribute_))
1799 ++(iter->second.first);
1802 if(iter->second.first == iter->second.second)
1811 template<
typename T,
typename A>
1814 return map_.empty();
1817 template<
typename T,
typename A>
1828 template<
typename T,
typename A>
1835 template<
typename TG,
typename TA>
1836 inline std::ostream& operator<<(std::ostream& os, const RemoteIndex<TG,TA>& index)
1838 os<<
"[global="<<index.localIndexPair().global()<<
", remote attribute="<<index.attribute()<<
" local attribute="<<index.localIndexPair().local().attribute()<<
"]";
1842 template<
typename T,
typename A>
1843 inline std::ostream& operator<<(std::ostream& os, const RemoteIndices<T,A>& indices)
1846 MPI_Comm_rank(indices.comm_, &rank);
1849 typedef typename std::map<int,std::pair<RList*,RList*> >::const_iterator const_iterator;
1851 const const_iterator rend = indices.remoteIndices_.
end();
1853 for(const_iterator rindex = indices.remoteIndices_.begin(); rindex!=rend; ++rindex) {
1854 os<<rank<<
": Prozess "<<rindex->first<<
":";
1856 if(!rindex->second.first->empty()) {
1859 const typename RList::const_iterator send= rindex->second.first->end();
1861 for(
typename RList::const_iterator index = rindex->second.first->begin();
1862 index != send; ++index)
1866 if(!rindex->second.second->empty()) {
1867 os<<rank<<
": Prozess "<<rindex->first<<
": "<<
"receive: ";
1869 const typename RList::const_iterator rend= rindex->second.second->end();
1871 for(
typename RList::const_iterator index = rindex->second.second->begin();
1872 index != rend; ++index)
1875 os<<std::endl<<std::flush;
CollectiveIterator< T, A > CollectiveIteratorT
The type of the collective iterator over all remote indices.
Definition: remoteindices.hh:202
A Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:593
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T::GlobalIndex, typename T::LocalIndex::Attribute >, A > > &, RemoteIndices< T, A1 > &, const T &)
bool operator==(const RemoteIndex &ri) const
Definition: remoteindices.hh:924
RemoteIndexList::const_iterator ConstIterator
The type of the remote index list iterator.
Definition: remoteindices.hh:607
SLListModifyIterator< RemoteIndex, Allocator > ModifyIterator
The type of the modifying iterator of the remote index list.
Definition: remoteindices.hh:602
The indices present on remote processes.
Definition: remoteindices.hh:45
CollectiveIterator & operator++()
Definition: remoteindices.hh:1785
const std::set< int > & getNeighbours() const
Definition: remoteindices.hh:299
iterator end()
Definition: remoteindices.hh:1830
Information about an index residing on another processor.
Definition: remoteindices.hh:48
Class for recomputing missing indices of a distributed index set.
Definition: indicessyncer.hh:39
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition: sllist.hh:72
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:597
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:743
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:204
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex index, Attribute attribute)
Definition: remoteindices.hh:802
Traits classes for mapping types onto MPI_Datatype.
A constant iterator for the SLList.
Definition: sllist.hh:28
A few common exception classes.
void setNeighbours(const C &neighbours)
Definition: remoteindices.hh:292
SLListModifyIterator< GlobalIndex, Allocator > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:101
T ParallelIndexSet
Type of the index set we use.
Definition: remoteindices.hh:568
iterator begin()
Get an iterator over the indices positioned at the first index.
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:776
T ParallelIndexSet
Type of the index set we use, e.g. ParallelLocalIndexSet.
Definition: remoteindices.hh:198
Modifier for adding and/or deleting remote indices from the remote index list.
Definition: remoteindices.hh:58
iterator & operator++()
Definition: remoteindices.hh:817
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:93
Provides a map between global and local indices.
bool empty()
Checks whether there are still iterators in the map.
Definition: remoteindices.hh:1812
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:30
MPI_Comm communicator() const
Get the mpi communicator used.
Definition: remoteindices.hh:1697
void repairLocalIndexPointers()
Repair the pointers to the local index pairs.
Definition: remoteindices.hh:1573
const_iterator begin() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1517
Map::iterator RealIterator
Definition: remoteindices.hh:789
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:583
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:573
A single linked list.
Definition: sllist.hh:41
RemoteIndex()
Parameterless Constructor.
Definition: remoteindices.hh:920
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:185
const RemoteIndex & operator*() const
Definition: remoteindices.hh:833
void rebuild()
Rebuilds the set of remote indices.
Definition: remoteindices.hh:1448
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1524
bool isSynced() const
Checks whether the remote indices are synced with the indexsets.
Definition: remoteindices.hh:1468
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:973
Dune namespace.
Definition: alignment.hh:9
iterator begin()
Definition: remoteindices.hh:1819
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:223
Implements a singly linked list together with the necessary iterators.
CollectiveIteratorT iterator() const
Get an iterator for colletively iterating over the remote indices of all remote processes.
Definition: remoteindices.hh:1691
std::size_t index_
The other rank that this interface communcates with.
Definition: variablesizecommunicator.hh:257
iterator end()
Get an iterator over the indices positioned after the last index.
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:788
void insert(const RemoteIndex &index)
Insert an index to the list.
Definition: remoteindices.hh:1606
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex &index)
Definition: remoteindices.hh:794
bool remove(const GlobalIndex &global)
Remove a remote index.
Definition: remoteindices.hh:1654
Definition: remoteindices.hh:159
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:213
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:233
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:207
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:20
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T1::GlobalIndex, typename T1::LocalIndex::Attribute >, A2 > > &, RemoteIndices< T1, A1 > &, const T1 &)
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:237
friend void fillIndexSetHoles(const G &graph, Dune::OwnerOverlapCopyCommunication< T1, T2 > &oocomm)
Iterator over the valid underlying iterators.
Definition: remoteindices.hh:786
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:218
iterator(const iterator &other)
Definition: remoteindices.hh:812
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:578
const Attribute attribute() const
Get the attribute of the index on the remote process.
Definition: remoteindices.hh:936
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
bool operator!=(const iterator &other)
Definition: remoteindices.hh:857
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
A pair consisting of a global and local index.
Definition: indexset.hh:30
static MPI_Datatype getType()
Definition: mpitraits.hh:44
T2 Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: remoteindices.hh:92
int process() const
Definition: remoteindices.hh:839
bool operator!=(const RemoteIndex &ri) const
Definition: remoteindices.hh:930
Standard Dune debug streams.
const RemoteIndex * operator->() const
Definition: remoteindices.hh:845
If true the index set corresponding to the remote indices might get modified.
Definition: remoteindices.hh:562
Map::iterator ConstRealIterator
Definition: remoteindices.hh:790
const ParallelIndexSet & destinationIndexSet() const
Get the index set at destination.
Definition: remoteindices.hh:996
Base class of all classes representing a communication interface.
Definition: interface.hh:32
An stl-compliant pool allocator.
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:27
A collective iterator for moving over the remote indices for all processes collectively.
Definition: remoteindices.hh:152
Default exception class for range errors.
Definition: exceptions.hh:279
CollectiveIterator(const RemoteIndexMap &map_, bool send)
Constructor.
Definition: remoteindices.hh:1704
RemoteIndexMap::const_iterator const_iterator
Definition: remoteindices.hh:239
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:225
const ParallelIndexSet & sourceIndexSet() const
Get the index set at the source.
Definition: remoteindices.hh:988
bool operator==(const iterator &other)
Definition: remoteindices.hh:851
RemoteIndexListModifier()
Default constructor.
Definition: remoteindices.hh:671
A::template rebind< RemoteIndex >::other Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:229
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1510
void free()
Free the index lists.
Definition: remoteindices.hh:1423
T1 GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: remoteindices.hh:83
RemoteIndices()
Definition: remoteindices.hh:967
RemoteIndexListModifier< T, A, mode > getModifier(int process)
Get a modifier for a remote index list.
Definition: remoteindices.hh:1475
void advance(const GlobalIndex &global)
Advances all underlying iterators.
Definition: remoteindices.hh:1718
~RemoteIndices()
Destructor.
Definition: remoteindices.hh:1003
int neighbours() const
Get the number of processors we share indices with.
Definition: remoteindices.hh:1441
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:588
IndexPair< GlobalIndex, ParallelLocalIndex< Attribute > > PairType
The type of the index pair.
Definition: remoteindices.hh:98
bool operator==(const RemoteIndices &ri)
Definition: remoteindices.hh:1531
Definition: remoteindices.hh:550
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:238
const PairType & localIndexPair() const
Get the corresponding local index pair.
Definition: remoteindices.hh:942
void setIncludeSelf(bool includeSelf)
Tell whether sending from indices of the processor to other indices on the same processor is enabled ...
Definition: remoteindices.hh:961
Provides classes for use as the local index in ParallelIndexSet for distributed computing.