refactor shared memory parallelization (wip)
This commit is contained in:
@@ -387,7 +387,8 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
|
||||
return allPositions;
|
||||
}
|
||||
|
||||
static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *currExp, const int side,
|
||||
static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops, vector<set<string>>& privatesVarsForLoop,
|
||||
SgExpression *currExp, const int side,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const int currLine,
|
||||
map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW,
|
||||
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls)
|
||||
@@ -440,7 +441,9 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
|
||||
vector<int> 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<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
|
||||
}
|
||||
|
||||
static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp,
|
||||
const vector<SgForStmt*>& parentLoops, const int side, const int lineNum,
|
||||
const vector<SgForStmt*>& parentLoops, vector<set<string>>& privatesVarsForLoop,
|
||||
const int side, const int lineNum,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
|
||||
map<int, LoopGraph*> &sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
|
||||
set<string>& 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<int> matched = matchArrayToLoopSymbols(parentLoops, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls);
|
||||
vector<int> 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<SgForStmt*> &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<SgForStmt*> &parentLoops, SgExpression *cu
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
if (itLoop->second->perfectLoop != depth)
|
||||
break;
|
||||
|
||||
if (!(sharedMemoryParallelization && side == RIGHT))
|
||||
itLoop->second->hasIndirectAccess = true;
|
||||
if (sharedMemoryParallelization && side == RIGHT)
|
||||
itLoop->second->hasIndirectAccess = false;
|
||||
}
|
||||
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);
|
||||
@@ -653,8 +658,6 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
|
||||
|
||||
const string key = string(OriginalSymbol(currExp->symbol())->identifier());
|
||||
if (loopsPrivates.find(key) == loopsPrivates.end())
|
||||
{
|
||||
if (sharedMemoryParallelization == 0)
|
||||
{
|
||||
for (auto& loop : parentLoops)
|
||||
{
|
||||
@@ -670,7 +673,6 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
|
||||
sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO: this case looks strange
|
||||
/*else if (loopsRedUnited.find(key) == loopsRedUnited.end())
|
||||
{
|
||||
@@ -1384,7 +1386,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
|
||||
SgStatement *decl = declaratedInStmt(currentArray);
|
||||
const char *symbIdent = currentArray->identifier();
|
||||
|
||||
if (privateArrays.find(symbIdent) == privateArrays.end())
|
||||
if (privateArrays.find(symbIdent) == privateArrays.end() || sharedMemoryParallelization)
|
||||
{
|
||||
const tuple<int, string, string> uniqKey = getUniqName(commonBlocks, decl, currentArray);
|
||||
|
||||
@@ -1401,7 +1403,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
|
||||
else
|
||||
arrayToAdd = itFound->second;
|
||||
|
||||
if (arrayToAdd->IsNotDistribute() == true)
|
||||
if (!sharedMemoryParallelization && arrayToAdd->IsNotDistribute() == true)
|
||||
continue;
|
||||
|
||||
set<DIST::Array*> links;
|
||||
@@ -2094,14 +2096,18 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
if(!sharedMemoryParallelization)
|
||||
for (auto it = itF->second.begin(); it != itF->second.end(); ++it)
|
||||
privatesVars.insert(*it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!sharedMemoryParallelization)
|
||||
{
|
||||
tryToFindPrivateInAttributes(st, privatesVars);
|
||||
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars);
|
||||
}
|
||||
|
||||
if (isDVM_stat(st) == false && isSgExecutableStatement(st))
|
||||
{
|
||||
@@ -2195,6 +2201,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
||||
}
|
||||
}
|
||||
|
||||
if(!sharedMemoryParallelization)
|
||||
addToDistributionGraph(convertedLoopInfo, arrayLinksByFuncCalls);
|
||||
|
||||
for (auto &toDel : tmpLoops)
|
||||
@@ -2203,7 +2210,6 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
||||
|
||||
if (!skipDeps)
|
||||
{
|
||||
|
||||
for (auto &loopLine : loopWithOutArrays)
|
||||
{
|
||||
if (loopLine > 0)
|
||||
@@ -2311,6 +2317,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
||||
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile);
|
||||
}
|
||||
|
||||
if(regime == SHARED_MEMORY_PAR)
|
||||
createParallelDirectives(convertedLoopInfo, regions, arrayLinksByFuncCalls, messagesForFile);
|
||||
|
||||
__spf_print(PRINT_PROF_INFO, "Function ended\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user