diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index 9c7010355f..81786246cc 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -200,6 +200,11 @@ void BP5Reader::EndStep() m_BetweenStepPairs = false; PERFSTUBS_SCOPED_TIMER("BP5Reader::EndStep"); PerformGets(); + for (auto &item : MinBlocksInfoMap) + { + delete item.second; + } + MinBlocksInfoMap.clear(); } std::pair BP5Reader::ReadData(adios2::transportman::TransportMan &FileManager, @@ -385,15 +390,44 @@ void BP5Reader::PerformRemoteGetsWithKVCache() for (size_t req_seq = 0; req_seq < GetRequests.size(); req_seq++) { - const auto &Req = GetRequests[req_seq]; + auto &Req = GetRequests[req_seq]; const DataType varType = m_IO.InquireVariableType(Req.VarName); + std::string keyPrefix = m_Fingerprint + "|" + Req.VarName + std::to_string(Req.RelStep); + if (Req.BlockID != std::numeric_limits::max()) + { + MinVarInfo *minBlocksInfo = nullptr; + if (MinBlocksInfoMap.find(keyPrefix) == MinBlocksInfoMap.end()) + { + VariableBase *VB = m_BP5Deserializer->GetVariableBaseFromBP5VarRec(Req.VarRec); + minBlocksInfo = MinBlocksInfo(*VB, Req.RelStep); + MinBlocksInfoMap[keyPrefix] = minBlocksInfo; + } + else + { + minBlocksInfo = MinBlocksInfoMap[keyPrefix]; + } + Req.Start.resize(minBlocksInfo->Dims); + Req.Count.resize(minBlocksInfo->Dims); + for (auto &blockInfo : minBlocksInfo->BlocksInfo) + { + if (Req.BlockID == blockInfo.BlockID) + { + for (int i = 0; i < minBlocksInfo->Dims; i++) + { + Req.Start[i] = blockInfo.Start[i]; + Req.Count[i] = blockInfo.Count[i]; + } + break; + } + } + } + RequestInfo ReqInfo(Req.Count.size()); ReqInfo.ReqSeq = req_seq; ReqInfo.TypeSize = helper::GetDataTypeSize(varType); kvcache::QueryBox targetBox(Req.Start, Req.Count); - std::string keyPrefix = m_Fingerprint + "|" + Req.VarName + std::to_string(Req.RelStep); std::string targetKey = keyPrefix + targetBox.toString(); // Exact Match: check if targetKey exists diff --git a/source/adios2/engine/bp5/BP5Reader.h b/source/adios2/engine/bp5/BP5Reader.h index 5e352935cd..45db4c5e60 100644 --- a/source/adios2/engine/bp5/BP5Reader.h +++ b/source/adios2/engine/bp5/BP5Reader.h @@ -104,6 +104,7 @@ class BP5Reader : public BP5Engine, public Engine /* KVCache for remote data */ kvcache::KVCacheCommon m_KVCache; + std::unordered_map MinBlocksInfoMap; /* Fingerprint to verify local validity against remote data */ std::string m_Fingerprint = ""; diff --git a/source/adios2/toolkit/format/bp5/BP5Deserializer.h b/source/adios2/toolkit/format/bp5/BP5Deserializer.h index fb9db65596..1dd97aa14d 100644 --- a/source/adios2/toolkit/format/bp5/BP5Deserializer.h +++ b/source/adios2/toolkit/format/bp5/BP5Deserializer.h @@ -247,6 +247,12 @@ class BP5Deserializer : virtual public BP5Base /* We assume operators are not thread-safe, call Decompress() one at a time */ std::mutex mutexDecompress; + +public: + VariableBase *GetVariableBaseFromBP5VarRec(void *VarRec) + { + return static_cast(static_cast(VarRec)->Variable); + }; }; } // end namespace format