From b1eeac0b102ecc52803d0ccfcccf9861a1d62eac Mon Sep 17 00:00:00 2001 From: ALEXks Date: Tue, 20 May 2025 16:20:27 +0300 Subject: [PATCH] added json for SPF_CreateParallelVariant pass --- src/Predictor/PredictScheme.h | 49 ++++++++++++++----------- src/Sapfor.cpp | 3 +- src/VisualizerCalls/get_information.cpp | 38 +------------------ 3 files changed, 30 insertions(+), 60 deletions(-) diff --git a/src/Predictor/PredictScheme.h b/src/Predictor/PredictScheme.h index b444aa1..35ccf9e 100644 --- a/src/Predictor/PredictScheme.h +++ b/src/Predictor/PredictScheme.h @@ -2,6 +2,7 @@ #include #include "dvm.h" #include "../GraphCall/graph_calls.h" +#include "../Utils/json.hpp" class ParallelStats { @@ -11,10 +12,10 @@ public: RemoteCount = ShadowCount = ReductionCount = AcrossCount = 0; } - int RemoteCount; - int ShadowCount; - int ReductionCount; - int AcrossCount; + int RemoteCount = 0; + int ShadowCount = 0; + int ReductionCount = 0; + int AcrossCount = 0; }; class PredictorStats @@ -27,28 +28,32 @@ public: } ParallelStats ParallelStat; - int ParallelCount; - int RemoteCount; - int RedistributeCount; - int IntervalCount; - int TotalScoreComm; - int TotalScorePar; - int TotalScoreDist; + int ParallelCount = 0; + int RemoteCount = 0; + int RedistributeCount = 0; + int IntervalCount = 0; + int TotalScoreComm = 0; + int TotalScorePar = 0; + int TotalScoreDist = 0; - std::string to_string() + nlohmann::json toJson() { - std::string res = ""; - res += std::to_string(ParallelCount) + "|"; - res += std::to_string(RemoteCount) + "|"; - res += std::to_string(RedistributeCount) + "|"; - res += std::to_string(IntervalCount) + "|"; + nlohmann::json stat; - res += std::to_string(ParallelStat.RemoteCount) + "|"; - res += std::to_string(ParallelStat.ShadowCount) + "|"; - res += std::to_string(ParallelStat.ReductionCount) + "|"; - res += std::to_string(ParallelStat.AcrossCount); + stat["ParallelCount"] = ParallelCount; + stat["RemoteCount"] = RemoteCount; + stat["RedistributeCount"] = RedistributeCount; + stat["IntervalCount"] = IntervalCount; - return res; + stat["PS_RemoteCount"] = ParallelStat.RemoteCount; + stat["PS_ShadowCount"] = ParallelStat.ShadowCount; + stat["PS_ReductionCount"] = ParallelStat.ReductionCount; + stat["PS_AcrossCount"] = ParallelStat.AcrossCount; + + //TODO: need to improve + // (summed.TotalScoreComm != 0 ? 1.0 / summed.TotalScoreComm : 0.0) + (double)summed.TotalScorePar * 1000 + (countOfDist == 0 ? -5000 : countOfDist); + stat["TotalScore"] = -1 * (ParallelStat.RemoteCount + ParallelStat.ShadowCount + ParallelStat.ReductionCount + ParallelStat.AcrossCount); + return stat; } }; diff --git a/src/Sapfor.cpp b/src/Sapfor.cpp index 13a8a9e..7c7254d 100644 --- a/src/Sapfor.cpp +++ b/src/Sapfor.cpp @@ -2221,8 +2221,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName); runAnalysis(*project, CALCULATE_STATS_SCHEME, false); - for (auto& elem : allPredictorStats) - __spf_print(1, " stat for file %s: %s\n", elem.first.c_str(), elem.second.to_string().c_str()); + //TODO: need to rewrite this to new algo /*if (!folderName && !consoleMode || predictOn) runAnalysis(*project, PREDICT_SCHEME, false); */ diff --git a/src/VisualizerCalls/get_information.cpp b/src/VisualizerCalls/get_information.cpp index 520e929..eb08941 100644 --- a/src/VisualizerCalls/get_information.cpp +++ b/src/VisualizerCalls/get_information.cpp @@ -1065,7 +1065,6 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh printf("SAPFOR: set all info done\n"); runPassesForVisualizer(projName, { INSERT_PARALLEL_DIRS }, folderName); - string predictRes = ""; PredictorStats summed; for (auto &predFile : allPredictorStats) { @@ -1081,44 +1080,11 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh summed.TotalScoreComm += predFile.second.TotalScoreComm; summed.TotalScoreDist += predFile.second.TotalScoreDist; summed.TotalScorePar += predFile.second.TotalScorePar; - } - predictRes += summed.to_string(); - //predictRes += "|" + to_string((summed.TotalScoreComm != 0 ? 1.0 / summed.TotalScoreComm : 0.0 )+ (double)summed.TotalScorePar * 1000 + (countOfDist == 0 ? -5000 : countOfDist)); - if (countOfDist == 0) - predictRes += "|x"; - else - predictRes += "|" + to_string(-1 * (summed.ParallelStat.AcrossCount + summed.ParallelStat.RemoteCount + summed.RedistributeCount + summed.RemoteCount)); - //predictRes += "|0"; - - //TODO: need to rewrite to new algo - /*if (folderName == NULL) - { - SpfInterval *mainIterval = getMainInterval(project, intervals); - const int idxBest = mainIterval->getBestTimeIdx(); - double speedUpBest = 1; - int procCount = 1; - string topo = ""; - if (idxBest != -1 && mainIterval->exec_time != 0) - { - speedUpBest = mainIterval->exec_time / mainIterval->predictedTimes[idxBest]; - topo += "["; - for (int z = 0; z < topologies[idxBest].size(); ++z) - { - topo += to_string(topologies[idxBest][z]); - procCount *= topologies[idxBest][z]; - if (z != topologies[idxBest].size() - 1) - topo += "x"; - } - topo += "]"; - } - char buf[256]; - sprintf(buf, "%.2f", speedUpBest / procCount * 100.0); - predictRes += "|" + string(buf) + topo; } - else - predictRes += "|0";*/ + string predictRes = summed.toJson().dump(); copyStringToShort(predictorStats, predictRes); + __spf_print(1, " statistic to send: %s\n", predictRes.c_str()); retSize = (int)predictRes.size(); }