From 308cdc6d0bf15478a162c196f35c86ea70951a09 Mon Sep 17 00:00:00 2001 From: Chang Guo Date: Wed, 22 May 2024 06:02:34 -0700 Subject: [PATCH] optimize the output messages --- source/adios2/engine/bp5/BP5Reader.cpp | 28 ++++++---- source/adios2/toolkit/cache/KVCacheCommon.inl | 51 +++---------------- source/adios2/toolkit/cache/QueryBox.h | 13 ++--- 3 files changed, 30 insertions(+), 62 deletions(-) diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index f80c5c4a6..2d37d7985 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -289,7 +289,8 @@ void BP5Reader::PerformRemoteGets() if (getenv("useKVCache")) { m_KVCacheCommon.openConnection(); - std::cout << "kv cache version control: v1.1" << std::endl; + // print the size of GetRequests + std::cout << "GetRequests size: " << GetRequests.size() << std::endl; } for (auto &Req : GetRequests) { @@ -316,39 +317,47 @@ void BP5Reader::PerformRemoteGets() continue; } else { int max_depth = 8; + if (getenv("maxDepth")) + { + max_depth = std::stoi(getenv("maxDepth")); + } + std::cout << "Setting max_depth is: " << max_depth << std::endl; + std::set samePrefixKeys; m_KVCacheCommon.keyPrefixExistence(keyPrefix, samePrefixKeys); + // print the size of samePrefixKeys - std::cout << "same prefix keys size: " << samePrefixKeys.size() << std::endl; + std::cout << "Same prefix keys size: " << samePrefixKeys.size() << std::endl; // print out samePrefixKeys for (auto &key : samePrefixKeys) { - std::cout << "same prefix keys: " << key << std::endl; + std::cout << "Same prefix keys: " << key << std::endl; } + std::vector regularBoxes; std::vector cachedBoxes; std::vector cachedKeys; + if (samePrefixKeys.size() > 0) { - std::cout << "same prefix keys size > 0" << std::endl; targetBox.getMaxInteractBox(samePrefixKeys, max_depth, 0, regularBoxes, cachedBoxes, cachedKeys); } else { - std::cout << "no same prefix keys" << std::endl; regularBoxes.push_back(targetBox); } + // print out regularBoxes and cachedBoxes size - std::cout << "regularBoxes size: " << regularBoxes.size() << std::endl; - std::cout << "cachedBoxes size: " << cachedBoxes.size() << std::endl; + std::cout << "Going to retrieve regular boxes size: " << regularBoxes.size() << std::endl; + std::cout << "Already cached boxes size: " << cachedBoxes.size() << std::endl; // print out regularBoxes and cachedBoxes by toString for (int i = 0; i < regularBoxes.size(); i++) { - std::cout << "regular i box: " << regularBoxes[i].toString() << std::endl; + std::cout << "Regular box " << i << " : " << regularBoxes[i].toString() << " size: " << regularBoxes[i].size() << std::endl; } for (int i = 0; i < cachedBoxes.size(); i++) { - std::cout << "cached i box: " << cachedBoxes[i].toString() << std::endl; + std::cout << "Cached box " << i << " : " << cachedBoxes[i].toString() << " size: " << cachedBoxes[i].size() << std::endl; } @@ -437,6 +446,7 @@ ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_type_full_contain) if (getenv("useKVCache")) { m_KVCacheCommon.closeConnection(); + std::cout << "KVCache connection closed" << std::endl; } } diff --git a/source/adios2/toolkit/cache/KVCacheCommon.inl b/source/adios2/toolkit/cache/KVCacheCommon.inl index 9c284d222..df95aa911 100644 --- a/source/adios2/toolkit/cache/KVCacheCommon.inl +++ b/source/adios2/toolkit/cache/KVCacheCommon.inl @@ -25,7 +25,8 @@ void KVCacheCommon::openConnection() } else { - std::cout << "Connected to kvcache server" << std::endl; + std::cout << "------------------------------------------------" << std::endl; + std::cout << "Connected to kvcache server. KV Cache Version Control: V1.1" << std::endl; } } @@ -49,7 +50,7 @@ void KVCacheCommon::set(std::string key, const std::vector& vec) } else { - std::cout << "SET: " << m_redisReply->str << std::endl; + std::cout << "SET Key: " << m_key << " Value size: " << vec.size() << std::endl; freeReplyObject(m_redisReply); } } @@ -92,19 +93,19 @@ bool KVCacheCommon::exists(std::string key) { m_key = key; m_command = "EXISTS " + m_key; - std::cout << "EXISTS: " << m_command.c_str() << std::endl; + std::cout << "Try to find the key: IF EXISTS: " << m_command.c_str() << std::endl; // m_command = "EXISTS mytest"; m_redisReply = (redisReply *)redisCommand(m_redisContext, m_command.c_str()); if (m_redisReply == NULL) { - std::cout << "Key does not exist" << std::endl; + std::cout << "Key does not exist" << m_command.c_str() << std::endl; return false; } else { if (!m_redisReply->integer) { - std::cout << "Key does not exist" << std::endl; + std::cout << "Key does not exist" << m_command.c_str() << std::endl; return false; } // std::cout << "EXISTS: " << m_redisReply->str << std::endl; @@ -153,46 +154,6 @@ void KVCacheCommon::keyPrefixExistence(const std::string &key_prefix, std::set &samePrefixKeys, const QueryBox &queryBox, const size_t &max_depth, size_t current_depth, std::vector ®ularBoxes, std::vector &cachedBox, std::vector &cachedKeys) -// { -// if (current_depth > max_depth) -// { -// return; -// } -// current_depth++; -// QueryBox maxInteractBox; -// std::string maxInteractKey; -// for (auto &key : samePrefixKeys) -// { -// std::cout << "key111: " << key << std::endl; -// QueryBox const box(key); -// QueryBox intersection; -// if (queryBox.isInteracted(box, intersection)) -// { -// if (maxInteractBox.size() < intersection.size()) -// { -// maxInteractBox = intersection; -// maxInteractKey = key; -// } -// } -// } - -// cachedBox.push_back(maxInteractBox); -// cachedKeys.push_back(maxInteractKey); - -// if (current_depth == max_depth) -// { -// maxInteractBox.interactionCut(queryBox, regularBoxes); -// } else { -// std::vector nextBoxes; -// maxInteractBox.interactionCut(queryBox, nextBoxes); -// for (auto &box : nextBoxes) -// { -// getMaxInteractBox(samePrefixKeys, box, max_depth, current_depth, regularBoxes, cachedBox, cachedKeys); -// } -// } -// } - std::string KVCacheCommon::base64Encode(const std::vector &data) { BIO *bio, *b64; diff --git a/source/adios2/toolkit/cache/QueryBox.h b/source/adios2/toolkit/cache/QueryBox.h index b0f50b494..2656e500a 100644 --- a/source/adios2/toolkit/cache/QueryBox.h +++ b/source/adios2/toolkit/cache/QueryBox.h @@ -26,13 +26,9 @@ class QueryBox // sample key: "U3218446744073709551615__count_:_64_64_64___start_:_0_0_0__", count [64, 64, 64], start [0, 0, 0] // using Dims = std::vector; auto lf_ExtractDimensions = [](const std::string &key, const std::string &delimiter) -> Dims { - std::cout << "key: " << key << std::endl; - std::cout << "delimiter: " << delimiter << std::endl; size_t const pos = key.find(delimiter); size_t const end = key.find("__", pos + delimiter.length()); - std::cout << "pos: " << pos << " end: " << end << std::endl; std::string dimStr = key.substr(pos + delimiter.length(), end - pos - delimiter.length()); - std::cout << "dimStr: " << dimStr << std::endl; Dims dimensions; std::istringstream dimStream(dimStr); std::string token; @@ -207,7 +203,7 @@ class QueryBox std::string maxInteractKey; for (auto &key : samePrefixKeys) { - std::cout << "key11111: " << key << " Current Depth: " << current_depth << std::endl; + // std::cout << "Same Prefix Keys: " << key << " Current Depth: " << current_depth << std::endl; QueryBox const box(key); QueryBox intersection; if (this->isInteracted(box, intersection)) @@ -220,14 +216,15 @@ class QueryBox } } - std::cout << "pushing maxInteractBox: " << maxInteractBox.toString() << "key: " << maxInteractKey << "size: " << maxInteractBox.size() << std::endl; - std::cout << "maxInteractBox.count size: " << maxInteractBox.count.size() << std::endl; - if (maxInteractBox.count.size() == 0) { return; } + std::cout << "=============================" << std::endl; + std::cout << "Current Depth: " << current_depth << " Target box: " << this->toString() << " Target box size: " << this->size() << std::endl; + std::cout << "Pushing maxInteractBox: " << maxInteractBox.toString() << " key: " << maxInteractKey << ", Interacted size: " << maxInteractBox.size() << std::endl; + cachedBox.push_back(maxInteractBox); cachedKeys.push_back(maxInteractKey);