52 Index nativeIndexOfPeer;
53 Index myOwnNativeIndex;
55 using PeerBlackList = std::vector<PeerBlackListedEntry>;
56 using PeerBlackLists = std::map<ProcessRank, PeerBlackList>;
63 bool hasIndex(
Index nativeIdx)
const
64 {
return nativeBlackListedIndices_.count(nativeIdx) > 0; }
66 void addIndex(Index nativeIdx)
67 { nativeBlackListedIndices_.insert(nativeIdx); }
69 Index nativeToDomestic(Index nativeIdx)
const
71 auto it = nativeToDomesticMap_.find(nativeIdx);
72 if (it == nativeToDomesticMap_.end())
77 void setPeerList(ProcessRank peerRank,
const PeerBlackList& peerBlackList)
78 { peerBlackLists_[peerRank] = peerBlackList; }
80 template <
class DomesticOverlap>
81 void updateNativeToDomesticMap([[maybe_unused]]
const DomesticOverlap& domesticOverlap)
84 auto peerListIt = peerBlackLists_.begin();
85 const auto& peerListEndIt = peerBlackLists_.end();
86 for (; peerListIt != peerListEndIt; ++peerListIt) {
87 sendGlobalIndices_(peerListIt->first,
92 peerListIt = peerBlackLists_.begin();
93 for (; peerListIt != peerListEndIt; ++peerListIt) {
94 receiveGlobalIndices_(peerListIt->first, domesticOverlap);
97 peerListIt = peerBlackLists_.begin();
98 for (; peerListIt != peerListEndIt; ++peerListIt) {
99 numGlobalIdxSendBuff_.at(peerListIt->first).wait();
100 globalIdxSendBuff_.at(peerListIt->first).wait();
107 std::cout <<
"my own blacklisted indices:\n";
108 auto idxIt = nativeBlackListedIndices_.begin();
109 const auto& idxEndIt = nativeBlackListedIndices_.end();
110 for (; idxIt != idxEndIt; ++idxIt)
111 std::cout <<
" (native index: " << *idxIt
112 <<
", domestic index: " << nativeToDomestic(*idxIt) <<
")\n";
113 std::cout <<
"blacklisted indices of the peers in my own domain:\n";
114 auto peerListIt = peerBlackLists_.begin();
115 const auto& peerListEndIt = peerBlackLists_.end();
116 for (; peerListIt != peerListEndIt; ++peerListIt) {
118 std::cout <<
" peer " << peerRank <<
":\n";
119 auto idx2It = peerListIt->second.begin();
120 const auto& idx2EndIt = peerListIt->second.end();
121 for (; idx2It != idx2EndIt; ++ idx2It)
122 std::cout <<
" (native index: " << idx2It->myOwnNativeIndex
123 <<
", native peer index: " << idx2It->nativeIndexOfPeer <<
")\n";
129 template <
class DomesticOverlap>
130 void sendGlobalIndices_(ProcessRank peerRank,
131 const PeerBlackList& peerIndices,
132 const DomesticOverlap& domesticOverlap)
134 auto& numIdxBuff = numGlobalIdxSendBuff_[peerRank];
135 auto& idxBuff = globalIdxSendBuff_[peerRank];
137 numIdxBuff.resize(1);
138 numIdxBuff[0] =
static_cast<unsigned>(peerIndices.size());
139 numIdxBuff.send(peerRank);
141 idxBuff.resize(2*peerIndices.size());
142 for (
size_t i = 0; i < peerIndices.size(); ++i) {
144 Index myNativeIdx = peerIndices[i].myOwnNativeIndex;
145 Index myDomesticIdx = domesticOverlap.nativeToDomestic(myNativeIdx);
146 idxBuff[2*i + 0] = domesticOverlap.domesticToGlobal(myDomesticIdx);
149 idxBuff[2*i + 1] = peerIndices[i].nativeIndexOfPeer;
151 idxBuff.send(peerRank);
154 template <
class DomesticOverlap>
155 void receiveGlobalIndices_(ProcessRank peerRank,
156 const DomesticOverlap& domesticOverlap)
158 MpiBuffer<unsigned> numGlobalIdxBuf(1);
159 numGlobalIdxBuf.receive(peerRank);
160 unsigned numIndices = numGlobalIdxBuf[0];
162 MpiBuffer<Index> globalIdxBuf(2*numIndices);
163 globalIdxBuf.receive(peerRank);
164 for (
unsigned i = 0; i < numIndices; ++i) {
165 Index globalIdx = globalIdxBuf[2*i + 0];
166 Index nativeIdx = globalIdxBuf[2*i + 1];
168 nativeToDomesticMap_[nativeIdx] = domesticOverlap.globalToDomestic(globalIdx);
173 std::set<Index> nativeBlackListedIndices_;
174 std::map<Index, Index> nativeToDomesticMap_;
176 std::map<ProcessRank, MpiBuffer<unsigned>> numGlobalIdxSendBuff_;
177 std::map<ProcessRank, MpiBuffer<Index>> globalIdxSendBuff_;
180 PeerBlackLists peerBlackLists_;