From 455d0e4a3c49b46b3e22d7147d1478b501c3a00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=BE=D1=87?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B8=D0=BD?= Date: Sun, 23 Jun 2024 11:44:17 +0300 Subject: [PATCH] refactor shared memory parallelization (wip) --- .../_src/LoopAnalyzer/loop_analyzer.cpp | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index 074b5ae..a3e3494 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -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()) @@ -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,23 +587,23 @@ 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 { - if ((currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR) && side == LEFT) + if (currRegime == DATA_DISTR && side == LEFT) { auto symb = OriginalSymbol(currExp->symbol()); SgStatement *decl = declaratedInStmt(symb); @@ -654,21 +659,18 @@ static void findArrayRef(const vector &parentLoops, SgExpression *cu const string key = string(OriginalSymbol(currExp->symbol())->identifier()); if (loopsPrivates.find(key) == loopsPrivates.end()) { - if (sharedMemoryParallelization == 0) + for (auto& loop : parentLoops) { - 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 @@ -1384,7 +1386,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 +1403,7 @@ static void convertOneLoop(LoopGraph *currLoop, mapsecond; - if (arrayToAdd->IsNotDistribute() == true) + if (!sharedMemoryParallelization && arrayToAdd->IsNotDistribute() == true) continue; set links; @@ -2094,14 +2096,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)) { @@ -2194,8 +2200,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, map ®ions, map 0) @@ -2310,6 +2316,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, map