From 1be169e7ff245b9ade30395ca0a7be0a8d751a5e Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Wed, 19 Jun 2024 18:08:27 +0300 Subject: [PATCH 01/10] Rename mpiProgram flag to sharedMemoryParallelization --- .../DirectiveProcessing/directive_creator.cpp | 4 +-- .../directive_creator_base.cpp | 6 ++-- .../DirectiveProcessing/insert_directive.cpp | 6 ++-- .../Sapfor_2017/_src/Distribution/Array.h | 4 +-- .../Distribution/CreateDistributionDirs.cpp | 4 +-- .../_src/Distribution/DvmhDirective.cpp | 22 ++++++------ .../_src/Distribution/DvmhDirective.h | 2 +- .../_src/Distribution/DvmhDirectiveBase.cpp | 6 ++-- .../_src/DvmhRegions/DvmhRegionInserter.cpp | 6 ++-- .../_src/GraphCall/graph_calls_base.cpp | 4 +-- .../_src/GraphCall/graph_calls_func.h | 2 +- .../_src/GraphLoop/graph_loops.cpp | 4 +-- .../Sapfor_2017/_src/GraphLoop/graph_loops.h | 2 +- .../_src/GraphLoop/graph_loops_base.cpp | 8 ++--- .../_src/GraphLoop/graph_loops_func.h | 2 +- .../_src/LoopAnalyzer/loop_analyzer.cpp | 12 +++---- .../LoopAnalyzer/loop_analyzer_internal.h | 2 +- .../resolve_par_reg_conflicts.cpp | 10 +++--- .../resolve_par_reg_conflicts.h | 4 +-- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 36 +++++++++---------- sapfor/experts/Sapfor_2017/_src/Sapfor.h | 2 +- sapfor/experts/Sapfor_2017/_src/SapforData.h | 2 +- .../Sapfor_2017/_src/Utils/SgUtils.cpp | 2 +- .../experts/Sapfor_2017/_src/Utils/utils.cpp | 2 +- .../_src/VisualizerCalls/get_information.cpp | 14 ++++---- 25 files changed, 84 insertions(+), 84 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp index a4fd864..e9e804d 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp @@ -45,7 +45,7 @@ using std::get; using std::string; using std::wstring; -extern int mpiProgram; +extern int sharedMemoryParallelization; static vector>> groupRealignsDirs(const vector>>& toRealign) @@ -453,7 +453,7 @@ void createParallelDirs(File *file, auto& tmp = dataDirectives.distrRules; vector> currentVar; - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { for (int z1 = 0; z1 < currentVariant.size(); ++z1) currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]])); diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp index 6277dd2..8730a95 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp @@ -525,7 +525,7 @@ void createParallelDirectives(const mapcalculatedCountOfIters; uint64_t regId = currReg->GetId(); - if (mpiProgram) + if (sharedMemoryParallelization) regId = (uint64_t)currLoop; const DIST::Arrays &allArrays = currReg->GetAllArrays(); @@ -749,7 +749,7 @@ void createParallelDirectives(const mapIsLoopArray())) + if (mainArray.underAcross == false && !(sharedMemoryParallelization == 1 && mainArray.arrayRef->IsLoopArray())) { set realArrayRef; getRealArrayRefs(mainArray.arrayRef, mainArray.arrayRef, realArrayRef, arrayLinksByFuncCalls); @@ -1762,7 +1762,7 @@ static bool addRedistributionDirs(File* file, const vector &exprs) @@ -2384,7 +2384,7 @@ void insertParallelDirs(SgFile *file, bool extract, const char* file_name = file->filename(); insertDirectiveToFile(file, file_name, createdDirectives, extract, messages); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { map mapFuncInfo; createMapOfFunc(callGraph, mapFuncInfo); @@ -2420,7 +2420,7 @@ void insertParallelDirs(SgFile *file, bool extract, for (auto& array : declaredArrays) array.second.first->ClearShadowSpecs(); } - else if (mpiProgram == 0) + else if (sharedMemoryParallelization == 0) { set regNum; for (int z = 0; z < parallelRegions.size(); ++z) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h b/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h index 7dd823e..8380a6b 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h @@ -22,7 +22,7 @@ struct FuncInfo; #define TO_STR std::to_string #if __SPF -extern int mpiProgram; +extern int sharedMemoryParallelization; #endif namespace Distribution @@ -117,7 +117,7 @@ namespace Distribution if (it == templateInfo.end()) { #if __SPF - if (withCheck && mpiProgram != 0) + if (withCheck && sharedMemoryParallelization != 0) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); #endif currLink = new TemplateLink(dimSize); diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/CreateDistributionDirs.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/CreateDistributionDirs.cpp index ada8f0e..ef34757 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/CreateDistributionDirs.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/CreateDistributionDirs.cpp @@ -530,7 +530,7 @@ int createAlignDirs(DIST::GraphCSR &reducedG, const DIST: { DIST::Array* array = arrayPair.second; - if (mpiProgram != 0) + if (sharedMemoryParallelization != 0) if (onlyThese.find(array) == onlyThese.end()) continue; @@ -604,7 +604,7 @@ int createAlignDirs(DIST::GraphCSR &reducedG, const DIST: printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } - if (isAllRulesEqualWithoutArray(rules) || mpiProgram != 0) + if (isAllRulesEqualWithoutArray(rules) || sharedMemoryParallelization != 0) { bool hasError = createNewAlignRule(array, allArrays, rules[0], dataDirectives, SPF_messages, canNotAlign == NULL); if (hasError) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index c50c644..cb8dbd9 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -281,10 +281,10 @@ static vector for (int z = 0; z < loops.size(); ++z) { currLoop = loops[z]; - const uint64_t regId = mpiProgram ? (uint64_t)currLoop : currLoop->region->GetId(); + const uint64_t regId = sharedMemoryParallelization ? (uint64_t)currLoop : currLoop->region->GetId(); auto dirForLoop = currLoop->directiveForLoop; - auto tmplP = pairs.first->GetTemplateArray(regId, mpiProgram != 0); + auto tmplP = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); auto links = pairs.first->GetLinksWithTemplate(regId); // no mapping for this loop, skip this @@ -324,10 +324,10 @@ static vector if (realRefsLocal.size() == 0) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - auto tmplP = (*realRefsLocal.begin())->GetTemplateArray(regId, mpiProgram != 0); + auto tmplP = (*realRefsLocal.begin())->GetTemplateArray(regId, sharedMemoryParallelization != 0); auto links = (*realRefsLocal.begin())->GetLinksWithTemplate(regId); - auto tmplP_et = pairs.first->GetTemplateArray(regId, mpiProgram != 0); + auto tmplP_et = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); auto links_et = pairs.first->GetLinksWithTemplate(regId); if (tmplP == tmplP_et) @@ -557,7 +557,7 @@ ParallelDirective::genDirective(File* file, const vectorGetShortName() + "("; @@ -565,7 +565,7 @@ ParallelDirective::genDirective(File* file, const vectorIsTemplate()) @@ -652,7 +652,7 @@ ParallelDirective::genDirective(File* file, const vectorsetLhs(makeExprList(list)); } - if (mpiProgram || across.size() != 0) + if (sharedMemoryParallelization || across.size() != 0) { if (!arrayRef2->IsLoopArray()) { @@ -662,7 +662,7 @@ ParallelDirective::genDirective(File* file, const vector onlyFor; - if (mpiProgram == 0 && across.size()) + if (sharedMemoryParallelization == 0 && across.size()) { for (int k = 0; k < (int)across.size(); ++k) { @@ -672,7 +672,7 @@ ParallelDirective::genDirective(File* file, const vector tieList; - if (mpiProgram) + if (sharedMemoryParallelization) tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); else if (onlyFor.size()) // not MPI regime tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); @@ -807,7 +807,7 @@ ParallelDirective::genDirective(File* file, const vectorarrayRef == second->arrayRef; - if (mpiProgram) + if (sharedMemoryParallelization) condition = !hasConflictUniteOnRules(first->on, second->on) && !hasConflictUniteOnRules(first->on2, second->on2); if (condition) @@ -279,7 +279,7 @@ static inline string calculateShifts(DIST::GraphCSR &redu set refs; getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) {//TODO: need to correct errors /*for (auto& array : refs) { @@ -501,7 +501,7 @@ string ParallelDirective::genBounds(pair, vectorIsTemplate() == false && mpiProgram == 0) + if (arrayRef->IsTemplate() == false && sharedMemoryParallelization == 0) { vector>> ruleForRef = getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index a76a193..f051e22 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -1166,7 +1166,7 @@ void DvmhRegionInserter::removePrivatesFromParallelLoops() if (lexPrev->variant() == DVM_PARALLEL_ON_DIR) { - if (mpiProgram == 1) + if (sharedMemoryParallelization == 1) lexPrev->deleteStmt(); else { @@ -1309,7 +1309,7 @@ void insertDvmhRegions(SgProject& project, int files, const vector> arrayLinksByFuncCalls) { vector inserters; - const bool regionCondition = ((parallelRegions.size() == 0 && parallelRegions[0]->GetName() == "DEFAULT") || mpiProgram == 1); + const bool regionCondition = ((parallelRegions.size() == 0 && parallelRegions[0]->GetName() == "DEFAULT") || sharedMemoryParallelization == 1); set usedArraysInRegions; set usedWriteArraysInRegions; @@ -1328,7 +1328,7 @@ void insertDvmhRegions(SgProject& project, int files, const vectoranalyzeParallelDirs(); - DvmhRegionInserter* regionInserter = new DvmhRegionInserter(file, loopsForFile, rw_analyzer, arrayLinksByFuncCalls, mapOfFuncs, funcsForFile, mpiProgram == 1); + DvmhRegionInserter* regionInserter = new DvmhRegionInserter(file, loopsForFile, rw_analyzer, arrayLinksByFuncCalls, mapOfFuncs, funcsForFile, sharedMemoryParallelization == 1); inserters.push_back(regionInserter); //collect info about functions diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp index f2c835a..824e8f5 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp @@ -849,12 +849,12 @@ void excludeArraysFromDistribution(const map>& a vector parallelRegions, map>& SPF_messages, map, DIST::Array*>& createdArrays, - int mpiProgram) + int sharedMemoryParallelization) { checkArraysMapping(loopGraph, SPF_messages, arrayLinksByFuncCalls); propagateArrayFlags(arrayLinksByFuncCalls, declaredArrays, SPF_messages); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { for (int z = 0; z < parallelRegions.size(); ++z) filterArrayInCSRGraph(loopGraph, allFuncInfo, parallelRegions[z], arrayLinksByFuncCalls, SPF_messages); diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_func.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_func.h index 94c5b56..a4d3715 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_func.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_func.h @@ -34,7 +34,7 @@ void createMapOfFunc(const std::vector &allFuncInfo, std::map &funcMap, const std::string &funcName); void updateFuncInfo(const std::map> &allFuncInfo); -void excludeArraysFromDistribution(const std::map>& arrayLinksByFuncCalls, const std::map, std::pair> declaredArrays, std::map>& loopGraph, std::vector parallelRegions, std::map>& SPF_messages, std::map, DIST::Array*>& createdArrays, int mpiProgram = 0); +void excludeArraysFromDistribution(const std::map>& arrayLinksByFuncCalls, const std::map, std::pair> declaredArrays, std::map>& loopGraph, std::vector parallelRegions, std::map>& SPF_messages, std::map, DIST::Array*>& createdArrays, int sharedMemoryParallelization = 0); #if __SPF void functionAnalyzer(SgFile *file, std::map> &allFuncInfo, const std::vector &loops, std::vector &messagesForFile, std::map>& fullIR); diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp index f2d02c4..4b22dc3 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp @@ -423,7 +423,7 @@ static bool hasNonRect(SgForStmt *st, const vector &parentLoops, vec SgExpression* end = st->end(); SgExpression* step = st->step(); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { set usedArrays; @@ -609,7 +609,7 @@ static bool hasSubstringRef(SgStatement* loop) return false; } -void loopGraphAnalyzer(SgFile *file, vector &loopGraph, const vector &intervalTree, vector &messages, int mpiProgram) +void loopGraphAnalyzer(SgFile *file, vector &loopGraph, const vector &intervalTree, vector &messages, int sharedMemoryParallelization) { map mapIntervals; createMapOfinterval(mapIntervals, intervalTree); diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.h b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.h index 6faef07..ce3939e 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.h @@ -327,7 +327,7 @@ public: bool isArrayTemplatesTheSame(DIST::Array*& sameTemplate, const uint64_t regId, const std::map>& arrayLinksByFuncCalls) { - if (mpiProgram != 0) + if (sharedMemoryParallelization != 0) return true; std::set usedForRegAccess; diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_base.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_base.cpp index 6c97d05..b1f9e35 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_base.cpp @@ -567,12 +567,12 @@ void addToDistributionGraph(const map> getRealArrayRefs(access.first, access.first, realArrayRefs[access.first], arrayLinksByFuncCalls); bool has_Wr_edges = false, has_Ww_edges = false, has_Rr_edges = false; - has_Wr_edges = processLinks(currAccessesV, allArrays, realArrayRefs, mpiProgram == 0 ? G :loopGraph, WW_link); - has_Ww_edges |= processLinks(currAccessesV, allArrays, realArrayRefs, mpiProgram == 0 ? G : loopGraph, WR_link); + has_Wr_edges = processLinks(currAccessesV, allArrays, realArrayRefs, sharedMemoryParallelization == 0 ? G :loopGraph, WW_link); + has_Ww_edges |= processLinks(currAccessesV, allArrays, realArrayRefs, sharedMemoryParallelization == 0 ? G : loopGraph, WR_link); if (!has_Wr_edges && !has_Ww_edges) - has_Rr_edges = processLinks(currAccessesV, allArrays, realArrayRefs, mpiProgram == 0 ? G : loopGraph, RR_link); + has_Rr_edges = processLinks(currAccessesV, allArrays, realArrayRefs, sharedMemoryParallelization == 0 ? G : loopGraph, RR_link); - if (mpiProgram) + if (sharedMemoryParallelization) { if (!has_Wr_edges && !has_Ww_edges && !has_Rr_edges) for (auto& elem : realArrayRefs) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_func.h b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_func.h index 99cfa0b..92f7576 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_func.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops_func.h @@ -7,7 +7,7 @@ struct SpfInterval; -void loopGraphAnalyzer(SgFile *file, std::vector &loopGraph, const std::vector &statisticTimes, std::vector &messages, int mpiProgram); +void loopGraphAnalyzer(SgFile *file, std::vector &loopGraph, const std::vector &statisticTimes, std::vector &messages, int sharedMemoryParallelization); void findAllRefsToLables(SgStatement *st, std::map> &labelsRef, bool includeWrite = true); std::map findAllDirectives(SgFile *file, const std::vector &loops, const uint64_t regId); std::vector, std::pair>> findAllSingleRemotes(SgFile *file, const uint64_t regId, std::vector ®ions); diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index 393f234..caadd09 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -335,7 +335,7 @@ vector matchSubscriptToLoopSymbols(const vector &parentLoops, S addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_FALSE, currLine, numOfSubscriptions); } - if (coefs.first < 0 && mpiProgram == 0) + if (coefs.first < 0 && sharedMemoryParallelization == 0) { if (currRegime == DATA_DISTR) { @@ -583,7 +583,7 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu if (itLoop->second->perfectLoop != depth) break; itLoop->second->hasIndirectAccess = true; - if (mpiProgram && side == RIGHT) + if (sharedMemoryParallelization && side == RIGHT) itLoop->second->hasIndirectAccess = false; } mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, @@ -654,7 +654,7 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu const string key = string(OriginalSymbol(currExp->symbol())->identifier()); if (loopsPrivates.find(key) == loopsPrivates.end()) { - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { for (auto& loop : parentLoops) { @@ -687,7 +687,7 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu if (wasMapped) { - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { int z = 0; for (auto& loop : parentLoops) @@ -2257,7 +2257,7 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapexpr(0)->lhs()->symbol(); if (s && privates.find(s->identifier()) == privates.end()) - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) hasWritesToArray = true; } } @@ -2776,7 +2776,7 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p new DIST::Array(getShortName(uniqKey), symb->identifier(), ((SgArrayType*)(symb->type()))->dimension(), getUniqArrayId(), decl->fileName(), decl->lineNumber(), arrayLocation, new Symbol(symb), findOmpThreadPrivDecl(scope, ompThreadPrivate, symb), false, false, - inRegion, typeSize, mpiProgram ? DIST::NO_DISTR : DIST::DISTR); + inRegion, typeSize, sharedMemoryParallelization ? DIST::NO_DISTR : DIST::DISTR); itNew = declaredArrays.insert(itNew, make_pair(uniqKey, make_pair(arrayToAdd, new DIST::ArrayAccessInfo()))); diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_internal.h b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_internal.h index 9ab28a7..dcaeb58 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_internal.h +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_internal.h @@ -50,7 +50,7 @@ extern int passDone; extern REGIME currRegime; extern std::vector* currMessages; -extern int mpiProgram; +extern int sharedMemoryParallelization; extern int ignoreIO; extern int parallizeFreeLoops; diff --git a/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp b/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp index 4df11ec..4321705 100644 --- a/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp +++ b/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp @@ -1251,7 +1251,7 @@ void fillUsedArraysInExp(const pair &interval, const int bool checkRegionsResolving(const vector ®ions, const map> &allFuncInfo, const map &commonBlocks, - map> &SPF_messages, bool mpiProgram) + map> &SPF_messages, bool sharedMemoryParallelization) { bool error = false; @@ -1319,7 +1319,7 @@ bool checkRegionsResolving(const vector ®ions, } } - if (mpiProgram) + if (sharedMemoryParallelization) return error; // check local arrays @@ -1611,7 +1611,7 @@ static void compliteUseOnlyList(SgStatement *func, const string &location, const } int resolveParRegions(vector ®ions, const map> &allFuncInfo, - map> &SPF_messages, bool mpiProgram, + map> &SPF_messages, bool sharedMemoryParallelization, map>> &newDeclsToInclude) { bool error = false; @@ -1619,7 +1619,7 @@ int resolveParRegions(vector ®ions, const map funcMap; createMapOfFunc(allFuncInfo, funcMap); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { map>> copied; @@ -1905,7 +1905,7 @@ int resolveParRegions(vector ®ions, const map ®ions, const std::map ®ions, const std::map> &allFuncInfo, std::map> &SPF_messages); int printCheckRegions(const char *fileName, const std::vector ®ions, const std::map> &allFuncInfo); -bool checkRegionsResolving(const std::vector ®ions, const std::map> &allFuncInfo, const std::map &commonBlocks, std::map> &SPF_messages, bool mpiProgram); -int resolveParRegions(std::vector& regions, const std::map>& allFuncInfo, std::map>& SPF_messages, bool mpiProgram, std::map>>& copyDecls); +bool checkRegionsResolving(const std::vector ®ions, const std::map> &allFuncInfo, const std::map &commonBlocks, std::map> &SPF_messages, bool sharedMemoryParallelization); +int resolveParRegions(std::vector& regions, const std::map>& allFuncInfo, std::map>& SPF_messages, bool sharedMemoryParallelization, std::map>>& copyDecls); void insertRealignsBeforeFragments(ParallelRegion* reg, SgFile* file, const std::set& distrArrays, 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 fa3c72f..ae13641 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -506,7 +506,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne insertIntrinsicStat(getObjectForFileFromMap(file_name, allFuncInfo)); } else if (curr_regime == LOOP_GRAPH) - loopGraphAnalyzer(file, getObjectForFileFromMap(file_name, loopGraph), getObjectForFileFromMap(file_name, intervals), getObjectForFileFromMap(file_name, SPF_messages), mpiProgram); + loopGraphAnalyzer(file, getObjectForFileFromMap(file_name, loopGraph), getObjectForFileFromMap(file_name, intervals), getObjectForFileFromMap(file_name, SPF_messages), sharedMemoryParallelization); else if (curr_regime == VERIFY_ENDDO) { bool res = EndDoLoopChecker(file, getObjectForFileFromMap(file_name, SPF_messages)); @@ -1076,7 +1076,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne if (curr_regime == ONLY_ARRAY_GRAPH) keepFiles = 1; - if (mpiProgram) + if (sharedMemoryParallelization) { for (auto& byFile : loopGraph) for (auto& loop : byFile.second) @@ -1387,7 +1387,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne vector result; set arraysDone; - if (mpiProgram) + if (sharedMemoryParallelization) { bool wasDone = false; for (int z = 0; z < parallelRegions.size(); ++z) @@ -1411,7 +1411,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne { for (auto& byFile : loopGraph) for (auto& loop : byFile.second) - loop->createVirtualTemplateLinks(arrayLinksByFuncCalls, SPF_messages, mpiProgram > 0); + loop->createVirtualTemplateLinks(arrayLinksByFuncCalls, SPF_messages, sharedMemoryParallelization > 0); //add dummy array DataDirective& dataDirectives = parallelRegions[0]->GetDataDirToModify(); @@ -1456,7 +1456,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne //recalculate array sizes after expression substitution recalculateArraySizes(arraysDone, allArrays.GetArrays(), arrayLinksByFuncCalls, allFuncInfo); - createDistributionDirs(reducedG, allArrays, dataDirectives, SPF_messages, arrayLinksByFuncCalls, mpiProgram > 0); + createDistributionDirs(reducedG, allArrays, dataDirectives, SPF_messages, arrayLinksByFuncCalls, sharedMemoryParallelization > 0); ALGORITHMS_DONE[CREATE_DISTIBUTION][z] = 1; } @@ -1574,7 +1574,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne } else if (curr_regime == RESOLVE_PAR_REGIONS) { - bool error = resolveParRegions(parallelRegions, allFuncInfo, SPF_messages, mpiProgram, newCopyDeclToIncl); + bool error = resolveParRegions(parallelRegions, allFuncInfo, SPF_messages, sharedMemoryParallelization, newCopyDeclToIncl); if (error) internalExit = 1; } @@ -1610,7 +1610,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne else if (curr_regime == INSERT_PARALLEL_DIRS || curr_regime == EXTRACT_PARALLEL_DIRS) { bool cond = (folderName != NULL) || (consoleMode) || (!consoleMode && curr_regime == EXTRACT_PARALLEL_DIRS); - if (cond && mpiProgram == 0) + if (cond && sharedMemoryParallelization == 0) { //insert template declaration to main program const bool extract = (curr_regime == EXTRACT_PARALLEL_DIRS); @@ -1659,7 +1659,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne printDefUseSets("_defUseList.txt", defUseByFunctions); } else if (curr_regime == LOOP_ANALYZER_DATA_DIST_S0) - excludeArraysFromDistribution(arrayLinksByFuncCalls, declaredArrays, loopGraph, parallelRegions, SPF_messages, createdArrays, mpiProgram); + excludeArraysFromDistribution(arrayLinksByFuncCalls, declaredArrays, loopGraph, parallelRegions, SPF_messages, createdArrays, sharedMemoryParallelization); else if (curr_regime == LOOP_ANALYZER_DATA_DIST_S1) { for (int z = 0; z < parallelRegions.size(); ++z) @@ -1671,7 +1671,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne } else if (curr_regime == PRINT_PAR_REGIONS_ERRORS) { - bool error = checkRegionsResolving(parallelRegions, allFuncInfo, commonBlocks, SPF_messages, mpiProgram); + bool error = checkRegionsResolving(parallelRegions, allFuncInfo, commonBlocks, SPF_messages, sharedMemoryParallelization); if (error) internalExit = 1; } @@ -2135,7 +2135,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam case INSERT_PARALLEL_DIRS_NODIST: { - mpiProgram = 1; + sharedMemoryParallelization = 1; string additionalName = (consoleMode && folderName == NULL) ? "__shared" : ""; @@ -2168,7 +2168,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam int maxDimsIdxReg = -1; int lastI = 1; - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) lastI = countMaxValuesForParallelVariants(maxDims, maxDimsIdx, maxDimsIdxReg, currentVariants); if (genAllVars == 0) lastI = 1; @@ -2176,7 +2176,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam for (int i = 0; i < lastI; ++i) { //if specific variant number is requested, skip all others - if (genSpecificVar >= 0 && i != genSpecificVar && mpiProgram == 0) + if (genSpecificVar >= 0 && i != genSpecificVar && sharedMemoryParallelization == 0) continue; string tmpFolder = ""; @@ -2203,7 +2203,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam runAnalysis(*project, INSERT_PARALLEL_DIRS, false, consoleMode ? additionalName.c_str() : NULL, folderName); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { runPass(CREATE_REMOTES, proj_name, folderName); runPass(REMOVE_AND_CALC_SHADOW, proj_name, folderName); @@ -2214,11 +2214,11 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam runPass(RESTORE_LOOP_FROM_ASSIGN, proj_name, folderName); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) runPass(ADD_TEMPL_TO_USE_ONLY, proj_name, folderName); runAnalysis(*project, INSERT_REGIONS, false); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName); runAnalysis(*project, CALCULATE_STATS_SCHEME, false); @@ -2242,7 +2242,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam runPass(REVERSE_CREATED_NESTED_LOOPS, proj_name, folderName); runPass(CLEAR_SPF_DIRS, proj_name, folderName); runPass(RESTORE_LOOP_FROM_ASSIGN_BACK, proj_name, folderName); - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) runPass(GROUP_ACTUAL_AND_REMOTE_RESTORE, proj_name, folderName); //clear shadow grouping @@ -2567,7 +2567,7 @@ int main(int argc, char **argv) else if (string(curr_arg) == "-fdvm") convertFiles(argc - i, argv + i); else if (string(curr_arg) == "-mpi") { - mpiProgram = 1; + sharedMemoryParallelization = 1; ignoreArrayDistributeState = true; } else if (string(curr_arg) == "-client") @@ -2622,7 +2622,7 @@ int main(int argc, char **argv) } } - if (mpiProgram == 1) + if (sharedMemoryParallelization == 1) { keepDvmDirectives = 0; ignoreIO = 1; diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.h b/sapfor/experts/Sapfor_2017/_src/Sapfor.h index 70e3f7c..e9d8bf9 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.h +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.h @@ -9,7 +9,7 @@ extern int automaticDeprecateArrays; extern int maxShadowWidth; extern int langOfMessages; extern bool removeNestedIntervals; -extern int mpiProgram; +extern int sharedMemoryParallelization; extern int parallizeFreeLoops; extern int ignoreIO; extern int parseForInlining; diff --git a/sapfor/experts/Sapfor_2017/_src/SapforData.h b/sapfor/experts/Sapfor_2017/_src/SapforData.h index d495e12..d3df28c 100644 --- a/sapfor/experts/Sapfor_2017/_src/SapforData.h +++ b/sapfor/experts/Sapfor_2017/_src/SapforData.h @@ -35,7 +35,7 @@ int intervals_threshold = 100; // threshold for intervals bool removeNestedIntervals = false; // nested intervals removal flag int langOfMessages = 1; // 0 - ENG, 1 - RUS int parallizeFreeLoops = 0; // parallize free calculations -int mpiProgram = 0; // detected mpi calls +int sharedMemoryParallelization = 0; // detected mpi calls int ignoreIO = 0; // ignore io checker for arrays (DVM IO limitations) int parseForInlining = 0; // special regime for files parsing for inliner int dumpIR = 0; // allow dump IR after BUILD_IR pass diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index befe3e6..f0e217a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -3344,7 +3344,7 @@ SgProject* createProject(const char* proj_name, if (detectMpiCalls(project, SPF_messages)) { - mpiProgram = 1; + sharedMemoryParallelization = 1; keepDvmDirectives = 0; ignoreIO = 1; parallizeFreeLoops = 0; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp index 4b60f13..76fec47 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp @@ -203,7 +203,7 @@ const string printVersionAsFortranComm() ret += "! *** consider DVMH directives\n"; if (keepSpfDirs) ret += "! *** save SPF directives\n"; - if (mpiProgram) + if (sharedMemoryParallelization) ret += "! *** MPI program regime (shared memory parallelization)\n"; if (ignoreIO) ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n"; diff --git a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp index 958f673..28be54d 100644 --- a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp @@ -166,10 +166,10 @@ static void setOptions(const short* options, bool isBuildParallel = false, const removeNestedIntervals = (intOptions[KEEP_LOOPS_CLOSE_NESTING] == 1); showDebug = (intOptions[DEBUG_PRINT_ON] == 1); - mpiProgram = (mpiProgram != 1) ? intOptions[MPI_PROGRAM] : mpiProgram; - parallizeFreeLoops = (mpiProgram == 1) ? 0 : intOptions[PARALLIZE_FREE_LOOPS]; - ignoreIO = (mpiProgram == 1) ? 1 : intOptions[IGNORE_IO_SAPFOR]; - keepDvmDirectives = (mpiProgram == 1) ? 0 : intOptions[KEEP_DVM_DIRECTIVES]; + sharedMemoryParallelization = (sharedMemoryParallelization != 1) ? intOptions[MPI_PROGRAM] : sharedMemoryParallelization; + parallizeFreeLoops = (sharedMemoryParallelization == 1) ? 0 : intOptions[PARALLIZE_FREE_LOOPS]; + ignoreIO = (sharedMemoryParallelization == 1) ? 1 : intOptions[IGNORE_IO_SAPFOR]; + keepDvmDirectives = (sharedMemoryParallelization == 1) ? 0 : intOptions[KEEP_DVM_DIRECTIVES]; parseForInlining = intOptions[PARSE_FOR_INLINE]; @@ -819,7 +819,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho runPassesForVisualizer(projName, { CREATE_TEMPLATE_LINKS }); else if (regime == 1) { - if (mpiProgram) + if (sharedMemoryParallelization) runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF }); else runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 }); @@ -1061,7 +1061,7 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh throw (-5); int countOfDist = 0; - if (mpiProgram == 0) + if (sharedMemoryParallelization == 0) { map>> varLens; for (int i = 0, k = 0; i < *varLen; i += 3, ++k) @@ -1892,7 +1892,7 @@ int SPF_SharedMemoryParallelization(void*& context, int winHandler, short* optio MessageManager::clearCache(); MessageManager::setWinHandler(winHandler); ignoreArrayDistributeState = true; - mpiProgram = 1; + sharedMemoryParallelization = 1; return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize, true); } -- 2.49.1 From 7daf1b40381822c5fe1db31a06f70cdecdcb8100 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Thu, 20 Jun 2024 13:00:01 +0300 Subject: [PATCH 02/10] loop analyzer refactor for shared memory parallelization --- .../directive_creator_base.cpp | 383 +++++++++--------- .../_src/LoopAnalyzer/loop_analyzer.cpp | 267 ++++++------ .../_src/LoopAnalyzer/loop_analyzer.h | 2 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 4 +- 4 files changed, 324 insertions(+), 332 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp index 8730a95..d1ee848 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp @@ -91,26 +91,17 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai } currentLoop->directive = directive; - for (auto& read : currentLoop->readOpsArray) + if(!sharedMemoryParallelization) { - const string shortName = read->GetName(); - const string orignName = read->GetShortName(); - pair key = make_pair(orignName, shortName); - bool found = false; - for (int i = 0; i < directive->shadowRenew.size(); ++i) + for (auto& read : currentLoop->readOpsArray) { - if (directive->shadowRenew[i].first == key) + const string shortName = read->GetName(); + const string orignName = read->GetShortName(); + pair key = make_pair(orignName, shortName); + bool found = false; + for (int i = 0; i < directive->shadowRenew.size(); ++i) { - found = true; - break; - } - } - - if (found == false) - { - for (int i = 0; i < directive->across.size(); ++i) - { - if (directive->across[i].first == key) + if (directive->shadowRenew[i].first == key) { found = true; break; @@ -119,11 +110,23 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai if (found == false) { - directive->shadowRenew.push_back(make_pair(key, vector>())); + for (int i = 0; i < directive->across.size(); ++i) + { + if (directive->across[i].first == key) + { + found = true; + break; + } + } - const DIST::Array *arrayRef = read; - for (int i = 0; i < arrayRef->GetDimSize(); ++i) - directive->shadowRenew.back().second.push_back(make_pair(0, 0)); + if (found == false) + { + directive->shadowRenew.push_back(make_pair(key, vector>())); + + const DIST::Array *arrayRef = read; + for (int i = 0; i < arrayRef->GetDimSize(); ++i) + directive->shadowRenew.back().second.push_back(make_pair(0, 0)); + } } } } @@ -553,150 +556,155 @@ void createParallelDirectives(const map uniqNamesWithAcross; - fillArraysWithAcrossStatus(currLoop, uniqNamesWithAcross); - - if (arrayWriteAcc.size() == 1) + if(!sharedMemoryParallelization) { - mainArray.arrayRef = arrayWriteAcc.begin()->first; - mainArray.dimentionPos = arrayWriteAcc.begin()->second.first; - mainArray.mainAccess = arrayWriteAcc.begin()->second.second; + set uniqNamesWithAcross; + fillArraysWithAcrossStatus(currLoop, uniqNamesWithAcross); - if (uniqNamesWithAcross.size()) - mainArray.underAcross = true; - } - else if (arrayWriteAcc.size() > 1) - { - if (uniqNamesWithAcross.size()) - mainArray.underAcross = true; - - int posDim = -1; - int minDim = 999999; - int k = 0; - - vector>>> accesses; - map>> sameDims; - for (auto i = arrayWriteAcc.begin(); i != arrayWriteAcc.end(); ++i, ++k) + if (arrayWriteAcc.size() == 1) { - const auto array = i->first; - const string &uniqName = array->GetName(); + mainArray.arrayRef = arrayWriteAcc.begin()->first; + mainArray.dimentionPos = arrayWriteAcc.begin()->second.first; + mainArray.mainAccess = arrayWriteAcc.begin()->second.second; - //ACROSS arrays have priority state for all nested loops! - if (uniqNamesWithAcross.size() > 0) - if (uniqNamesWithAcross.find(uniqName) == uniqNamesWithAcross.end()) - continue; + if (uniqNamesWithAcross.size()) + mainArray.underAcross = true; + } + else if (arrayWriteAcc.size() > 1) + { + if (uniqNamesWithAcross.size()) + mainArray.underAcross = true; - const int currDim = array->GetDimSize(); - auto& sizes = array->GetSizes(); - const int currSize = sizes[i->second.first].second - sizes[i->second.first].first + 1; - sameDims[currDim].insert(make_tuple(uniqName, k, currSize)); + int posDim = -1; + int minDim = 999999; + int k = 0; - if (currDim < minDim) + vector>>> accesses; + map>> sameDims; + for (auto i = arrayWriteAcc.begin(); i != arrayWriteAcc.end(); ++i, ++k) { - if (itersCount == 0 || (itersCount != 0) && currSize >= itersCount) + const auto array = i->first; + const string &uniqName = array->GetName(); + + //ACROSS arrays have priority state for all nested loops! + if (uniqNamesWithAcross.size() > 0) + if (uniqNamesWithAcross.find(uniqName) == uniqNamesWithAcross.end()) + continue; + + const int currDim = array->GetDimSize(); + auto& sizes = array->GetSizes(); + const int currSize = sizes[i->second.first].second - sizes[i->second.first].first + 1; + sameDims[currDim].insert(make_tuple(uniqName, k, currSize)); + + if (currDim < minDim) { - minDim = currDim; - posDim = k; - } - } - __spf_print(PRINT_DIR_RESULT, " found writes for array %s -> [%d %d]\n", array->GetShortName().c_str(), i->second.second.first, i->second.second.second); - accesses.push_back(make_pair(array->GetName(), i->second)); - } - - if (posDim != -1) - { - auto itDim = sameDims.find(minDim); - if (itDim == sameDims.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - int maxArraySize = -1; - for (auto& elem : itDim->second) - { - if (get<2>(elem) > maxArraySize) - { - maxArraySize = get<2>(elem); - posDim = get<1>(elem); - } - } - } - else - { - mainArray.hasWrite = false; - __spf_print(PRINT_DIR_RESULT, " no appropriate regular writes on loop\n"); - } - - vector> realArrayRefs(accesses.size()); - for (int i = 0; i < (int)accesses.size(); ++i) - { - DIST::Array *array = allArrays.GetArrayByName(accesses[i].first); - getRealArrayRefs(array, array, realArrayRefs[i], arrayLinksByFuncCalls); - } - - //check the same distribution - bool statusOk = true; - for (int i = 0; i < (int)accesses.size(); ++i) - { - for (int k = i + 1; k < (int)accesses.size(); ++k) - { - DIST::Array *array1 = allArrays.GetArrayByName(accesses[i].first); - DIST::Array *array2 = allArrays.GetArrayByName(accesses[k].first); - - const set &realArrayRefs1 = realArrayRefs[i]; - const set &realArrayRefs2 = realArrayRefs[k]; - - for (auto &refs1 : realArrayRefs1) - { - for (auto &refs2 : realArrayRefs2) + if (itersCount == 0 || (itersCount != 0) && currSize >= itersCount) { - auto links = findLinksBetweenArrays(refs1, refs2, regId); + minDim = currDim; + posDim = k; + } + } + __spf_print(PRINT_DIR_RESULT, " found writes for array %s -> [%d %d]\n", array->GetShortName().c_str(), i->second.second.first, i->second.second.second); + accesses.push_back(make_pair(array->GetName(), i->second)); + } - const int dimFrom = accesses[i].second.first; - const int dimTo = accesses[k].second.first; + if (posDim != -1) + { + auto itDim = sameDims.find(minDim); + if (itDim == sameDims.end()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - if (dimTo != links[dimFrom]) + int maxArraySize = -1; + for (auto& elem : itDim->second) + { + if (get<2>(elem) > maxArraySize) + { + maxArraySize = get<2>(elem); + posDim = get<1>(elem); + } + } + } + else + { + mainArray.hasWrite = false; + __spf_print(PRINT_DIR_RESULT, " no appropriate regular writes on loop\n"); + } + + vector> realArrayRefs(accesses.size()); + for (int i = 0; i < (int)accesses.size(); ++i) + { + DIST::Array *array = allArrays.GetArrayByName(accesses[i].first); + getRealArrayRefs(array, array, realArrayRefs[i], arrayLinksByFuncCalls); + } + + //check the same distribution + bool statusOk = true; + for (int i = 0; i < (int)accesses.size(); ++i) + { + for (int k = i + 1; k < (int)accesses.size(); ++k) + { + DIST::Array *array1 = allArrays.GetArrayByName(accesses[i].first); + DIST::Array *array2 = allArrays.GetArrayByName(accesses[k].first); + + const set &realArrayRefs1 = realArrayRefs[i]; + const set &realArrayRefs2 = realArrayRefs[k]; + + for (auto &refs1 : realArrayRefs1) + { + for (auto &refs2 : realArrayRefs2) { - __spf_print(1, "arrays '%s' and '%s' have different align dimensions for loop on line %d\n --> %d vs %d(%d) \n", - array1->GetShortName().c_str(), array2->GetShortName().c_str(), - currLoop->lineNum, dimTo, links[dimFrom], dimFrom); - statusOk = false; - } - else - { - const auto accessFrom = accesses[i].second.second; - const auto accessTo = accesses[k].second.second; + auto links = findLinksBetweenArrays(refs1, refs2, regId); - auto templRule1 = refs1->GetAlignRulesWithTemplate(regId); - auto templRule2 = refs2->GetAlignRulesWithTemplate(regId); + const int dimFrom = accesses[i].second.first; + const int dimTo = accesses[k].second.first; - if (DIST::Fx(accessFrom, templRule1[dimFrom]) != DIST::Fx(accessTo, templRule2[dimTo])) + if (dimTo != links[dimFrom]) { - string format = "arrays '%s' and '%s' have different align rules -- \n -->"; - format += "F1 = [%d.%d], x1 = [%d.%d], F2 = [%d.%d], x2 = [%d.%d] \n -->"; - format += "F1(x1) = [%d.%d] != F2(x2) = [%d.%d]\n"; - - __spf_print(1, format.c_str(), + __spf_print(1, "arrays '%s' and '%s' have different align dimensions for loop on line %d\n --> %d vs %d(%d) \n", array1->GetShortName().c_str(), array2->GetShortName().c_str(), - templRule1[dimFrom].first, templRule1[dimFrom].second, accessFrom.first, accessFrom.second, - templRule2[dimTo].first, templRule2[dimTo].second, accessTo.first, accessTo.second, - DIST::Fx(accessFrom, templRule1[dimFrom]).first, DIST::Fx(accessFrom, templRule1[dimFrom]).second, - DIST::Fx(accessTo, templRule2[dimTo]).first, DIST::Fx(accessTo, templRule2[dimTo]).second); + currLoop->lineNum, dimTo, links[dimFrom], dimFrom); statusOk = false; } - } + else + { + const auto accessFrom = accesses[i].second.second; + const auto accessTo = accesses[k].second.second; + auto templRule1 = refs1->GetAlignRulesWithTemplate(regId); + auto templRule2 = refs2->GetAlignRulesWithTemplate(regId); + + if (DIST::Fx(accessFrom, templRule1[dimFrom]) != DIST::Fx(accessTo, templRule2[dimTo])) + { + string format = "arrays '%s' and '%s' have different align rules -- \n -->"; + format += "F1 = [%d.%d], x1 = [%d.%d], F2 = [%d.%d], x2 = [%d.%d] \n -->"; + format += "F1(x1) = [%d.%d] != F2(x2) = [%d.%d]\n"; + + __spf_print(1, format.c_str(), + array1->GetShortName().c_str(), array2->GetShortName().c_str(), + templRule1[dimFrom].first, templRule1[dimFrom].second, accessFrom.first, accessFrom.second, + templRule2[dimTo].first, templRule2[dimTo].second, accessTo.first, accessTo.second, + DIST::Fx(accessFrom, templRule1[dimFrom]).first, DIST::Fx(accessFrom, templRule1[dimFrom]).second, + DIST::Fx(accessTo, templRule2[dimTo]).first, DIST::Fx(accessTo, templRule2[dimTo]).second); + statusOk = false; + } + } + + if (!statusOk) + { + wstring bufE, bufR; + __spf_printToLongBuf(bufE, L"arrays '%s' and '%s' have different align rules in this loop according to their write accesses", + to_wstring(array1->GetShortName()).c_str(), to_wstring(array2->GetShortName()).c_str()); + + __spf_printToLongBuf(bufR, R132, to_wstring(array1->GetShortName()).c_str(), to_wstring(array2->GetShortName()).c_str()); + + + messages.push_back(Messages(WARR, currLoop->lineNum, bufR, bufE, 3011)); + currLoop->hasDifferentAlignRules = true; + break; + } + } if (!statusOk) - { - wstring bufE, bufR; - __spf_printToLongBuf(bufE, L"arrays '%s' and '%s' have different align rules in this loop according to their write accesses", - to_wstring(array1->GetShortName()).c_str(), to_wstring(array2->GetShortName()).c_str()); - - __spf_printToLongBuf(bufR, R132, to_wstring(array1->GetShortName()).c_str(), to_wstring(array2->GetShortName()).c_str()); - - - messages.push_back(Messages(WARR, currLoop->lineNum, bufR, bufE, 3011)); - currLoop->hasDifferentAlignRules = true; break; - } } if (!statusOk) break; @@ -704,43 +712,43 @@ void createParallelDirectives(const mapfirst; - mainArray.dimentionPos = array->second.first; - mainArray.mainAccess = array->second.second; - break; + if (k == posDim) + { + mainArray.arrayRef = array->first; + mainArray.dimentionPos = array->second.first; + mainArray.mainAccess = array->second.second; + break; + } } } + else + { + __spf_print(PRINT_DIR_RESULT, " has conflict writes\n"); + hasConflict = true; + } } else { - __spf_print(PRINT_DIR_RESULT, " has conflict writes\n"); - hasConflict = true; + mainArray.hasWrite = false; + __spf_print(PRINT_DIR_RESULT, " no regular writes on loop\n"); } - } - else - { - mainArray.hasWrite = false; - __spf_print(PRINT_DIR_RESULT, " no regular writes on loop\n"); + + // fill mainArray if no regular writes found + // now OmegaTest is used for searching dependencies + if (!mainArray.hasWrite) + findMainArrayFromRead(currAccesses, mainArray, itersCount, arrayLinksByFuncCalls); } - // fill mainArray if no regular writes found - // now OmegaTest is used for searching dependencies - if (!mainArray.hasWrite) - findMainArrayFromRead(currAccesses, mainArray, itersCount, arrayLinksByFuncCalls); + bool dimPosFound = sharedMemoryParallelization || + (mainArray.arrayRef != NULL && mainArray.dimentionPos != -1); - if (!hasConflict && - mainArray.arrayRef != NULL && mainArray.dimentionPos != -1 && + if (dimPosFound && !currLoop->hasLimitsToParallel() && (currLoop->lineNum > 0 || (currLoop->lineNum < 0 && currLoop->altLineNum > 0))) { @@ -749,7 +757,7 @@ void createParallelDirectives(const mapIsLoopArray())) + if (!sharedMemoryParallelization && mainArray.underAcross == false && !mainArray.arrayRef->IsLoopArray()) { set realArrayRef; getRealArrayRefs(mainArray.arrayRef, mainArray.arrayRef, realArrayRef, arrayLinksByFuncCalls); @@ -788,25 +796,30 @@ void createParallelDirectives(const mapdirective; if (parDir != NULL) { - parDir->arrayRef2 = mainArrayOfLoop; - if (mainArray.underAcross == false) + if(!sharedMemoryParallelization) { - for (int i = 0; i < mainArrayOfLoop->GetDimSize(); ++i) - { - if (i == dimPos) - parDir->on2.push_back(make_pair(currLoop->loopSymbol, mainAccess)); - else - parDir->on2.push_back(make_pair("*", make_pair(0, 0))); - } + parDir->arrayRef2 = mainArrayOfLoop; - for (int z = 0; z < parDir->on2.size(); ++z) - if (parDir->on2[z].first != "*" && parDir->on2[z].second == make_pair(0, 0)) - parDir->on2[z].second = mainAccess; + if (mainArray.underAcross == false) + { + for (int i = 0; i < mainArrayOfLoop->GetDimSize(); ++i) + { + if (i == dimPos) + parDir->on2.push_back(make_pair(currLoop->loopSymbol, mainAccess)); + else + parDir->on2.push_back(make_pair("*", make_pair(0, 0))); + } + + for (int z = 0; z < parDir->on2.size(); ++z) + if (parDir->on2[z].first != "*" && parDir->on2[z].second == make_pair(0, 0)) + parDir->on2[z].second = mainAccess; + } + else + parDir->on2 = parDir->on; + + addShadowFromAnalysis(parDir, currAccesses); } - else - parDir->on2 = parDir->on; - addShadowFromAnalysis(parDir, currAccesses); loop->directiveForLoop = new ParallelDirective(*loop->directive); } __spf_print(PRINT_DIR_RESULT, " directive created\n"); diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index caadd09..3c91121 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -204,7 +204,7 @@ vector matchSubscriptToLoopSymbols(const vector &parentLoops, S if (countOfSymbols > 1) { __spf_print(PRINT_ARRAY_ARCS, " <%d|%d> ", 0, 0); - if (currRegime == DATA_DISTR) + if (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR) { const pair &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); __spf_print(1, "WARN: array ref '%s' at line %d has more than one loop's variables\n", arrayRefString.second.c_str(), currLine); @@ -238,7 +238,7 @@ vector matchSubscriptToLoopSymbols(const vector &parentLoops, S for (int i = 0; i < (int)parentLoops.size(); ++i) addInfoToMap(loopInfo, parentLoops[i], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions); } - else if (currRegime == DATA_DISTR) + else if (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR) { const pair &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); @@ -294,7 +294,7 @@ vector matchSubscriptToLoopSymbols(const vector &parentLoops, S if (side == RIGHT) addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions); } - else if (currRegime == DATA_DISTR) + else if (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR) { const pair &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); __spf_print(1, "WARN: can not calculate index expression for array ref '%s' at line %d\n", arrayRefString.second.c_str(), currLine); @@ -387,7 +387,8 @@ vector matchSubscriptToLoopSymbols(const vector &parentLoops, S return allPositions; } -static vector matchArrayToLoopSymbols(const vector &parentLoops, SgExpression *currExp, const int side, +static vector matchArrayToLoopSymbols(const vector &parentLoops, vector>& privatesVarsForLoop, + SgExpression *currExp, const int side, map> &loopInfo, const int currLine, map &sortedLoopGraph, const ParallelRegion *reg, const double currentW, const map> &arrayLinksByFuncCalls) @@ -440,7 +441,9 @@ static vector matchArrayToLoopSymbols(const vector &parentLoops vector canNotMapToLoop; for (int i = 0; i < wasFoundForLoop.size(); ++i) { - if (wasFoundForLoop[i] != 1) + if (wasFoundForLoop[i] != 1 && + // always true for distributed data case + privatesVarsForLoop[i].find(string(arrayRef->symbol()->identifier())) == privatesVarsForLoop[i].end()) { auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber()); if (itLoop == sortedLoopGraph.end()) @@ -456,7 +459,7 @@ static vector matchArrayToLoopSymbols(const vector &parentLoops if (side == LEFT) { - if (ifUnknownArrayAssignFound && (currRegime == DATA_DISTR)) + if (ifUnknownArrayAssignFound && (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR)) { const string arrayRefS = arrayRef->unparse(); for (auto &line : canNotMapToLoop) @@ -517,7 +520,8 @@ static vector matchArrayToLoopSymbols(const vector &parentLoops } static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp, - const vector& parentLoops, const int side, const int lineNum, + const vector& parentLoops, vector>& privatesVarsForLoop, + const int side, const int lineNum, map>& loopInfo, map &sortedLoopGraph, map>& notMappedDistributedArrays, set& mappedDistrbutedArrays, @@ -533,7 +537,7 @@ static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp, __spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum); bool wasMapped = false; - vector matched = matchArrayToLoopSymbols(parentLoops, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls); + vector matched = matchArrayToLoopSymbols(parentLoops, privatesVarsForLoop, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls); for (int z = 0; z < matched.size(); ++z) wasMapped |= (matched[z] != 0); @@ -570,7 +574,8 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu if (isArrayRef(currExp)) { //... and current array is not in private list - if (privatesVars.find(string(OriginalSymbol(currExp->symbol())->identifier())) == privatesVars.end()) + if (sharedMemoryParallelization || + privatesVars.find(string(OriginalSymbol(currExp->symbol())->identifier())) == privatesVars.end()) { if (wasDistributedArrayRef) { @@ -582,147 +587,104 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu printInternalError(convertFileName(__FILE__).c_str(), __LINE__); if (itLoop->second->perfectLoop != depth) break; - itLoop->second->hasIndirectAccess = true; - if (sharedMemoryParallelization && side == RIGHT) - itLoop->second->hasIndirectAccess = false; + + if (!(sharedMemoryParallelization && side == RIGHT)) + itLoop->second->hasIndirectAccess = true; } - mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, + mapArrayRef(currentSt, currExp, parentLoops, privatesVarsForLoop, side, lineNum, loopInfo, sortedLoopGraph, notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); } else { wasDistributedArrayRef = true; - mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, + mapArrayRef(currentSt, currExp, parentLoops, privatesVarsForLoop, side, lineNum, loopInfo, sortedLoopGraph, notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); } } - else + else if (currRegime == DATA_DISTR && side == LEFT) { - if (currRegime == DATA_DISTR && side == LEFT) + auto symb = OriginalSymbol(currExp->symbol()); + SgStatement *decl = declaratedInStmt(symb); + auto uniqKey = getUniqName(commonBlocks, decl, symb); + + auto itFound = declaredArrays.find(uniqKey); + if (itFound == declaredArrays.end()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + //TODO: array access to non distributed arrays, add CONSISTENT + if (itFound->second.first->GetDistributeFlagVal() != DIST::DISTR) { - auto symb = OriginalSymbol(currExp->symbol()); - SgStatement *decl = declaratedInStmt(symb); - auto uniqKey = getUniqName(commonBlocks, decl, symb); + set loopsPrivates; + set loopsPrivatesS; + set loopsRedUnited; + map> loopsReductions; + map>> loopsReductionsLoc; - auto itFound = declaredArrays.find(uniqKey); - if (itFound == declaredArrays.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - //TODO: array access to non distributed arrays, add CONSISTENT - if (itFound->second.first->GetDistributeFlagVal() != DIST::DISTR) + + for (int z = 0; z < parentLoops.size(); ++z) { - set loopsPrivates; - set loopsPrivatesS; - set loopsRedUnited; - map> loopsReductions; - map>> loopsReductionsLoc; - - - for (int z = 0; z < parentLoops.size(); ++z) + auto& loop = parentLoops[z]; + for (auto &data : getAttributes(loop, set{ SPF_ANALYSIS_DIR })) { - auto& loop = parentLoops[z]; - for (auto &data : getAttributes(loop, set{ SPF_ANALYSIS_DIR })) - { - fillPrivatesFromComment(new Statement(data), loopsPrivatesS); - for (auto& elem : loopsPrivatesS) - loopsPrivates.insert(elem->GetOriginal()->identifier()); - fillReductionsFromComment(new Statement(data), loopsReductions); - fillReductionsFromComment(new Statement(data), loopsReductionsLoc); - } + fillPrivatesFromComment(new Statement(data), loopsPrivatesS); + for (auto& elem : loopsPrivatesS) + loopsPrivates.insert(elem->GetOriginal()->identifier()); + fillReductionsFromComment(new Statement(data), loopsReductions); + fillReductionsFromComment(new Statement(data), loopsReductionsLoc); } + } - for (auto &elem : loopsReductions) + for (auto &elem : loopsReductions) + { + for (auto &setElem : elem.second) { - for (auto &setElem : elem.second) - { - loopsPrivates.insert(setElem->GetOriginal()->identifier()); - loopsRedUnited.insert(setElem->GetOriginal()->identifier()); - } + loopsPrivates.insert(setElem->GetOriginal()->identifier()); + loopsRedUnited.insert(setElem->GetOriginal()->identifier()); } + } - for (auto &elem : loopsReductionsLoc) + for (auto &elem : loopsReductionsLoc) + { + for (auto &setElem : elem.second) { - for (auto &setElem : elem.second) - { - loopsPrivates.insert(get<0>(setElem)->GetOriginal()->identifier()); - loopsPrivates.insert(get<1>(setElem)->GetOriginal()->identifier()); - loopsRedUnited.insert(get<0>(setElem)->GetOriginal()->identifier()); - loopsRedUnited.insert(get<1>(setElem)->GetOriginal()->identifier()); - } + loopsPrivates.insert(get<0>(setElem)->GetOriginal()->identifier()); + loopsPrivates.insert(get<1>(setElem)->GetOriginal()->identifier()); + loopsRedUnited.insert(get<0>(setElem)->GetOriginal()->identifier()); + loopsRedUnited.insert(get<1>(setElem)->GetOriginal()->identifier()); } + } - const string key = string(OriginalSymbol(currExp->symbol())->identifier()); - if (loopsPrivates.find(key) == loopsPrivates.end()) + const string key = string(OriginalSymbol(currExp->symbol())->identifier()); + if (loopsPrivates.find(key) == loopsPrivates.end()) + { + for (auto& loop : parentLoops) { - if (sharedMemoryParallelization == 0) - { - for (auto& loop : parentLoops) - { - __spf_print(1, "WARN: write to non distributed array '%s' in loop on line %d\n", symb->identifier(), loop->lineNumber()); + __spf_print(1, "WARN: write to non distributed array '%s' in loop on line %d\n", symb->identifier(), loop->lineNumber()); - wstring messageE, messageR; - __spf_printToLongBuf(messageE, L"write to non distributed array '%s' in this loop", to_wstring(symb->identifier()).c_str()); + wstring messageE, messageR; + __spf_printToLongBuf(messageE, L"write to non distributed array '%s' in this loop", to_wstring(symb->identifier()).c_str()); - __spf_printToLongBuf(messageR, R61, to_wstring(symb->identifier()).c_str()); + __spf_printToLongBuf(messageR, R61, to_wstring(symb->identifier()).c_str()); - if (loop->lineNumber() > 0) - currMessages->push_back(Messages(WARR, loop->lineNumber(), messageR, messageE, 1026)); - sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true; - } - } + if (loop->lineNumber() > 0) + currMessages->push_back(Messages(WARR, loop->lineNumber(), messageR, messageE, 1026)); + sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true; } - //TODO: this case looks strange - /*else if (loopsRedUnited.find(key) == loopsRedUnited.end()) + } + + if (loopsPrivates.find(key) != loopsPrivates.end() || loopsRedUnited.find(key) != loopsRedUnited.end()) + { + auto currOrigArrayS = OriginalSymbol(currExp->symbol()); + if (currOrigArrayS->type()->variant() == T_ARRAY) { - auto saveReg = currRegime; - currRegime = ARRAY_ACC_CORNER; - bool wasMapped = false; - map> tmpLoopInfo = loopInfo; - - vector matched = matchArrayToLoopSymbols(parentLoops, currExp, side, tmpLoopInfo, currLine, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls); - for (int z = 0; z < matched.size(); ++z) - wasMapped |= (matched[z] != 0); - - currRegime = saveReg; - - if (wasMapped) + DIST::Array* currArray = getArrayFromDeclarated(declaratedInStmt(currOrigArrayS), currOrigArrayS->identifier()); + checkNull(currArray, convertFileName(__FILE__).c_str(), __LINE__); { - if (sharedMemoryParallelization == 0) - { - int z = 0; - for (auto& loop : parentLoops) - { - if (tmpLoopInfo.find(loop) != tmpLoopInfo.end() && matched[z]) - { - wstring messageE, messageR; - __spf_printToLongBuf(messageE, L"write to non distributed array '%s' in this loop", to_wstring(symb->identifier()).c_str()); + set realArrayRefs; + getRealArrayRefs(currArray, currArray, realArrayRefs, arrayLinksByFuncCalls); - __spf_printToLongBuf(messageR, R60, to_wstring(symb->identifier()).c_str()); - - if (loop->lineNumber() > 0) - currMessages->push_back(Messages(WARR, loop->lineNumber(), messageR, messageE, 1026)); - sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true; - } - ++z; - } - } - } - } */ - - if (loopsPrivates.find(key) != loopsPrivates.end() || loopsRedUnited.find(key) != loopsRedUnited.end()) - { - auto currOrigArrayS = OriginalSymbol(currExp->symbol()); - if (currOrigArrayS->type()->variant() == T_ARRAY) - { - DIST::Array* currArray = getArrayFromDeclarated(declaratedInStmt(currOrigArrayS), currOrigArrayS->identifier()); - checkNull(currArray, convertFileName(__FILE__).c_str(), __LINE__); - { - set realArrayRefs; - getRealArrayRefs(currArray, currArray, realArrayRefs, arrayLinksByFuncCalls); - - for (auto& array : realArrayRefs) - array->SetPrivateInLoopStatus(true); - } + for (auto& array : realArrayRefs) + array->SetPrivateInLoopStatus(true); } } } @@ -1384,7 +1346,7 @@ static void convertOneLoop(LoopGraph *currLoop, mapidentifier(); - if (privateArrays.find(symbIdent) == privateArrays.end()) + if (privateArrays.find(symbIdent) == privateArrays.end() || sharedMemoryParallelization) { const tuple uniqKey = getUniqName(commonBlocks, decl, currentArray); @@ -1401,7 +1363,7 @@ static void convertOneLoop(LoopGraph *currLoop, mapsecond; - if (arrayToAdd->IsNotDistribute() == true) + if (!sharedMemoryParallelization && arrayToAdd->IsNotDistribute() == true) continue; set links; @@ -1609,8 +1571,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapsymbol()->identifier()] = modules[i]; map> privatesByModule; - for (int i = 0; i < modules.size(); ++i) - privatesByModule[modules[i]->symbol()->identifier()] = getPrivatesFromModule(modules[i], declaredArrays, declaratedArraysSt, modulesByName); + if(!sharedMemoryParallelization) + for (int i = 0; i < modules.size(); ++i) + privatesByModule[modules[i]->symbol()->identifier()] = getPrivatesFromModule(modules[i], declaredArrays, declaratedArraysSt, modulesByName); map funcByName; createMapOfFunc(AllfuncInfo, funcByName); @@ -1674,13 +1637,17 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapvariant() != GLOBAL) + if(!sharedMemoryParallelization) { - tmpModFind = tmpModFind->controlParent(); - if (tmpModFind->variant() == MODULE_STMT) - fillFromModule(tmpModFind->symbol(), privatesByModule, privatesVars); + SgStatement* tmpModFind = st; + while (tmpModFind->variant() != GLOBAL) + { + tmpModFind = tmpModFind->controlParent(); + if (tmpModFind->variant() == MODULE_STMT) + fillFromModule(tmpModFind->symbol(), privatesByModule, privatesVars); + } } + commonBlocks.clear(); getCommonBlocksRef(commonBlocks, st, st->lastNodeOfStmt()); __spf_print(PRINT_PROF_INFO, " number of common blocks %d\n", (int)commonBlocks.size()); @@ -1727,7 +1694,8 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapexpr(i), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars); @@ -1735,9 +1703,12 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapvariant(); if (currV == FOR_NODE) { - tryToFindPrivateInAttributes(st, privatesVars); - fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); - + if(!sharedMemoryParallelization) + { + tryToFindPrivateInAttributes(st, privatesVars); + fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); + } + set toAdd; tryToFindPrivateInAttributes(st, toAdd); @@ -1783,9 +1754,10 @@ void loopAnalyzer(SgFile *file, vector ®ions, map setDiff; - for (auto &privVars : privatesVars) - if (unitedPrivates.find(privVars) == unitedPrivates.end()) - setDiff.insert(privVars); + if(!sharedMemoryParallelization) + for (auto &privVars : privatesVars) + if (unitedPrivates.find(privVars) == unitedPrivates.end()) + setDiff.insert(privVars); allLoops[contrlParent->lineNumber()] = make_pair((SgForStmt*)contrlParent, make_pair(unitedPrivates, setDiff)); parentLoops.pop_back(); @@ -2084,14 +2056,18 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapsecond.begin(); it != itF->second.end(); ++it) - privatesVars.insert(*it); + if(!sharedMemoryParallelization) + for (auto it = itF->second.begin(); it != itF->second.end(); ++it) + privatesVars.insert(*it); } } else { - tryToFindPrivateInAttributes(st, privatesVars); - fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); + if(!sharedMemoryParallelization) + { + tryToFindPrivateInAttributes(st, privatesVars); + fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); + } if (isDVM_stat(st) == false && isSgExecutableStatement(st)) { @@ -2125,7 +2101,7 @@ void loopAnalyzer(SgFile *file, vector ®ions, map ®ions, map ®ions, map 0) @@ -2300,6 +2276,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, map, std::pair> attrType; namespace DIST = Distribution; -enum REGIME { DATA_DISTR, COMP_DISTR, REMOTE_ACC, ARRAY_ACC_CORNER, UNDEF }; +enum REGIME { DATA_DISTR, COMP_DISTR, REMOTE_ACC, ARRAY_ACC_CORNER, SHARED_MEMORY_PAR, UNDEF }; // loop_analyzer.cpp bool checkExistence(SgExpression *exp, const std::string& doName); diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index ae13641..5bf8626 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -562,9 +562,9 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne else if (curr_regime == LOOP_ANALYZER_NODIST) { auto& loopsInFile = getObjectForFileFromMap(file_name, loopGraph); - loopAnalyzerNoDist(file, parallelRegions, createdArrays, getObjectForFileFromMap(file_name, SPF_messages), + loopAnalyzer(file, parallelRegions, createdArrays, getObjectForFileFromMap(file_name, SPF_messages), SHARED_MEMORY_PAR, allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(), - &(loopsInFile)); + false, &(loopsInFile)); UniteNestedDirectives(loopsInFile); } -- 2.49.1 From 444f7e36bce3f2f0d9b85a9f32c3480cc6d93d75 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Fri, 5 Jul 2024 18:03:12 +0300 Subject: [PATCH 03/10] merge code of directives creation for general and shared memory cases --- .../directive_creator_base.cpp | 45 ++--- .../_src/Distribution/DvmhDirective.cpp | 168 +++++++++++------- .../_src/Distribution/DvmhDirectiveBase.cpp | 165 ++++++++--------- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 38 +--- 4 files changed, 207 insertions(+), 209 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp index d1ee848..32ab1a2 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp @@ -1843,10 +1843,10 @@ void selectParallelDirectiveForVariant(File* file, ParallelRegion* currParReg, const bool isMyRegion = loop->region == currParReg; const bool noUserDir = loop->userDvmDirective == NULL; DIST::Array* sameAlignTemplate = NULL; - const bool sameAligns = loop->isArrayTemplatesTheSame(sameAlignTemplate, regionId, arrayLinksByFuncCalls); + const bool sameAligns = sharedMemoryParallelization ? true : loop->isArrayTemplatesTheSame(sameAlignTemplate, regionId, arrayLinksByFuncCalls); bool freeLoopDistr = true; - if (hasDirective && loop->directive->arrayRef2->IsLoopArray()) + if (!sharedMemoryParallelization && hasDirective && loop->directive->arrayRef2->IsLoopArray()) { bool ok = false; for (auto& elem : distribution) @@ -1879,33 +1879,38 @@ void selectParallelDirectiveForVariant(File* file, ParallelRegion* currParReg, //try to unite loops if (createNestedLoops(loop, depInfoForLoopGraph, mapFuncInfo, messages)) parDirective = loop->recalculateParallelDirective(); - bool topCheck = isOnlyTopPerfect(loop, distribution); - - bool needToContinue = false; - if (topCheck) + + if(!sharedMemoryParallelization) { - // -> dims not mached - map> dimsNotMatch; - if (!checkCorrectness(*parDirective, distribution, reducedG, allArrays, arrayLinksByFuncCalls, loop->getAllArraysInLoop(), messages, loop->lineNum, dimsNotMatch, regionId)) - { - if (!tryToResolveUnmatchedDims(dimsNotMatch, loop, regionId, parDirective, reducedG, allArrays, arrayLinksByFuncCalls, distribution, mapFuncInfo)) - needToContinue = addRedistributionDirs(file, distribution, toInsert, loop, mapLoopsInFile, parDirective, regionId, messages, arrayLinksByFuncCalls, sameAlignTemplate); - } - } - else - needToContinue = addRedistributionDirs(file, distribution, toInsert, loop, mapLoopsInFile, parDirective, regionId, messages, arrayLinksByFuncCalls, sameAlignTemplate); + bool topCheck = isOnlyTopPerfect(loop, distribution); - if (needToContinue) - continue; + bool needToContinue = false; + if (topCheck) + { + // -> dims not mached + map> dimsNotMatch; + if (!checkCorrectness(*parDirective, distribution, reducedG, allArrays, arrayLinksByFuncCalls, loop->getAllArraysInLoop(), messages, loop->lineNum, dimsNotMatch, regionId)) + { + if (!tryToResolveUnmatchedDims(dimsNotMatch, loop, regionId, parDirective, reducedG, allArrays, arrayLinksByFuncCalls, distribution, mapFuncInfo)) + needToContinue = addRedistributionDirs(file, distribution, toInsert, loop, mapLoopsInFile, parDirective, regionId, messages, arrayLinksByFuncCalls, sameAlignTemplate); + } + } + else + needToContinue = addRedistributionDirs(file, distribution, toInsert, loop, mapLoopsInFile, parDirective, regionId, messages, arrayLinksByFuncCalls, sameAlignTemplate); + + if (needToContinue) + continue; + } vector> newRules; - constructRules(newRules, distribution, loop); + if(!sharedMemoryParallelization) + constructRules(newRules, distribution, loop); Directive* dirImpl = parDirective->genDirective(file, newRules, loop, reducedG, allArrays, regionId, arrayLinksByFuncCalls); #if __SPF //move label before loop - if (loop->hasRedistribute()) + if (!sharedMemoryParallelization && loop->hasRedistribute()) { auto prev = loop->loop->lexPrev(); if (!prev) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index cb8dbd9..a93544e 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -281,75 +281,102 @@ static vector for (int z = 0; z < loops.size(); ++z) { currLoop = loops[z]; - const uint64_t regId = sharedMemoryParallelization ? (uint64_t)currLoop : currLoop->region->GetId(); - auto dirForLoop = currLoop->directiveForLoop; - auto tmplP = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); - auto links = pairs.first->GetLinksWithTemplate(regId); - - // no mapping for this loop, skip this - if (tmplP == dirForLoop->arrayRef) + if(!sharedMemoryParallelization) { - for (int z = 0; z < links.size(); ++z) + const uint64_t regId = sharedMemoryParallelization ? (uint64_t)currLoop : currLoop->region->GetId(); + auto dirForLoop = currLoop->directiveForLoop; + + auto tmplP = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); + auto links = pairs.first->GetLinksWithTemplate(regId); + + // no mapping for this loop, skip this + if (tmplP == dirForLoop->arrayRef) { - int dim = links[z]; - if (dim >= 0) + for (int z = 0; z < links.size(); ++z) { - if (dirForLoop->on[dim].first != "*") + int dim = links[z]; + if (dim >= 0) { - needToAdd = true; - subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[dim].first)); - break; + if (dirForLoop->on[dim].first != "*") + { + needToAdd = true; + subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[dim].first)); + break; + } } } } - } - else if (pairs.second == dirForLoop->arrayRef) - { - for (int z = 0; z < dirForLoop->on.size(); ++z) - { - if (dirForLoop->on[z].first != "*") - { - needToAdd = true; - subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first)); - break; - } - } - } - else if (!dirForLoop->arrayRef->IsTemplate()) - { - set realRefsLocal; - getRealArrayRefs(dirForLoop->arrayRef, dirForLoop->arrayRef, realRefsLocal, arrayLinksByFuncCalls); - - if (realRefsLocal.size() == 0) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - auto tmplP = (*realRefsLocal.begin())->GetTemplateArray(regId, sharedMemoryParallelization != 0); - auto links = (*realRefsLocal.begin())->GetLinksWithTemplate(regId); - - auto tmplP_et = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); - auto links_et = pairs.first->GetLinksWithTemplate(regId); - - if (tmplP == tmplP_et) + else if (pairs.second == dirForLoop->arrayRef) { for (int z = 0; z < dirForLoop->on.size(); ++z) { if (dirForLoop->on[z].first != "*") - { - const int idx = links[z]; - for (int p = 0; p < links_et.size(); ++p) - { - if (idx >= 0 && links_et[p] == idx) - { - subs[p] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first)); - needToAdd = true; - break; - } - } + { + needToAdd = true; + subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first)); break; } } } + else if (!dirForLoop->arrayRef->IsTemplate()) + { + set realRefsLocal; + getRealArrayRefs(dirForLoop->arrayRef, dirForLoop->arrayRef, realRefsLocal, arrayLinksByFuncCalls); + + if (realRefsLocal.size() == 0) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + auto tmplP = (*realRefsLocal.begin())->GetTemplateArray(regId, sharedMemoryParallelization != 0); + auto links = (*realRefsLocal.begin())->GetLinksWithTemplate(regId); + + auto tmplP_et = pairs.first->GetTemplateArray(regId, sharedMemoryParallelization != 0); + auto links_et = pairs.first->GetLinksWithTemplate(regId); + + if (tmplP == tmplP_et) + { + for (int z = 0; z < dirForLoop->on.size(); ++z) + { + if (dirForLoop->on[z].first != "*") + { + const int idx = links[z]; + for (int p = 0; p < links_et.size(); ++p) + { + if (idx >= 0 && links_et[p] == idx) + { + subs[p] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first)); + needToAdd = true; + break; + } + } + break; + } + } + } + } + } + else + { + for (const auto& source : { currLoop->readOpsForLoop, currLoop->writeOpsForLoop }) { + auto array_it = source.find(pairs.second); + + if (array_it != source.end()) { + bool dim_found = false; + + for (int i = 0; i < array_it->second.size(); i++) { + if (array_it->second[i].coefficients.size() != 0) + { + needToAdd = true; + dim_found = true; + subs[i] = new SgVarRefExp(findSymbolOrCreate(file, currLoop->loopSymbol)); + break; + } + } + + if (dim_found) + break; + } + } } } @@ -477,7 +504,7 @@ ParallelDirective::genDirective(File* file, const vector& acrossOutAttribute = currLoop->acrossOutAttribute; const map, vector>>& readOps = currLoop->readOps; - map< DIST::Array*, vector>& remoteReads = currLoop->remoteRegularReads; + map>& remoteReads = currLoop->remoteRegularReads; Statement* loop = currLoop->loop; string directive = ""; @@ -501,6 +528,10 @@ ParallelDirective::genDirective(File* file, const vector allFiles = getAllFilesInProject(); + map arrayByName; + for (DIST::Array* arr : currLoop->getAllArraysInLoop()) + arrayByName[arr->GetName()] = arr; + for (int z = 0; z < nested; ++z) { loopSymbs.push_back(loopG->symbol()); @@ -552,21 +583,25 @@ ParallelDirective::genDirective(File* file, const vectorsetRhs(NULL); } - DIST::Array* mapTo = arrayRef2->IsLoopArray() ? arrayRef : arrayRef2; - auto onTo = arrayRef2->IsLoopArray() ? on : on2; - + DIST::Array* mapTo; dirStatement[2] = new Expression(expr); if (sharedMemoryParallelization) + { directive += ")"; + } else + { + mapTo = arrayRef2->IsLoopArray() ? arrayRef : arrayRef2; directive += ") ON " + mapTo->GetShortName() + "("; + } SgArrayRefExp* arrayExpr = NULL; string arrayExprS = ""; if (!sharedMemoryParallelization) { + auto onTo = arrayRef2->IsLoopArray() ? on : on2; SgSymbol* symbForPar = NULL; if (arrayRef->IsTemplate()) { @@ -729,10 +764,23 @@ ParallelDirective::genDirective(File* file, const vector, int>> shiftsByAccess; + DIST::Array* currArray = NULL; - DIST::Array* currArray = allArrays.GetArrayByName(across[i1].first.second); - if (currArray == NULL) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + if (!sharedMemoryParallelization) + { + currArray = allArrays.GetArrayByName(across[i1].first.second); + if (currArray == NULL) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + else + { + auto currArray_it = arrayByName.find(across[i1].first.second); + + if (currArray_it == arrayByName.end()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + currArray = currArray_it->second; + } bool isOut = acrossOutAttribute.find(currArray) != acrossOutAttribute.end(); string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp index f1c9f38..403044e 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp @@ -268,71 +268,30 @@ static inline string calculateShifts(DIST::GraphCSR &redu const uint64_t regionId, const map> &arrayLinksByFuncCalls) { - vector>> ruleForOn = - getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); + vector>> ruleForOn, ruleForShadow; - vector>> ruleForShadow = - getAlignRuleWithTemplate(calcForArray, arrayLinksByFuncCalls, reducedG, allArrays, regionId); + if (!sharedMemoryParallelization) + { + ruleForOn = getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); + ruleForShadow = getAlignRuleWithTemplate(calcForArray, arrayLinksByFuncCalls, reducedG, allArrays, regionId); + } string out = ""; // check for distributed and not mapped dims -> zero them out ('coeffs.second') set refs; getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls); - - if (sharedMemoryParallelization == 0) - {//TODO: need to correct errors - /*for (auto& array : refs) - { - DIST::Array* tmpl = array->GetTemplateArray(regionId); - checkNull(tmpl, convertFileName(__FILE__).c_str(), __LINE__); - - auto align = array->GetLinksWithTemplate(regionId); - - bool found = false; - for (auto& t : distribution) - { - if (t.first == tmpl) - { - found = true; - - for (int aDim = 0; aDim < align.size(); ++aDim) - { - int link = align[aDim]; - if (link != -1) - { - int tLink = link; - if (!arrayRef->IsTemplate()) - { - auto alignMain = arrayRef->GetLinksWithTemplate(regionId); - for (int z = 0; z < alignMain.size(); ++z) - if (alignMain[z] == tLink) - tLink = z; - } - - if (t.second->distRule[link] == dist::BLOCK && baseOnRule[aDim].first == "*") - { - for (int z = 0; z < coeffs.second.size(); ++z) - coeffs.second[z].first = coeffs.second[z].second = 0; - return out; - } - } - } - } - } - - if (!found) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } */ - } - + const pair, vector> *currReadOp = NULL; auto readIt = readOps.find(calcForArray); if (readIt != readOps.end()) currReadOp = &(readIt->second); - findAndReplaceDimentions(ruleForOn, allArrays); - findAndReplaceDimentions(ruleForShadow, allArrays); - + if(!sharedMemoryParallelization) + { + findAndReplaceDimentions(ruleForOn, allArrays); + findAndReplaceDimentions(ruleForShadow, allArrays); + } + const int len = (int)coeffs.second.size(); vector> shift(len); @@ -352,7 +311,20 @@ static inline string calculateShifts(DIST::GraphCSR &redu // no unrecognized read operations if (currReadOp->second[k] == false) { - if (get<0>(ruleForShadow[k]) != NULL) + if (sharedMemoryParallelization) + { + for (auto& coefs : currReadOp->first[k].coefficients) + { + auto currAccess = coefs.first; + + const int currShift = coefs.first.second; + + auto itFound = shiftsByAccess[k].find(currAccess); + if (itFound == shiftsByAccess[k].end()) + itFound = shiftsByAccess[k].insert(itFound, make_pair(currAccess, currShift)); + } + } + else if (get<0>(ruleForShadow[k]) != NULL) { const pair currRuleShadow = get<2>(ruleForShadow[k]); @@ -451,22 +423,25 @@ static inline string calculateShifts(DIST::GraphCSR &redu } } - if (coeffs.second[k].first + shift[k].first < 0) - shift[k].first = -coeffs.second[k].first; - - if (coeffs.second[k].second + shift[k].second < 0) - shift[k].second = -coeffs.second[k].second; - - if (isAcross) + if(!sharedMemoryParallelization) { - if (coeffs.second[k] == make_pair(0, 0)) - shift[k] = make_pair(0, 0); - } - else if (isNonDistributedDim(ruleForOn, ruleForShadow, k, distribution, parallelOnRule)) - { - shift[k].first = -coeffs.second[k].first; - shift[k].second = -coeffs.second[k].second; - shiftsByAccess[k].clear(); + if (coeffs.second[k].first + shift[k].first < 0) + shift[k].first = -coeffs.second[k].first; + + if (coeffs.second[k].second + shift[k].second < 0) + shift[k].second = -coeffs.second[k].second; + + if (isAcross) + { + if (coeffs.second[k] == make_pair(0, 0)) + shift[k] = make_pair(0, 0); + } + else if (isNonDistributedDim(ruleForOn, ruleForShadow, k, distribution, parallelOnRule)) + { + shift[k].first = -coeffs.second[k].first; + shift[k].second = -coeffs.second[k].second; + shiftsByAccess[k].clear(); + } } sprintf(buf, "%d:%d", coeffs.second[k].first + shift[k].first, coeffs.second[k].second + shift[k].second); @@ -500,34 +475,37 @@ string ParallelDirective::genBounds(pair, vectorIsTemplate() == false && sharedMemoryParallelization == 0) + + if(!sharedMemoryParallelization) { - vector>> ruleForRef = - getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); - findAndReplaceDimentions(ruleForRef, allArrays); - - on_ext.clear(); - for (int i = 0; i < ruleForRef.size(); ++i) + //replace to template align ::on + if (arrayRef->IsTemplate() == false) { - if (get<0>(ruleForRef[i])) + vector>> ruleForRef = + getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); + findAndReplaceDimentions(ruleForRef, allArrays); + + on_ext.clear(); + for (int i = 0; i < ruleForRef.size(); ++i) { - on_ext.resize(get<0>(ruleForRef[i])->GetDimSize()); - break; + if (get<0>(ruleForRef[i])) + { + on_ext.resize(get<0>(ruleForRef[i])->GetDimSize()); + break; + } } + if (on_ext.size() == 0) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + std::fill(on_ext.begin(), on_ext.end(), make_pair("*", make_pair(0, 0))); + + for (int i = 0; i < ruleForRef.size(); ++i) + if (get<0>(ruleForRef[i])) + on_ext[get<1>(ruleForRef[i])] = on[i]; } - if (on_ext.size() == 0) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - std::fill(on_ext.begin(), on_ext.end(), make_pair("*", make_pair(0, 0))); - - for (int i = 0; i < ruleForRef.size(); ++i) - if (get<0>(ruleForRef[i])) - on_ext[get<1>(ruleForRef[i])] = on[i]; - } - - //replace single dim to key word 'SINGLE' - for (int i = 0; i < on_ext.size(); ++i) + //replace single dim to key word 'SINGLE' + for (int i = 0; i < on_ext.size(); ++i) { if (on_ext[i].first != "*") { @@ -535,8 +513,9 @@ string ParallelDirective::genBounds(pair, vector mapLoopsInFile; - createMapLoopGraph(loopsInFile, mapLoopsInFile); - - map mapFuncInfo; - createMapOfFunc(allFuncInfo, mapFuncInfo); - - for (int z = 0; z < parallelRegions.size(); ++z) - { - vector toInsert; - - DIST::Arrays& allArrays = parallelRegions[z]->GetAllArraysToModify(); - - map depInfoForLoopGraphV; - for (auto& elem : depInfoForLoopGraph) - depInfoForLoopGraphV[elem.first] = elem.second; - - selectParallelDirectiveForVariantNoDist(new File(file), parallelRegions[z], allArrays, loopsInFile, mapLoopsInFile, mapFuncInfo, - toInsert, arrayLinksByFuncCalls, depInfoForLoopGraphV, getObjectForFileFromMap(file_name, SPF_messages)); - - if (toInsert.size() > 0) - { - auto it = createdDirectives.find(file_name); - if (it == createdDirectives.end()) - createdDirectives.insert(it, make_pair(file_name, toInsert)); - else - for (int m = 0; m < toInsert.size(); ++m) - it->second.push_back(toInsert[m]); - } - } - } else if (curr_regime == INSERT_SHADOW_DIRS || curr_regime == EXTRACT_SHADOW_DIRS) { const bool extract = (curr_regime == EXTRACT_SHADOW_DIRS); @@ -2139,7 +2105,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam string additionalName = (consoleMode && folderName == NULL) ? "__shared" : ""; - runAnalysis(*project, INSERT_PARALLEL_DIRS_NODIST, false); + runAnalysis(*project, CREATE_PARALLEL_DIRS, false); runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName); -- 2.49.1 From 3cb6f6dd5c72add9545978f4aa667d5a8ebdab70 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sat, 6 Jul 2024 14:27:00 +0300 Subject: [PATCH 04/10] shared memory parallelization: remove duplicated code --- sapfor/experts/Sapfor_2017/CMakeLists.txt | 8 - .../directive_creator_base_nodist.cpp | 166 ----- .../directive_creator_nodist.h | 26 - .../_src/Distribution/DvmhDirective.cpp | 97 ++- .../_src/Distribution/DvmhDirective.h | 4 - .../Distribution/DvmhDirectiveBase_nodist.cpp | 96 --- .../Distribution/DvmhDirective_internal.h | 17 - .../Distribution/DvmhDirective_nodist.cpp | 477 ------------- .../_src/LoopAnalyzer/loop_analyzer.cpp | 70 +- .../LoopAnalyzer/loop_analyzer_internal.h | 70 -- .../LoopAnalyzer/loop_analyzer_nodist.cpp | 667 ------------------ .../_src/LoopAnalyzer/loop_analyzer_nodist.h | 13 - sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 2 - 13 files changed, 108 insertions(+), 1605 deletions(-) delete mode 100644 sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base_nodist.cpp delete mode 100644 sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_nodist.h delete mode 100644 sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase_nodist.cpp delete mode 100644 sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_internal.h delete mode 100644 sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_nodist.cpp delete mode 100644 sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_internal.h delete mode 100644 sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp delete mode 100644 sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.h diff --git a/sapfor/experts/Sapfor_2017/CMakeLists.txt b/sapfor/experts/Sapfor_2017/CMakeLists.txt index 7e5220f..6c70baf 100644 --- a/sapfor/experts/Sapfor_2017/CMakeLists.txt +++ b/sapfor/experts/Sapfor_2017/CMakeLists.txt @@ -240,8 +240,6 @@ set(DIRA _src/DirectiveProcessing/directive_analyzer.cpp _src/DirectiveProcessing/directive_creator.cpp _src/DirectiveProcessing/directive_creator_base.cpp _src/DirectiveProcessing/directive_creator.h - _src/DirectiveProcessing/directive_creator_base_nodist.cpp - _src/DirectiveProcessing/directive_creator_nodist.h _src/DirectiveProcessing/directive_parser.cpp _src/DirectiveProcessing/directive_parser.h _src/DirectiveProcessing/directive_omp_parser.cpp @@ -266,11 +264,8 @@ set(DISTR _src/Distribution/Array.cpp _src/Distribution/Distribution.h _src/Distribution/DvmhDirective.cpp _src/Distribution/DvmhDirective.h - _src/Distribution/DvmhDirective_nodist.cpp - _src/Distribution/DvmhDirective_internal.h _src/Distribution/DvmhDirective_func.h _src/Distribution/DvmhDirectiveBase.cpp - _src/Distribution/DvmhDirectiveBase_nodist.cpp _src/Distribution/DvmhDirectiveBase.h _src/Distribution/GraphCSR.cpp _src/Distribution/GraphCSR.h) @@ -319,9 +314,6 @@ set(INLINER _src/Inliner/inliner.cpp set(LOOP_ANALYZER _src/LoopAnalyzer/allocations_prepoc.cpp _src/LoopAnalyzer/dep_analyzer.cpp _src/LoopAnalyzer/loop_analyzer.cpp - _src/LoopAnalyzer/loop_analyzer_nodist.cpp - _src/LoopAnalyzer/loop_analyzer_nodist.h - _src/LoopAnalyzer/loop_analyzer_internal.h _src/LoopAnalyzer/loop_analyzer.h) set(RENAME_SYMBOLS _src/RenameSymbols/rename_symbols.cpp diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base_nodist.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base_nodist.cpp deleted file mode 100644 index 9febb79..0000000 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base_nodist.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "../Utils/leak_detector.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "../ParallelizationRegions/ParRegions.h" -#include "../Distribution/Arrays.h" -#include "../Transformations/loop_transform.h" - -#include "../Utils/errors.h" -#include "directive_parser.h" -#include "directive_creator.h" -#include "directive_creator_nodist.h" - -#define PRINT_PROF_INFO 1 -#define PRINT_DIR_RESULT 0 - -using std::vector; -using std::pair; -using std::tuple; -using std::map; -using std::set; -using std::make_pair; -using std::make_tuple; -using std::get; -using std::string; -using std::wstring; - - -void createParallelDirectivesNoDist(const map> &loopInfos, - const vector& regions, - const map> &arrayLinksByFuncCalls, - vector &messages) -{ - for (auto &loopInfo : loopInfos) - { - LoopGraph* currLoop = loopInfo.first; - ParallelRegion *currReg = getRegionByLine(regions, currLoop->fileName.c_str(), currLoop->lineNum); - if (currReg == NULL || currLoop->userDvmDirective != NULL) - { - __spf_print(PRINT_PROF_INFO, "Skip loop on file %s and line %d\n", currLoop->fileName.c_str(), currLoop->lineNum); - continue; - } - - const int itersCount = currLoop->calculatedCountOfIters; - uint64_t regId = (uint64_t)currLoop; - - const DIST::Arrays &allArrays = currReg->GetAllArrays(); - - vector, vector>>> acrossInfo; - fillAcrossInfoFromDirectives(currLoop, acrossInfo); - bool hasConflict = false; - // uniqKey -> pair> ///write acceses /// - map>, DIST::ArrayComparator> arrayWriteAcc; - set acrossOutArrays; - - __spf_print(PRINT_DIR_RESULT, " Loop on line %d:\n", currLoop->lineNum); - - const map &currAccesses = loopInfo.second; - // find conflict and fill arrayWriteAcc - hasConflict = checkForConflict(currAccesses, currLoop, arrayWriteAcc, acrossInfo, acrossOutArrays); - if (hasConflict) - __spf_print(PRINT_DIR_RESULT, " has conflict\n"); - else - { - if (!currLoop->hasLimitsToParallel() && - (currLoop->lineNum > 0 || (currLoop->lineNum < 0 && currLoop->altLineNum > 0))) - { - ParallelDirective* parDir = new ParallelDirective(); -#if __SPF - parDir->langType = LANG_F; -#else - parDir->langType = LANG_C; -#endif - parDir->line = currLoop->lineNum; - parDir->col = 0; - parDir->file = currLoop->fileName; - - fillInfoFromDirectives(currLoop, parDir); - - - parDir->parallel.push_back(currLoop->loopSymbol); - - currLoop->directive = parDir; - - currLoop->acrossOutAttribute.insert(acrossOutArrays.begin(), acrossOutArrays.end()); - - addShadowFromAnalysis(parDir, currAccesses); - currLoop->directiveForLoop = new ParallelDirective(*currLoop->directive); - - __spf_print(PRINT_DIR_RESULT, " directive created\n"); - } - } - } -} - - -void selectParallelDirectiveForVariantNoDist(File* file, ParallelRegion* currParReg, - DIST::Arrays& allArrays, - const vector& loopGraph, - const map& mapLoopsInFile, - const map& mapFuncInfo, - vector& toInsert, - const map>& arrayLinksByFuncCalls, - const map& depInfoForLoopGraph, - vector& messages) -{ - for (int i = 0; i < loopGraph.size(); ++i) - { - LoopGraph* loop = loopGraph[i]; - const bool hasDirective = loop->directive; - const bool noLimits = loop->hasLimitsToParallel() == false; - const bool isMyRegion = loop->region == currParReg; - const bool noUserDir = loop->userDvmDirective == NULL; - - if (hasDirective && noLimits && isMyRegion && noUserDir) - { - if (loop->perfectLoop >= 1) - { - ParallelDirective* parDirective = loop->directive; - parDirective->cloneOfTemplate = ""; - - //try to unite loops - if (createNestedLoops(loop, depInfoForLoopGraph, mapFuncInfo, messages)) - parDirective = loop->recalculateParallelDirective(); - // rewrite bool topCheck = isOnlyTopPerfect(loop, distribution); - - Directive* dirImpl = parDirective->genDirectiveNoDist(file, loop, allArrays, arrayLinksByFuncCalls); - -#if __SPF - //move label before loop - if(loop->lineNum > 0) - moveLabelBefore(loop->loop); - - // check correctness - if (loop->lineNum < 0) - { - if (loop->altLineNum == -1) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - SgStatement* local = NULL; - local = SgStatement::getStatementByFileAndLine(loop->loop->fileName(), loop->lineNum); - if (local == NULL) - local = SgStatement::getStatementByFileAndLine(loop->loop->fileName(), loop->altLineNum); - checkNull(local, convertFileName(__FILE__).c_str(), __LINE__); - } -#endif - toInsert.push_back(dirImpl); - } - } - else //TODO: add checker for indexing in this loop - { - if (loopGraph[i]->children.size() != 0) - selectParallelDirectiveForVariantNoDist(file, currParReg, allArrays, loopGraph[i]->children, mapLoopsInFile, mapFuncInfo, - toInsert, arrayLinksByFuncCalls,depInfoForLoopGraph, messages); - } - } -} - -#undef PRINT_PROF_INFO -#undef PRINT_DIR_RESULT \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_nodist.h b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_nodist.h deleted file mode 100644 index 22e04ec..0000000 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_nodist.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "../Distribution/Distribution.h" -#include "../Utils/errors.h" -#include "../GraphLoop/graph_loops.h" -#include "../Utils/types.h" - -void createParallelDirectivesNoDist(const std::map>& loopInfos, - const std::vector& regions, - const std::map>& arrayLinksByFuncCalls, - std::vector& messages); - -void selectParallelDirectiveForVariantNoDist(File* file, ParallelRegion* currParReg, - DIST::Arrays& allArrays, - const std::vector& loopGraph, - const std::map& mapLoopsInFile, - const std::map& mapFuncInfo, - std::vector& toInsert, - const std::map>& arrayLinksByFuncCalls, - const std::map& depInfoForLoopGraph, - std::vector& messages); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index a93544e..b866a67 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -9,7 +9,6 @@ #include "../Utils/types.h" #include "DvmhDirective.h" -#include "DvmhDirective_internal.h" #include "../Utils/errors.h" #include "../Utils/SgUtils.h" #include "../Sapfor.h" @@ -75,7 +74,7 @@ static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray, return res; } -bool needCorner(const DIST::Array* currArray, const vector, int>> &shiftsByAccess, Statement *loop) +static bool needCorner(const DIST::Array* currArray, const vector, int>> &shiftsByAccess, Statement *loop) { bool need = false; @@ -93,7 +92,6 @@ bool needCorner(const DIST::Array* currArray, const vector, i return need; } - vector genSubscripts(const vector> &shadowRenew, const vector> &shadowRenewShifts) { vector subs; @@ -174,7 +172,7 @@ static SgExpression* genSgExpr(SgFile *file, const string &letter, const pair setToMapWithSortByStr(const set &setIn) +static std::multimap setToMapWithSortByStr(const set &setIn) { std::multimap retMap; for (auto& elem : setIn) @@ -207,7 +205,7 @@ static set fillUsedSymbols(SgStatement *loop) return usedS; } -SgStatement* getRealStat(const char *file, const int line, const int altLine) +static SgStatement* getRealStat(const char *file, const int line, const int altLine) { SgStatement* local = SgStatement::getStatementByFileAndLine(file, line); if (local == NULL) @@ -216,7 +214,7 @@ SgStatement* getRealStat(const char *file, const int line, const int altLine) return local; } -string correctSymbolModuleName(const string& origFull) +static string correctSymbolModuleName(const string& origFull) { auto it = origFull.find("::"); if (it == string::npos) @@ -225,7 +223,7 @@ string correctSymbolModuleName(const string& origFull) return origFull.substr(it + 2); } -SgStatement* getModuleScope(const string& origFull, vector& moduleList, SgStatement *local) +static SgStatement* getModuleScope(const string& origFull, vector& moduleList, SgStatement *local) { auto it = origFull.find("::"); if (it == string::npos) @@ -249,7 +247,9 @@ static vector { vector tieList; vector> realRefsUsed; - for (auto& elem : currLoop->usedArrays) + + const auto& usedArrays = sharedMemoryParallelization ? currLoop->usedArraysAll : currLoop->usedArrays; + for (auto& elem : usedArrays) { if (onlyFor.size()) if (onlyFor.find(elem) == onlyFor.end()) @@ -392,7 +392,7 @@ static vector } //TODO: need to improve -set fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine) +static set fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine) { set used; set usedInSpfPar; @@ -412,7 +412,7 @@ set fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altL return usedInSpfPar; } -set changeLoopOrder(const vector& parallel, const vector& newParallel, vector& loops) +static set changeLoopOrder(const vector& parallel, const vector& newParallel, vector& loops) { set additionalPrivates; if (parallel == newParallel) @@ -479,7 +479,7 @@ set changeLoopOrder(const vector& parallel, const vector sortShadow(const vector, vector>>>& toSort) +static vector sortShadow(const vector, vector>>>& toSort) { map order; for (int z = 0; z < toSort.size(); ++z) @@ -687,52 +687,49 @@ ParallelDirective::genDirective(File* file, const vectorsetLhs(makeExprList(list)); } - if (sharedMemoryParallelization || across.size() != 0) + if (sharedMemoryParallelization || (across.size() != 0 && !arrayRef2->IsLoopArray())) { - if (!arrayRef2->IsLoopArray()) + vector loopsTie; + for (int i = 0; i < (int)parallel.size(); ++i) + if (parallel[i] != "*") + loopsTie.push_back(loops[i]); + + set onlyFor; + if (sharedMemoryParallelization == 0 && across.size()) { - vector loopsTie; - for (int i = 0; i < (int)parallel.size(); ++i) - if (parallel[i] != "*") - loopsTie.push_back(loops[i]); - - set onlyFor; - if (sharedMemoryParallelization == 0 && across.size()) + for (int k = 0; k < (int)across.size(); ++k) { - for (int k = 0; k < (int)across.size(); ++k) - { - DIST::Array* currArray = allArrays.GetArrayByName(across[k].first.second); - if (currArray != mapTo) - onlyFor.insert(currArray); - } + DIST::Array* currArray = allArrays.GetArrayByName(across[k].first.second); + if (currArray != mapTo) + onlyFor.insert(currArray); } - vector tieList; - if (sharedMemoryParallelization) - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); - else if (onlyFor.size()) // not MPI regime - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); + } + vector tieList; + if (sharedMemoryParallelization) + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); + else if (onlyFor.size()) // not MPI regime + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); - if (tieList.size()) + if (tieList.size()) + { + if (dirStatement[1] != NULL) { - if (dirStatement[1] != NULL) - { - expr = createAndSetNext(RIGHT, EXPR_LIST, expr); - p = expr; - } - p = createAndSetNext(LEFT, ACC_TIE_OP, p); - p->setLhs(makeExprList(tieList)); - - directive += ", TIE("; - int k = 0; - for (auto& tieL : tieList) - { - if (k != 0) - directive += ","; - directive += tieL->unparse(); - ++k; - } - directive += ")"; + expr = createAndSetNext(RIGHT, EXPR_LIST, expr); + p = expr; } + p = createAndSetNext(LEFT, ACC_TIE_OP, p); + p->setLhs(makeExprList(tieList)); + + directive += ", TIE("; + int k = 0; + for (auto& tieL : tieList) + { + if (k != 0) + directive += ","; + directive += tieL->unparse(); + ++k; + } + directive += ")"; } } diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h index 03c9623..5e72048 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h @@ -143,10 +143,6 @@ public: const uint64_t regionId, const std::map> &arrayLinksByFuncCalls); - Directive* - genDirectiveNoDist(File* file, LoopGraph* currLoop, DIST::Arrays& allArrays, - const std::map>& arrayLinksByFuncCalls); - friend ParallelDirective* operator+(const ParallelDirective &first, const ParallelDirective &second); ~ParallelDirective() diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase_nodist.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase_nodist.cpp deleted file mode 100644 index f8415c2..0000000 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase_nodist.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "../Utils/leak_detector.h" - -#include -#include -#include -#include -#include - -#include "DvmhDirective.h" -#include "../Distribution/Array.h" -#include "../Distribution/Arrays.h" -#include "../Distribution/GraphCSR.h" -#include "../Utils/errors.h" -#include "../Utils/utils.h" -#include "../GraphCall/graph_calls_func.h" - -using std::vector; -using std::string; -using std::pair; -using std::set; -using std::map; - - -static inline string calculateShiftsNoDist( - DIST::Array* arrayRef, DIST::Array* calcForArray, - pair, vector>>& coeffs, - vector>& shifts, - vector, int>>& shiftsByAccess, - const map, vector>>& readOps, - const map>& arrayLinksByFuncCalls) -{ - string out = ""; - // check for distributed and not mapped dims -> zero them out ('coeffs.second') - set refs; - getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls); - - const pair, vector>* currReadOp = NULL; - auto readIt = readOps.find(calcForArray); - if (readIt != readOps.end()) - currReadOp = &(readIt->second); - - const int len = (int)coeffs.second.size(); - - bool allZero = true; - for (int k = 0; k < len; ++k) - { - shiftsByAccess.push_back(map, int>()); - - if (k != 0) - out += ","; - char buf[256]; - - // calculate correct shifts from readOp info - if (currReadOp) - { - // no unrecognized read operations - if (currReadOp->second[k] == false) - { - for (auto& coefs : currReadOp->first[k].coefficients) - { - auto currAccess = coefs.first; - - const int currShift = coefs.first.second; - - auto itFound = shiftsByAccess[k].find(currAccess); - if (itFound == shiftsByAccess[k].end()) - itFound = shiftsByAccess[k].insert(itFound, make_pair(currAccess, currShift)); - } - } - } - - sprintf(buf, "%d:%d", coeffs.second[k].first, coeffs.second[k].second); - shifts[k] = {0, 0}; - - if (coeffs.second[k].first != 0 || coeffs.second[k].second != 0) - allZero = false; - out += buf; - } - - if (allZero) - return ""; - else - return out; -} - -string ParallelDirective::genBoundsNoDist(pair, vector>>& shadowOp, - vector>& shadowOpShift, - DIST::Array* currArray, - const map, vector>>& readOps, - set& arraysInAcross, - vector, int>>& shiftsByAccess, - const map>& arrayLinksByFuncCalls) const -{ - arraysInAcross.insert(currArray); - return calculateShiftsNoDist(arrayRef, currArray, shadowOp, shadowOpShift, shiftsByAccess, readOps, arrayLinksByFuncCalls); -} diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_internal.h b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_internal.h deleted file mode 100644 index 53a3233..0000000 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_internal.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -#include -#include - - -std::vector sortShadow(const std::vector, std::vector>>>& toSort); -std::set changeLoopOrder(const std::vector& parallel, const std::vector& newParallel, std::vector& loops); -std::set fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine); -SgStatement* getModuleScope(const std::string& origFull, std::vector& moduleList, SgStatement* local); -std::string correctSymbolModuleName(const std::string& origFull); -SgStatement* getRealStat(const char* file, const int line, const int altLine); -std::multimap setToMapWithSortByStr(const std::set& setIn); -bool needCorner(const DIST::Array* currArray, const std::vector, int>>& shiftsByAccess, Statement* loop); - diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_nodist.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_nodist.cpp deleted file mode 100644 index c25ad4d..0000000 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective_nodist.cpp +++ /dev/null @@ -1,477 +0,0 @@ -#include "../Utils/leak_detector.h" - -#include -#include -#include -#include -#include -#include - -#include "../Utils/types.h" -#include "DvmhDirective.h" -#include "DvmhDirective_func.h" -#include "DvmhDirective_internal.h" -#include "../Utils/errors.h" -#include "../Utils/SgUtils.h" -#include "../Sapfor.h" -#include "../GraphCall/graph_calls_func.h" - -#include "dvm.h" - -using std::vector; -using std::tuple; -using std::get; -using std::string; -using std::pair; -using std::set; -using std::map; - -using std::make_pair; - -static vector -compliteTieListNoDist(const LoopGraph* currLoop, - const set& privates, - const vector& loops, - const map>& arrayLinksByFuncCalls, - const map>& byUseInFunc, - File* file, const pair& lineRange) -{ - vector tieList; - - if (currLoop->usedArraysAll.size() == 0) - return tieList; - - SgVarRefExp* zeroS = new SgVarRefExp(findSymbolOrCreate(file, "*")); - - for (auto& elem : currLoop->usedArraysAll) - { - if (privates.find(elem->GetShortName()) != privates.end()) - continue; - - auto type = elem->GetDeclSymbol(currLoop->fileName, lineRange, getAllFilesInProject())->GetOriginal()->type(); - SgSymbol* arrayS = getFromModule(byUseInFunc, findSymbolOrCreate(file, elem->GetShortName(), type)); - SgArrayRefExp* array = new SgArrayRefExp(*arrayS); - bool needToAdd = false; - - vector subs; - for (int k = 0; k < elem->GetDimSize(); ++k) - subs.push_back(&zeroS->copy()); - - for (int z = 0; z < loops.size(); ++z) - { - currLoop = loops[z]; - - for (const auto& source : { currLoop->readOpsForLoop, currLoop->writeOpsForLoop }) { - auto array_it = source.find(elem); - - if (array_it != source.end()) { - bool dim_found = false; - - for (int i = 0; i < array_it->second.size(); i++) { - if (array_it->second[i].coefficients.size() != 0) - { - needToAdd = true; - dim_found = true; - subs[i] = new SgVarRefExp(findSymbolOrCreate(file, currLoop->loopSymbol)); - break; - } - } - - if (dim_found) - break; - } - } - } - - if (needToAdd) - { - for (int k = 0; k < subs.size(); ++k) - array->addSubscript(*subs[k]); - tieList.push_back(array); - } - } - - return tieList; -} - -Directive* -ParallelDirective::genDirectiveNoDist(File* file, LoopGraph* currLoop, DIST::Arrays& allArrays, - const map>& arrayLinksByFuncCalls) -{ - const set& acrossOutAttribute = currLoop->acrossOutAttribute; - const map, vector>>& readOps = currLoop->readOps; - map< DIST::Array*, vector>& remoteReads = currLoop->remoteRegularReads; - - Statement* loop = currLoop->loop; - string directive = ""; - vector dirStatement = { NULL, NULL, NULL }; - - SgForStmt* loopG = (SgForStmt*)loop->GetOriginal(); - - vector moduleList; - findModulesInFile(file, moduleList); - - SgStatement* realStat = getRealStat(file->filename(), currLoop->lineNum, currLoop->altLineNum); - SgStatement* parentFunc = getFuncStat(realStat); - const map> byUseInFunc = moduleRefsByUseInFunction(realStat); - const int nested = countPerfectLoopNest(loopG); - const pair lineRange = make_pair(parentFunc->lineNumber(), parentFunc->lastNodeOfStmt()->lineNumber()); - const string& filename = currLoop->fileName; - - vector loopSymbs; - vector loops; - LoopGraph* pLoop = currLoop; - const set allFiles = getAllFilesInProject(); - - map arrayByName; - for (DIST::Array* arr : currLoop->getAllArraysInLoop()) - arrayByName[arr->GetName()] = arr; - - for (int z = 0; z < nested; ++z) - { - loopSymbs.push_back(loopG->symbol()); - auto next = loopG->lexNext(); - auto attrSpfPar = getAttributes(next, set{ SPF_PARAMETER_OP }); - while (attrSpfPar.size() != 0 && next) - { - next = next->lexNext(); - attrSpfPar = getAttributes(next, set{ SPF_PARAMETER_OP }); - } - - if (next->variant() != FOR_NODE && z + 1 < nested) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - loopG = (SgForStmt*)next; - - loops.push_back(pLoop); - if (pLoop->children.size()) - pLoop = pLoop->children[0]; - } - - SgExpression* expr = new SgExpression(EXPR_LIST); - SgExpression* p = expr; - - directive += "!DVM$ PARALLEL("; - //filter parallel - vector filteredParalel; - for (int i = 0; i < (int)parallel.size(); ++i) - if (parallel[i] != "*") - filteredParalel.push_back(parallel[i]); - set privatesAfterSwap = changeLoopOrder(parallel, filteredParalel, loops); - - for (int i = 0; i < (int)filteredParalel.size(); ++i) - { - if (filteredParalel[i] == "*") - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - if (i == 0) - directive += filteredParalel[i]; - else - directive += "," + filteredParalel[i]; - - SgVarRefExp* tmp = NULL; - tmp = new SgVarRefExp(findSymbolOrCreate(file, filteredParalel[i])); - - p->setLhs(tmp); - if (i != (int)filteredParalel.size() - 1) - p = createAndSetNext(RIGHT, EXPR_LIST, p); - else - p->setRhs(NULL); - } - - dirStatement[2] = new Expression(expr); - - directive += ")"; - - SgArrayRefExp* arrayExpr = NULL; - string arrayExprS = ""; - - expr = new SgExpression(EXPR_LIST); - p = expr; - - dirStatement[1] = NULL; - - set uniqNamesOfPrivates; - for (auto& elem : privates) - uniqNamesOfPrivates.insert(elem->identifier()); - - auto unitedPrivates = privates; - for (auto& elem : privatesAfterSwap) - { - if (uniqNamesOfPrivates.find(elem->identifier()) == uniqNamesOfPrivates.end()) - { - unitedPrivates.insert(new Symbol(elem)); - uniqNamesOfPrivates.insert(elem->identifier()); - } - } - - if (unitedPrivates.size() != 0) - { - p = createAndSetNext(LEFT, ACC_PRIVATE_OP, p); - - directive += ", PRIVATE("; - int k = 0; - vector list; - auto spfParVars = fillPrivateOnlyFromSpfParameter(loop, currLoop->lineNum < 0 ? currLoop->altLineNum : 0); - for (auto& privVar : setToMapWithSortByStr(unitedPrivates)) - { - bool isSfpPriv = false; - for (auto& elem : spfParVars) - if (OriginalSymbol(elem)->identifier() == string(OriginalSymbol(privVar.second)->identifier())) - isSfpPriv = true; - - if (isSfpPriv) - continue; - - directive += (k != 0) ? "," + privVar.first : privVar.first; - list.push_back(new SgVarRefExp(getFromModule(byUseInFunc, privVar.second))); - ++k; - } - directive += ")"; - dirStatement[1] = new Expression(expr); - - p->setLhs(makeExprList(list)); - } - - vector loopsTie; - for (int i = 0; i < (int)parallel.size(); ++i) - if (parallel[i] != "*") - loopsTie.push_back(loops[i]); - - vector tieList; - tieList = compliteTieListNoDist(currLoop, uniqNamesOfPrivates, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange); - - if (tieList.size()) - { - if (dirStatement[1] != NULL) - { - expr = createAndSetNext(RIGHT, EXPR_LIST, expr); - p = expr; - } - p = createAndSetNext(LEFT, ACC_TIE_OP, p); - p->setLhs(makeExprList(tieList)); - - directive += ", TIE("; - int k = 0; - for (auto& tieL : tieList) - { - if (k != 0) - directive += ","; - directive += tieL->unparse(); - ++k; - } - directive += ")"; - } - set arraysInAcross; - if (across.size() != 0) - { - if (acrossShifts.size() == 0) - { - acrossShifts.resize(across.size()); - for (int i = 0; i < across.size(); ++i) - acrossShifts[i].resize(across[i].second.size()); - } - - //TODO: add "OUT" key for string representation - string acrossAdd = ", ACROSS("; - int inserted = 0; - SgExpression* acr_out = new SgExpression(EXPR_LIST); - SgExpression* p_out = acr_out; - - SgExpression* acr_in = new SgExpression(EXPR_LIST); - SgExpression* p_in = acr_in; - - SgExpression* acr_op = NULL; - int inCount = 0; - int outCount = 0; - - vector ordered = sortShadow(across); - for (int k = 0; k < (int)across.size(); ++k) - { - const int i1 = ordered[k]; - vector, int>> shiftsByAccess; - - auto currArray_it = arrayByName.find(across[i1].first.second); - - if (currArray_it == arrayByName.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - DIST::Array* currArray = currArray_it->second; - - bool isOut = acrossOutAttribute.find(currArray) != acrossOutAttribute.end(); - string bounds = genBoundsNoDist(across[i1], acrossShifts[i1], currArray, readOps, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); - if (bounds != "") - { - if (inserted != 0) - { - acrossAdd += ","; - if (isOut) - { - if (outCount > 0) - p_out = createAndSetNext(RIGHT, EXPR_LIST, p_out); - outCount++; - p = p_out; - } - else - { - if (inCount > 0) - p_in = createAndSetNext(RIGHT, EXPR_LIST, p_in); - inCount++; - p = p_in; - } - } - else if (inserted == 0) - { - if (dirStatement[1] != NULL) - expr = createAndSetNext(RIGHT, EXPR_LIST, expr); - acr_op = createAndSetNext(LEFT, ACROSS_OP, expr); - - if (isOut) - { - outCount++; - p = p_out; - } - else - { - inCount++; - p = p_in; - } - } - - acrossAdd += across[i1].first.first + "(" + bounds + ")"; - - SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, currArray->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal())); - newArrayRef->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); - - for (auto& elem : genSubscripts(across[i1].second, acrossShifts[i1])) - newArrayRef->addSubscript(*elem); - - p->setLhs(newArrayRef); - inserted++; - } - } - acrossAdd += ")"; - - if (inserted > 0) - { - directive += acrossAdd; - - if (dirStatement[1] == NULL) - dirStatement[1] = new Expression(expr); - - if (acrossOutAttribute.size() > 0) - { - SgExpression* tmp = new SgExpression(DDOT, new SgKeywordValExp("OUT"), acr_out, NULL); - acr_op->setLhs(*tmp); - if (inCount != 0) - acr_op->setRhs(acr_in); - } - else - acr_op->setLhs(acr_in); - } - } - - if (reduction.size() != 0) - { - if (dirStatement[1] != NULL) - { - expr = createAndSetNext(RIGHT, EXPR_LIST, expr); - p = expr; - } - - p = createAndSetNext(LEFT, REDUCTION_OP, p); - p = createAndSetNext(LEFT, EXPR_LIST, p); - - directive += ", REDUCTION("; - int k = 0; - for (auto it = reduction.begin(); it != reduction.end(); ++it) - { - const string& nameGroup = it->first; - for (auto& list : it->second) - { - if (k != 0) - { - directive += ","; - p = createAndSetNext(RIGHT, EXPR_LIST, p); - } - - SgSymbol* base = findSymbolOrCreate(file, correctSymbolModuleName(list), NULL, getModuleScope(list, moduleList, parentFunc)); - SgSymbol* redS = getFromModule(byUseInFunc, base, list.find("::") != string::npos); - directive += nameGroup + "(" + redS->identifier() + ")"; - - SgVarRefExp* tmp2 = new SgVarRefExp(redS); - SgFunctionCallExp* tmp1 = new SgFunctionCallExp(*findSymbolOrCreate(file, nameGroup), *tmp2); - - p->setLhs(tmp1); - ++k; - } - } - if (reductionLoc.size() != 0) - directive += ", "; - else - { - directive += ")"; - - if (dirStatement[1] == NULL) - dirStatement[1] = new Expression(expr); - } - } - - if (reductionLoc.size() != 0) - { - if (dirStatement[1] != NULL && reduction.size() == 0) - { - expr = createAndSetNext(RIGHT, EXPR_LIST, expr); - p = expr; - } - - if (reduction.size() == 0) - { - p = createAndSetNext(LEFT, REDUCTION_OP, p); - p = createAndSetNext(LEFT, EXPR_LIST, p); - directive += ", REDUCTION("; - } - else - p = createAndSetNext(RIGHT, EXPR_LIST, p); - - int k = 0; - for (auto it = reductionLoc.begin(); it != reductionLoc.end(); ++it) - { - const string& nameGroup = it->first; - for (auto& list : it->second) - { - if (k != 0) - { - directive += ","; - p = createAndSetNext(RIGHT, EXPR_LIST, p); - } - - SgSymbol* base1 = findSymbolOrCreate(file, correctSymbolModuleName(get<0>(list)), NULL, getModuleScope(get<0>(list), moduleList, parentFunc)); - SgSymbol* base2 = findSymbolOrCreate(file, correctSymbolModuleName(get<1>(list)), NULL, getModuleScope(get<1>(list), moduleList, parentFunc)); - - SgSymbol* redS1 = getFromModule(byUseInFunc, base1, get<0>(list).find("::") != string::npos); - SgSymbol* redS2 = getFromModule(byUseInFunc, base2, get<1>(list).find("::") != string::npos); - - directive += nameGroup + "(" + redS1->identifier() + ", " + redS2->identifier() + ", " + std::to_string(get<2>(list)) + ")"; - - SgFunctionCallExp* tmp1 = new SgFunctionCallExp(*findSymbolOrCreate(file, nameGroup)); - - tmp1->addArg(*new SgVarRefExp(redS1)); - tmp1->addArg(*new SgVarRefExp(redS2)); - tmp1->addArg(*new SgValueExp(get<2>(list))); - - p->setLhs(tmp1); - ++k; - } - } - directive += ")"; - - if (dirStatement[1] == NULL) - dirStatement[1] = new Expression(expr); - } - - directive += "\n"; - - auto dir = new CreatedDirective(directive, dirStatement); - dir->line = currLoop->lineNum; - return dir; -} \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index 3c91121..f9652f8 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -14,10 +14,57 @@ #include #include -#include "loop_analyzer_internal.h" #include "loop_analyzer.h" +#include +#include + +#include "../Utils/leak_detector.h" + +#if _WIN32 && NDEBUG && __BOOST +#include +#endif +extern int passDone; + +#include "../Distribution/Distribution.h" +#include "../Distribution/GraphCSR.h" +#include "../Distribution/Arrays.h" +#include "../ParallelizationRegions/ParRegions.h" + +#include "../Utils/errors.h" +#include "../DirectiveProcessing/directive_parser.h" +#include "../DirectiveProcessing/directive_creator.h" + +#include "../Utils/SgUtils.h" +#include "../Utils/AstWrapper.h" + +#include "../GraphCall/graph_calls_func.h" +#include "../GraphLoop/graph_loops_func.h" +#include "../ParallelizationRegions/ParRegions_func.h" +#include "../DynamicAnalysis/gCov_parser_func.h" + +#include "../ExpressionTransform/expr_transform.h" +#include "../SageAnalysisTool/depInterfaceExt.h" + +#include "../VisualizerCalls/get_information.h" +#include "../VisualizerCalls/SendMessage.h" + +#include "../Transformations/enddo_loop_converter.h" + +#include "../DirectiveProcessing/remote_access.h" #include "../DirectiveProcessing/directive_omp_parser.h" +#define PRINT_ARRAY_ARCS 0 +#define PRINT_LOOP_STRUCT 0 +#define PRINT_PROF_INFO 0 +#define DEB 0 + +extern REGIME currRegime; +extern std::vector* currMessages; + +extern int sharedMemoryParallelization; +extern int ignoreIO; +extern int parallizeFreeLoops; + using std::vector; using std::pair; using std::tuple; @@ -126,7 +173,9 @@ static void addInfoToMap(map> &loopInfo, S __spf_print(DEB, "RemoteAccess[%d]: true for dim %d and array %s, loop line %d\n", __LINE__, dimNum, symb->identifier(), position->lineNumber()); } -void addInfoToVectors(map> &loopInfo, SgForStmt *position, SgSymbol *symb, +enum { READ_OP, WRITE_OP, UNREC_OP }; + +static void addInfoToVectors(map> &loopInfo, SgForStmt *position, SgSymbol *symb, const int dimNum, const pair newCoef, int type, const int maxDimSize, const double currentW) { auto itLoop = loopInfo.find(position); @@ -159,10 +208,10 @@ void addInfoToVectors(map> &loopInfo, SgFo } -vector matchSubscriptToLoopSymbols(const vector &parentLoops, SgExpression *subscr, - SgArrayRefExp *arrayRefIn, const int side, const int dimNum, - map> &loopInfo, - const int currLine, const int numOfSubscriptions, const double currentW) +static vector matchSubscriptToLoopSymbols(const vector &parentLoops, SgExpression *subscr, + SgArrayRefExp *arrayRefIn, const int side, const int dimNum, + map> &loopInfo, + const int currLine, const int numOfSubscriptions, const double currentW) { SgExpression *origSubscr = subscr; ArrayRefExp *arrayRef = new ArrayRefExp(arrayRefIn); @@ -1464,7 +1513,7 @@ inline static void fillPrivatesFromDecl(SgExpression *ex, set &delcsS fillPrivatesFromDecl(ex->lhs(), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars); } -void changeLoopWeight(double ¤tWeight, const map &sortedLoopGraph, const int line, bool increase) +static void changeLoopWeight(double ¤tWeight, const map &sortedLoopGraph, const int line, bool increase = true) { auto loopIt = sortedLoopGraph.find(line); if (loopIt == sortedLoopGraph.end()) @@ -1476,7 +1525,7 @@ void changeLoopWeight(double ¤tWeight, const map &sortedL currentWeight /= loopIt->second->countOfIters; } -bool hasNonPureFunctions(SgExpression *ex, LoopGraph *loopRef, vector &messagesForFile, const int line, const map &funcByName) +static bool hasNonPureFunctions(SgExpression *ex, LoopGraph *loopRef, vector &messagesForFile, const int line, const map &funcByName) { bool retVal = false; @@ -1521,7 +1570,7 @@ void fillFromModule(SgSymbol* s, const map>& privatesByModul } } -SgStatement* takeOutConditions(stack& conditions, stack& ifBlocks, SgStatement* st) +static SgStatement* takeOutConditions(stack& conditions, stack& ifBlocks, SgStatement* st) { auto res = createIfConditions(conditions, ifBlocks, st); @@ -2165,7 +2214,10 @@ void loopAnalyzer(SgFile *file, vector ®ions, map -#include -#include -#include -#include -#include - -#include "../Utils/leak_detector.h" - -#if _WIN32 && NDEBUG && __BOOST -#include -#endif -extern int passDone; - -#include "../Distribution/Distribution.h" -#include "../Distribution/GraphCSR.h" -#include "../Distribution/Arrays.h" -#include "../ParallelizationRegions/ParRegions.h" - -#include "../Utils/errors.h" -#include "../DirectiveProcessing/directive_parser.h" -#include "../DirectiveProcessing/directive_creator.h" - -#include "../Utils/SgUtils.h" -#include "../Utils/AstWrapper.h" - -#include "../GraphCall/graph_calls_func.h" -#include "../GraphLoop/graph_loops_func.h" -#include "../ParallelizationRegions/ParRegions_func.h" -#include "../DynamicAnalysis/gCov_parser_func.h" - -#include "../ExpressionTransform/expr_transform.h" -#include "../SageAnalysisTool/depInterfaceExt.h" - -#include "../VisualizerCalls/get_information.h" -#include "../VisualizerCalls/SendMessage.h" - -#include "../Transformations/enddo_loop_converter.h" -#include "../DirectiveProcessing/remote_access.h" - -#define PRINT_ARRAY_ARCS 0 -#define PRINT_LOOP_STRUCT 0 -#define PRINT_PROF_INFO 0 -#define DEB 0 - -extern REGIME currRegime; -extern std::vector* currMessages; - -extern int sharedMemoryParallelization; -extern int ignoreIO; -extern int parallizeFreeLoops; - -void changeLoopWeight(double& currentWeight, const std::map& sortedLoopGraph, const int line, bool increase = true); - -SgStatement* takeOutConditions(std::stack& conditions, std::stack& ifBlocks, SgStatement* st); - -enum { READ_OP, WRITE_OP, UNREC_OP }; -void addInfoToVectors(std::map>& loopInfo, SgForStmt* position, SgSymbol* symb, - const int dimNum, const std::pair newCoef, int type, const int maxDimSize, const double currentW); - -std::vector matchSubscriptToLoopSymbols(const std::vector& parentLoops, SgExpression* subscr, - SgArrayRefExp* arrayRefIn, const int side, const int dimNum, - std::map>& loopInfo, - const int currLine, const int numOfSubscriptions, const double currentW); - -bool hasNonPureFunctions(SgExpression* ex, LoopGraph* loopRef, std::vector& messagesForFile, const int line, const std::map& funcByName); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp deleted file mode 100644 index b423e47..0000000 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.cpp +++ /dev/null @@ -1,667 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "../DirectiveProcessing/directive_creator_nodist.h" - -#include "loop_analyzer_internal.h" -#include "loop_analyzer_nodist.h" - -using std::vector; -using std::pair; -using std::tuple; -using std::map; -using std::set; -using std::make_pair; -using std::make_tuple; -using std::get; -using std::string; -using std::wstring; -using std::stack; - -extern void createMapLoopGraph(map& sortedLoopGraph, const vector* loopGraph); - -extern map> tableOfUniqNamesByArray; -static void convertOneLoopNoDist(LoopGraph* currLoop, map>& outInfo, - const map& toConvert, - const map>& commonBlocks, - const map, pair>& declaredArrays, - const map>& arrayLinksByFuncCalls, - map, DIST::Array*>& createdArrays, - bool freeArrays = false) -{ - map toAdd; - for (auto& conv : toConvert) - { - SgSymbol* currentArray = OriginalSymbol(conv.first); - ArrayInfo* currentInfo = (ArrayInfo*)(&conv.second); - - DIST::Array* arrayToAdd; - - SgStatement* decl = declaratedInStmt(currentArray); - const char* symbIdent = currentArray->identifier(); - - const tuple uniqKey = getUniqName(commonBlocks, decl, currentArray); - - auto itFound = createdArrays.find(uniqKey); - if (itFound == createdArrays.end()) - { - auto itArray = declaredArrays.find(uniqKey); - if (itArray == declaredArrays.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - arrayToAdd = itArray->second.first; - itFound = createdArrays.insert(itFound, make_pair(uniqKey, arrayToAdd)); - } - else - arrayToAdd = itFound->second; - - set links; - getRealArrayRefs(arrayToAdd, arrayToAdd, links, arrayLinksByFuncCalls); - - int countOflinks = 0; - for (auto& linkedArray : links) - { - if (arrayToAdd == linkedArray) - continue; - - ++countOflinks; - auto key = tableOfUniqNamesByArray[linkedArray]; - auto value = declaredArrays.find(key)->second; - if (value.second == 0 && createdArrays.find(key) == createdArrays.end()) - createdArrays.insert(make_pair(key, linkedArray)); - } - - if (freeArrays) - if (countOflinks == 0) - continue; - - toAdd[arrayToAdd] = currentInfo; - - for (int z = 0; z < currentInfo->getDimSize(); ++z) - { - if (currentInfo->readOps[z].coefficients.size() || currentInfo->writeOps[z].coefficients.size()) - { - arrayToAdd->SetMappedDim(z); - - for (auto& realRef : links) - realRef->SetMappedDim(z); - } - } - } - - outInfo[currLoop] = toAdd; -} - -static map> -convertLoopInfoNoDist(const map>& loopInfo, - const map& sortedLoopGraph, - const map>& commonBlocks, - const map, pair>& declaredArrays, - const map>& arrayLinksByFuncCalls, - map, DIST::Array*>& createdArrays) -{ - map> outInfo; - - for (auto it = loopInfo.begin(); it != loopInfo.end(); ++it) - { - auto itGraph = sortedLoopGraph.find(it->first->lineNumber()); - if (itGraph == sortedLoopGraph.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - - convertOneLoopNoDist(itGraph->second, outInfo, it->second, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays); - } - - return outInfo; -} - -static vector matchArrayToLoopSymbols(const vector &parentLoops, vector>& privatesVarsForLoop, - SgExpression *currExp, const int side, - map> &loopInfo, const int currLine, - map &sortedLoopGraph, const ParallelRegion *reg, const double currentW, - const map> &arrayLinksByFuncCalls) -{ - SgArrayRefExp *arrayRef = (SgArrayRefExp*)currExp; - int numOfSubs = arrayRef->numberOfSubscripts(); - - currExp = currExp->lhs(); - vector wasFoundForLoop(parentLoops.size()); - vector matched(numOfSubs); - vector matchedToDim(parentLoops.size()); - std::fill(wasFoundForLoop.begin(), wasFoundForLoop.end(), 0); - std::fill(matched.begin(), matched.end(), -1); - std::fill(matchedToDim.begin(), matchedToDim.end(), -1); - int maxMatched = 0; - int sumMatched = 0; - - for (int i = 0; i < numOfSubs; ++i) - { - vector matchToLoops = matchSubscriptToLoopSymbols(parentLoops, currExp->lhs(), arrayRef, side, i, loopInfo, currLine, numOfSubs, currentW); - for (int k = 0; k < matchToLoops.size(); ++k) - { - wasFoundForLoop[matchToLoops[k]]++; - matchedToDim[matchToLoops[k]] = i; - } - - matched[i] = matchToLoops.size(); - sumMatched += matchToLoops.size(); - maxMatched = std::max(maxMatched, (int)matchToLoops.size()); - currExp = currExp->rhs(); - } - - //full array is used, add unknown operations to all loops - if (numOfSubs == 0) - { - SgSymbol *currOrigArrayS = OriginalSymbol(arrayRef->symbol()); - auto arrType = isSgArrayType(currOrigArrayS->type()); - if (arrType != NULL) - { - for (int d = 0; d < arrType->dimension(); ++d) - for (int i = 0; i < parentLoops.size(); ++i) - addInfoToVectors(loopInfo, parentLoops[i], currOrigArrayS, d, make_pair(0, 0), UNREC_OP, arrType->dimension(), currentW); - } - } - - bool ifUnknownArrayAssignFound = false; - vector canNotMapToLoop; - for (int i = 0; i < wasFoundForLoop.size(); ++i) - { - if (wasFoundForLoop[i] != 1 && - privatesVarsForLoop[i].find(string(arrayRef->symbol()->identifier())) == privatesVarsForLoop[i].end()) - { - auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber()); - if (itLoop == sortedLoopGraph.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - ifUnknownArrayAssignFound = true; - if (side == LEFT) - itLoop->second->hasUnknownArrayAssigns = true; - - itLoop->second->hasUnknownDistributedMap = true; - canNotMapToLoop.push_back(parentLoops[i]->lineNumber()); - } - } - - if (side == LEFT) - { - if (ifUnknownArrayAssignFound) - { - const string arrayRefS = arrayRef->unparse(); - for (auto &line : canNotMapToLoop) - { - __spf_print(1, "WARN: can not map write to array '%s' to loop on line %d\n", arrayRefS.c_str(), line); - wstring messageE, messageR; - __spf_printToLongBuf(messageE, L"can not map write to array '%s' to this loop", to_wstring(arrayRefS).c_str()); - - __spf_printToLongBuf(messageR, R59, to_wstring(arrayRefS).c_str()); - - if (line > 0) - currMessages->push_back(Messages(WARR, line, messageR, messageE, 1025)); - } - } - } - - return wasFoundForLoop; -} - -static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp, - const vector& parentLoops, const int side, const int lineNum, - map>& loopInfo, - vector>& privatesVarsForLoop, - map& sortedLoopGraph, map>& notMappedDistributedArrays, - set& mappedDistrbutedArrays, - const ParallelRegion* reg, const double currentW, const map>& arrayLinksByFuncCalls) -{ - const char* printSide = NULL; - if (PRINT_ARRAY_ARCS) - printBlanks(2, (int)parentLoops.size()); - if (side == LEFT) - printSide = "W_OP"; - else - printSide = "R_OP"; - - __spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum); - bool wasMapped = false; - vector matched = matchArrayToLoopSymbols(parentLoops, privatesVarsForLoop, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls); - for (int z = 0; z < matched.size(); ++z) - wasMapped |= (matched[z] != 0); - - if (parentLoops.size() == 0) - { - SgSymbol* symb = currExp->symbol(); - if (symb->type()->variant() == T_ARRAY) - notMappedDistributedArrays[symb->identifier()] = make_pair(symb, currentSt); - } - else - { - if (wasMapped) - mappedDistrbutedArrays.insert(currExp->symbol()->identifier()); - else - { - SgSymbol* symb = currExp->symbol(); - if (symb->type()->variant() == T_ARRAY) - notMappedDistributedArrays[symb->identifier()] = make_pair(symb, currentSt); - } - } - __spf_print(PRINT_ARRAY_ARCS, "\n"); -} - -static void findArrayRef(const vector& parentLoops, SgExpression* currExp, const int lineNum, const int side, - map>& loopInfo, - vector>& privatesVarsForLoop, map& sortedLoopGraph, - map>& notMappedDistributedArrays, - set& mappedDistrbutedArrays, SgStatement* currentSt, const ParallelRegion* reg, const double currentW, - const map>& arrayLinksByFuncCalls) -{ - int nextSide = side; - if (isArrayRef(currExp)) - { - mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, privatesVarsForLoop, sortedLoopGraph, - notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); - nextSide = (side == LEFT) ? RIGHT : side; - } - - bool needToContinue = true; - if (currExp->variant() == FUNC_CALL) - { - SgFunctionCallExp* funcExp = (SgFunctionCallExp*)currExp; - auto currFunc = isUserFunctionInProject(funcExp->funName()->identifier()); - if (currFunc) - { - for (int z = 0; z < funcExp->numberOfArgs(); ++z) - { - if ((currFunc->funcParams.inout_types[z] & OUT_BIT) != 0) - nextSide = LEFT; - else - nextSide = RIGHT; - findArrayRef(parentLoops, funcExp->arg(z), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph, - notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls); - } - needToContinue = false; - } - } - - if (needToContinue) - { - if (currExp->lhs()) - findArrayRef(parentLoops, currExp->lhs(), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph, - notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls); - if (currExp->rhs()) - findArrayRef(parentLoops, currExp->rhs(), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph, - notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls); - } -} - -void loopAnalyzerNoDist(SgFile* file, vector& regions, map, DIST::Array*>& createdArrays, - vector& messagesForFile, const map>& AllfuncInfo, - const map, pair>& declaredArrays, - const map>>& declaratedArraysSt, - const map>& arrayLinksByFuncCalls, - const map>& defUseByPlace, - vector* loopGraph) -{ - currMessages = &messagesForFile; - currRegime = DATA_DISTR; //? - - map> commonBlocks; - map sortedLoopGraph; - map, set>>> allLoops; - - createMapLoopGraph(sortedLoopGraph, loopGraph); - - int funcNum = file->numberOfFunctions(); - __spf_print(PRINT_PROF_INFO, "functions num in file = %d\n", funcNum); - - vector modules; - findModulesInFile(file, modules); - - map modulesByName; - for (int i = 0; i < modules.size(); ++i) - modulesByName[modules[i]->symbol()->identifier()] = modules[i]; - - map funcByName; - createMapOfFunc(AllfuncInfo, funcByName); - - const vector& funcInfo = AllfuncInfo.find(file->filename())->second; - - for (int i = 0; i < funcNum; ++i) - { - createNeededException(); - - string fName = file->functions(i)->symbol()->identifier(); -#if _WIN32 - if (file->functions(i)->variant() != MODULE_STMT) - sendMessage_2lvl(wstring(L"обработка функции '") + wstring(fName.begin(), fName.end()) + L"'"); - else - sendMessage_2lvl(wstring(L"обработка модуля '") + wstring(fName.begin(), fName.end()) + L"'"); -#else - if (file->functions(i)->variant() != MODULE_STMT) - sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'"); - else - sendMessage_2lvl(wstring(L"processing module '") + wstring(fName.begin(), fName.end()) + L"'"); -#endif - - set delcsSymbViewed; - set delcsStatViewed; - - if (funcInfo[i]->doNotAnalyze) - continue; - - map> loopInfo; - set loopWithOutArrays; - - SgStatement* st = file->functions(i); - string funcName = ""; - if (st->variant() == PROG_HEDR) - { - SgProgHedrStmt* progH = (SgProgHedrStmt*)st; - __spf_print(PRINT_PROF_INFO, "*** Program <%s> started at line %d / %s\n", progH->symbol()->identifier(), st->lineNumber(), st->fileName()); - funcName = progH->symbol()->identifier(); - } - else if (st->variant() == PROC_HEDR) - { - SgProcHedrStmt* procH = (SgProcHedrStmt*)st; - __spf_print(PRINT_PROF_INFO, "*** Function <%s> started at line %d / %s\n", procH->symbol()->identifier(), st->lineNumber(), st->fileName()); - funcName = procH->symbol()->identifier(); - } - else if (st->variant() == FUNC_HEDR) - { - SgFuncHedrStmt* funcH = (SgFuncHedrStmt*)st; - __spf_print(PRINT_PROF_INFO, "*** Function <%s> started at line %d / %s\n", funcH->symbol()->identifier(), st->lineNumber(), st->fileName()); - funcName = funcH->symbol()->identifier(); - } - - vector loopsForFunction; - for (auto& loop : *loopGraph) - { - auto fStat = getFuncStat(loop->loop->GetOriginal()); - if (fStat->symbol()->identifier() == funcName) - loopsForFunction.push_back(loop); - } - - commonBlocks.clear(); - getCommonBlocksRef(commonBlocks, st, st->lastNodeOfStmt()); - __spf_print(PRINT_PROF_INFO, " number of common blocks %d\n", (int)commonBlocks.size()); - - SgStatement* lastNode = st->lastNodeOfStmt(); - vector parentLoops; - vector> privatesVarsForLoop; - - //For remote access - pair* under_dvm_dir = NULL; - - map> notMappedDistributedArrays; - set mappedDistrbutedArrays; - - double currentWeight = 1.0; - while (st != lastNode) - { - createNeededException(); - - if (st == NULL) - { - currMessages->push_back(Messages(ERROR, 1, R128, L"internal error in analysis, parallel directives will not be generated for this file!", 3008)); - - __spf_print(1, "internal error in analysis, parallel directives will not be generated for this file!\n"); - break; - } - - if (st->variant() == CONTAINS_STMT) - break; - - if (!__gcov_doesThisLineExecuted(st->fileName(), st->lineNumber())) - { - st = st->lexNext(); - continue; - } - - const int currentLine = st->lineNumber() < -1 ? st->localLineNumber() : st->lineNumber(); - ParallelRegion* currReg = getRegionByLine(regions, st->fileName(), currentLine); - if (currReg == NULL) - { - st = st->lexNext(); - continue; - } - - if (isSgExecutableStatement(st) == NULL) - delcsStatViewed.insert(st); - - //printf("new st with var = %d, on line %d\n", st->variant(), st->lineNumber()); - const int currV = st->variant(); - if (currV == FOR_NODE) - { - //tryToFindPrivateInAttributes(st, privatesVars); - - set toAdd; - tryToFindPrivateInAttributes(st, toAdd); - - if (PRINT_LOOP_STRUCT) - printBlanks(2, (int)parentLoops.size()); - __spf_print(PRINT_LOOP_STRUCT, "FOR NODE on line %d\n", st->lineNumber()); - - parentLoops.push_back((SgForStmt*)st); - changeLoopWeight(currentWeight, sortedLoopGraph, st->lineNumber()); - privatesVarsForLoop.push_back(toAdd); - } - else if (currV == CONTROL_END) - { - SgStatement* contrlParent = st->controlParent(); - if (contrlParent) - { - if (contrlParent->variant() == FOR_NODE) - { - changeLoopWeight(currentWeight, sortedLoopGraph, contrlParent->lineNumber(), false); - - if (loopInfo.find((SgForStmt*)contrlParent) == loopInfo.end() && !sortedLoopGraph[contrlParent->lineNumber()]->hasUnknownDistributedMap) - loopWithOutArrays.insert(contrlParent->lineNumber()); - - set unitedPrivates; - for (int p = 0; p < parentLoops.size(); ++p) - for (auto& privVar : privatesVarsForLoop[p]) - unitedPrivates.insert(privVar); - - set setDiff; - - allLoops[contrlParent->lineNumber()] = make_pair((SgForStmt*)contrlParent, make_pair(unitedPrivates, setDiff)); - parentLoops.pop_back(); - privatesVarsForLoop.pop_back(); - } - } - else - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } - else if (currV == ASSIGN_STAT) - { - if (st->expr(0)) - findArrayRef(parentLoops, st->expr(0), st->lineNumber(), LEFT, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - if (st->expr(1)) - findArrayRef(parentLoops, st->expr(1), st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - } - else if (currV == IF_NODE || currV == ELSEIF_NODE || currV == LOGIF_NODE || currV == SWITCH_NODE) - { - SgStatement* before = NULL; - if (st->expr(0)) - { - findArrayRef(parentLoops, st->expr(0), st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - } - } - else if (currV == PROC_STAT) - { - auto func = isUserFunctionInProject(st->symbol()->identifier()); - if (func != NULL) - { - SgExpression* parList = st->expr(0); - set toRedistr; - if (parList) - { - SgExprListExp* list = isSgExprListExp(parList); - for (int z = 0; z < list->length(); ++z) - { - SgExpression* par = list->elem(z); - if ((func->funcParams.inout_types[z] & OUT_BIT) != 0) - findArrayRef(parentLoops, par, st->lineNumber(), LEFT, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - else - findArrayRef(parentLoops, par, st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - } - - } - } - } - else if (currV == USE_STMT) - { - if (st->lineNumber() > 0) - { - auto itF = modulesByName.find(st->symbol()->identifier()); - - if (itF == modulesByName.end()) - { - wstring messageE, messageR; - __spf_printToLongBuf(messageE, L"Module with name '%s' must be placed in current file", to_wstring(st->symbol()->identifier()).c_str()); - - __spf_printToLongBuf(messageR, R62, to_wstring(st->symbol()->identifier()).c_str()); - - currMessages->push_back(Messages(ERROR, st->lineNumber(), messageR, messageE, 1028)); - - __spf_print(1, "Module at line %d with name '%s' must be placed in current file\n", st->lineNumber(), st->symbol()->identifier()); - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } - } - } - else - { - if (isDVM_stat(st) == false && isSgExecutableStatement(st)) - { - int const var = st->variant(); - int side = (var == READ_STAT || var == WRITE_STAT || var == PRINT_STAT) ? LEFT : RIGHT; - - for (int z = 0; z < 3; ++z) - if (st->expr(z)) - findArrayRef(parentLoops, st->expr(z), st->lineNumber(), side, loopInfo, privatesVarsForLoop, - sortedLoopGraph, notMappedDistributedArrays, - mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls); - - } - } - - st = st->lexNext(); - } - - auto convertedLoopInfo = convertLoopInfoNoDist(loopInfo, sortedLoopGraph, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays); - - processLoopInformationForFunction(convertedLoopInfo); - - //find dependencies for loops in function - initAnnotationsSysExt(0); - set funcWasInit; - map collection; - - int idx = 0; - for (auto& loop : convertedLoopInfo) - { - ++idx; - createNeededException(); - - string fName = file->functions(i)->symbol()->identifier(); -#ifdef _WIN32 - sendMessage_2lvl(wstring(L"обработка цикла ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); -#else - sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); -#endif - tryToFindDependencies(loop.first, allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace); - - } - - for (auto& loopLine : loopWithOutArrays) - { - if (loopLine > 0) - { - tryToFindDependencies(sortedLoopGraph[loopLine], allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace); - sortedLoopGraph[loopLine]->withoutDistributedArrays = true; - - //TODO: enable linear writes to non distr arrays for CONSISTENT - bool hasWritesToArray = false; - //TODO: add IPA for non pure - bool hasNonPureProcedures = false; - - auto loopRef = sortedLoopGraph[loopLine]; - SgStatement* loopSt = loopRef->loop; - - for (SgStatement* start = loopSt->lexNext(); start != loopSt->lastNodeOfStmt(); start = start->lexNext()) - { - - if (start->variant() == PROC_STAT && isIntrinsicFunctionName(start->symbol()->identifier()) == 0) - { - checkNull(isSgCallStmt(start), convertFileName(__FILE__).c_str(), __LINE__); - - auto itF = funcByName.find(isSgCallStmt(start)->name()->identifier()); - bool isPure = false; - if (itF != funcByName.end()) - isPure = itF->second->isPure; - - if (!isPure) - { - hasNonPureProcedures = true; - loopRef->hasNonPureProcedures = true; - - messagesForFile.push_back(Messages(WARR, start->lineNumber(), R80, L"Only pure procedures were supported", 1044)); - } - } - - for (int z = 1; z < 3; ++z) - if (hasNonPureFunctions(start->expr(z), loopRef, messagesForFile, start->lineNumber(), funcByName)) - hasNonPureProcedures = true; - } - - if (hasWritesToArray || hasNonPureProcedures) - loopRef->withoutDistributedArrays = false; - } - } - - sendMessage_2lvl(L""); - - createParallelDirectivesNoDist(convertedLoopInfo, regions, arrayLinksByFuncCalls, messagesForFile); - for (auto& loopLine : loopWithOutArrays) - { - auto loopRef = sortedLoopGraph[loopLine]; - if (loopRef->withoutDistributedArrays && loopRef->region && !loopRef->hasLimitsToParallel() && loopRef->lineNum > 0) - { - int nesting = 0; - LoopGraph* it = loopRef; - for (int z = 0; z < loopRef->perfectLoop; ++z, it->children.size() ? it = it->children[0] : it) - if (it->withoutDistributedArrays && it->region && !it->hasLimitsToParallel() && it->lineNum > 0) - ++nesting; - - map> convertedLoopInfo; - - it = loopRef; - for (int z = 0; z < nesting; ++z, it->children.size() ? it = it->children[0] : it) - convertedLoopInfo.insert(make_pair(it, map())); - - createParallelDirectivesNoDist(convertedLoopInfo, regions, map>(), messagesForFile); - } - } - - __spf_print(PRINT_PROF_INFO, "Function ended\n"); - } -} \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.h b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.h deleted file mode 100644 index e3c7583..0000000 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer_nodist.h +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include -#include - -void loopAnalyzerNoDist(SgFile* file, std::vector& regions, std::map, DIST::Array*>& createdArrays, - std::vector& messagesForFile, const std::map>& AllfuncInfo, - const std::map, std::pair>& declaredArrays, - const std::map>>& declaratedArraysSt, - const std::map>& arrayLinksByFuncCalls, - const std::map>& defUseByPlace, - std::vector* loopGraph); \ 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 dd1ee99..f052cad 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -38,7 +38,6 @@ #include "ProjectManipulation/ConvertFiles.h" #include "LoopAnalyzer/loop_analyzer.h" -#include "LoopAnalyzer/loop_analyzer_nodist.h" #include "GraphCall/graph_calls_func.h" #include "GraphCall/select_array_conf.h" @@ -48,7 +47,6 @@ #include "DirectiveProcessing/directive_analyzer.h" #include "DirectiveProcessing/directive_creator.h" -#include "DirectiveProcessing/directive_creator_nodist.h" #include "DirectiveProcessing/insert_directive.h" #include "DirectiveProcessing/directive_omp_parser.h" #include "VerificationCode/verifications.h" -- 2.49.1 From 06f908c1b2e778e97f2bf9eba2265b05f17ea92c Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sat, 6 Jul 2024 18:09:59 +0300 Subject: [PATCH 05/10] shared memory parallelization: do not find privates in modules --- .../Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index f9652f8..04a69ee 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -2088,7 +2088,7 @@ void loopAnalyzer(SgFile *file, vector ®ions, maplineNumber() > 0) + if (st->lineNumber() > 0 && !sharedMemoryParallelization) { auto itF = privatesByModule.find(st->symbol()->identifier()); @@ -2105,9 +2105,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapsecond.begin(); it != itF->second.end(); ++it) - privatesVars.insert(*it); + + for (auto it = itF->second.begin(); it != itF->second.end(); ++it) + privatesVars.insert(*it); } } else -- 2.49.1 From 793408f9a8022446f2704b0d9ea0a1a521fff6ac Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sat, 6 Jul 2024 20:11:07 +0300 Subject: [PATCH 06/10] shared memory parallelization: avoid use of arrays struct in shared memory case --- .../experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp | 5 +++-- sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h | 2 +- .../Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index b866a67..a853945 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -780,7 +780,7 @@ ParallelDirective::genDirective(File* file, const vector, int>> shiftsByAccess; - const string bounds = genBounds(shadowRenew[i1], shadowRenewShifts[i1], reducedG, allArrays, remoteReads, readOps, false, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); + DIST::Array* shadowArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); + const string bounds = genBounds(shadowRenew[i1], shadowRenewShifts[i1], reducedG, allArrays, shadowArray, remoteReads, readOps, false, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); if (bounds != "") { DIST::Array* currArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h index 5e72048..24c5425 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.h @@ -162,7 +162,7 @@ private: std::string genBounds(std::pair, std::vector>> &shadowOp, std::vector> &shadowOpShift, DIST::GraphCSR &reducedG, - DIST::Arrays &allArrays, + DIST::Arrays &allArrays, DIST::Array* shadowArray, std::map>& remoteRegularReads, const std::map, std::vector>> &readOps, const bool isAcross, const uint64_t regionId, diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp index 403044e..51c8ac0 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp @@ -461,7 +461,7 @@ static inline string calculateShifts(DIST::GraphCSR &redu string ParallelDirective::genBounds(pair, vector>> &shadowOp, vector> &shadowOpShift, DIST::GraphCSR &reducedG, - DIST::Arrays &allArrays, + DIST::Arrays &allArrays, DIST::Array* shadowArray, map>& remoteRegularReads, const map, vector>> &readOps, const bool isAcross, @@ -471,8 +471,7 @@ string ParallelDirective::genBounds(pair, vector, int>> &shiftsByAccess, const map> &arrayLinksByFuncCalls) const { - DIST::Array *shadowArray = allArrays.GetArrayByName(shadowOp.first.second); - checkNull(shadowArray, convertFileName(__FILE__).c_str(), __LINE__); + checkNull(shadowArray, convertFileName(__FILE__).c_str(), __LINE__); auto on_ext = on; -- 2.49.1 From 8931aced8556ea9982c00b2549e14f1f52e3ec76 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Tue, 16 Jul 2024 20:35:33 +0300 Subject: [PATCH 07/10] shared memory parallelization: small fixes --- .../_src/DirectiveProcessing/directive_creator_base.cpp | 3 +++ sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp | 2 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp index 32ab1a2..3747126 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator_base.cpp @@ -390,6 +390,9 @@ bool checkForConflict(const map &currAccesses, for (auto &itArray : currAccesses) { + if(!itArray.first) + continue; // skip fictitious array access in free loop + const ArrayInfo &currInfo = *(itArray.second); const string &arrayName = itArray.first->GetShortName(); diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index 04a69ee..5eaebd0 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -498,7 +498,7 @@ static vector matchArrayToLoopSymbols(const vector &parentLoops if (itLoop == sortedLoopGraph.end()) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); ifUnknownArrayAssignFound = true; - if (side == LEFT && (currRegime == DATA_DISTR || currRegime == COMP_DISTR)) + if (side == LEFT && (currRegime == DATA_DISTR || currRegime == COMP_DISTR || currRegime == SHARED_MEMORY_PAR)) itLoop->second->hasUnknownArrayAssigns = true; itLoop->second->hasUnknownDistributedMap = true; diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index f052cad..834bd12 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -560,6 +560,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne else if (curr_regime == LOOP_ANALYZER_NODIST) { auto& loopsInFile = getObjectForFileFromMap(file_name, loopGraph); + parallizeFreeLoops = 1; + sharedMemoryParallelization = 1; loopAnalyzer(file, parallelRegions, createdArrays, getObjectForFileFromMap(file_name, SPF_messages), SHARED_MEMORY_PAR, allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(), false, &(loopsInFile)); -- 2.49.1 From 7b46798785de5bf62b336b5af995f46aa689180a Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Wed, 17 Jul 2024 20:01:50 +0300 Subject: [PATCH 08/10] shared memory parallelization: do not include private arrays in TIE list --- .../Sapfor_2017/_src/Distribution/DvmhDirective.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index a853945..33afba1 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -243,7 +243,8 @@ static vector const map>& arrayLinksByFuncCalls, const map>& byUseInFunc, File* file, const pair& lineRange, - const set& onlyFor) + const set& onlyFor, + const set& privates) { vector tieList; vector> realRefsUsed; @@ -269,6 +270,9 @@ static vector for (auto& pairs : realRefsUsed) { + if (privates.find(pairs.second->GetShortName()) != privates.end()) + continue; + auto type = pairs.second->GetDeclSymbol(currLoop->fileName, lineRange, getAllFilesInProject())->GetOriginal()->type(); SgSymbol* arrayS = getFromModule(byUseInFunc, findSymbolOrCreate(file, pairs.second->GetShortName(), type)); SgArrayRefExp* array = new SgArrayRefExp(*arrayS); @@ -706,9 +710,9 @@ ParallelDirective::genDirective(File* file, const vector tieList; if (sharedMemoryParallelization) - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor, uniqNamesOfPrivates); else if (onlyFor.size()) // not MPI regime - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor, uniqNamesOfPrivates); if (tieList.size()) { -- 2.49.1 From 962e0fab7759dcee102a7505421f68be71388236 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Thu, 18 Jul 2024 09:49:14 +0300 Subject: [PATCH 09/10] restored --- .../_src/Distribution/DvmhDirectiveBase.cpp | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp index 51c8ac0..55b6586 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirectiveBase.cpp @@ -280,7 +280,54 @@ static inline string calculateShifts(DIST::GraphCSR &redu // check for distributed and not mapped dims -> zero them out ('coeffs.second') set refs; getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls); - + + //TODO: need to correct errors + /*if (!sharedMemoryParallelization) + { + for (auto& array : refs) + { + DIST::Array* tmpl = array->GetTemplateArray(regionId); + checkNull(tmpl, convertFileName(__FILE__).c_str(), __LINE__); + + auto align = array->GetLinksWithTemplate(regionId); + + bool found = false; + for (auto& t : distribution) + { + if (t.first == tmpl) + { + found = true; + + for (int aDim = 0; aDim < align.size(); ++aDim) + { + int link = align[aDim]; + if (link != -1) + { + int tLink = link; + if (!arrayRef->IsTemplate()) + { + auto alignMain = arrayRef->GetLinksWithTemplate(regionId); + for (int z = 0; z < alignMain.size(); ++z) + if (alignMain[z] == tLink) + tLink = z; + } + + if (t.second->distRule[link] == dist::BLOCK && baseOnRule[aDim].first == "*") + { + for (int z = 0; z < coeffs.second.size(); ++z) + coeffs.second[z].first = coeffs.second[z].second = 0; + return out; + } + } + } + } + } + + if (!found) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + }*/ + const pair, vector> *currReadOp = NULL; auto readIt = readOps.find(calcForArray); if (readIt != readOps.end()) -- 2.49.1 From 5991a833089e1f4b4836d14ceb2e97d063995834 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Thu, 18 Jul 2024 09:49:56 +0300 Subject: [PATCH 10/10] version updated --- sapfor/experts/Sapfor_2017/_src/Utils/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 6044142..170b9c5 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 "2350" +#define VERSION_SPF "2351" -- 2.49.1