diff --git a/ebos/collecttoiorank.hh b/ebos/collecttoiorank.hh index 8c817bd6a..0458d9fdd 100644 --- a/ebos/collecttoiorank.hh +++ b/ebos/collecttoiorank.hh @@ -101,6 +101,7 @@ public: IndexMapType& localIndexMap_; IndexMapStorageType& indexMaps_; std::map globalPosition_; + std::set& recv_; std::vector& ranks_; public: @@ -108,21 +109,26 @@ public: const std::vector& distributedGlobalIndex, IndexMapType& localIndexMap, IndexMapStorageType& indexMaps, - std::vector& ranks) + std::vector& ranks, + std::set& recv, + bool isIORank) : distributedGlobalIndex_(distributedGlobalIndex) , localIndexMap_(localIndexMap) , indexMaps_(indexMaps) , globalPosition_() + , recv_(recv) , ranks_(ranks) { size_t size = globalIndex.size(); // create mapping globalIndex --> localIndex - for (size_t index = 0; index < size; ++index) - globalPosition_.insert(std::make_pair(globalIndex[index], index)); + if ( isIORank ) // ioRank + for (size_t index = 0; index < size; ++index) + globalPosition_.insert(std::make_pair(globalIndex[index], index)); // we need to create a mapping from local to global if (!indexMaps_.empty()) { - ranks_.resize(size, -1); + if (isIORank) + ranks_.resize(size, -1); // for the ioRank create a localIndex to index in global state map IndexMapType& indexMap = indexMaps_.back(); size_t localSize = localIndexMap_.size(); @@ -130,12 +136,44 @@ public: for (size_t i=0; isecond; + // Using max should be backwards compatible + ranks_[entry] = std::max(ranks_[entry], rank); + } + if (rankIt != recv_.end()) + ++rankIt; + } +#ifndef NDEBUG + for (const auto& rank: ranks_) + assert(rank>=0); +#endif + } + } + void pack(int link, MessageBufferType& buffer) { // we should only get one link @@ -163,11 +201,7 @@ public: buffer.read(numCells); indexMap.resize(numCells); for (int index = 0; index < numCells; ++index) { - int globalId = -1; - buffer.read(globalId); - assert(globalPosition_.find(globalId) != globalPosition_.end()); - indexMap[index] = globalPosition_[globalId]; - ranks_[indexMap[index]] = link + 1; + buffer.read(indexMap[index]); } } }; @@ -270,7 +304,9 @@ public: distributedCartesianIndex, localIndexMap_, indexMaps_, - globalRanks_); + globalRanks_, + recv, + isIORank()); toIORankComm_.exchange(distIndexMapping); } }