From 66feb1571419599087368b4e492eadf1279ec389 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Fri, 29 Mar 2024 15:27:41 +0300 Subject: [PATCH 1/6] fix for analysis mode --- .../_src/GraphCall/select_array_conf.cpp | 155 ++++-------------- .../_src/GraphCall/select_array_conf.h | 10 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 3 +- .../Sapfor_2017/_src/Utils/PassManager.h | 4 +- .../_src/VisualizerCalls/get_information.cpp | 2 +- 5 files changed, 38 insertions(+), 136 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp index b4567c7..3e11f6b 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp @@ -65,26 +65,13 @@ static void findUsedArraysInParallelLoops(LoopGraph* loop, set& re } static void preventLoopsFromParallelizations(LoopGraph* loop, const set& prevent, - vector& createdDirectives,vector& messagesForFile) + vector& messagesForFile) { if (loop->directive) { if (IsSetsIntersect(prevent, loop->usedArraysAll)) { // prevent this loop - int loopLine = loop->lineNum; - - for (auto dir_it = createdDirectives.begin(); dir_it != createdDirectives.end(); dir_it++) - { - if ((*dir_it)->line == loopLine) - { - delete *dir_it; - dir_it = createdDirectives.erase(dir_it); - - break; - } - } - delete loop->directive; loop->directive = NULL; @@ -123,7 +110,7 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const setchildren) - preventLoopsFromParallelizations(child, prevent, createdDirectives, messagesForFile); + preventLoopsFromParallelizations(child, prevent, messagesForFile); } struct DimConf @@ -169,9 +156,9 @@ pickBest(const map>>& arrs) } void SelectArrayConfForParallelization(SgProject* proj, map>& funcByFile, - const map>& loopGraph, map>& createdDirectives, - map>& allMessages, const map>& arrayLinksByFuncCalls, - const vector& regions) + const map>& loopGraph, + map>& allMessages, + const map>& arrayLinksByFuncCalls) { map funcByName; for (const auto& byFile : funcByFile) @@ -265,121 +252,43 @@ void SelectArrayConfForParallelization(SgProject* proj, map& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages); - auto dirs_it = createdDirectives.find(byFile.first); - if (dirs_it != createdDirectives.end()) + SgFile::switchToFile(byFile.first); + + auto& loops = byFile.second; + + auto file_funcs_it = funcByFile.find(byFile.first); + + if (file_funcs_it == funcByFile.end()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile + + map> usedInLoops; + + for (const auto& loop : loops) { - SgFile::switchToFile(byFile.first); + SgStatement* search_func = loop->loop->GetOriginal(); - auto& loops = byFile.second; + while (search_func && (!isSgProgHedrStmt(search_func))) + search_func = search_func->controlParent(); - auto file_funcs_it = funcByFile.find(byFile.first); + if (!search_func) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement - if (file_funcs_it == funcByFile.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile - - map> usedInLoops; - - for (const auto& loop : loops) + bool loop_analyzed = false; + for (const auto& byFunc : file_funcs_it->second) { - SgStatement* search_func = loop->loop->GetOriginal(); - - while (search_func && (!isSgProgHedrStmt(search_func))) - search_func = search_func->controlParent(); - - if (!search_func) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement - - bool loop_analyzed = false; - for (const auto& byFunc : file_funcs_it->second) + if (byFunc->funcPointer->GetOriginal() == search_func) { - if (byFunc->funcPointer->GetOriginal() == search_func) - { - auto prevent_it = preventFromParallelization.find(byFunc); - if (prevent_it != preventFromParallelization.end()) - preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second, fileM); + auto prevent_it = preventFromParallelization.find(byFunc); + if (prevent_it != preventFromParallelization.end()) + preventLoopsFromParallelizations(loop, prevent_it->second, fileM); - loop_analyzed = true; - break; - } - } - - if (!loop_analyzed) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop - } - } - } -} - -void removeRegionsWithoutDirs(const map>& createdDirectives, - vector& parallelRegions, - const map>& allFuncInfo, - map>& SPF_messages) -{ - set empty_regs(parallelRegions.begin(), parallelRegions.end()); - - for (const auto& byFile : createdDirectives) - for (const auto& dir : byFile.second) - empty_regs.erase(getRegionByLine(parallelRegions, byFile.first, dir->line)); - - set idxToDel; - for (int z = 0; z < parallelRegions.size(); ++z) - { - if (empty_regs.find(parallelRegions[z]) != empty_regs.end()) - { - __spf_print(1, " no parallel directives for parallel region '%s'\n", parallelRegions[z]->GetName().c_str()); - - if (parallelRegions[z]->GetId() == 0) // DEFAULT - { - wstring bufE, bufR; - __spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this project"); - __spf_printToLongBuf(bufR, R130); - - for (auto& funcByFile : allFuncInfo) - { - vector& fileM = getObjectForFileFromMap(funcByFile.first.c_str(), SPF_messages); - for (auto& func : funcByFile.second) - { - auto stat = func->funcPointer->GetOriginal(); - if (stat->variant() == PROG_HEDR) - fileM.push_back(Messages(ERROR, stat->lineNumber(), bufR, bufE, 3010)); - } + loop_analyzed = true; + break; } } - else - { - wstring bufE, bufR; - __spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this region"); - __spf_printToLongBuf(bufR, R131); - for (auto& linesByFile : parallelRegions[z]->GetAllLines()) - { - vector& fileM = getObjectForFileFromMap(linesByFile.first.c_str(), SPF_messages); - for (auto& lines : linesByFile.second) - if (!lines.isImplicit()) - fileM.push_back(Messages(ERROR, lines.lines.first, bufR, bufE, 3010)); - } - } - idxToDel.insert(z); + if (!loop_analyzed) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop } } - - vector newParReg; - for (int z = 0; z < parallelRegions.size(); ++z) - { - if (idxToDel.find(z) != idxToDel.end()) - { - ParallelRegion* regToDel = parallelRegions[z]; -#ifdef _WIN32 - removeFromCollection(parallelRegions[z]); -#endif - delete parallelRegions[z]; - } - else - newParReg.push_back(parallelRegions[z]); - } - parallelRegions.clear(); - parallelRegions = newParReg; - - if (parallelRegions.size() == 0) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h index cb35893..4d2e392 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h @@ -11,12 +11,6 @@ void SelectArrayConfForParallelization(SgProject* proj, std::map>& funcByFile, - const std::map>& loopGraph, - std::map>& createdDirectives, + const std::map>& loopGraph, std::map>& allMessages, - const std::map>& arrayLinksByFuncCalls, const std::vector& regions); - -void removeRegionsWithoutDirs(const std::map>& createdDirectives, - std::vector& parallelRegions, - const std::map>& allFuncInfo, - std::map>& SPF_messages); \ No newline at end of file + const std::map>& arrayLinksByFuncCalls); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 33c7e9b..a1bc01d 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -1924,8 +1924,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne else if (curr_regime == FIX_COMMON_BLOCKS) fixCommonBlocks(allFuncInfo, commonBlocks, &project); else if (curr_regime == SELECT_ARRAY_DIM_CONF) { - SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions); - removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages); + SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, SPF_messages, arrayLinksByFuncCalls); } else if (curr_regime == GET_MIN_MAX_BLOCK_DIST) { diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h index 7a4a3f2..b8e6c2e 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h @@ -233,7 +233,7 @@ void InitPassesDependencies(map> &passDepsIn, set list({ GET_ALL_ARRAY_DECL, CALL_GRAPH2, CODE_CHECKER_PASSES, SUBST_EXPR_RD, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= list({ LOOP_ANALYZER_NODIST, LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH }); - list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(INSERT_PARALLEL_DIRS_NODIST); + list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(SELECT_ARRAY_DIM_CONF) <= Pass(INSERT_PARALLEL_DIRS_NODIST); Pass(CHECK_ARGS_DECL) <= Pass(CREATE_TEMPLATE_LINKS); @@ -251,7 +251,7 @@ void InitPassesDependencies(map> &passDepsIn, set list({ CORRECT_VAR_DECL, PREPROC_SPF }) <= list({ LOOP_GRAPH, CALL_GRAPH, CALL_GRAPH2 }); - list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL, SELECT_ARRAY_DIM_CONF}); + list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL }); list({ PREPROC_SPF, CALL_GRAPH2, FILL_PAR_REGIONS_LINES }) <= Pass(FILL_PAR_REGIONS) <= Pass(RESOLVE_PAR_REGIONS); diff --git a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp index 10fe288..5acca3b 100644 --- a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp @@ -820,7 +820,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho else if (regime == 1) { if (mpiProgram) - runPassesForVisualizer(projName, { LOOP_ANALYZER_NODIST }); + runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF }); else runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 }); } From 1713c26547c7f0b9cc5575050ff1913b35644d57 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Fri, 29 Mar 2024 18:01:08 +0300 Subject: [PATCH 2/6] prevent loops with return statements from parallelization --- sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp index 1141841..1d00443 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp @@ -643,7 +643,7 @@ void loopGraphAnalyzer(SgFile *file, vector &loopGraph, const vector newLoop->perfectLoop = countPerfectLoopNest(st); newLoop->hasGoto = hasGoto(st, st->lastNodeOfStmt(), newLoop->linesOfInternalGoTo, newLoop->linesOfExternalGoTo, labelsRef, newLoop->linesOfCycle); newLoop->hasPrints = hasThisIds(st, newLoop->linesOfIO, { WRITE_STAT, READ_STAT, OPEN_STAT, CLOSE_STAT, PRINT_STAT } ); // FORMAT_STAT - newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE }); + newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE, RETURN_STAT }); newLoop->hasDvmIntervals = hasThisIds(st, tmpLines, { DVM_INTERVAL_DIR, DVM_ENDINTERVAL_DIR, DVM_EXIT_INTERVAL_DIR }); newLoop->isFor = isSgForStmt(st) ? true : false; newLoop->inCanonicalFrom = isSgForStmt(st) ? true : false; From e32bdb0e07dea888d6202043d4e728e704b456a0 Mon Sep 17 00:00:00 2001 From: XNPSTER Date: Sat, 30 Mar 2024 18:51:36 +0300 Subject: [PATCH 3/6] fix linux build --- sapfor/experts/Sapfor_2017/_src/Utils/utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/utils.h b/sapfor/experts/Sapfor_2017/_src/Utils/utils.h index df8e325..d46a9db 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/utils.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/utils.h @@ -3,6 +3,7 @@ #include #include #include +#include struct DataDirective; namespace Distribution From b9a488c7ea0df1c9d138497a4b5a30a4a3d01c5a Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sat, 30 Mar 2024 19:04:49 +0300 Subject: [PATCH 4/6] remove redunant call of SELECT_ARRAY_DIM_CONF pass --- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index a1bc01d..a5d55e3 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -2153,8 +2153,6 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName); runPass(CONVERT_LOOP_TO_ASSIGN, proj_name, folderName); - - runPass(SELECT_ARRAY_DIM_CONF, proj_name, folderName); runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName); From 9812ced8ca52661c29e8cbc938829ba18980716e Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sat, 30 Mar 2024 19:07:24 +0300 Subject: [PATCH 5/6] fix russian messages in loop_ananlyzer_nodist.cpp --- .../Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp index e788d25..b423e47 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include From 2d7fea1d7c9281f8fe7c72ec9f55c4b34460d91b Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 30 Mar 2024 19:27:38 +0300 Subject: [PATCH 6/6] improved --- sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp | 8 +++++++- sapfor/experts/Sapfor_2017/_src/Utils/version.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp index 1d00443..0eb0896 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp @@ -207,6 +207,12 @@ static inline bool hasGoto(SgStatement *begin, SgStatement *end, has = true; } + if (curr->variant() == RETURN_STAT) + { + linesOfIntGoTo.push_back(curr->lineNumber()); + has = true; + } + if (curr->variant() == CYCLE_STMT) cycleStmts.push_back(curr->lineNumber()); curr = curr->lexNext(); @@ -643,7 +649,7 @@ void loopGraphAnalyzer(SgFile *file, vector &loopGraph, const vector newLoop->perfectLoop = countPerfectLoopNest(st); newLoop->hasGoto = hasGoto(st, st->lastNodeOfStmt(), newLoop->linesOfInternalGoTo, newLoop->linesOfExternalGoTo, labelsRef, newLoop->linesOfCycle); newLoop->hasPrints = hasThisIds(st, newLoop->linesOfIO, { WRITE_STAT, READ_STAT, OPEN_STAT, CLOSE_STAT, PRINT_STAT } ); // FORMAT_STAT - newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE, RETURN_STAT }); + newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE }); newLoop->hasDvmIntervals = hasThisIds(st, tmpLines, { DVM_INTERVAL_DIR, DVM_ENDINTERVAL_DIR, DVM_EXIT_INTERVAL_DIR }); newLoop->isFor = isSgForStmt(st) ? true : false; newLoop->inCanonicalFrom = isSgForStmt(st) ? true : false; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index c7604bc..8a3f0fb 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2296" +#define VERSION_SPF "2298"