27 #ifndef EWOMS_BLACK_LIST_HH
28 #define EWOMS_BLACK_LIST_HH
35 #include <dune/grid/common/datahandleif.hh>
36 #include <dune/grid/common/gridenums.hh>
51 Index nativeIndexOfPeer;
52 Index myOwnNativeIndex;
54 typedef std::vector<PeerBlackListedEntry> PeerBlackList;
55 typedef std::map<ProcessRank, PeerBlackList> PeerBlackLists;
62 bool hasIndex(Index nativeIdx)
const
63 {
return nativeBlackListedIndices_.count(nativeIdx) > 0; }
65 void addIndex(Index nativeIdx)
66 { nativeBlackListedIndices_.insert(nativeIdx); }
68 Index nativeToDomestic(Index nativeIdx)
const
70 auto it = nativeToDomesticMap_.find(nativeIdx);
71 if (it == nativeToDomesticMap_.end())
76 void setPeerList(ProcessRank peerRank,
const PeerBlackList& peerBlackList)
77 { peerBlackLists_[peerRank] = peerBlackList; }
79 template <
class DomesticOverlap>
80 void updateNativeToDomesticMap(
const DomesticOverlap& domesticOverlap)
83 auto peerListIt = peerBlackLists_.begin();
84 const auto& peerListEndIt = peerBlackLists_.end();
85 for (; peerListIt != peerListEndIt; ++peerListIt) {
86 sendGlobalIndices_(peerListIt->first,
91 peerListIt = peerBlackLists_.begin();
92 for (; peerListIt != peerListEndIt; ++peerListIt) {
93 receiveGlobalIndices_(peerListIt->first, domesticOverlap);
96 peerListIt = peerBlackLists_.begin();
97 for (; peerListIt != peerListEndIt; ++peerListIt) {
98 numGlobalIdxSendBuff_.at(peerListIt->first).wait();
99 globalIdxSendBuff_.at(peerListIt->first).wait();
106 std::cout <<
"my own blacklisted indices:\n";
107 auto idxIt = nativeBlackListedIndices_.begin();
108 const auto& idxEndIt = nativeBlackListedIndices_.end();
109 for (; idxIt != idxEndIt; ++idxIt)
110 std::cout <<
" (native index: " << *idxIt
111 <<
", domestic index: " << nativeToDomestic(*idxIt) <<
")\n";
112 std::cout <<
"blacklisted indices of the peers in my own domain:\n";
113 auto peerListIt = peerBlackLists_.begin();
114 const auto& peerListEndIt = peerBlackLists_.end();
115 for (; peerListIt != peerListEndIt; ++peerListIt) {
116 ProcessRank peerRank = peerListIt->first;
117 std::cout <<
" peer " << peerRank <<
":\n";
118 auto idx2It = peerListIt->second.begin();
119 const auto& idx2EndIt = peerListIt->second.end();
120 for (; idx2It != idx2EndIt; ++ idx2It)
121 std::cout <<
" (native index: " << idx2It->myOwnNativeIndex
122 <<
", native peer index: " << idx2It->nativeIndexOfPeer <<
")\n";
128 template <
class DomesticOverlap>
129 void sendGlobalIndices_(ProcessRank peerRank,
130 const PeerBlackList& peerIndices,
131 const DomesticOverlap& domesticOverlap)
133 auto& numIdxBuff = numGlobalIdxSendBuff_[peerRank];
134 auto& idxBuff = globalIdxSendBuff_[peerRank];
136 numIdxBuff.resize(1);
137 numIdxBuff[0] =
static_cast<unsigned>(peerIndices.size());
138 numIdxBuff.send(peerRank);
140 idxBuff.resize(2*peerIndices.size());
141 for (
size_t i = 0; i < peerIndices.size(); ++i) {
143 Index myNativeIdx = peerIndices[i].myOwnNativeIndex;
144 Index myDomesticIdx = domesticOverlap.nativeToDomestic(myNativeIdx);
145 idxBuff[2*i + 0] = domesticOverlap.domesticToGlobal(myDomesticIdx);
148 idxBuff[2*i + 1] = peerIndices[i].nativeIndexOfPeer;
150 idxBuff.send(peerRank);
153 template <
class DomesticOverlap>
154 void receiveGlobalIndices_(ProcessRank peerRank,
155 const DomesticOverlap& domesticOverlap)
157 MpiBuffer<unsigned> numGlobalIdxBuf(1);
158 numGlobalIdxBuf.receive(peerRank);
159 unsigned numIndices = numGlobalIdxBuf[0];
161 MpiBuffer<Index> globalIdxBuf(2*numIndices);
162 globalIdxBuf.receive(peerRank);
163 for (
unsigned i = 0; i < numIndices; ++i) {
164 Index globalIdx = globalIdxBuf[2*i + 0];
165 Index nativeIdx = globalIdxBuf[2*i + 1];
167 nativeToDomesticMap_[nativeIdx] = domesticOverlap.globalToDomestic(globalIdx);
172 std::set<Index> nativeBlackListedIndices_;
173 std::map<Index, Index> nativeToDomesticMap_;
175 std::map<ProcessRank, MpiBuffer<unsigned>> numGlobalIdxSendBuff_;
176 std::map<ProcessRank, MpiBuffer<Index>> globalIdxSendBuff_;
179 PeerBlackLists peerBlackLists_;
Simplifies handling of buffers to be used in conjunction with MPI.
Expresses which degrees of freedom are blacklisted for the parallel linear solvers and which domestic...
Definition: blacklist.hh:47
This files provides several data structures for storing tuples of indices of remote and/or local proc...
Definition: blacklist.hh:50