Skip to content

Commit

Permalink
optimize the output messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang Guo committed May 22, 2024
1 parent dccd3b8 commit 308cdc6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 62 deletions.
28 changes: 19 additions & 9 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<std::string> 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<QueryBox> regularBoxes;
std::vector<QueryBox> cachedBoxes;
std::vector<std::string> 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;
}


Expand Down Expand Up @@ -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;
}
}

Expand Down
51 changes: 6 additions & 45 deletions source/adios2/toolkit/cache/KVCacheCommon.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -49,7 +50,7 @@ void KVCacheCommon::set(std::string key, const std::vector<T>& 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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -153,46 +154,6 @@ void KVCacheCommon::keyPrefixExistence(const std::string &key_prefix, std::set<s
}
}

// void KVCacheCommon::getMaxInteractBox(const std::set<std::string> &samePrefixKeys, const QueryBox &queryBox, const size_t &max_depth, size_t current_depth, std::vector<QueryBox> &regularBoxes, std::vector<QueryBox> &cachedBox, std::vector<std::string> &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<QueryBox> 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<char> &data)
{
BIO *bio, *b64;
Expand Down
13 changes: 5 additions & 8 deletions source/adios2/toolkit/cache/QueryBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>;
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;
Expand Down Expand Up @@ -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))
Expand All @@ -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);

Expand Down

0 comments on commit 308cdc6

Please sign in to comment.