4 #ifndef DUNE_REMOTEINDICES_HH
5 #define DUNE_REMOTEINDICES_HH
35 template<
typename TG,
typename TA>
40 inline static MPI_Datatype
getType();
42 static MPI_Datatype type;
46 template<
typename T,
typename A>
49 template<
typename T1,
typename T2>
55 template<
typename T1,
typename T2>
56 std::ostream& operator<<(std::ostream& os, const RemoteIndex<T1,T2>& index);
59 template<
typename T,
typename A,
bool mode>
66 template<
typename T1,
typename T2>
72 template<
typename T,
typename A,
typename A1>
77 template<
typename T,
typename A,
bool mode>
148 template<
class T,
class A>
149 std::ostream& operator<<(std::ostream& os, const RemoteIndices<T,A>& indices);
153 template<
class T,
class A>
160 template<
typename T1,
typename T2>
180 template<
class T,
class A=std::allocator<
RemoteIndex<
typename T::GlobalIndex,
181 typename T::LocalIndex::Attribute> > >
186 template<
typename T1,
typename A2,
typename A1>
191 template<
class G,
class T1,
class T2>
231 typedef typename A::template rebind<RemoteIndex>::other
Allocator;
238 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
260 inline RemoteIndices(
const ParallelIndexSet& source,
const ParallelIndexSet& destination,
261 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>(),
bool includeSelf=
false);
290 void setIndexSets(
const ParallelIndexSet& source,
const ParallelIndexSet& destination,
291 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>());
296 neighbourIds.clear();
297 neighbourIds.insert(neighbours.begin(), neighbours.end());
320 template<
bool ignorePublic>
353 template<
bool mode,
bool send>
362 inline const_iterator
find(
int proc)
const;
368 inline const_iterator
begin()
const;
374 inline const_iterator
end()
const;
380 inline CollectiveIteratorT
iterator()
const;
405 const ParallelIndexSet* source_;
408 const ParallelIndexSet* target_;
415 std::set<int> neighbourIds;
418 const static int commTag_=333;
451 typedef IndexPair<GlobalIndex, LocalIndex>
472 template<
bool ignorePublic>
473 inline void buildRemote(
bool includeSelf);
480 inline int noPublic(
const ParallelIndexSet& indexSet);
493 template<
bool ignorePublic>
494 inline void packEntries(PairType** myPairs,
const ParallelIndexSet& indexSet,
495 char* p_out, MPI_Datatype type,
int bufferSize,
496 int* position,
int n);
512 PairType** local,
int localEntries,
char* p_in,
513 MPI_Datatype type,
int* positon,
int bufferSize,
517 int remoteEntries, PairType** localSource,
518 int localSourceEntries, PairType** localDest,
519 int localDestEntries,
char* p_in,
520 MPI_Datatype type,
int* position,
int bufferSize);
522 void unpackCreateRemote(
char* p_in, PairType** sourcePairs, PairType** DestPairs,
523 int remoteProc,
int sourcePublish,
int destPublish,
524 int bufferSize,
bool sendTwo,
bool fromOurSelf=
false);
544 template<
class T,
class A,
bool mode>
545 class RemoteIndexListModifier
548 template<
typename T1,
typename A1>
673 RemoteIndexListModifier()
690 const ParallelIndexSet* indexSet_;
692 ModifyIterator iter_;
693 GlobalModifyIterator giter_;
703 template<
class T,
class A>
704 class CollectiveIterator
710 typedef T ParallelIndexSet;
725 typedef typename LocalIndex::Attribute Attribute;
731 typedef typename A::template rebind<RemoteIndex>::other Allocator;
738 const typename RemoteIndexList::const_iterator> >
744 typedef std::map<int, std::pair<RemoteIndexList*,RemoteIndexList*> >
762 inline void advance(
const GlobalIndex& global);
773 inline void advance(
const GlobalIndex& global,
const Attribute& attribute);
796 iterator(
const RealIterator& iter,
const ConstRealIterator&
end, GlobalIndex& index)
797 : iter_(iter), end_(end), index_(index), hasAttribute(false)
800 while(iter_!=end_ && iter_->second.first->localIndexPair().global()!=index_)
804 iterator(
const RealIterator& iter,
const ConstRealIterator&
end, GlobalIndex index,
806 : iter_(iter), end_(end), index_(index), attribute_(attribute), hasAttribute(true)
809 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_
810 || iter_->second.first->localIndexPair().local().attribute()!=attribute))
815 : iter_(other.iter_), end_(other.end_), index_(other.index_)
823 while(iter_!=end_ && (iter_->second.first->localIndexPair().global()!=index_ ||
825 iter_->second.first->localIndexPair().local().attribute()!=attribute_)))
827 assert(iter_==end_ ||
828 (iter_->second.first->localIndexPair().global()==index_));
829 assert(iter_==end_ || !hasAttribute ||
830 (iter_->second.first->localIndexPair().local().attribute()==attribute_));
837 return *(iter_->second.first);
849 return iter_->second.first.operator->();
855 return other.iter_==iter_;
861 return other.iter_!=iter_;
870 Attribute attribute_;
882 Attribute attribute_;
886 template<
typename TG,
typename TA>
889 if(type==MPI_DATATYPE_NULL) {
895 length[0]=length[1]=length[2]=length[3]=1;
896 MPI_Address(rep, disp);
897 MPI_Address(&(rep[0].global_), disp+1);
898 MPI_Address(&(rep[0].local_), disp+2);
899 MPI_Address(rep+1, disp+3);
900 for(
int i=3; i >= 0; --i)
902 MPI_Type_struct(4, length, disp, types, &type);
903 MPI_Type_commit(&type);
908 template<
typename TG,
typename TA>
911 template<
typename T1,
typename T2>
913 : localIndex_(local), attribute_(attribute)
916 template<
typename T1,
typename T2>
918 : localIndex_(0), attribute_(attribute)
921 template<
typename T1,
typename T2>
923 : localIndex_(0), attribute_()
925 template<
typename T1,
typename T2>
928 return localIndex_==ri.localIndex_ && attribute_==ri.
attribute;
931 template<
typename T1,
typename T2>
934 return localIndex_!=ri.localIndex_ || attribute_!=ri.attribute_;
937 template<
typename T1,
typename T2>
940 return T2(attribute_);
943 template<
typename T1,
typename T2>
949 template<
typename T,
typename A>
951 const ParallelIndexSet& destination,
952 const MPI_Comm& comm,
953 const std::vector<int>& neighbours,
955 : source_(&source), target_(&destination), comm_(comm),
956 sourceSeqNo_(-1), destSeqNo_(-1), publicIgnored(false), firstBuild(true),
957 includeSelf(includeSelf_)
962 template<
typename T,
typename A>
968 template<
typename T,
typename A>
970 : source_(0), target_(0), sourceSeqNo_(-1),
971 destSeqNo_(-1), publicIgnored(false), firstBuild(true)
974 template<
class T,
typename A>
976 const ParallelIndexSet& destination,
977 const MPI_Comm& comm,
978 const std::vector<int>& neighbours)
982 target_ = &destination;
985 setNeighbours(neighbours);
988 template<
typename T,
typename A>
996 template<
typename T,
typename A>
1004 template<
typename T,
typename A>
1010 template<
typename T,
typename A>
1011 template<
bool ignorePublic>
1013 const ParallelIndexSet& indexSet,
1014 char* p_out, MPI_Datatype type,
1016 int *position,
int n)
1021 const const_iterator end = indexSet.end();
1025 for(const_iterator index = indexSet.begin(); index != end; ++index)
1026 if(ignorePublic || index->local().isPublic()) {
1028 MPI_Pack(const_cast<PairType*>(&(*index)), 1,
1030 p_out, bufferSize, position, comm_);
1031 pairs[i++] =
const_cast<PairType*
>(&(*index));
1037 template<
typename T,
typename A>
1044 const const_iterator end=indexSet.
end();
1045 for(const_iterator index=indexSet.
begin(); index!=end; ++index)
1046 if(index->local().isPublic())
1054 template<
typename T,
typename A>
1055 inline void RemoteIndices<T,A>::unpackCreateRemote(
char* p_in, PairType** sourcePairs,
1056 PairType** destPairs,
int remoteProc,
1057 int sourcePublish,
int destPublish,
1058 int bufferSize,
bool sendTwo,
1063 int noRemoteSource=-1, noRemoteDest=-1;
1064 char twoIndexSets=0;
1067 MPI_Unpack(p_in, bufferSize, &position, &twoIndexSets, 1, MPI_CHAR, comm_);
1069 MPI_Unpack(p_in, bufferSize, &position, &noRemoteSource, 1, MPI_INT, comm_);
1071 MPI_Unpack(p_in, bufferSize, &position, &noRemoteDest, 1, MPI_INT, comm_);
1075 RemoteIndexList* receive=
new RemoteIndexList();
1077 RemoteIndexList* send=0;
1083 send =
new RemoteIndexList();
1085 unpackIndices(*send, *receive, noRemoteSource, sourcePairs, sourcePublish,
1086 destPairs, destPublish, p_in, type, &position, bufferSize);
1089 unpackIndices(*receive, noRemoteSource, sourcePairs, sourcePublish,
1090 p_in, type, &position, bufferSize, fromOurSelf);
1095 int oldPos=position;
1097 unpackIndices(*receive, noRemoteSource, destPairs, destPublish,
1098 p_in, type, &position, bufferSize, fromOurSelf);
1103 send =
new RemoteIndexList();
1104 unpackIndices(*send, noRemoteDest, sourcePairs, sourcePublish,
1105 p_in, type, &position, bufferSize, fromOurSelf);
1108 if(receive->empty() && send->empty()) {
1116 remoteIndices_.insert(std::make_pair(remoteProc,
1117 std::make_pair(send,receive)));
1122 template<
typename T,
typename A>
1123 template<
bool ignorePublic>
1124 inline void RemoteIndices<T,A>::buildRemote(
bool includeSelf)
1128 MPI_Comm_rank(comm_, &rank);
1129 MPI_Comm_size(comm_, &procs);
1133 int sourcePublish, destPublish;
1136 char sendTwo = (source_ != target_);
1138 if(procs==1 && !(sendTwo || includeSelf))
1142 sourcePublish = (ignorePublic) ? source_->size() : noPublic(*source_);
1145 destPublish = (ignorePublic) ? target_->size() : noPublic(*target_);
1150 int maxPublish, publish=sourcePublish+destPublish;
1153 MPI_Allreduce(&publish, &maxPublish, 1, MPI_INT, MPI_MAX, comm_);
1156 typedef IndexPair<GlobalIndex,LocalIndex> PairType;
1158 PairType** destPairs;
1159 PairType** sourcePairs =
new PairType*[sourcePublish>0 ? sourcePublish : 1];
1162 destPairs =
new PairType*[destPublish>0 ? destPublish : 1];
1164 destPairs=sourcePairs;
1166 char** buffer =
new char*[2];
1175 MPI_Pack_size(maxPublish, type, comm_,
1177 MPI_Pack_size(1, MPI_INT, comm_,
1179 MPI_Pack_size(1, MPI_CHAR, comm_,
1185 bufferSize += 2 * intSize + charSize;
1187 if(bufferSize<=0) bufferSize=1;
1189 buffer[0] =
new char[bufferSize];
1190 buffer[1] =
new char[bufferSize];
1194 MPI_Pack(&sendTwo, 1, MPI_CHAR, buffer[0], bufferSize, &position,
1198 MPI_Pack(&sourcePublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1200 MPI_Pack(&destPublish, 1, MPI_INT, buffer[0], bufferSize, &position,
1204 packEntries<ignorePublic>(sourcePairs, *source_, buffer[0], type,
1205 bufferSize, &position, sourcePublish);
1208 packEntries<ignorePublic>(destPairs, *target_, buffer[0], type,
1209 bufferSize, &position, destPublish);
1213 if(sendTwo|| includeSelf)
1214 unpackCreateRemote(buffer[0], sourcePairs, destPairs, rank, sourcePublish,
1215 destPublish, bufferSize, sendTwo, includeSelf);
1217 neighbourIds.erase(rank);
1219 if(neighbourIds.size()==0)
1221 Dune::dvverb<<rank<<
": Sending messages in a ring"<<std::endl;
1223 for(
int proc=1; proc<procs; proc++) {
1225 char* p_out = buffer[1-(proc%2)];
1226 char* p_in = buffer[proc%2];
1230 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1232 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1233 commTag_, comm_, &status);
1235 MPI_Recv(p_in, bufferSize, MPI_PACKED, (rank+procs-1)%procs,
1236 commTag_, comm_, &status);
1237 MPI_Ssend(p_out, bufferSize, MPI_PACKED, (rank+1)%procs,
1243 int remoteProc = (rank+procs-proc)%procs;
1245 unpackCreateRemote(p_in, sourcePairs, destPairs, remoteProc, sourcePublish,
1246 destPublish, bufferSize, sendTwo);
1253 MPI_Request* requests=
new MPI_Request[neighbourIds.size()];
1254 MPI_Request* req=requests;
1256 typedef typename std::set<int>::size_type size_type;
1257 size_type noNeighbours=neighbourIds.size();
1260 for(std::set<int>::iterator neighbour=neighbourIds.begin();
1261 neighbour!= neighbourIds.end(); ++neighbour) {
1263 MPI_Issend(buffer[0], position , MPI_PACKED, *neighbour, commTag_, comm_, req++);
1268 for(size_type received=0; received <noNeighbours; ++received)
1272 MPI_Probe(MPI_ANY_SOURCE, commTag_, comm_, &status);
1273 int remoteProc=status.MPI_SOURCE;
1275 MPI_Get_count(&status, MPI_PACKED, &size);
1277 MPI_Recv(buffer[1], size, MPI_PACKED, remoteProc,
1278 commTag_, comm_, &status);
1280 unpackCreateRemote(buffer[1], sourcePairs, destPairs, remoteProc, sourcePublish,
1281 destPublish, bufferSize, sendTwo);
1284 MPI_Status* statuses =
new MPI_Status[neighbourIds.size()];
1286 if(MPI_ERR_IN_STATUS==MPI_Waitall(neighbourIds.size(), requests, statuses)) {
1287 for(size_type i=0; i < neighbourIds.size(); ++i)
1288 if(statuses[i].MPI_ERROR!=MPI_SUCCESS) {
1289 std::cerr<<rank<<
": MPI_Error occurred while receiving message."<<std::endl;
1290 MPI_Abort(comm_, 999);
1299 if(destPairs!=sourcePairs)
1302 delete[] sourcePairs;
1308 template<
typename T,
typename A>
1309 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& remote,
1319 if(remoteEntries==0)
1323 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1325 GlobalIndex oldGlobal=index.global();
1326 int n_in=0, localIndex=0;
1329 while(localIndex<localEntries) {
1330 if(local[localIndex]->global()==index.global()) {
1331 int oldLocalIndex=localIndex;
1333 while(localIndex<localEntries &&
1334 local[localIndex]->global()==index.global()) {
1335 if(!fromOurSelf || index.local().attribute() !=
1336 local[localIndex]->local().attribute())
1338 remote.push_back(RemoteIndex(index.local().attribute(),
1339 local[localIndex]));
1344 if((++n_in) < remoteEntries) {
1345 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1347 if(index.global()==oldGlobal)
1349 localIndex=oldLocalIndex;
1351 oldGlobal=index.global();
1359 if (local[localIndex]->global()<index.global()) {
1364 if((++n_in) < remoteEntries) {
1365 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1367 oldGlobal=index.global();
1375 while(++n_in < remoteEntries)
1376 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1381 template<
typename T,
typename A>
1382 inline void RemoteIndices<T,A>::unpackIndices(RemoteIndexList& send,
1383 RemoteIndexList& receive,
1385 PairType** localSource,
1386 int localSourceEntries,
1387 PairType** localDest,
1388 int localDestEntries,
1394 int n_in=0, sourceIndex=0, destIndex=0;
1397 while(n_in<remoteEntries && (sourceIndex<localSourceEntries || destIndex<localDestEntries)) {
1400 MPI_Unpack(p_in, bufferSize, position, &index, 1,
1405 while(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()<index.global())
1408 while(destIndex<localDestEntries && localDest[destIndex]->global()<index.global())
1412 if(sourceIndex<localSourceEntries && localSource[sourceIndex]->global()==index.global())
1413 send.push_back(RemoteIndex(index.local().attribute(),
1414 localSource[sourceIndex]));
1416 if(destIndex < localDestEntries && localDest[destIndex]->global() == index.global())
1417 receive.push_back(RemoteIndex(index.local().attribute(),
1418 localDest[sourceIndex]));
1423 template<
typename T,
typename A>
1426 typedef typename RemoteIndexMap::iterator Iterator;
1427 Iterator lend = remoteIndices_.end();
1428 for(Iterator lists=remoteIndices_.begin(); lists != lend; ++lists) {
1429 if(lists->second.first==lists->second.second) {
1431 delete lists->second.first;
1433 delete lists->second.first;
1434 delete lists->second.second;
1437 remoteIndices_.clear();
1441 template<
typename T,
typename A>
1444 return remoteIndices_.size();
1447 template<
typename T,
typename A>
1448 template<
bool ignorePublic>
1453 ignorePublic!=publicIgnored || !
1457 buildRemote<ignorePublic>(includeSelf);
1459 sourceSeqNo_ = source_->seqNo();
1460 destSeqNo_ = target_->seqNo();
1462 publicIgnored=ignorePublic;
1468 template<
typename T,
typename A>
1471 return sourceSeqNo_==source_->seqNo() && destSeqNo_ ==target_->seqNo();
1474 template<
typename T,
typename A>
1475 template<
bool mode,
bool send>
1482 sourceSeqNo_ = source_->seqNo();
1483 destSeqNo_ = target_->seqNo();
1485 typename RemoteIndexMap::iterator found = remoteIndices_.find(process);
1487 if(found == remoteIndices_.end())
1489 if(source_ != target_)
1490 found = remoteIndices_.insert(found, std::make_pair(process,
1495 found = remoteIndices_.insert(found,
1496 std::make_pair(process,
1497 std::make_pair(rlist, rlist)));
1509 template<
typename T,
typename A>
1513 return remoteIndices_.find(proc);
1516 template<
typename T,
typename A>
1520 return remoteIndices_.begin();
1523 template<
typename T,
typename A>
1527 return remoteIndices_.end();
1531 template<
typename T,
typename A>
1538 typedef typename std::map<int,std::pair<RList*,RList*> >
::const_iterator const_iterator;
1540 const const_iterator rend = remoteIndices_.
end();
1542 for(const_iterator rindex = remoteIndices_.begin(), rindex1=ri.remoteIndices_.begin(); rindex!=rend; ++rindex, ++rindex1) {
1543 if(rindex->first != rindex1->first)
1545 if(*(rindex->second.first) != *(rindex1->second.first))
1547 if(*(rindex->second.second) != *(rindex1->second.second))
1553 template<
class T,
class A,
bool mode>
1555 RemoteIndexList& rList)
1556 : rList_(&rList), indexSet_(&indexSet), iter_(rList.beginModify()), end_(rList.end()), first_(true)
1558 if(MODIFYINDEXSET) {
1560 for(ConstIterator iter=iter_; iter != end_; ++iter)
1561 glist_.push_back(iter->localIndexPair().global());
1562 giter_ = glist_.beginModify();
1566 template<
typename T,
typename A,
bool mode>
1568 : rList_(other.rList_), indexSet_(other.indexSet_),
1569 glist_(other.glist_), iter_(other.iter_), giter_(other.giter_), end_(other.end_),
1570 first_(other.first_), last_(other.last_)
1573 template<
typename T,
typename A,
bool mode>
1576 if(MODIFYINDEXSET) {
1578 #ifdef DUNE_ISTL_WITH_CHECKING
1579 if(indexSet_->state()!=
GROUND)
1580 DUNE_THROW(InvalidIndexSetState,
"Index has to be in ground mode for repairing pointers to indices");
1585 GlobalIterator giter = glist_.begin();
1586 IndexIterator index = indexSet_->begin();
1588 for(Iterator iter=rList_->begin(); iter != end_; ++iter) {
1589 while(index->global()<*giter) {
1591 #ifdef DUNE_ISTL_WITH_CHECKING
1592 if(index == indexSet_->end())
1597 #ifdef DUNE_ISTL_WITH_CHECKING
1598 if(index->global() != *giter)
1601 iter->localIndex_ = &(*index);
1606 template<
typename T,
typename A,
bool mode>
1610 "might be added to the underlying index set. Use "
1611 "insert(const RemoteIndex&, const GlobalIndex&) instead");
1613 #ifdef DUNE_ISTL_WITH_CHECKING
1614 if(!first_ && index.localIndexPair().global()<last_)
1618 while(iter_ != end_ && iter_->localIndexPair().global() < index.localIndexPair().global()) {
1623 assert(iter_==end_ || iter_->localIndexPair().global() != index.localIndexPair().global());
1624 iter_.insert(index);
1625 last_ = index.localIndexPair().global();
1629 template<
typename T,
typename A,
bool mode>
1633 "might be added to the underlying index set. Use "
1634 "insert(const RemoteIndex&) instead");
1635 #ifdef DUNE_ISTL_WITH_CHECKING
1636 if(!first_ && global<last_)
1640 while(iter_ != end_ && *giter_ < global) {
1646 assert(iter_->localIndexPair().global() != global);
1647 iter_.insert(index);
1648 giter_.insert(global);
1654 template<
typename T,
typename A,
bool mode>
1657 #ifdef DUNE_ISTL_WITH_CHECKING
1658 if(!first_ && global<last_)
1664 if(MODIFYINDEXSET) {
1666 while(iter_!=end_ && *giter_< global) {
1670 if(*giter_ == global) {
1676 while(iter_!=end_ && iter_->localIndexPair().global() < global)
1679 if(iter_->localIndexPair().global()==global) {
1690 template<
typename T,
typename A>
1697 template<
typename T,
typename A>
1704 template<
typename T,
typename A>
1707 typedef typename RemoteIndexMap::const_iterator const_iterator;
1709 const const_iterator end=pmap.end();
1710 for(const_iterator process=pmap.begin(); process != end; ++process) {
1711 const RemoteIndexList* list = send ? process->second.first : process->second.second;
1713 map_.insert(std::make_pair(process->first,
1714 std::pair<iterator, const iterator>(list->
begin(), list->
end())));
1718 template<
typename T,
typename A>
1721 typedef typename Map::iterator
iterator;
1722 typedef typename Map::const_iterator const_iterator;
1723 const const_iterator end = map_.end();
1725 for(iterator iter = map_.begin(); iter != end;) {
1729 RemoteIndex remoteIndex;
1731 remoteIndex = *current;
1733 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1734 ++(iter->second.first);
1737 if(iter->second.first == iter->second.second)
1747 template<
typename T,
typename A>
1749 const Attribute& attribute)
1751 typedef typename Map::iterator
iterator;
1752 typedef typename Map::const_iterator const_iterator;
1753 const const_iterator end = map_.end();
1755 for(iterator iter = map_.begin(); iter != end;) {
1759 RemoteIndex remoteIndex;
1761 remoteIndex = *current;
1764 while(iter->second.first!=iter->second.second && iter->second.first->localIndexPair().global()<index)
1765 ++(iter->second.first);
1768 while(iter->second.first!=iter->second.second
1769 && iter->second.first->localIndexPair().global()==index
1770 && iter->second.first->localIndexPair().local().attribute()<attribute)
1771 ++(iter->second.first);
1774 if(iter->second.first == iter->second.second)
1781 attribute_=attribute;
1785 template<
typename T,
typename A>
1788 typedef typename Map::iterator
iterator;
1789 typedef typename Map::const_iterator const_iterator;
1790 const const_iterator end = map_.end();
1792 for(iterator iter = map_.begin(); iter != end;) {
1798 if(iter->second.first->localIndexPair().global()==
index_ &&
1799 (noattribute || iter->second.first->localIndexPair().local().attribute() == attribute_))
1800 ++(iter->second.first);
1803 if(iter->second.first == iter->second.second)
1812 template<
typename T,
typename A>
1815 return map_.empty();
1818 template<
typename T,
typename A>
1829 template<
typename T,
typename A>
1836 template<
typename TG,
typename TA>
1837 inline std::ostream& operator<<(std::ostream& os, const RemoteIndex<TG,TA>& index)
1839 os<<
"[global="<<index.localIndexPair().global()<<
", remote attribute="<<index.attribute()<<
" local attribute="<<index.localIndexPair().local().attribute()<<
"]";
1843 template<
typename T,
typename A>
1844 inline std::ostream& operator<<(std::ostream& os, const RemoteIndices<T,A>& indices)
1847 MPI_Comm_rank(indices.comm_, &rank);
1850 typedef typename std::map<int,std::pair<RList*,RList*> >::const_iterator const_iterator;
1852 const const_iterator rend = indices.remoteIndices_.
end();
1854 for(const_iterator rindex = indices.remoteIndices_.begin(); rindex!=rend; ++rindex) {
1855 os<<rank<<
": Prozess "<<rindex->first<<
":";
1857 if(!rindex->second.first->empty()) {
1860 const typename RList::const_iterator send= rindex->second.first->end();
1862 for(
typename RList::const_iterator index = rindex->second.first->begin();
1863 index != send; ++index)
1867 if(!rindex->second.second->empty()) {
1868 os<<rank<<
": Prozess "<<rindex->first<<
": "<<
"receive: ";
1870 const typename RList::const_iterator rend= rindex->second.second->end();
1872 for(
typename RList::const_iterator index = rindex->second.second->begin();
1873 index != rend; ++index)
1876 os<<std::endl<<std::flush;
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:94
bool operator!=(const iterator &other)
Definition: remoteindices.hh:859
RemoteIndices()
Definition: remoteindices.hh:969
bool operator==(const iterator &other)
Definition: remoteindices.hh:853
Provides classes for use as the local index in ParallelIndexSet for distributed computing.
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1511
void rebuild()
Rebuilds the set of remote indices.
Definition: remoteindices.hh:1449
CollectiveIterator< T, A > CollectiveIteratorT
The type of the collective iterator over all remote indices.
Definition: remoteindices.hh:204
Dune namespace.
Definition: alignment.hh:13
T2 Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: remoteindices.hh:94
A few common exception classes.
Fallback implementation of the C++0x static_assert feature.
void insert(const RemoteIndex &index)
Insert an index to the list.
Definition: remoteindices.hh:1607
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:777
A collective iterator for moving over the remote indices for all processes collectively.
Definition: remoteindices.hh:154
bool remove(const GlobalIndex &global)
Remove a remote index.
Definition: remoteindices.hh:1655
T1 GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: remoteindices.hh:85
bool operator==(const RemoteIndices &ri)
Definition: remoteindices.hh:1532
If true the index set corresponding to the remote indices might get modified.
Definition: remoteindices.hh:564
iterator end()
Get an iterator over the indices positioned after the last index.
Provides a map between global and local indices.
friend void fillIndexSetHoles(const G &graph, Dune::OwnerOverlapCopyCommunication< T1, T2 > &oocomm)
The indices present on remote processes.
Definition: remoteindices.hh:47
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:220
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:21
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:205
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:580
iterator begin()
Definition: remoteindices.hh:1820
iterator begin()
Get an iterator over the indices positioned at the first index.
IndexPair< GlobalIndex, ParallelLocalIndex< Attribute > > PairType
The type of the index pair.
Definition: remoteindices.hh:100
const PairType & localIndexPair() const
Get the corresponding local index pair.
Definition: remoteindices.hh:944
RemoteIndexListModifier()
Default constructor.
Definition: remoteindices.hh:673
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:215
A pair consisting of a global and local index.
Definition: indexset.hh:31
A single linked list.
Definition: sllist.hh:42
Iterator over the valid underlying iterators.
Definition: remoteindices.hh:788
Definition: remoteindices.hh:161
const Attribute attribute() const
Get the attribute of the index on the remote process.
Definition: remoteindices.hh:938
iterator end()
Definition: remoteindices.hh:1831
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:590
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:29
const RemoteIndex * operator->() const
Definition: remoteindices.hh:847
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex index, Attribute attribute)
Definition: remoteindices.hh:804
bool operator!=(const RemoteIndex &ri) const
Definition: remoteindices.hh:932
iterator(const iterator &other)
Definition: remoteindices.hh:814
void setNeighbours(const C &neighbours)
Definition: remoteindices.hh:294
bool empty()
Checks whether there are still iterators in the map.
Definition: remoteindices.hh:1813
iterator & operator++()
Definition: remoteindices.hh:819
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex &index)
Definition: remoteindices.hh:796
void free()
Free the index lists.
Definition: remoteindices.hh:1424
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:235
SLListModifyIterator< RemoteIndex, Allocator > ModifyIterator
The type of the modifying iterator of the remote index list.
Definition: remoteindices.hh:604
const_iterator begin() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1518
Traits classes for mapping types onto MPI_Datatype.
bool operator==(const RemoteIndex &ri) const
Definition: remoteindices.hh:926
SLListModifyIterator< GlobalIndex, Allocator > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:102
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T::GlobalIndex, typename T::LocalIndex::Attribute >, A > > &, RemoteIndices< T, A1 > &, const T &)
Modifier for adding and/or deleting remote indices from the remote index list.
Definition: remoteindices.hh:60
Default exception class for range errors.
Definition: exceptions.hh:280
Standard Dune debug streams.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
MPI_Comm communicator() const
Get the mpi communicator used.
Definition: remoteindices.hh:1698
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:599
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:209
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1525
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
A Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:595
CollectiveIterator(const RemoteIndexMap &map_, bool send)
Constructor.
Definition: remoteindices.hh:1705
CollectiveIteratorT iterator() const
Get an iterator for colletively iterating over the remote indices of all remote processes.
Definition: remoteindices.hh:1692
Map::iterator ConstRealIterator
Definition: remoteindices.hh:792
std::size_t index_
The other rank that this interface communcates with.
Definition: variablesizecommunicator.hh:257
RemoteIndexList::const_iterator ConstIterator
The type of the remote index list iterator.
Definition: remoteindices.hh:609
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:225
const std::set< int > & getNeighbours() const
Definition: remoteindices.hh:301
const RemoteIndex & operator*() const
Definition: remoteindices.hh:835
T ParallelIndexSet
Type of the index set we use.
Definition: remoteindices.hh:570
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:28
RemoteIndexListModifier< T, A, mode > getModifier(int process)
Get a modifier for a remote index list.
Definition: remoteindices.hh:1476
static MPI_Datatype getType()
Definition: parallel/mpitraits.hh:44
friend void repairLocalIndexPointers(std::map< int, SLList< std::pair< typename T1::GlobalIndex, typename T1::LocalIndex::Attribute >, A2 > > &, RemoteIndices< T1, A1 > &, const T1 &)
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition: sllist.hh:73
Information about an index residing on another processor.
Definition: remoteindices.hh:50
Class for recomputing missing indices of a distributed index set.
Definition: indicessyncer.hh:40
RemoteIndex()
Parameterless Constructor.
Definition: remoteindices.hh:922
RemoteIndexMap::const_iterator const_iterator
Definition: remoteindices.hh:241
const ParallelIndexSet & sourceIndexSet() const
Get the index set at the source.
Definition: remoteindices.hh:990
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:239
bool isSynced() const
Checks whether the remote indices are synced with the indexsets.
Definition: remoteindices.hh:1469
void repairLocalIndexPointers()
Repair the pointers to the local index pairs.
Definition: remoteindices.hh:1574
A::template rebind< RemoteIndex >::other Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:231
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:789
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:585
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:575
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:975
T ParallelIndexSet
Type of the index set we use, e.g. ParallelLocalIndexSet.
Definition: remoteindices.hh:200
An stl-compliant pool allocator.
int neighbours() const
Get the number of processors we share indices with.
Definition: remoteindices.hh:1442
int process() const
Definition: remoteindices.hh:841
CollectiveIterator & operator++()
Definition: remoteindices.hh:1786
void setIncludeSelf(bool includeSelf)
Tell whether sending from indices of the processor to other indices on the same processor is enabled ...
Definition: remoteindices.hh:963
Definition: remoteindices.hh:552
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:186
void advance(const GlobalIndex &global)
Advances all underlying iterators.
Definition: remoteindices.hh:1719
const ParallelIndexSet & destinationIndexSet() const
Get the index set at destination.
Definition: remoteindices.hh:998
Implements a singly linked list together with the necessary iterators.
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:745
Map::iterator RealIterator
Definition: remoteindices.hh:791
~RemoteIndices()
Destructor.
Definition: remoteindices.hh:1005
Base class of all classes representing a communication interface.
Definition: interface.hh:33
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:239
A constant iterator for the SLList.
Definition: sllist.hh:29