4#ifndef DUNE_REMOTEINDICES_HH
5#define DUNE_REMOTEINDICES_HH
36 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>
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>
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*> >
241 typedef typename RemoteIndexMap::const_iterator const_iterator;
261 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>(),
bool includeSelf=
false);
291 const MPI_Comm& comm,
const std::vector<int>&
neighbours=std::vector<int>());
296 neighbourIds.clear();
301 const std::set<int>& getNeighbours()
const
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;
415 std::set<int> neighbourIds;
418 const static int commTag_=333;
472 template<
bool ignorePublic>
473 inline void buildRemote(
bool includeSelf);
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>
548 template<
typename T1,
typename A1>
693 GlobalModifyIterator giter_;
703 template<
class T,
class A>
710 typedef T ParallelIndexSet;
725 typedef typename LocalIndex::Attribute Attribute;
731 typedef typename A::template rebind<RemoteIndex>::other Allocator;
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);
791 typedef typename Map::iterator RealIterator;
792 typedef typename Map::iterator ConstRealIterator;
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>
887 MPI_Datatype MPITraits<IndexPair<TG,ParallelLocalIndex<TA> > >::getType()
889 if(type==MPI_DATATYPE_NULL) {
892 MPI_Datatype types[4] = {MPI_LB, MPITraits<TG>::getType(),
893 MPITraits<ParallelLocalIndex<TA> >::getType(), MPI_UB};
894 IndexPair<TG,ParallelLocalIndex<TA> > rep[2];
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>
909 MPI_Datatype MPITraits<IndexPair<TG,ParallelLocalIndex<TA> > >::type=MPI_DATATYPE_NULL;
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>
932 inline bool RemoteIndex<T1,T2>::operator!=(
const RemoteIndex& ri)
const
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>
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>
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>
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>
1038 inline int RemoteIndices<T,A>::noPublic(
const ParallelIndexSet& indexSet)
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;
1079 MPI_Datatype type= MPITraits<PairType>::getType();
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];
1173 MPI_Datatype type = MPITraits<PairType>::getType();
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>
1510 inline typename RemoteIndices<T,A>::const_iterator
1513 return remoteIndices_.find(proc);
1516 template<
typename T,
typename A>
1517 inline typename RemoteIndices<T,A>::const_iterator
1520 return remoteIndices_.begin();
1523 template<
typename T,
typename A>
1524 inline typename RemoteIndices<T,A>::const_iterator
1527 return remoteIndices_.end();
1531 template<
typename T,
typename A>
1537 typedef RemoteIndexList RList;
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)
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())
1593 DUNE_THROW(InvalidPosition,
"No such global index in set!");
1597#ifdef DUNE_ISTL_WITH_CHECKING
1598 if(index->global() != *giter)
1599 DUNE_THROW(InvalidPosition,
"No such global index in set!");
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_)
1615 DUNE_THROW(InvalidPosition,
"Modifcation of remote indices have to occur with ascending global index.");
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_)
1637 DUNE_THROW(InvalidPosition,
"Modification of remote indices have to occur with ascending global index.");
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_)
1659 DUNE_THROW(InvalidPosition,
"Modifcation of remote indices have to occur with ascending global index.");
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;) {
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;) {
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;) {
1794 typename RemoteIndexList::const_iterator current = iter->second.first;
1795 typename RemoteIndexList::const_iterator rend = iter->second.second;
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>
1823 return iterator(map_.begin(), map_.end(), index_);
1825 return iterator(map_.begin(), map_.end(), index_,
1829 template<
typename T,
typename A>
1830 inline typename CollectiveIterator<T,A>::iterator
1831 CollectiveIterator<T,A>::end()
1833 return iterator(map_.end(), map_.end(), index_);
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;
Iterator over the valid underlying iterators.
Definition: remoteindices.hh:789
bool operator==(const iterator &other)
Definition: remoteindices.hh:853
iterator(const RealIterator &iter, const ConstRealIterator &end, GlobalIndex &index)
Definition: remoteindices.hh:796
bool operator!=(const iterator &other)
Definition: remoteindices.hh:859
iterator(const iterator &other)
Definition: remoteindices.hh:814
const RemoteIndex & operator*() const
Definition: remoteindices.hh:835
iterator & operator++()
Definition: remoteindices.hh:819
const RemoteIndex * operator->() const
Definition: remoteindices.hh:847
int process() const
Definition: remoteindices.hh:841
A collective iterator for moving over the remote indices for all processes collectively.
Definition: remoteindices.hh:705
CollectiveIterator(const RemoteIndexMap &map_, bool send)
Constructor.
Definition: remoteindices.hh:1705
bool empty()
Checks whether there are still iterators in the map.
Definition: remoteindices.hh:1813
void advance(const GlobalIndex &global)
Advances all underlying iterators.
Definition: remoteindices.hh:1719
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:745
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:380
A pair consisting of a global and local index.
Definition: indexset.hh:85
Class for recomputing missing indices of a distributed index set.
Definition: indicessyncer.hh:41
Base class of all classes representing a communication interface.
Definition: interface.hh:34
Exception indicating that the index set is not in the expected state.
Definition: indexset.hh:205
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:173
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:218
An index present on the local process with an additional attribute flag.
Definition: plocalindex.hh:48
Default exception class for range errors.
Definition: exceptions.hh:280
Modifier for adding and/or deleting remote indices from the remote index list.
Definition: remoteindices.hh:546
void repairLocalIndexPointers()
Repair the pointers to the local index pairs.
Definition: remoteindices.hh:1574
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:599
A Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:595
void insert(const RemoteIndex &index)
Insert an index to the list.
Definition: remoteindices.hh:1607
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:575
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:580
@ MODIFYINDEXSET
If true the index set corresponding to the remote indices might get modified.
Definition: remoteindices.hh:564
RemoteIndexList::const_iterator ConstIterator
The type of the remote index list iterator.
Definition: remoteindices.hh:609
SLListModifyIterator< RemoteIndex, Allocator > ModifyIterator
The type of the modifying iterator of the remote index list.
Definition: remoteindices.hh:604
bool remove(const GlobalIndex &global)
Remove a remote index.
Definition: remoteindices.hh:1655
T ParallelIndexSet
Type of the index set we use.
Definition: remoteindices.hh:570
RemoteIndexListModifier()
Default constructor.
Definition: remoteindices.hh:673
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:585
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:590
Information about an index residing on another processor.
Definition: remoteindices.hh:68
const Attribute attribute() const
Get the attribute of the index on the remote process.
Definition: remoteindices.hh:938
T1 GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: remoteindices.hh:85
T2 Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition: remoteindices.hh:94
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
RemoteIndex()
Parameterless Constructor.
Definition: remoteindices.hh:922
The indices present on remote processes.
Definition: remoteindices.hh:183
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:225
friend void fillIndexSetHoles(const G &graph, Dune::OwnerOverlapCopyCommunication< T1, T2 > &oocomm)
Fills the holes in an index set.
Definition: repartition.hh:58
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
void free()
Free the index lists.
Definition: remoteindices.hh:1424
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: remoteindices.hh:209
void rebuild()
Rebuilds the set of remote indices.
Definition: remoteindices.hh:1449
T ParallelIndexSet
Type of the index set we use, e.g. ParallelLocalIndexSet.
Definition: remoteindices.hh:200
MPI_Comm communicator() const
Get the mpi communicator used.
Definition: remoteindices.hh:1698
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: remoteindices.hh:220
CollectiveIteratorT iterator() const
Get an iterator for colletively iterating over the remote indices of all remote processes.
Definition: remoteindices.hh:1692
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
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1525
std::map< int, std::pair< RemoteIndexList *, RemoteIndexList * > > RemoteIndexMap
The type of the map from rank to remote index list.
Definition: remoteindices.hh:239
RemoteIndexListModifier< T, A, mode > getModifier(int process)
Get a modifier for a remote index list.
Definition: remoteindices.hh:1476
const ParallelIndexSet & sourceIndexSet() const
Get the index set at the source.
Definition: remoteindices.hh:990
~RemoteIndices()
Destructor.
Definition: remoteindices.hh:1005
Dune::SLList< RemoteIndex, Allocator > RemoteIndexList
The type of the remote index list.
Definition: remoteindices.hh:235
int neighbours() const
Get the number of processors we share indices with.
Definition: remoteindices.hh:1442
CollectiveIterator< T, A > CollectiveIteratorT
The type of the collective iterator over all remote indices.
Definition: remoteindices.hh:204
const ParallelIndexSet & destinationIndexSet() const
Get the index set at destination.
Definition: remoteindices.hh:998
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:950
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1511
bool isSynced() const
Checks whether the remote indices are synced with the indexsets.
Definition: remoteindices.hh:1469
const_iterator begin() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1518
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: remoteindices.hh:215
A::template rebind< RemoteIndex >::other Allocator
The type of the allocator for the remote index list.
Definition: remoteindices.hh:231
A constant iterator for the SLList.
Definition: sllist.hh:370
A single linked list.
Definition: sllist.hh:43
A few common exception classes.
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:306
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:492
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:239
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
@ GROUND
The default mode. Indicates that the index set is ready to be used.
Definition: indexset.hh:186
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:789
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition: sllist.hh:73
SLListModifyIterator< GlobalIndex, Allocator > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:102
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:777
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
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:231
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:253
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:94
Provides a map between global and local indices.
Dune namespace.
Definition: alignment.hh:14
Traits classes for mapping types onto MPI_Datatype.
Provides classes for use as the local index in ParallelIndexSet for distributed computing.
An stl-compliant pool allocator.
Implements a singly linked list together with the necessary iterators.
Fallback implementation of the C++0x static_assert feature.
Standard Dune debug streams.
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:37