Refactor shared memory parallelization #49

Merged
Alexander_KS merged 10 commits from refactor_shared_memory_parallelization into master 2024-07-18 06:50:40 +00:00
35 changed files with 732 additions and 2183 deletions

View File

@@ -240,8 +240,6 @@ set(DIRA _src/DirectiveProcessing/directive_analyzer.cpp
_src/DirectiveProcessing/directive_creator.cpp _src/DirectiveProcessing/directive_creator.cpp
_src/DirectiveProcessing/directive_creator_base.cpp _src/DirectiveProcessing/directive_creator_base.cpp
_src/DirectiveProcessing/directive_creator.h _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.cpp
_src/DirectiveProcessing/directive_parser.h _src/DirectiveProcessing/directive_parser.h
_src/DirectiveProcessing/directive_omp_parser.cpp _src/DirectiveProcessing/directive_omp_parser.cpp
@@ -266,11 +264,8 @@ set(DISTR _src/Distribution/Array.cpp
_src/Distribution/Distribution.h _src/Distribution/Distribution.h
_src/Distribution/DvmhDirective.cpp _src/Distribution/DvmhDirective.cpp
_src/Distribution/DvmhDirective.h _src/Distribution/DvmhDirective.h
_src/Distribution/DvmhDirective_nodist.cpp
_src/Distribution/DvmhDirective_internal.h
_src/Distribution/DvmhDirective_func.h _src/Distribution/DvmhDirective_func.h
_src/Distribution/DvmhDirectiveBase.cpp _src/Distribution/DvmhDirectiveBase.cpp
_src/Distribution/DvmhDirectiveBase_nodist.cpp
_src/Distribution/DvmhDirectiveBase.h _src/Distribution/DvmhDirectiveBase.h
_src/Distribution/GraphCSR.cpp _src/Distribution/GraphCSR.cpp
_src/Distribution/GraphCSR.h) _src/Distribution/GraphCSR.h)
@@ -319,9 +314,6 @@ set(INLINER _src/Inliner/inliner.cpp
set(LOOP_ANALYZER _src/LoopAnalyzer/allocations_prepoc.cpp set(LOOP_ANALYZER _src/LoopAnalyzer/allocations_prepoc.cpp
_src/LoopAnalyzer/dep_analyzer.cpp _src/LoopAnalyzer/dep_analyzer.cpp
_src/LoopAnalyzer/loop_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) _src/LoopAnalyzer/loop_analyzer.h)
set(RENAME_SYMBOLS _src/RenameSymbols/rename_symbols.cpp set(RENAME_SYMBOLS _src/RenameSymbols/rename_symbols.cpp

View File

@@ -45,7 +45,7 @@ using std::get;
using std::string; using std::string;
using std::wstring; using std::wstring;
extern int mpiProgram; extern int sharedMemoryParallelization;
static vector<pair<string, vector<Expression*>>> static vector<pair<string, vector<Expression*>>>
groupRealignsDirs(const vector<pair<string, vector<Expression*>>>& toRealign) groupRealignsDirs(const vector<pair<string, vector<Expression*>>>& toRealign)
@@ -453,7 +453,7 @@ void createParallelDirs(File *file,
auto& tmp = dataDirectives.distrRules; auto& tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar; vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
for (int z1 = 0; z1 < currentVariant.size(); ++z1) for (int z1 = 0; z1 < currentVariant.size(); ++z1)
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]])); currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));

View File

@@ -91,26 +91,17 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
} }
currentLoop->directive = directive; currentLoop->directive = directive;
for (auto& read : currentLoop->readOpsArray) if(!sharedMemoryParallelization)
{ {
const string shortName = read->GetName(); for (auto& read : currentLoop->readOpsArray)
const string orignName = read->GetShortName();
pair<string, string> key = make_pair(orignName, shortName);
bool found = false;
for (int i = 0; i < directive->shadowRenew.size(); ++i)
{ {
if (directive->shadowRenew[i].first == key) const string shortName = read->GetName();
const string orignName = read->GetShortName();
pair<string, string> key = make_pair(orignName, shortName);
bool found = false;
for (int i = 0; i < directive->shadowRenew.size(); ++i)
{ {
found = true; if (directive->shadowRenew[i].first == key)
break;
}
}
if (found == false)
{
for (int i = 0; i < directive->across.size(); ++i)
{
if (directive->across[i].first == key)
{ {
found = true; found = true;
break; break;
@@ -119,11 +110,23 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
if (found == false) if (found == false)
{ {
directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>())); for (int i = 0; i < directive->across.size(); ++i)
{
if (directive->across[i].first == key)
{
found = true;
break;
}
}
const DIST::Array *arrayRef = read; if (found == false)
for (int i = 0; i < arrayRef->GetDimSize(); ++i) {
directive->shadowRenew.back().second.push_back(make_pair(0, 0)); directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>()));
const DIST::Array *arrayRef = read;
for (int i = 0; i < arrayRef->GetDimSize(); ++i)
directive->shadowRenew.back().second.push_back(make_pair(0, 0));
}
} }
} }
} }
@@ -387,6 +390,9 @@ bool checkForConflict(const map<DIST::Array*, ArrayInfo*> &currAccesses,
for (auto &itArray : currAccesses) for (auto &itArray : currAccesses)
{ {
if(!itArray.first)
continue; // skip fictitious array access in free loop
const ArrayInfo &currInfo = *(itArray.second); const ArrayInfo &currInfo = *(itArray.second);
const string &arrayName = itArray.first->GetShortName(); const string &arrayName = itArray.first->GetShortName();
@@ -525,7 +531,7 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
const int itersCount = currLoop->calculatedCountOfIters; const int itersCount = currLoop->calculatedCountOfIters;
uint64_t regId = currReg->GetId(); uint64_t regId = currReg->GetId();
if (mpiProgram) if (sharedMemoryParallelization)
regId = (uint64_t)currLoop; regId = (uint64_t)currLoop;
const DIST::Arrays<int> &allArrays = currReg->GetAllArrays(); const DIST::Arrays<int> &allArrays = currReg->GetAllArrays();
@@ -553,150 +559,155 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
mainArray.hasWrite = true; mainArray.hasWrite = true;
mainArray.mainAccess; mainArray.mainAccess;
set<string> uniqNamesWithAcross; if(!sharedMemoryParallelization)
fillArraysWithAcrossStatus(currLoop, uniqNamesWithAcross);
if (arrayWriteAcc.size() == 1)
{ {
mainArray.arrayRef = arrayWriteAcc.begin()->first; set<string> uniqNamesWithAcross;
mainArray.dimentionPos = arrayWriteAcc.begin()->second.first; fillArraysWithAcrossStatus(currLoop, uniqNamesWithAcross);
mainArray.mainAccess = arrayWriteAcc.begin()->second.second;
if (uniqNamesWithAcross.size()) if (arrayWriteAcc.size() == 1)
mainArray.underAcross = true;
}
else if (arrayWriteAcc.size() > 1)
{
if (uniqNamesWithAcross.size())
mainArray.underAcross = true;
int posDim = -1;
int minDim = 999999;
int k = 0;
vector<pair<string, pair<int, pair<int, int>>>> accesses;
map<int, set<tuple<string, int, int>>> sameDims;
for (auto i = arrayWriteAcc.begin(); i != arrayWriteAcc.end(); ++i, ++k)
{ {
const auto array = i->first; mainArray.arrayRef = arrayWriteAcc.begin()->first;
const string &uniqName = array->GetName(); mainArray.dimentionPos = arrayWriteAcc.begin()->second.first;
mainArray.mainAccess = arrayWriteAcc.begin()->second.second;
//ACROSS arrays have priority state for all nested loops! if (uniqNamesWithAcross.size())
if (uniqNamesWithAcross.size() > 0) mainArray.underAcross = true;
if (uniqNamesWithAcross.find(uniqName) == uniqNamesWithAcross.end()) }
continue; else if (arrayWriteAcc.size() > 1)
{
if (uniqNamesWithAcross.size())
mainArray.underAcross = true;
const int currDim = array->GetDimSize(); int posDim = -1;
auto& sizes = array->GetSizes(); int minDim = 999999;
const int currSize = sizes[i->second.first].second - sizes[i->second.first].first + 1; int k = 0;
sameDims[currDim].insert(make_tuple(uniqName, k, currSize));
if (currDim < minDim) vector<pair<string, pair<int, pair<int, int>>>> accesses;
map<int, set<tuple<string, int, int>>> 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; if (itersCount == 0 || (itersCount != 0) && currSize >= itersCount)
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<set<DIST::Array*>> 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<DIST::Array*> &realArrayRefs1 = realArrayRefs[i];
const set<DIST::Array*> &realArrayRefs2 = realArrayRefs[k];
for (auto &refs1 : realArrayRefs1)
{
for (auto &refs2 : realArrayRefs2)
{ {
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; if (posDim != -1)
const int dimTo = accesses[k].second.first; {
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<set<DIST::Array*>> 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<DIST::Array*> &realArrayRefs1 = realArrayRefs[i];
const set<DIST::Array*> &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", auto links = findLinksBetweenArrays(refs1, refs2, regId);
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 templRule1 = refs1->GetAlignRulesWithTemplate(regId); const int dimFrom = accesses[i].second.first;
auto templRule2 = refs2->GetAlignRulesWithTemplate(regId); 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 -->"; __spf_print(1, "arrays '%s' and '%s' have different align dimensions for loop on line %d\n --> %d vs %d(%d) \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(), array1->GetShortName().c_str(), array2->GetShortName().c_str(),
templRule1[dimFrom].first, templRule1[dimFrom].second, accessFrom.first, accessFrom.second, currLoop->lineNum, dimTo, links[dimFrom], dimFrom);
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; 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) 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; break;
}
} }
if (!statusOk) if (!statusOk)
break; break;
@@ -704,43 +715,43 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
if (!statusOk) if (!statusOk)
break; break;
} }
if (!statusOk)
break;
}
if (statusOk) if (statusOk)
{
k = 0;
for (auto array = arrayWriteAcc.begin(); array != arrayWriteAcc.end(); array++, ++k)
{ {
if (k == posDim) k = 0;
for (auto array = arrayWriteAcc.begin(); array != arrayWriteAcc.end(); array++, ++k)
{ {
mainArray.arrayRef = array->first; if (k == posDim)
mainArray.dimentionPos = array->second.first; {
mainArray.mainAccess = array->second.second; mainArray.arrayRef = array->first;
break; mainArray.dimentionPos = array->second.first;
mainArray.mainAccess = array->second.second;
break;
}
} }
} }
else
{
__spf_print(PRINT_DIR_RESULT, " has conflict writes\n");
hasConflict = true;
}
} }
else else
{ {
__spf_print(PRINT_DIR_RESULT, " has conflict writes\n"); mainArray.hasWrite = false;
hasConflict = true; __spf_print(PRINT_DIR_RESULT, " no regular writes on loop\n");
} }
}
else // fill mainArray if no regular writes found
{ // now OmegaTest is used for searching dependencies
mainArray.hasWrite = false; if (!mainArray.hasWrite)
__spf_print(PRINT_DIR_RESULT, " no regular writes on loop\n"); findMainArrayFromRead(currAccesses, mainArray, itersCount, arrayLinksByFuncCalls);
} }
// fill mainArray if no regular writes found bool dimPosFound = sharedMemoryParallelization ||
// now OmegaTest is used for searching dependencies (mainArray.arrayRef != NULL && mainArray.dimentionPos != -1);
if (!mainArray.hasWrite)
findMainArrayFromRead(currAccesses, mainArray, itersCount, arrayLinksByFuncCalls);
if (!hasConflict && if (dimPosFound &&
mainArray.arrayRef != NULL && mainArray.dimentionPos != -1 &&
!currLoop->hasLimitsToParallel() && !currLoop->hasLimitsToParallel() &&
(currLoop->lineNum > 0 || (currLoop->lineNum < 0 && currLoop->altLineNum > 0))) (currLoop->lineNum > 0 || (currLoop->lineNum < 0 && currLoop->altLineNum > 0)))
{ {
@@ -749,7 +760,7 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
const int dimPos = mainArray.dimentionPos; const int dimPos = mainArray.dimentionPos;
//change array to template if ACROSS was not found or not loop_array //change array to template if ACROSS was not found or not loop_array
if (mainArray.underAcross == false && !(mpiProgram == 1 && mainArray.arrayRef->IsLoopArray())) if (!sharedMemoryParallelization && mainArray.underAcross == false && !mainArray.arrayRef->IsLoopArray())
{ {
set<DIST::Array*> realArrayRef; set<DIST::Array*> realArrayRef;
getRealArrayRefs(mainArray.arrayRef, mainArray.arrayRef, realArrayRef, arrayLinksByFuncCalls); getRealArrayRefs(mainArray.arrayRef, mainArray.arrayRef, realArrayRef, arrayLinksByFuncCalls);
@@ -788,25 +799,30 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
parDir = loop->directive; parDir = loop->directive;
if (parDir != NULL) if (parDir != NULL)
{ {
parDir->arrayRef2 = mainArrayOfLoop; if(!sharedMemoryParallelization)
if (mainArray.underAcross == false)
{ {
for (int i = 0; i < mainArrayOfLoop->GetDimSize(); ++i) parDir->arrayRef2 = mainArrayOfLoop;
{
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 (mainArray.underAcross == false)
if (parDir->on2[z].first != "*" && parDir->on2[z].second == make_pair(0, 0)) {
parDir->on2[z].second = mainAccess; 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); loop->directiveForLoop = new ParallelDirective(*loop->directive);
} }
__spf_print(PRINT_DIR_RESULT, " directive created\n"); __spf_print(PRINT_DIR_RESULT, " directive created\n");
@@ -1762,7 +1778,7 @@ static bool addRedistributionDirs(File* file, const vector<pair<DIST::Array*, co
} }
needToSkip = false; needToSkip = false;
if (mpiProgram) if (sharedMemoryParallelization)
return false; return false;
// Realign with global template clones // Realign with global template clones
@@ -1830,10 +1846,10 @@ void selectParallelDirectiveForVariant(File* file, ParallelRegion* currParReg,
const bool isMyRegion = loop->region == currParReg; const bool isMyRegion = loop->region == currParReg;
const bool noUserDir = loop->userDvmDirective == NULL; const bool noUserDir = loop->userDvmDirective == NULL;
DIST::Array* sameAlignTemplate = 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; bool freeLoopDistr = true;
if (hasDirective && loop->directive->arrayRef2->IsLoopArray()) if (!sharedMemoryParallelization && hasDirective && loop->directive->arrayRef2->IsLoopArray())
{ {
bool ok = false; bool ok = false;
for (auto& elem : distribution) for (auto& elem : distribution)
@@ -1866,33 +1882,38 @@ void selectParallelDirectiveForVariant(File* file, ParallelRegion* currParReg,
//try to unite loops //try to unite loops
if (createNestedLoops(loop, depInfoForLoopGraph, mapFuncInfo, messages)) if (createNestedLoops(loop, depInfoForLoopGraph, mapFuncInfo, messages))
parDirective = loop->recalculateParallelDirective(); parDirective = loop->recalculateParallelDirective();
bool topCheck = isOnlyTopPerfect(loop, distribution);
if(!sharedMemoryParallelization)
bool needToContinue = false;
if (topCheck)
{ {
//<Array, linksWithTempl> -> dims not mached bool topCheck = isOnlyTopPerfect(loop, distribution);
map<DIST::Array*, vector<bool>> 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) bool needToContinue = false;
continue; if (topCheck)
{
//<Array, linksWithTempl> -> dims not mached
map<DIST::Array*, vector<bool>> 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<pair<DIST::Array*, const DistrVariant*>> newRules; vector<pair<DIST::Array*, const DistrVariant*>> newRules;
constructRules(newRules, distribution, loop); if(!sharedMemoryParallelization)
constructRules(newRules, distribution, loop);
Directive* dirImpl = parDirective->genDirective(file, newRules, loop, reducedG, allArrays, regionId, arrayLinksByFuncCalls); Directive* dirImpl = parDirective->genDirective(file, newRules, loop, reducedG, allArrays, regionId, arrayLinksByFuncCalls);
#if __SPF #if __SPF
//move label before loop //move label before loop
if (loop->hasRedistribute()) if (!sharedMemoryParallelization && loop->hasRedistribute())
{ {
auto prev = loop->loop->lexPrev(); auto prev = loop->loop->lexPrev();
if (!prev) if (!prev)

View File

@@ -1,166 +0,0 @@
#include "../Utils/leak_detector.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <vector>
#include <map>
#include <set>
#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<LoopGraph*, map<DIST::Array*, ArrayInfo*>> &loopInfos,
const vector<ParallelRegion*>& regions,
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls,
vector<Messages> &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<int> &allArrays = currReg->GetAllArrays();
vector<pair<pair<string, string>, vector<pair<int, int>>>> acrossInfo;
fillAcrossInfoFromDirectives(currLoop, acrossInfo);
bool hasConflict = false;
// uniqKey -> pair<position of access, pair<acces>> ///write acceses ///
map<DIST::Array*, pair<int, pair<int, int>>, DIST::ArrayComparator> arrayWriteAcc;
set<DIST::Array*> acrossOutArrays;
__spf_print(PRINT_DIR_RESULT, " Loop on line %d:\n", currLoop->lineNum);
const map<DIST::Array*, ArrayInfo*> &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<int>& allArrays,
const vector<LoopGraph*>& loopGraph,
const map<int, LoopGraph*>& mapLoopsInFile,
const map<string, FuncInfo*>& mapFuncInfo,
vector<Directive*>& toInsert,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
const map<LoopGraph*, void*>& depInfoForLoopGraph,
vector<Messages>& 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

View File

@@ -1,26 +0,0 @@
#pragma once
#include <vector>
#include <map>
#include <set>
#include <string>
#include "../Distribution/Distribution.h"
#include "../Utils/errors.h"
#include "../GraphLoop/graph_loops.h"
#include "../Utils/types.h"
void createParallelDirectivesNoDist(const std::map<LoopGraph*, std::map<DIST::Array*, ArrayInfo*>>& loopInfos,
const std::vector<ParallelRegion*>& regions,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls,
std::vector<Messages>& messages);
void selectParallelDirectiveForVariantNoDist(File* file, ParallelRegion* currParReg,
DIST::Arrays<int>& allArrays,
const std::vector<LoopGraph*>& loopGraph,
const std::map<int, LoopGraph*>& mapLoopsInFile,
const std::map<std::string, FuncInfo*>& mapFuncInfo,
std::vector<Directive*>& toInsert,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls,
const std::map<LoopGraph*, void*>& depInfoForLoopGraph,
std::vector<Messages>& messages);

View File

@@ -39,7 +39,7 @@ using std::make_tuple;
static const string dvmhModuleName = "dvmh_template_mod"; static const string dvmhModuleName = "dvmh_template_mod";
extern int mpiProgram; extern int sharedMemoryParallelization;
//the size of vector indiceates type of DVM_DIR //the size of vector indiceates type of DVM_DIR
SgStatement* createStatFromExprs(const vector<Expression*> &exprs) SgStatement* createStatFromExprs(const vector<Expression*> &exprs)
@@ -2384,7 +2384,7 @@ void insertParallelDirs(SgFile *file, bool extract,
const char* file_name = file->filename(); const char* file_name = file->filename();
insertDirectiveToFile(file, file_name, createdDirectives, extract, messages); insertDirectiveToFile(file, file_name, createdDirectives, extract, messages);
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
map<string, FuncInfo*> mapFuncInfo; map<string, FuncInfo*> mapFuncInfo;
createMapOfFunc(callGraph, mapFuncInfo); createMapOfFunc(callGraph, mapFuncInfo);
@@ -2420,7 +2420,7 @@ void insertParallelDirs(SgFile *file, bool extract,
for (auto& array : declaredArrays) for (auto& array : declaredArrays)
array.second.first->ClearShadowSpecs(); array.second.first->ClearShadowSpecs();
} }
else if (mpiProgram == 0) else if (sharedMemoryParallelization == 0)
{ {
set<uint64_t> regNum; set<uint64_t> regNum;
for (int z = 0; z < parallelRegions.size(); ++z) for (int z = 0; z < parallelRegions.size(); ++z)

View File

@@ -22,7 +22,7 @@ struct FuncInfo;
#define TO_STR std::to_string #define TO_STR std::to_string
#if __SPF #if __SPF
extern int mpiProgram; extern int sharedMemoryParallelization;
#endif #endif
namespace Distribution namespace Distribution
@@ -117,7 +117,7 @@ namespace Distribution
if (it == templateInfo.end()) if (it == templateInfo.end())
{ {
#if __SPF #if __SPF
if (withCheck && mpiProgram != 0) if (withCheck && sharedMemoryParallelization != 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
#endif #endif
currLink = new TemplateLink(dimSize); currLink = new TemplateLink(dimSize);

View File

@@ -530,7 +530,7 @@ int createAlignDirs(DIST::GraphCSR<int, double, attrType> &reducedG, const DIST:
{ {
DIST::Array* array = arrayPair.second; DIST::Array* array = arrayPair.second;
if (mpiProgram != 0) if (sharedMemoryParallelization != 0)
if (onlyThese.find(array) == onlyThese.end()) if (onlyThese.find(array) == onlyThese.end())
continue; continue;
@@ -604,7 +604,7 @@ int createAlignDirs(DIST::GraphCSR<int, double, attrType> &reducedG, const DIST:
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); 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); bool hasError = createNewAlignRule(array, allArrays, rules[0], dataDirectives, SPF_messages, canNotAlign == NULL);
if (hasError) if (hasError)

View File

@@ -9,7 +9,6 @@
#include "../Utils/types.h" #include "../Utils/types.h"
#include "DvmhDirective.h" #include "DvmhDirective.h"
#include "DvmhDirective_internal.h"
#include "../Utils/errors.h" #include "../Utils/errors.h"
#include "../Utils/SgUtils.h" #include "../Utils/SgUtils.h"
#include "../Sapfor.h" #include "../Sapfor.h"
@@ -75,7 +74,7 @@ static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray,
return res; return res;
} }
bool needCorner(const DIST::Array* currArray, const vector<map<pair<int, int>, int>> &shiftsByAccess, Statement *loop) static bool needCorner(const DIST::Array* currArray, const vector<map<pair<int, int>, int>> &shiftsByAccess, Statement *loop)
{ {
bool need = false; bool need = false;
@@ -93,7 +92,6 @@ bool needCorner(const DIST::Array* currArray, const vector<map<pair<int, int>, i
return need; return need;
} }
vector<SgExpression*> genSubscripts(const vector<pair<int, int>> &shadowRenew, const vector<pair<int, int>> &shadowRenewShifts) vector<SgExpression*> genSubscripts(const vector<pair<int, int>> &shadowRenew, const vector<pair<int, int>> &shadowRenewShifts)
{ {
vector<SgExpression*> subs; vector<SgExpression*> subs;
@@ -174,7 +172,7 @@ static SgExpression* genSgExpr(SgFile *file, const string &letter, const pair<in
return retVal; return retVal;
} }
std::multimap<string, Symbol*> setToMapWithSortByStr(const set<Symbol*> &setIn) static std::multimap<string, Symbol*> setToMapWithSortByStr(const set<Symbol*> &setIn)
{ {
std::multimap<string, Symbol*> retMap; std::multimap<string, Symbol*> retMap;
for (auto& elem : setIn) for (auto& elem : setIn)
@@ -207,7 +205,7 @@ static set<string> fillUsedSymbols(SgStatement *loop)
return usedS; 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); SgStatement* local = SgStatement::getStatementByFileAndLine(file, line);
if (local == NULL) if (local == NULL)
@@ -216,7 +214,7 @@ SgStatement* getRealStat(const char *file, const int line, const int altLine)
return local; return local;
} }
string correctSymbolModuleName(const string& origFull) static string correctSymbolModuleName(const string& origFull)
{ {
auto it = origFull.find("::"); auto it = origFull.find("::");
if (it == string::npos) if (it == string::npos)
@@ -225,7 +223,7 @@ string correctSymbolModuleName(const string& origFull)
return origFull.substr(it + 2); return origFull.substr(it + 2);
} }
SgStatement* getModuleScope(const string& origFull, vector<SgStatement*>& moduleList, SgStatement *local) static SgStatement* getModuleScope(const string& origFull, vector<SgStatement*>& moduleList, SgStatement *local)
{ {
auto it = origFull.find("::"); auto it = origFull.find("::");
if (it == string::npos) if (it == string::npos)
@@ -245,11 +243,14 @@ static vector<SgExpression*>
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
const map<string, set<SgSymbol*>>& byUseInFunc, const map<string, set<SgSymbol*>>& byUseInFunc,
File* file, const pair<int, int>& lineRange, File* file, const pair<int, int>& lineRange,
const set<DIST::Array*>& onlyFor) const set<DIST::Array*>& onlyFor,
const set<string>& privates)
{ {
vector<SgExpression*> tieList; vector<SgExpression*> tieList;
vector<pair<DIST::Array*, DIST::Array*>> realRefsUsed; vector<pair<DIST::Array*, DIST::Array*>> realRefsUsed;
for (auto& elem : currLoop->usedArrays)
const auto& usedArrays = sharedMemoryParallelization ? currLoop->usedArraysAll : currLoop->usedArrays;
for (auto& elem : usedArrays)
{ {
if (onlyFor.size()) if (onlyFor.size())
if (onlyFor.find(elem) == onlyFor.end()) if (onlyFor.find(elem) == onlyFor.end())
@@ -269,6 +270,9 @@ static vector<SgExpression*>
for (auto& pairs : realRefsUsed) for (auto& pairs : realRefsUsed)
{ {
if (privates.find(pairs.second->GetShortName()) != privates.end())
continue;
auto type = pairs.second->GetDeclSymbol(currLoop->fileName, lineRange, getAllFilesInProject())->GetOriginal()->type(); auto type = pairs.second->GetDeclSymbol(currLoop->fileName, lineRange, getAllFilesInProject())->GetOriginal()->type();
SgSymbol* arrayS = getFromModule(byUseInFunc, findSymbolOrCreate(file, pairs.second->GetShortName(), type)); SgSymbol* arrayS = getFromModule(byUseInFunc, findSymbolOrCreate(file, pairs.second->GetShortName(), type));
SgArrayRefExp* array = new SgArrayRefExp(*arrayS); SgArrayRefExp* array = new SgArrayRefExp(*arrayS);
@@ -281,75 +285,102 @@ static vector<SgExpression*>
for (int z = 0; z < loops.size(); ++z) for (int z = 0; z < loops.size(); ++z)
{ {
currLoop = loops[z]; currLoop = loops[z];
const uint64_t regId = mpiProgram ? (uint64_t)currLoop : currLoop->region->GetId();
auto dirForLoop = currLoop->directiveForLoop;
auto tmplP = pairs.first->GetTemplateArray(regId, mpiProgram != 0); if(!sharedMemoryParallelization)
auto links = pairs.first->GetLinksWithTemplate(regId);
// no mapping for this loop, skip this
if (tmplP == dirForLoop->arrayRef)
{ {
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]; for (int z = 0; z < links.size(); ++z)
if (dim >= 0)
{ {
if (dirForLoop->on[dim].first != "*") int dim = links[z];
if (dim >= 0)
{ {
needToAdd = true; if (dirForLoop->on[dim].first != "*")
subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[dim].first)); {
break; needToAdd = true;
subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[dim].first));
break;
}
} }
} }
} }
} else if (pairs.second == dirForLoop->arrayRef)
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<DIST::Array*> realRefsLocal;
getRealArrayRefs(dirForLoop->arrayRef, dirForLoop->arrayRef, realRefsLocal, arrayLinksByFuncCalls);
if (realRefsLocal.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto tmplP = (*realRefsLocal.begin())->GetTemplateArray(regId, mpiProgram != 0);
auto links = (*realRefsLocal.begin())->GetLinksWithTemplate(regId);
auto tmplP_et = pairs.first->GetTemplateArray(regId, mpiProgram != 0);
auto links_et = pairs.first->GetLinksWithTemplate(regId);
if (tmplP == tmplP_et)
{ {
for (int z = 0; z < dirForLoop->on.size(); ++z) for (int z = 0; z < dirForLoop->on.size(); ++z)
{ {
if (dirForLoop->on[z].first != "*") if (dirForLoop->on[z].first != "*")
{ {
const int idx = links[z]; needToAdd = true;
for (int p = 0; p < links_et.size(); ++p) subs[z] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first));
{
if (idx >= 0 && links_et[p] == idx)
{
subs[p] = new SgVarRefExp(findSymbolOrCreate(file, dirForLoop->on[z].first));
needToAdd = true;
break;
}
}
break; break;
} }
} }
} }
else if (!dirForLoop->arrayRef->IsTemplate())
{
set<DIST::Array*> 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;
}
}
} }
} }
@@ -365,7 +396,7 @@ static vector<SgExpression*>
} }
//TODO: need to improve //TODO: need to improve
set<SgSymbol*> fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine) static set<SgSymbol*> fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine)
{ {
set<SgSymbol*> used; set<SgSymbol*> used;
set<SgSymbol*> usedInSpfPar; set<SgSymbol*> usedInSpfPar;
@@ -385,7 +416,7 @@ set<SgSymbol*> fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altL
return usedInSpfPar; return usedInSpfPar;
} }
set<SgSymbol*> changeLoopOrder(const vector<string>& parallel, const vector<string>& newParallel, vector<LoopGraph*>& loops) static set<SgSymbol*> changeLoopOrder(const vector<string>& parallel, const vector<string>& newParallel, vector<LoopGraph*>& loops)
{ {
set<SgSymbol*> additionalPrivates; set<SgSymbol*> additionalPrivates;
if (parallel == newParallel) if (parallel == newParallel)
@@ -452,7 +483,7 @@ set<SgSymbol*> changeLoopOrder(const vector<string>& parallel, const vector<stri
return additionalPrivates; return additionalPrivates;
} }
vector<int> sortShadow(const vector<pair<pair<string, string>, vector<pair<int, int>>>>& toSort) static vector<int> sortShadow(const vector<pair<pair<string, string>, vector<pair<int, int>>>>& toSort)
{ {
map<string, int> order; map<string, int> order;
for (int z = 0; z < toSort.size(); ++z) for (int z = 0; z < toSort.size(); ++z)
@@ -477,7 +508,7 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
{ {
const set<DIST::Array*>& acrossOutAttribute = currLoop->acrossOutAttribute; const set<DIST::Array*>& acrossOutAttribute = currLoop->acrossOutAttribute;
const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>>& readOps = currLoop->readOps; const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>>& readOps = currLoop->readOps;
map< DIST::Array*, vector<ArrayOp>>& remoteReads = currLoop->remoteRegularReads; map<DIST::Array*, vector<ArrayOp>>& remoteReads = currLoop->remoteRegularReads;
Statement* loop = currLoop->loop; Statement* loop = currLoop->loop;
string directive = ""; string directive = "";
@@ -501,6 +532,10 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
LoopGraph* pLoop = currLoop; LoopGraph* pLoop = currLoop;
const set<string> allFiles = getAllFilesInProject(); const set<string> allFiles = getAllFilesInProject();
map<string, DIST::Array*> arrayByName;
for (DIST::Array* arr : currLoop->getAllArraysInLoop())
arrayByName[arr->GetName()] = arr;
for (int z = 0; z < nested; ++z) for (int z = 0; z < nested; ++z)
{ {
loopSymbs.push_back(loopG->symbol()); loopSymbs.push_back(loopG->symbol());
@@ -552,21 +587,25 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
p->setRhs(NULL); p->setRhs(NULL);
} }
DIST::Array* mapTo = arrayRef2->IsLoopArray() ? arrayRef : arrayRef2; DIST::Array* mapTo;
auto onTo = arrayRef2->IsLoopArray() ? on : on2;
dirStatement[2] = new Expression(expr); dirStatement[2] = new Expression(expr);
if (mpiProgram) if (sharedMemoryParallelization)
{
directive += ")"; directive += ")";
}
else else
{
mapTo = arrayRef2->IsLoopArray() ? arrayRef : arrayRef2;
directive += ") ON " + mapTo->GetShortName() + "("; directive += ") ON " + mapTo->GetShortName() + "(";
}
SgArrayRefExp* arrayExpr = NULL; SgArrayRefExp* arrayExpr = NULL;
string arrayExprS = ""; string arrayExprS = "";
if (!mpiProgram) if (!sharedMemoryParallelization)
{ {
auto onTo = arrayRef2->IsLoopArray() ? on : on2;
SgSymbol* symbForPar = NULL; SgSymbol* symbForPar = NULL;
if (arrayRef->IsTemplate()) if (arrayRef->IsTemplate())
{ {
@@ -652,52 +691,49 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
p->setLhs(makeExprList(list)); p->setLhs(makeExprList(list));
} }
if (mpiProgram || across.size() != 0) if (sharedMemoryParallelization || (across.size() != 0 && !arrayRef2->IsLoopArray()))
{ {
if (!arrayRef2->IsLoopArray()) vector<LoopGraph*> loopsTie;
for (int i = 0; i < (int)parallel.size(); ++i)
if (parallel[i] != "*")
loopsTie.push_back(loops[i]);
set<DIST::Array*> onlyFor;
if (sharedMemoryParallelization == 0 && across.size())
{ {
vector<LoopGraph*> loopsTie; for (int k = 0; k < (int)across.size(); ++k)
for (int i = 0; i < (int)parallel.size(); ++i)
if (parallel[i] != "*")
loopsTie.push_back(loops[i]);
set<DIST::Array*> onlyFor;
if (mpiProgram == 0 && across.size())
{ {
for (int k = 0; k < (int)across.size(); ++k) DIST::Array* currArray = allArrays.GetArrayByName(across[k].first.second);
{ if (currArray != mapTo)
DIST::Array* currArray = allArrays.GetArrayByName(across[k].first.second); onlyFor.insert(currArray);
if (currArray != mapTo)
onlyFor.insert(currArray);
}
} }
vector<SgExpression*> tieList; }
if (mpiProgram) vector<SgExpression*> tieList;
tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor); if (sharedMemoryParallelization)
else if (onlyFor.size()) // not MPI regime tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor, uniqNamesOfPrivates);
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, uniqNamesOfPrivates);
if (tieList.size()) if (tieList.size())
{
if (dirStatement[1] != NULL)
{ {
if (dirStatement[1] != NULL) expr = createAndSetNext(RIGHT, EXPR_LIST, expr);
{ p = expr;
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 += ")";
} }
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 += ")";
} }
} }
@@ -729,13 +765,26 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
{ {
const int i1 = ordered[k]; const int i1 = ordered[k];
vector<map<pair<int, int>, int>> shiftsByAccess; vector<map<pair<int, int>, int>> shiftsByAccess;
DIST::Array* currArray = NULL;
DIST::Array* currArray = allArrays.GetArrayByName(across[i1].first.second); if (!sharedMemoryParallelization)
if (currArray == NULL) {
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); 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(); bool isOut = acrossOutAttribute.find(currArray) != acrossOutAttribute.end();
string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, currArray, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls);
if (bounds != "") if (bounds != "")
{ {
if (inserted != 0) if (inserted != 0)
@@ -807,7 +856,7 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
} }
} }
if (shadowRenew.size() != 0 && mpiProgram == 0) if (shadowRenew.size() != 0 && sharedMemoryParallelization == 0)
{ {
if (shadowRenewShifts.size() == 0) if (shadowRenewShifts.size() == 0)
{ {
@@ -824,7 +873,8 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
{ {
const int i1 = ordered[k]; const int i1 = ordered[k];
vector<map<pair<int, int>, int>> shiftsByAccess; vector<map<pair<int, int>, 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 != "") if (bounds != "")
{ {
DIST::Array* currArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); DIST::Array* currArray = allArrays.GetArrayByName(shadowRenew[i1].first.second);
@@ -976,7 +1026,7 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
dirStatement[1] = new Expression(expr); dirStatement[1] = new Expression(expr);
} }
if (remoteAccess.size() != 0 && mpiProgram == 0) if (remoteAccess.size() != 0 && sharedMemoryParallelization == 0)
{ {
if (dirStatement[1] != NULL) if (dirStatement[1] != NULL)
{ {

View File

@@ -11,7 +11,7 @@
#include "../Utils/types.h" #include "../Utils/types.h"
#include "../Utils/utils.h" #include "../Utils/utils.h"
extern int mpiProgram; extern int sharedMemoryParallelization;
struct LoopGraph; struct LoopGraph;
@@ -143,10 +143,6 @@ public:
const uint64_t regionId, const uint64_t regionId,
const std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls); const std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls);
Directive*
genDirectiveNoDist(File* file, LoopGraph* currLoop, DIST::Arrays<int>& allArrays,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
friend ParallelDirective* operator+(const ParallelDirective &first, const ParallelDirective &second); friend ParallelDirective* operator+(const ParallelDirective &first, const ParallelDirective &second);
~ParallelDirective() ~ParallelDirective()
@@ -166,7 +162,7 @@ private:
std::string genBounds(std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>> &shadowOp, std::string genBounds(std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>> &shadowOp,
std::vector<std::pair<int, int>> &shadowOpShift, std::vector<std::pair<int, int>> &shadowOpShift,
DIST::GraphCSR<int, double, attrType> &reducedG, DIST::GraphCSR<int, double, attrType> &reducedG,
DIST::Arrays<int> &allArrays, DIST::Arrays<int> &allArrays, DIST::Array* shadowArray,
std::map<DIST::Array*, std::vector<ArrayOp>>& remoteRegularReads, std::map<DIST::Array*, std::vector<ArrayOp>>& remoteRegularReads,
const std::map<DIST::Array*, std::pair<std::vector<ArrayOp>, std::vector<bool>>> &readOps, const std::map<DIST::Array*, std::pair<std::vector<ArrayOp>, std::vector<bool>>> &readOps,
const bool isAcross, const uint64_t regionId, const bool isAcross, const uint64_t regionId,

View File

@@ -111,7 +111,7 @@ ParallelDirective* operator+(const ParallelDirective &left, const ParallelDirect
checkNull(second, convertFileName(__FILE__).c_str(), __LINE__); checkNull(second, convertFileName(__FILE__).c_str(), __LINE__);
bool condition = first->arrayRef == second->arrayRef; bool condition = first->arrayRef == second->arrayRef;
if (mpiProgram) if (sharedMemoryParallelization)
condition = !hasConflictUniteOnRules(first->on, second->on) && !hasConflictUniteOnRules(first->on2, second->on2); condition = !hasConflictUniteOnRules(first->on, second->on) && !hasConflictUniteOnRules(first->on2, second->on2);
if (condition) if (condition)
@@ -268,20 +268,23 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
const uint64_t regionId, const uint64_t regionId,
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls) const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls)
{ {
vector<tuple<DIST::Array*, int, pair<int, int>>> ruleForOn = vector<tuple<DIST::Array*, int, pair<int, int>>> ruleForOn, ruleForShadow;
getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId);
vector<tuple<DIST::Array*, int, pair<int, int>>> ruleForShadow = if (!sharedMemoryParallelization)
getAlignRuleWithTemplate(calcForArray, arrayLinksByFuncCalls, reducedG, allArrays, regionId); {
ruleForOn = getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId);
ruleForShadow = getAlignRuleWithTemplate(calcForArray, arrayLinksByFuncCalls, reducedG, allArrays, regionId);
}
string out = ""; string out = "";
// check for distributed and not mapped dims -> zero them out ('coeffs.second') // check for distributed and not mapped dims -> zero them out ('coeffs.second')
set<DIST::Array*> refs; set<DIST::Array*> refs;
getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls); getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls);
if (mpiProgram == 0) //TODO: need to correct errors
{//TODO: need to correct errors /*if (!sharedMemoryParallelization)
/*for (auto& array : refs) {
for (auto& array : refs)
{ {
DIST::Array* tmpl = array->GetTemplateArray(regionId); DIST::Array* tmpl = array->GetTemplateArray(regionId);
checkNull(tmpl, convertFileName(__FILE__).c_str(), __LINE__); checkNull(tmpl, convertFileName(__FILE__).c_str(), __LINE__);
@@ -322,17 +325,20 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
if (!found) if (!found)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
} */ }
} }*/
const pair<vector<ArrayOp>, vector<bool>> *currReadOp = NULL; const pair<vector<ArrayOp>, vector<bool>> *currReadOp = NULL;
auto readIt = readOps.find(calcForArray); auto readIt = readOps.find(calcForArray);
if (readIt != readOps.end()) if (readIt != readOps.end())
currReadOp = &(readIt->second); currReadOp = &(readIt->second);
findAndReplaceDimentions(ruleForOn, allArrays); if(!sharedMemoryParallelization)
findAndReplaceDimentions(ruleForShadow, allArrays); {
findAndReplaceDimentions(ruleForOn, allArrays);
findAndReplaceDimentions(ruleForShadow, allArrays);
}
const int len = (int)coeffs.second.size(); const int len = (int)coeffs.second.size();
vector<pair<int, int>> shift(len); vector<pair<int, int>> shift(len);
@@ -352,7 +358,20 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
// no unrecognized read operations // no unrecognized read operations
if (currReadOp->second[k] == false) 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<int, int> currRuleShadow = get<2>(ruleForShadow[k]); const pair<int, int> currRuleShadow = get<2>(ruleForShadow[k]);
@@ -451,22 +470,25 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
} }
} }
if (coeffs.second[k].first + shift[k].first < 0) if(!sharedMemoryParallelization)
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)) if (coeffs.second[k].first + shift[k].first < 0)
shift[k] = make_pair(0, 0); shift[k].first = -coeffs.second[k].first;
}
else if (isNonDistributedDim(ruleForOn, ruleForShadow, k, distribution, parallelOnRule)) if (coeffs.second[k].second + shift[k].second < 0)
{ shift[k].second = -coeffs.second[k].second;
shift[k].first = -coeffs.second[k].first;
shift[k].second = -coeffs.second[k].second; if (isAcross)
shiftsByAccess[k].clear(); {
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); sprintf(buf, "%d:%d", coeffs.second[k].first + shift[k].first, coeffs.second[k].second + shift[k].second);
@@ -486,7 +508,7 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
string ParallelDirective::genBounds(pair<pair<string, string>, vector<pair<int, int>>> &shadowOp, string ParallelDirective::genBounds(pair<pair<string, string>, vector<pair<int, int>>> &shadowOp,
vector<pair<int, int>> &shadowOpShift, vector<pair<int, int>> &shadowOpShift,
DIST::GraphCSR<int, double, attrType> &reducedG, DIST::GraphCSR<int, double, attrType> &reducedG,
DIST::Arrays<int> &allArrays, DIST::Arrays<int> &allArrays, DIST::Array* shadowArray,
map<DIST::Array*, vector<ArrayOp>>& remoteRegularReads, map<DIST::Array*, vector<ArrayOp>>& remoteRegularReads,
const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>> &readOps, const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>> &readOps,
const bool isAcross, const bool isAcross,
@@ -496,38 +518,40 @@ string ParallelDirective::genBounds(pair<pair<string, string>, vector<pair<int,
vector<map<pair<int, int>, int>> &shiftsByAccess, vector<map<pair<int, int>, int>> &shiftsByAccess,
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls) const const map<DIST::Array*, set<DIST::Array*>> &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; auto on_ext = on;
//replace to template align ::on
if (arrayRef->IsTemplate() == false && mpiProgram == 0) if(!sharedMemoryParallelization)
{ {
vector<tuple<DIST::Array*, int, pair<int, int>>> ruleForRef = //replace to template align ::on
getAlignRuleWithTemplate(arrayRef, arrayLinksByFuncCalls, reducedG, allArrays, regionId); if (arrayRef->IsTemplate() == false)
findAndReplaceDimentions(ruleForRef, allArrays);
on_ext.clear();
for (int i = 0; i < ruleForRef.size(); ++i)
{ {
if (get<0>(ruleForRef[i])) vector<tuple<DIST::Array*, int, pair<int, int>>> 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()); if (get<0>(ruleForRef[i]))
break; {
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))); //replace single dim to key word 'SINGLE'
for (int i = 0; i < on_ext.size(); ++i)
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)
{ {
if (on_ext[i].first != "*") if (on_ext[i].first != "*")
{ {
@@ -535,8 +559,9 @@ string ParallelDirective::genBounds(pair<pair<string, string>, vector<pair<int,
on_ext[i].first = "SINGLE"; on_ext[i].first = "SINGLE";
} }
} }
}
string ret = ""; string ret = "";
if (isAcross) if (isAcross)
{ {
arraysInAcross.insert(shadowArray); arraysInAcross.insert(shadowArray);

View File

@@ -1,96 +0,0 @@
#include "../Utils/leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#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<pair<string, string>, vector<pair<int, int>>>& coeffs,
vector<pair<int, int>>& shifts,
vector<map<pair<int, int>, int>>& shiftsByAccess,
const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>>& readOps,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
{
string out = "";
// check for distributed and not mapped dims -> zero them out ('coeffs.second')
set<DIST::Array*> refs;
getRealArrayRefs(calcForArray, calcForArray, refs, arrayLinksByFuncCalls);
const pair<vector<ArrayOp>, vector<bool>>* 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<pair<int, int>, 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<pair<string, string>, vector<pair<int, int>>>& shadowOp,
vector<pair<int, int>>& shadowOpShift,
DIST::Array* currArray,
const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>>& readOps,
set<DIST::Array*>& arraysInAcross,
vector<map<pair<int, int>, int>>& shiftsByAccess,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls) const
{
arraysInAcross.insert(currArray);
return calculateShiftsNoDist(arrayRef, currArray, shadowOp, shadowOpShift, shiftsByAccess, readOps, arrayLinksByFuncCalls);
}

View File

@@ -1,17 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <set>
#include <map>
std::vector<int> sortShadow(const std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>>& toSort);
std::set<SgSymbol*> changeLoopOrder(const std::vector<std::string>& parallel, const std::vector<std::string>& newParallel, std::vector<LoopGraph*>& loops);
std::set<SgSymbol*> fillPrivateOnlyFromSpfParameter(SgStatement* loop, const int altLine);
SgStatement* getModuleScope(const std::string& origFull, std::vector<SgStatement*>& moduleList, SgStatement* local);
std::string correctSymbolModuleName(const std::string& origFull);
SgStatement* getRealStat(const char* file, const int line, const int altLine);
std::multimap<std::string, Symbol*> setToMapWithSortByStr(const std::set<Symbol*>& setIn);
bool needCorner(const DIST::Array* currArray, const std::vector<std::map<std::pair<int, int>, int>>& shiftsByAccess, Statement* loop);

View File

@@ -1,477 +0,0 @@
#include "../Utils/leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <vector>
#include <string>
#include <algorithm>
#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<SgExpression*>
compliteTieListNoDist(const LoopGraph* currLoop,
const set<string>& privates,
const vector<LoopGraph*>& loops,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
const map<string, set<SgSymbol*>>& byUseInFunc,
File* file, const pair<int, int>& lineRange)
{
vector<SgExpression*> 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<SgExpression*> 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<int>& allArrays,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
{
const set<DIST::Array*>& acrossOutAttribute = currLoop->acrossOutAttribute;
const map<DIST::Array*, pair<vector<ArrayOp>, vector<bool>>>& readOps = currLoop->readOps;
map< DIST::Array*, vector<ArrayOp>>& remoteReads = currLoop->remoteRegularReads;
Statement* loop = currLoop->loop;
string directive = "";
vector<Expression*> dirStatement = { NULL, NULL, NULL };
SgForStmt* loopG = (SgForStmt*)loop->GetOriginal();
vector<SgStatement*> moduleList;
findModulesInFile(file, moduleList);
SgStatement* realStat = getRealStat(file->filename(), currLoop->lineNum, currLoop->altLineNum);
SgStatement* parentFunc = getFuncStat(realStat);
const map<string, set<SgSymbol*>> byUseInFunc = moduleRefsByUseInFunction(realStat);
const int nested = countPerfectLoopNest(loopG);
const pair<int, int> lineRange = make_pair(parentFunc->lineNumber(), parentFunc->lastNodeOfStmt()->lineNumber());
const string& filename = currLoop->fileName;
vector<SgSymbol*> loopSymbs;
vector<LoopGraph*> loops;
LoopGraph* pLoop = currLoop;
const set<string> allFiles = getAllFilesInProject();
map<string, DIST::Array*> 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<SgStatement*, SgStatement*>(next, set<int>{ SPF_PARAMETER_OP });
while (attrSpfPar.size() != 0 && next)
{
next = next->lexNext();
attrSpfPar = getAttributes<SgStatement*, SgStatement*>(next, set<int>{ 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<string> filteredParalel;
for (int i = 0; i < (int)parallel.size(); ++i)
if (parallel[i] != "*")
filteredParalel.push_back(parallel[i]);
set<SgSymbol*> 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<string> 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<SgExpression*> 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<LoopGraph*> loopsTie;
for (int i = 0; i < (int)parallel.size(); ++i)
if (parallel[i] != "*")
loopsTie.push_back(loops[i]);
vector<SgExpression*> 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<DIST::Array*> 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<int> ordered = sortShadow(across);
for (int k = 0; k < (int)across.size(); ++k)
{
const int i1 = ordered[k];
vector<map<pair<int, int>, 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;
}

View File

@@ -1166,7 +1166,7 @@ void DvmhRegionInserter::removePrivatesFromParallelLoops()
if (lexPrev->variant() == DVM_PARALLEL_ON_DIR) if (lexPrev->variant() == DVM_PARALLEL_ON_DIR)
{ {
if (mpiProgram == 1) if (sharedMemoryParallelization == 1)
lexPrev->deleteStmt(); lexPrev->deleteStmt();
else else
{ {
@@ -1309,7 +1309,7 @@ void insertDvmhRegions(SgProject& project, int files, const vector<ParallelRegio
const map<DIST::Array*, set<DIST::Array*>> arrayLinksByFuncCalls) const map<DIST::Array*, set<DIST::Array*>> arrayLinksByFuncCalls)
{ {
vector<DvmhRegionInserter*> inserters; vector<DvmhRegionInserter*> 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<DIST::Array*> usedArraysInRegions; set<DIST::Array*> usedArraysInRegions;
set<DIST::Array*> usedWriteArraysInRegions; set<DIST::Array*> usedWriteArraysInRegions;
@@ -1328,7 +1328,7 @@ void insertDvmhRegions(SgProject& project, int files, const vector<ParallelRegio
for (auto& loop : loopsForFile) for (auto& loop : loopsForFile)
loop->analyzeParallelDirs(); loop->analyzeParallelDirs();
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); inserters.push_back(regionInserter);
//collect info about <parallel> functions //collect info about <parallel> functions

View File

@@ -849,12 +849,12 @@ void excludeArraysFromDistribution(const map<DIST::Array*, set<DIST::Array*>>& a
vector<ParallelRegion*> parallelRegions, vector<ParallelRegion*> parallelRegions,
map<string, vector<Messages>>& SPF_messages, map<string, vector<Messages>>& SPF_messages,
map<tuple<int, string, string>, DIST::Array*>& createdArrays, map<tuple<int, string, string>, DIST::Array*>& createdArrays,
int mpiProgram) int sharedMemoryParallelization)
{ {
checkArraysMapping(loopGraph, SPF_messages, arrayLinksByFuncCalls); checkArraysMapping(loopGraph, SPF_messages, arrayLinksByFuncCalls);
propagateArrayFlags(arrayLinksByFuncCalls, declaredArrays, SPF_messages); propagateArrayFlags(arrayLinksByFuncCalls, declaredArrays, SPF_messages);
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
for (int z = 0; z < parallelRegions.size(); ++z) for (int z = 0; z < parallelRegions.size(); ++z)
filterArrayInCSRGraph(loopGraph, allFuncInfo, parallelRegions[z], arrayLinksByFuncCalls, SPF_messages); filterArrayInCSRGraph(loopGraph, allFuncInfo, parallelRegions[z], arrayLinksByFuncCalls, SPF_messages);

View File

@@ -34,7 +34,7 @@ void createMapOfFunc(const std::vector<FuncInfo*> &allFuncInfo, std::map<std::pa
FuncInfo* getFuncInfo(const std::map<std::string, FuncInfo*> &funcMap, const std::string &funcName); FuncInfo* getFuncInfo(const std::map<std::string, FuncInfo*> &funcMap, const std::string &funcName);
void updateFuncInfo(const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo); void updateFuncInfo(const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
void excludeArraysFromDistribution(const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::vector<ParallelRegion*> parallelRegions, std::map<std::string, std::vector<Messages>>& SPF_messages, std::map<std::tuple<int, std::string, std::string>, DIST::Array*>& createdArrays, int mpiProgram = 0); void excludeArraysFromDistribution(const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::vector<ParallelRegion*> parallelRegions, std::map<std::string, std::vector<Messages>>& SPF_messages, std::map<std::tuple<int, std::string, std::string>, DIST::Array*>& createdArrays, int sharedMemoryParallelization = 0);
#if __SPF #if __SPF
void functionAnalyzer(SgFile *file, std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::vector<LoopGraph*> &loops, std::vector<Messages> &messagesForFile, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& fullIR); void functionAnalyzer(SgFile *file, std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::vector<LoopGraph*> &loops, std::vector<Messages> &messagesForFile, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& fullIR);

View File

@@ -423,7 +423,7 @@ static bool hasNonRect(SgForStmt *st, const vector<LoopGraph*> &parentLoops, vec
SgExpression* end = st->end(); SgExpression* end = st->end();
SgExpression* step = st->step(); SgExpression* step = st->step();
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
set<DIST::Array*> usedArrays; set<DIST::Array*> usedArrays;
@@ -609,7 +609,7 @@ static bool hasSubstringRef(SgStatement* loop)
return false; return false;
} }
void loopGraphAnalyzer(SgFile *file, vector<LoopGraph*> &loopGraph, const vector<SpfInterval*> &intervalTree, vector<Messages> &messages, int mpiProgram) void loopGraphAnalyzer(SgFile *file, vector<LoopGraph*> &loopGraph, const vector<SpfInterval*> &intervalTree, vector<Messages> &messages, int sharedMemoryParallelization)
{ {
map<int, SpfInterval*> mapIntervals; map<int, SpfInterval*> mapIntervals;
createMapOfinterval(mapIntervals, intervalTree); createMapOfinterval(mapIntervals, intervalTree);

View File

@@ -327,7 +327,7 @@ public:
bool isArrayTemplatesTheSame(DIST::Array*& sameTemplate, const uint64_t regId, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls) bool isArrayTemplatesTheSame(DIST::Array*& sameTemplate, const uint64_t regId, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls)
{ {
if (mpiProgram != 0) if (sharedMemoryParallelization != 0)
return true; return true;
std::set<DIST::Array*> usedForRegAccess; std::set<DIST::Array*> usedForRegAccess;

View File

@@ -567,12 +567,12 @@ void addToDistributionGraph(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*>>
getRealArrayRefs(access.first, access.first, realArrayRefs[access.first], arrayLinksByFuncCalls); getRealArrayRefs(access.first, access.first, realArrayRefs[access.first], arrayLinksByFuncCalls);
bool has_Wr_edges = false, has_Ww_edges = false, has_Rr_edges = false; 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_Wr_edges = processLinks(currAccessesV, allArrays, realArrayRefs, sharedMemoryParallelization == 0 ? G :loopGraph, WW_link);
has_Ww_edges |= processLinks(currAccessesV, allArrays, realArrayRefs, mpiProgram == 0 ? G : loopGraph, WR_link); has_Ww_edges |= processLinks(currAccessesV, allArrays, realArrayRefs, sharedMemoryParallelization == 0 ? G : loopGraph, WR_link);
if (!has_Wr_edges && !has_Ww_edges) 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) if (!has_Wr_edges && !has_Ww_edges && !has_Rr_edges)
for (auto& elem : realArrayRefs) for (auto& elem : realArrayRefs)

View File

@@ -7,7 +7,7 @@
struct SpfInterval; struct SpfInterval;
void loopGraphAnalyzer(SgFile *file, std::vector<LoopGraph*> &loopGraph, const std::vector<SpfInterval*> &statisticTimes, std::vector<Messages> &messages, int mpiProgram); void loopGraphAnalyzer(SgFile *file, std::vector<LoopGraph*> &loopGraph, const std::vector<SpfInterval*> &statisticTimes, std::vector<Messages> &messages, int sharedMemoryParallelization);
void findAllRefsToLables(SgStatement *st, std::map<int, std::vector<int>> &labelsRef, bool includeWrite = true); void findAllRefsToLables(SgStatement *st, std::map<int, std::vector<int>> &labelsRef, bool includeWrite = true);
std::map<LoopGraph*, ParallelDirective*> findAllDirectives(SgFile *file, const std::vector<LoopGraph*> &loops, const uint64_t regId); std::map<LoopGraph*, ParallelDirective*> findAllDirectives(SgFile *file, const std::vector<LoopGraph*> &loops, const uint64_t regId);
std::vector<std::tuple<DIST::Array*, std::vector<long>, std::pair<std::string, int>>> findAllSingleRemotes(SgFile *file, const uint64_t regId, std::vector<ParallelRegion*> &regions); std::vector<std::tuple<DIST::Array*, std::vector<long>, std::pair<std::string, int>>> findAllSingleRemotes(SgFile *file, const uint64_t regId, std::vector<ParallelRegion*> &regions);

View File

@@ -14,10 +14,57 @@
#include <utility> #include <utility>
#include <assert.h> #include <assert.h>
#include "loop_analyzer_internal.h"
#include "loop_analyzer.h" #include "loop_analyzer.h"
#include <tuple>
#include <stack>
#include "../Utils/leak_detector.h"
#if _WIN32 && NDEBUG && __BOOST
#include <boost/thread.hpp>
#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" #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<Messages>* currMessages;
extern int sharedMemoryParallelization;
extern int ignoreIO;
extern int parallizeFreeLoops;
using std::vector; using std::vector;
using std::pair; using std::pair;
using std::tuple; using std::tuple;
@@ -126,7 +173,9 @@ static void addInfoToMap(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, S
__spf_print(DEB, "RemoteAccess[%d]: true for dim %d and array %s, loop line %d\n", __LINE__, dimNum, symb->identifier(), position->lineNumber()); __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<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, SgForStmt *position, SgSymbol *symb, enum { READ_OP, WRITE_OP, UNREC_OP };
static void addInfoToVectors(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, SgForStmt *position, SgSymbol *symb,
const int dimNum, const pair<int, int> newCoef, int type, const int maxDimSize, const double currentW) const int dimNum, const pair<int, int> newCoef, int type, const int maxDimSize, const double currentW)
{ {
auto itLoop = loopInfo.find(position); auto itLoop = loopInfo.find(position);
@@ -159,10 +208,10 @@ void addInfoToVectors(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, SgFo
} }
vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *subscr, static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *subscr,
SgArrayRefExp *arrayRefIn, const int side, const int dimNum, SgArrayRefExp *arrayRefIn, const int side, const int dimNum,
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo,
const int currLine, const int numOfSubscriptions, const double currentW) const int currLine, const int numOfSubscriptions, const double currentW)
{ {
SgExpression *origSubscr = subscr; SgExpression *origSubscr = subscr;
ArrayRefExp *arrayRef = new ArrayRefExp(arrayRefIn); ArrayRefExp *arrayRef = new ArrayRefExp(arrayRefIn);
@@ -204,7 +253,7 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
if (countOfSymbols > 1) if (countOfSymbols > 1)
{ {
__spf_print(PRINT_ARRAY_ARCS, " <%d|%d> ", 0, 0); __spf_print(PRINT_ARRAY_ARCS, " <%d|%d> ", 0, 0);
if (currRegime == DATA_DISTR) if (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR)
{ {
const pair<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); const pair<bool, string> &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); __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 +287,7 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
for (int i = 0; i < (int)parentLoops.size(); ++i) for (int i = 0; i < (int)parentLoops.size(); ++i)
addInfoToMap(loopInfo, parentLoops[i], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions); 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<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); const pair<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr);
@@ -294,7 +343,7 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
if (side == RIGHT) if (side == RIGHT)
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions); 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<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr); const pair<bool, string> &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); __spf_print(1, "WARN: can not calculate index expression for array ref '%s' at line %d\n", arrayRefString.second.c_str(), currLine);
@@ -335,7 +384,7 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_FALSE, currLine, numOfSubscriptions); 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) if (currRegime == DATA_DISTR)
{ {
@@ -387,7 +436,8 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
return allPositions; 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<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const int currLine,
map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW, map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW,
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls) const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls)
@@ -440,13 +490,15 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
vector<int> canNotMapToLoop; vector<int> canNotMapToLoop;
for (int i = 0; i < wasFoundForLoop.size(); ++i) 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()); auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber());
if (itLoop == sortedLoopGraph.end()) if (itLoop == sortedLoopGraph.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
ifUnknownArrayAssignFound = true; 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->hasUnknownArrayAssigns = true;
itLoop->second->hasUnknownDistributedMap = true; itLoop->second->hasUnknownDistributedMap = true;
@@ -456,7 +508,7 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
if (side == LEFT) if (side == LEFT)
{ {
if (ifUnknownArrayAssignFound && (currRegime == DATA_DISTR)) if (ifUnknownArrayAssignFound && (currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR))
{ {
const string arrayRefS = arrayRef->unparse(); const string arrayRefS = arrayRef->unparse();
for (auto &line : canNotMapToLoop) for (auto &line : canNotMapToLoop)
@@ -517,7 +569,8 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
} }
static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp, 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<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
map<int, LoopGraph*> &sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays, map<int, LoopGraph*> &sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
set<string>& mappedDistrbutedArrays, set<string>& mappedDistrbutedArrays,
@@ -533,7 +586,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); __spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum);
bool wasMapped = false; 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) for (int z = 0; z < matched.size(); ++z)
wasMapped |= (matched[z] != 0); wasMapped |= (matched[z] != 0);
@@ -570,7 +623,8 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
if (isArrayRef(currExp)) if (isArrayRef(currExp))
{ {
//... and current array is not in private list //... 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) if (wasDistributedArrayRef)
{ {
@@ -582,147 +636,104 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (itLoop->second->perfectLoop != depth) if (itLoop->second->perfectLoop != depth)
break; break;
itLoop->second->hasIndirectAccess = true;
if (mpiProgram && side == RIGHT) if (!(sharedMemoryParallelization && side == RIGHT))
itLoop->second->hasIndirectAccess = false; 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); notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls);
} }
else else
{ {
wasDistributedArrayRef = true; wasDistributedArrayRef = true;
mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, mapArrayRef(currentSt, currExp, parentLoops, privatesVarsForLoop, side, lineNum, loopInfo, sortedLoopGraph,
notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); 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()); set<string> loopsPrivates;
SgStatement *decl = declaratedInStmt(symb); set<Symbol*> loopsPrivatesS;
auto uniqKey = getUniqName(commonBlocks, decl, symb); set<string> loopsRedUnited;
map<string, set<Symbol*>> loopsReductions;
map<string, set<tuple<Symbol*, Symbol*, int>>> loopsReductionsLoc;
auto itFound = declaredArrays.find(uniqKey);
if (itFound == declaredArrays.end()) for (int z = 0; z < parentLoops.size(); ++z)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
//TODO: array access to non distributed arrays, add CONSISTENT
if (itFound->second.first->GetDistributeFlagVal() != DIST::DISTR)
{ {
set<string> loopsPrivates; auto& loop = parentLoops[z];
set<Symbol*> loopsPrivatesS; for (auto &data : getAttributes<SgStatement*, SgStatement*>(loop, set<int>{ SPF_ANALYSIS_DIR }))
set<string> loopsRedUnited;
map<string, set<Symbol*>> loopsReductions;
map<string, set<tuple<Symbol*, Symbol*, int>>> loopsReductionsLoc;
for (int z = 0; z < parentLoops.size(); ++z)
{ {
auto& loop = parentLoops[z]; fillPrivatesFromComment(new Statement(data), loopsPrivatesS);
for (auto &data : getAttributes<SgStatement*, SgStatement*>(loop, set<int>{ SPF_ANALYSIS_DIR })) for (auto& elem : loopsPrivatesS)
{ loopsPrivates.insert(elem->GetOriginal()->identifier());
fillPrivatesFromComment(new Statement(data), loopsPrivatesS); fillReductionsFromComment(new Statement(data), loopsReductions);
for (auto& elem : loopsPrivatesS) fillReductionsFromComment(new Statement(data), loopsReductionsLoc);
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());
loopsPrivates.insert(get<0>(setElem)->GetOriginal()->identifier()); loopsRedUnited.insert(get<0>(setElem)->GetOriginal()->identifier());
loopsPrivates.insert(get<1>(setElem)->GetOriginal()->identifier()); loopsRedUnited.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()); const string key = string(OriginalSymbol(currExp->symbol())->identifier());
if (loopsPrivates.find(key) == loopsPrivates.end()) if (loopsPrivates.find(key) == loopsPrivates.end())
{
for (auto& loop : parentLoops)
{ {
if (mpiProgram == 0) __spf_print(1, "WARN: write to non distributed array '%s' in loop on line %d\n", symb->identifier(), loop->lineNumber());
{
for (auto& loop : parentLoops)
{
__spf_print(1, "WARN: write to non distributed array '%s' in loop on line %d\n", symb->identifier(), loop->lineNumber());
wstring messageE, messageR; wstring messageE, messageR;
__spf_printToLongBuf(messageE, L"write to non distributed array '%s' in this loop", to_wstring(symb->identifier()).c_str()); __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) if (loop->lineNumber() > 0)
currMessages->push_back(Messages(WARR, loop->lineNumber(), messageR, messageE, 1026)); currMessages->push_back(Messages(WARR, loop->lineNumber(), messageR, messageE, 1026));
sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true; 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; DIST::Array* currArray = getArrayFromDeclarated(declaratedInStmt(currOrigArrayS), currOrigArrayS->identifier());
currRegime = ARRAY_ACC_CORNER; checkNull(currArray, convertFileName(__FILE__).c_str(), __LINE__);
bool wasMapped = false;
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> tmpLoopInfo = loopInfo;
vector<int> 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)
{ {
if (mpiProgram == 0) set<DIST::Array*> realArrayRefs;
{ getRealArrayRefs(currArray, currArray, realArrayRefs, arrayLinksByFuncCalls);
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());
__spf_printToLongBuf(messageR, R60, to_wstring(symb->identifier()).c_str()); for (auto& array : realArrayRefs)
array->SetPrivateInLoopStatus(true);
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<DIST::Array*> realArrayRefs;
getRealArrayRefs(currArray, currArray, realArrayRefs, arrayLinksByFuncCalls);
for (auto& array : realArrayRefs)
array->SetPrivateInLoopStatus(true);
}
} }
} }
} }
@@ -1384,7 +1395,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
SgStatement *decl = declaratedInStmt(currentArray); SgStatement *decl = declaratedInStmt(currentArray);
const char *symbIdent = currentArray->identifier(); 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); const tuple<int, string, string> uniqKey = getUniqName(commonBlocks, decl, currentArray);
@@ -1401,7 +1412,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
else else
arrayToAdd = itFound->second; arrayToAdd = itFound->second;
if (arrayToAdd->IsNotDistribute() == true) if (!sharedMemoryParallelization && arrayToAdd->IsNotDistribute() == true)
continue; continue;
set<DIST::Array*> links; set<DIST::Array*> links;
@@ -1502,7 +1513,7 @@ inline static void fillPrivatesFromDecl(SgExpression *ex, set<SgSymbol*> &delcsS
fillPrivatesFromDecl(ex->lhs(), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars); fillPrivatesFromDecl(ex->lhs(), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars);
} }
void changeLoopWeight(double &currentWeight, const map<int, LoopGraph*> &sortedLoopGraph, const int line, bool increase) static void changeLoopWeight(double &currentWeight, const map<int, LoopGraph*> &sortedLoopGraph, const int line, bool increase = true)
{ {
auto loopIt = sortedLoopGraph.find(line); auto loopIt = sortedLoopGraph.find(line);
if (loopIt == sortedLoopGraph.end()) if (loopIt == sortedLoopGraph.end())
@@ -1514,7 +1525,7 @@ void changeLoopWeight(double &currentWeight, const map<int, LoopGraph*> &sortedL
currentWeight /= loopIt->second->countOfIters; currentWeight /= loopIt->second->countOfIters;
} }
bool hasNonPureFunctions(SgExpression *ex, LoopGraph *loopRef, vector<Messages> &messagesForFile, const int line, const map<string, FuncInfo*> &funcByName) static bool hasNonPureFunctions(SgExpression *ex, LoopGraph *loopRef, vector<Messages> &messagesForFile, const int line, const map<string, FuncInfo*> &funcByName)
{ {
bool retVal = false; bool retVal = false;
@@ -1559,7 +1570,7 @@ void fillFromModule(SgSymbol* s, const map<string, set<string>>& privatesByModul
} }
} }
SgStatement* takeOutConditions(stack<SgExpression*>& conditions, stack<SgStatement*>& ifBlocks, SgStatement* st) static SgStatement* takeOutConditions(stack<SgExpression*>& conditions, stack<SgStatement*>& ifBlocks, SgStatement* st)
{ {
auto res = createIfConditions(conditions, ifBlocks, st); auto res = createIfConditions(conditions, ifBlocks, st);
@@ -1609,8 +1620,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
modulesByName[modules[i]->symbol()->identifier()] = modules[i]; modulesByName[modules[i]->symbol()->identifier()] = modules[i];
map<string, set<string>> privatesByModule; map<string, set<string>> privatesByModule;
for (int i = 0; i < modules.size(); ++i) if(!sharedMemoryParallelization)
privatesByModule[modules[i]->symbol()->identifier()] = getPrivatesFromModule(modules[i], declaredArrays, declaratedArraysSt, modulesByName); for (int i = 0; i < modules.size(); ++i)
privatesByModule[modules[i]->symbol()->identifier()] = getPrivatesFromModule(modules[i], declaredArrays, declaratedArraysSt, modulesByName);
map<string, FuncInfo*> funcByName; map<string, FuncInfo*> funcByName;
createMapOfFunc(AllfuncInfo, funcByName); createMapOfFunc(AllfuncInfo, funcByName);
@@ -1674,13 +1686,17 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
loopsForFunction.push_back(loop); loopsForFunction.push_back(loop);
} }
SgStatement* tmpModFind = st; if(!sharedMemoryParallelization)
while (tmpModFind->variant() != GLOBAL)
{ {
tmpModFind = tmpModFind->controlParent(); SgStatement* tmpModFind = st;
if (tmpModFind->variant() == MODULE_STMT) while (tmpModFind->variant() != GLOBAL)
fillFromModule(tmpModFind->symbol(), privatesByModule, privatesVars); {
tmpModFind = tmpModFind->controlParent();
if (tmpModFind->variant() == MODULE_STMT)
fillFromModule(tmpModFind->symbol(), privatesByModule, privatesVars);
}
} }
commonBlocks.clear(); commonBlocks.clear();
getCommonBlocksRef(commonBlocks, st, st->lastNodeOfStmt()); getCommonBlocksRef(commonBlocks, st, st->lastNodeOfStmt());
__spf_print(PRINT_PROF_INFO, " number of common blocks %d\n", (int)commonBlocks.size()); __spf_print(PRINT_PROF_INFO, " number of common blocks %d\n", (int)commonBlocks.size());
@@ -1727,7 +1743,8 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (isSgExecutableStatement(st) == NULL) if (isSgExecutableStatement(st) == NULL)
delcsStatViewed.insert(st); delcsStatViewed.insert(st);
else if (!isDVM_stat(st) && !isSPF_stat(st)) else if (!sharedMemoryParallelization &&
!isDVM_stat(st) && !isSPF_stat(st))
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
fillPrivatesFromDecl(st->expr(i), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars); fillPrivatesFromDecl(st->expr(i), delcsSymbViewed, delcsStatViewed, declaredArrays, declaratedArraysSt, privatesVars);
@@ -1735,9 +1752,12 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
const int currV = st->variant(); const int currV = st->variant();
if (currV == FOR_NODE) if (currV == FOR_NODE)
{ {
tryToFindPrivateInAttributes(st, privatesVars); if(!sharedMemoryParallelization)
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); {
tryToFindPrivateInAttributes(st, privatesVars);
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars);
}
set<string> toAdd; set<string> toAdd;
tryToFindPrivateInAttributes(st, toAdd); tryToFindPrivateInAttributes(st, toAdd);
@@ -1783,9 +1803,10 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
unitedPrivates.insert(privVar); unitedPrivates.insert(privVar);
set<string> setDiff; set<string> setDiff;
for (auto &privVars : privatesVars) if(!sharedMemoryParallelization)
if (unitedPrivates.find(privVars) == unitedPrivates.end()) for (auto &privVars : privatesVars)
setDiff.insert(privVars); if (unitedPrivates.find(privVars) == unitedPrivates.end())
setDiff.insert(privVars);
allLoops[contrlParent->lineNumber()] = make_pair((SgForStmt*)contrlParent, make_pair(unitedPrivates, setDiff)); allLoops[contrlParent->lineNumber()] = make_pair((SgForStmt*)contrlParent, make_pair(unitedPrivates, setDiff));
parentLoops.pop_back(); parentLoops.pop_back();
@@ -2067,7 +2088,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
} }
else if (currV == USE_STMT) else if (currV == USE_STMT)
{ {
if (st->lineNumber() > 0) if (st->lineNumber() > 0 && !sharedMemoryParallelization)
{ {
auto itF = privatesByModule.find(st->symbol()->identifier()); auto itF = privatesByModule.find(st->symbol()->identifier());
@@ -2084,14 +2105,18 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
} }
for (auto it = itF->second.begin(); it != itF->second.end(); ++it) for (auto it = itF->second.begin(); it != itF->second.end(); ++it)
privatesVars.insert(*it); privatesVars.insert(*it);
} }
} }
else else
{ {
tryToFindPrivateInAttributes(st, privatesVars); if(!sharedMemoryParallelization)
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); {
tryToFindPrivateInAttributes(st, privatesVars);
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars);
}
if (isDVM_stat(st) == false && isSgExecutableStatement(st)) if (isDVM_stat(st) == false && isSgExecutableStatement(st))
{ {
@@ -2125,7 +2150,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
} }
auto convertedLoopInfo = convertLoopInfo(loopInfo, sortedLoopGraph, privatesVars, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays); auto convertedLoopInfo = convertLoopInfo(loopInfo, sortedLoopGraph, privatesVars, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays);
if (regime == DATA_DISTR) if (regime == DATA_DISTR || regime == SHARED_MEMORY_PAR)
{ {
processLoopInformationForFunction(convertedLoopInfo); processLoopInformationForFunction(convertedLoopInfo);
@@ -2184,16 +2209,19 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
} }
} }
} }
addToDistributionGraph(convertedLoopInfo, arrayLinksByFuncCalls); if(!sharedMemoryParallelization)
addToDistributionGraph(convertedLoopInfo, arrayLinksByFuncCalls);
for (auto &toDel : tmpLoops) for (auto &toDel : tmpLoops)
{
convertedLoopInfo.erase(toDel);
delete toDel; delete toDel;
}
tmpToConvert.clear(); tmpToConvert.clear();
if (!skipDeps) if (!skipDeps)
{ {
for (auto &loopLine : loopWithOutArrays) for (auto &loopLine : loopWithOutArrays)
{ {
if (loopLine > 0) if (loopLine > 0)
@@ -2257,7 +2285,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
s = start->expr(0)->lhs()->symbol(); s = start->expr(0)->lhs()->symbol();
if (s && privates.find(s->identifier()) == privates.end()) if (s && privates.find(s->identifier()) == privates.end())
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
hasWritesToArray = true; hasWritesToArray = true;
} }
} }
@@ -2300,6 +2328,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (parallizeFreeLoops) if (parallizeFreeLoops)
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile); 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"); __spf_print(PRINT_PROF_INFO, "Function ended\n");
} }
@@ -2776,7 +2807,7 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
new DIST::Array(getShortName(uniqKey), symb->identifier(), ((SgArrayType*)(symb->type()))->dimension(), new DIST::Array(getShortName(uniqKey), symb->identifier(), ((SgArrayType*)(symb->type()))->dimension(),
getUniqArrayId(), decl->fileName(), decl->lineNumber(), arrayLocation, new Symbol(symb), getUniqArrayId(), decl->fileName(), decl->lineNumber(), arrayLocation, new Symbol(symb),
findOmpThreadPrivDecl(scope, ompThreadPrivate, symb), false, false, 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()))); itNew = declaredArrays.insert(itNew, make_pair(uniqKey, make_pair(arrayToAdd, new DIST::ArrayAccessInfo())));

View File

@@ -17,7 +17,7 @@
typedef std::pair<std::pair<int, int>, std::pair<int, int>> attrType; typedef std::pair<std::pair<int, int>, std::pair<int, int>> attrType;
namespace DIST = Distribution; 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 // loop_analyzer.cpp
bool checkExistence(SgExpression *exp, const std::string& doName); bool checkExistence(SgExpression *exp, const std::string& doName);

View File

@@ -1,70 +0,0 @@
#pragma once
#include "loop_analyzer.h"
#include <string>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include "../Utils/leak_detector.h"
#if _WIN32 && NDEBUG && __BOOST
#include <boost/thread.hpp>
#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<Messages>* currMessages;
extern int mpiProgram;
extern int ignoreIO;
extern int parallizeFreeLoops;
void changeLoopWeight(double& currentWeight, const std::map<int, LoopGraph*>& sortedLoopGraph, const int line, bool increase = true);
SgStatement* takeOutConditions(std::stack<SgExpression*>& conditions, std::stack<SgStatement*>& ifBlocks, SgStatement* st);
enum { READ_OP, WRITE_OP, UNREC_OP };
void addInfoToVectors(std::map<SgForStmt*, std::map<SgSymbol*, ArrayInfo>>& loopInfo, SgForStmt* position, SgSymbol* symb,
const int dimNum, const std::pair<int, int> newCoef, int type, const int maxDimSize, const double currentW);
std::vector<int> matchSubscriptToLoopSymbols(const std::vector<SgForStmt*>& parentLoops, SgExpression* subscr,
SgArrayRefExp* arrayRefIn, const int side, const int dimNum,
std::map<SgForStmt*, std::map<SgSymbol*, ArrayInfo>>& loopInfo,
const int currLine, const int numOfSubscriptions, const double currentW);
bool hasNonPureFunctions(SgExpression* ex, LoopGraph* loopRef, std::vector<Messages>& messagesForFile, const int line, const std::map<std::string, FuncInfo*>& funcByName);

View File

@@ -1,667 +0,0 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <assert.h>
#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<int, LoopGraph*>& sortedLoopGraph, const vector<LoopGraph*>* loopGraph);
extern map<DIST::Array*, std::tuple<int, string, string>> tableOfUniqNamesByArray;
static void convertOneLoopNoDist(LoopGraph* currLoop, map<LoopGraph*, map<DIST::Array*, ArrayInfo*>>& outInfo,
const map<SgSymbol*, ArrayInfo>& toConvert,
const map<string, vector<SgExpression*>>& commonBlocks,
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
map<tuple<int, string, string>, DIST::Array*>& createdArrays,
bool freeArrays = false)
{
map<DIST::Array*, ArrayInfo*> 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<int, string, string> 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<DIST::Array*> 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<LoopGraph*, map<DIST::Array*, ArrayInfo*>>
convertLoopInfoNoDist(const map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
const map<int, LoopGraph*>& sortedLoopGraph,
const map<string, vector<SgExpression*>>& commonBlocks,
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
map<tuple<int, string, string>, DIST::Array*>& createdArrays)
{
map<LoopGraph*, map<DIST::Array*, ArrayInfo*>> 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<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)
{
SgArrayRefExp *arrayRef = (SgArrayRefExp*)currExp;
int numOfSubs = arrayRef->numberOfSubscripts();
currExp = currExp->lhs();
vector<int> wasFoundForLoop(parentLoops.size());
vector<int> matched(numOfSubs);
vector<int> 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<int> 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<int> 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<SgForStmt*>& parentLoops, const int side, const int lineNum,
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
vector<set<string>>& privatesVarsForLoop,
map<int, LoopGraph*>& sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
set<string>& mappedDistrbutedArrays,
const ParallelRegion* reg, const double currentW, const map<DIST::Array*, set<DIST::Array*>>& 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<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);
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<SgForStmt*>& parentLoops, SgExpression* currExp, const int lineNum, const int side,
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
vector<set<string>>& privatesVarsForLoop, map<int, LoopGraph*>& sortedLoopGraph,
map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
set<string>& mappedDistrbutedArrays, SgStatement* currentSt, const ParallelRegion* reg, const double currentW,
const map<DIST::Array*, set<DIST::Array*>>& 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<ParallelRegion*>& regions, map<tuple<int, string, string>, DIST::Array*>& createdArrays,
vector<Messages>& messagesForFile, const map<string, vector<FuncInfo*>>& AllfuncInfo,
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
const map<SgStatement*, set<tuple<int, string, string>>>& declaratedArraysSt,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
const map<SgStatement*, vector<DefUseList>>& defUseByPlace,
vector<LoopGraph*>* loopGraph)
{
currMessages = &messagesForFile;
currRegime = DATA_DISTR; //?
map<string, vector<SgExpression*>> commonBlocks;
map<int, LoopGraph*> sortedLoopGraph;
map<int, pair<SgForStmt*, pair<set<string>, set<string>>>> allLoops;
createMapLoopGraph(sortedLoopGraph, loopGraph);
int funcNum = file->numberOfFunctions();
__spf_print(PRINT_PROF_INFO, "functions num in file = %d\n", funcNum);
vector<SgStatement*> modules;
findModulesInFile(file, modules);
map<string, SgStatement*> modulesByName;
for (int i = 0; i < modules.size(); ++i)
modulesByName[modules[i]->symbol()->identifier()] = modules[i];
map<string, FuncInfo*> funcByName;
createMapOfFunc(AllfuncInfo, funcByName);
const vector<FuncInfo*>& 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<SgSymbol*> delcsSymbViewed;
set<SgStatement*> delcsStatViewed;
if (funcInfo[i]->doNotAnalyze)
continue;
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> loopInfo;
set<int> 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<LoopGraph*> 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<SgForStmt*> parentLoops;
vector<set<string>> privatesVarsForLoop;
//For remote access
pair<SgForStmt*, LoopGraph*>* under_dvm_dir = NULL;
map<string, pair<SgSymbol*, SgStatement*>> notMappedDistributedArrays;
set<string> 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<string> 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<string> unitedPrivates;
for (int p = 0; p < parentLoops.size(); ++p)
for (auto& privVar : privatesVarsForLoop[p])
unitedPrivates.insert(privVar);
set<string> 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<DIST::Array*> 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<SgStatement*> funcWasInit;
map<SgExpression*, string> 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<LoopGraph*, map<DIST::Array*, ArrayInfo*>> convertedLoopInfo;
it = loopRef;
for (int z = 0; z < nesting; ++z, it->children.size() ? it = it->children[0] : it)
convertedLoopInfo.insert(make_pair(it, map<DIST::Array*, ArrayInfo*>()));
createParallelDirectivesNoDist(convertedLoopInfo, regions, map<DIST::Array*, set<DIST::Array*>>(), messagesForFile);
}
}
__spf_print(PRINT_PROF_INFO, "Function ended\n");
}
}

View File

@@ -1,13 +0,0 @@
#include<map>
#include<string>
#include<set>
#include<vector>
#include<tuple>
void loopAnalyzerNoDist(SgFile* file, std::vector<ParallelRegion*>& regions, std::map<std::tuple<int, std::string, std::string>, DIST::Array*>& createdArrays,
std::vector<Messages>& messagesForFile, const std::map<std::string, std::vector<FuncInfo*>>& AllfuncInfo,
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
const std::map<SgStatement*, std::set<std::tuple<int, std::string, std::string>>>& declaratedArraysSt,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls,
const std::map<SgStatement*, std::vector<DefUseList>>& defUseByPlace,
std::vector<LoopGraph*>* loopGraph);

View File

@@ -1251,7 +1251,7 @@ void fillUsedArraysInExp(const pair<Statement*, Statement*> &interval, const int
bool checkRegionsResolving(const vector<ParallelRegion*> &regions, bool checkRegionsResolving(const vector<ParallelRegion*> &regions,
const map<string, vector<FuncInfo*>> &allFuncInfo, const map<string, vector<FuncInfo*>> &allFuncInfo,
const map<string, CommonBlock*> &commonBlocks, const map<string, CommonBlock*> &commonBlocks,
map<string, vector<Messages>> &SPF_messages, bool mpiProgram) map<string, vector<Messages>> &SPF_messages, bool sharedMemoryParallelization)
{ {
bool error = false; bool error = false;
@@ -1319,7 +1319,7 @@ bool checkRegionsResolving(const vector<ParallelRegion*> &regions,
} }
} }
if (mpiProgram) if (sharedMemoryParallelization)
return error; return error;
// check local arrays // check local arrays
@@ -1611,7 +1611,7 @@ static void compliteUseOnlyList(SgStatement *func, const string &location, const
} }
int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector<FuncInfo*>> &allFuncInfo, int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector<FuncInfo*>> &allFuncInfo,
map<string, vector<Messages>> &SPF_messages, bool mpiProgram, map<string, vector<Messages>> &SPF_messages, bool sharedMemoryParallelization,
map<string, map<int, set<string>>> &newDeclsToInclude) map<string, map<int, set<string>>> &newDeclsToInclude)
{ {
bool error = false; bool error = false;
@@ -1619,7 +1619,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
map<string, FuncInfo*> funcMap; map<string, FuncInfo*> funcMap;
createMapOfFunc(allFuncInfo, funcMap); createMapOfFunc(allFuncInfo, funcMap);
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
map<string, map<int, set<string>>> copied; map<string, map<int, set<string>>> copied;
@@ -1905,7 +1905,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
} }
} }
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
__spf_print(1, "insert DVM intervals\n"); __spf_print(1, "insert DVM intervals\n");

View File

@@ -11,6 +11,6 @@ void fillRegionFunctions(std::vector<ParallelRegion*> &regions, const std::map<s
bool checkRegions(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<Messages>> &SPF_messages); bool checkRegions(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<Messages>> &SPF_messages);
int printCheckRegions(const char *fileName, const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo); int printCheckRegions(const char *fileName, const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
bool checkRegionsResolving(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks, std::map<std::string, std::vector<Messages>> &SPF_messages, bool mpiProgram); bool checkRegionsResolving(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks, std::map<std::string, std::vector<Messages>> &SPF_messages, bool sharedMemoryParallelization);
int resolveParRegions(std::vector<ParallelRegion*>& regions, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, std::map<std::string, std::vector<Messages>>& SPF_messages, bool mpiProgram, std::map<std::string, std::map<int, std::set<std::string>>>& copyDecls); int resolveParRegions(std::vector<ParallelRegion*>& regions, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, std::map<std::string, std::vector<Messages>>& SPF_messages, bool sharedMemoryParallelization, std::map<std::string, std::map<int, std::set<std::string>>>& copyDecls);
void insertRealignsBeforeFragments(ParallelRegion* reg, SgFile* file, const std::set<DIST::Array*>& distrArrays, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls); void insertRealignsBeforeFragments(ParallelRegion* reg, SgFile* file, const std::set<DIST::Array*>& distrArrays, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);

View File

@@ -38,7 +38,6 @@
#include "ProjectManipulation/ConvertFiles.h" #include "ProjectManipulation/ConvertFiles.h"
#include "LoopAnalyzer/loop_analyzer.h" #include "LoopAnalyzer/loop_analyzer.h"
#include "LoopAnalyzer/loop_analyzer_nodist.h"
#include "GraphCall/graph_calls_func.h" #include "GraphCall/graph_calls_func.h"
#include "GraphCall/select_array_conf.h" #include "GraphCall/select_array_conf.h"
@@ -48,7 +47,6 @@
#include "DirectiveProcessing/directive_analyzer.h" #include "DirectiveProcessing/directive_analyzer.h"
#include "DirectiveProcessing/directive_creator.h" #include "DirectiveProcessing/directive_creator.h"
#include "DirectiveProcessing/directive_creator_nodist.h"
#include "DirectiveProcessing/insert_directive.h" #include "DirectiveProcessing/insert_directive.h"
#include "DirectiveProcessing/directive_omp_parser.h" #include "DirectiveProcessing/directive_omp_parser.h"
#include "VerificationCode/verifications.h" #include "VerificationCode/verifications.h"
@@ -506,7 +504,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
insertIntrinsicStat(getObjectForFileFromMap(file_name, allFuncInfo)); insertIntrinsicStat(getObjectForFileFromMap(file_name, allFuncInfo));
} }
else if (curr_regime == LOOP_GRAPH) 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) else if (curr_regime == VERIFY_ENDDO)
{ {
bool res = EndDoLoopChecker(file, getObjectForFileFromMap(file_name, SPF_messages)); bool res = EndDoLoopChecker(file, getObjectForFileFromMap(file_name, SPF_messages));
@@ -541,7 +539,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
} }
else if (curr_regime == CORRECT_FORMAT_PLACE) else if (curr_regime == CORRECT_FORMAT_PLACE)
checkAndMoveFormatOperators(file, getObjectForFileFromMap(file_name, SPF_messages), false); checkAndMoveFormatOperators(file, getObjectForFileFromMap(file_name, SPF_messages), false);
else if (curr_regime == CREATE_PARALLEL_DIRS) else if (curr_regime == CREATE_PARALLEL_DIRS || curr_regime == INSERT_PARALLEL_DIRS_NODIST)
{ {
auto &loopsInFile = getObjectForFileFromMap(file_name, loopGraph); auto &loopsInFile = getObjectForFileFromMap(file_name, loopGraph);
@@ -562,46 +560,14 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == LOOP_ANALYZER_NODIST) else if (curr_regime == LOOP_ANALYZER_NODIST)
{ {
auto& loopsInFile = getObjectForFileFromMap(file_name, loopGraph); auto& loopsInFile = getObjectForFileFromMap(file_name, loopGraph);
loopAnalyzerNoDist(file, parallelRegions, createdArrays, getObjectForFileFromMap(file_name, SPF_messages), parallizeFreeLoops = 1;
sharedMemoryParallelization = 1;
loopAnalyzer(file, parallelRegions, createdArrays, getObjectForFileFromMap(file_name, SPF_messages), SHARED_MEMORY_PAR,
allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(), allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(),
&(loopsInFile)); false, &(loopsInFile));
UniteNestedDirectives(loopsInFile); UniteNestedDirectives(loopsInFile);
} }
else if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
{
auto& loopsInFile = getObjectForFileFromMap(file_name, loopGraph);
map<int, LoopGraph*> mapLoopsInFile;
createMapLoopGraph(loopsInFile, mapLoopsInFile);
map<string, FuncInfo*> mapFuncInfo;
createMapOfFunc(allFuncInfo, mapFuncInfo);
for (int z = 0; z < parallelRegions.size(); ++z)
{
vector<Directive*> toInsert;
DIST::Arrays<int>& allArrays = parallelRegions[z]->GetAllArraysToModify();
map<LoopGraph*, void*> 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) else if (curr_regime == INSERT_SHADOW_DIRS || curr_regime == EXTRACT_SHADOW_DIRS)
{ {
const bool extract = (curr_regime == EXTRACT_SHADOW_DIRS); const bool extract = (curr_regime == EXTRACT_SHADOW_DIRS);
@@ -1076,7 +1042,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
if (curr_regime == ONLY_ARRAY_GRAPH) if (curr_regime == ONLY_ARRAY_GRAPH)
keepFiles = 1; keepFiles = 1;
if (mpiProgram) if (sharedMemoryParallelization)
{ {
for (auto& byFile : loopGraph) for (auto& byFile : loopGraph)
for (auto& loop : byFile.second) for (auto& loop : byFile.second)
@@ -1387,7 +1353,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
vector<string> result; vector<string> result;
set<DIST::Array*> arraysDone; set<DIST::Array*> arraysDone;
if (mpiProgram) if (sharedMemoryParallelization)
{ {
bool wasDone = false; bool wasDone = false;
for (int z = 0; z < parallelRegions.size(); ++z) for (int z = 0; z < parallelRegions.size(); ++z)
@@ -1411,7 +1377,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
{ {
for (auto& byFile : loopGraph) for (auto& byFile : loopGraph)
for (auto& loop : byFile.second) for (auto& loop : byFile.second)
loop->createVirtualTemplateLinks(arrayLinksByFuncCalls, SPF_messages, mpiProgram > 0); loop->createVirtualTemplateLinks(arrayLinksByFuncCalls, SPF_messages, sharedMemoryParallelization > 0);
//add dummy array //add dummy array
DataDirective& dataDirectives = parallelRegions[0]->GetDataDirToModify(); DataDirective& dataDirectives = parallelRegions[0]->GetDataDirToModify();
@@ -1456,7 +1422,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
//recalculate array sizes after expression substitution //recalculate array sizes after expression substitution
recalculateArraySizes(arraysDone, allArrays.GetArrays(), arrayLinksByFuncCalls, allFuncInfo); 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; ALGORITHMS_DONE[CREATE_DISTIBUTION][z] = 1;
} }
@@ -1574,7 +1540,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
} }
else if (curr_regime == RESOLVE_PAR_REGIONS) 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) if (error)
internalExit = 1; internalExit = 1;
} }
@@ -1610,7 +1576,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) else if (curr_regime == INSERT_PARALLEL_DIRS || curr_regime == EXTRACT_PARALLEL_DIRS)
{ {
bool cond = (folderName != NULL) || (consoleMode) || (!consoleMode && 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 //insert template declaration to main program
const bool extract = (curr_regime == EXTRACT_PARALLEL_DIRS); const bool extract = (curr_regime == EXTRACT_PARALLEL_DIRS);
@@ -1659,7 +1625,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
printDefUseSets("_defUseList.txt", defUseByFunctions); printDefUseSets("_defUseList.txt", defUseByFunctions);
} }
else if (curr_regime == LOOP_ANALYZER_DATA_DIST_S0) 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) else if (curr_regime == LOOP_ANALYZER_DATA_DIST_S1)
{ {
for (int z = 0; z < parallelRegions.size(); ++z) for (int z = 0; z < parallelRegions.size(); ++z)
@@ -1671,7 +1637,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
} }
else if (curr_regime == PRINT_PAR_REGIONS_ERRORS) 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) if (error)
internalExit = 1; internalExit = 1;
} }
@@ -2135,11 +2101,11 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case INSERT_PARALLEL_DIRS_NODIST: case INSERT_PARALLEL_DIRS_NODIST:
{ {
mpiProgram = 1; sharedMemoryParallelization = 1;
string additionalName = (consoleMode && folderName == NULL) ? "__shared" : ""; 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); runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName);
@@ -2168,7 +2134,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
int maxDimsIdxReg = -1; int maxDimsIdxReg = -1;
int lastI = 1; int lastI = 1;
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
lastI = countMaxValuesForParallelVariants(maxDims, maxDimsIdx, maxDimsIdxReg, currentVariants); lastI = countMaxValuesForParallelVariants(maxDims, maxDimsIdx, maxDimsIdxReg, currentVariants);
if (genAllVars == 0) if (genAllVars == 0)
lastI = 1; lastI = 1;
@@ -2176,7 +2142,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
for (int i = 0; i < lastI; ++i) for (int i = 0; i < lastI; ++i)
{ {
//if specific variant number is requested, skip all others //if specific variant number is requested, skip all others
if (genSpecificVar >= 0 && i != genSpecificVar && mpiProgram == 0) if (genSpecificVar >= 0 && i != genSpecificVar && sharedMemoryParallelization == 0)
continue; continue;
string tmpFolder = ""; string tmpFolder = "";
@@ -2203,7 +2169,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); 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(CREATE_REMOTES, proj_name, folderName);
runPass(REMOVE_AND_CALC_SHADOW, proj_name, folderName); runPass(REMOVE_AND_CALC_SHADOW, proj_name, folderName);
@@ -2214,11 +2180,11 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
runPass(RESTORE_LOOP_FROM_ASSIGN, proj_name, folderName); runPass(RESTORE_LOOP_FROM_ASSIGN, proj_name, folderName);
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
runPass(ADD_TEMPL_TO_USE_ONLY, proj_name, folderName); runPass(ADD_TEMPL_TO_USE_ONLY, proj_name, folderName);
runAnalysis(*project, INSERT_REGIONS, false); runAnalysis(*project, INSERT_REGIONS, false);
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName); runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName);
runAnalysis(*project, CALCULATE_STATS_SCHEME, false); runAnalysis(*project, CALCULATE_STATS_SCHEME, false);
@@ -2242,7 +2208,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
runPass(REVERSE_CREATED_NESTED_LOOPS, proj_name, folderName); runPass(REVERSE_CREATED_NESTED_LOOPS, proj_name, folderName);
runPass(CLEAR_SPF_DIRS, proj_name, folderName); runPass(CLEAR_SPF_DIRS, proj_name, folderName);
runPass(RESTORE_LOOP_FROM_ASSIGN_BACK, 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); runPass(GROUP_ACTUAL_AND_REMOTE_RESTORE, proj_name, folderName);
//clear shadow grouping //clear shadow grouping
@@ -2567,7 +2533,7 @@ int main(int argc, char **argv)
else if (string(curr_arg) == "-fdvm") else if (string(curr_arg) == "-fdvm")
convertFiles(argc - i, argv + i); convertFiles(argc - i, argv + i);
else if (string(curr_arg) == "-mpi") { else if (string(curr_arg) == "-mpi") {
mpiProgram = 1; sharedMemoryParallelization = 1;
ignoreArrayDistributeState = true; ignoreArrayDistributeState = true;
} }
else if (string(curr_arg) == "-client") else if (string(curr_arg) == "-client")
@@ -2622,7 +2588,7 @@ int main(int argc, char **argv)
} }
} }
if (mpiProgram == 1) if (sharedMemoryParallelization == 1)
{ {
keepDvmDirectives = 0; keepDvmDirectives = 0;
ignoreIO = 1; ignoreIO = 1;

View File

@@ -9,7 +9,7 @@ extern int automaticDeprecateArrays;
extern int maxShadowWidth; extern int maxShadowWidth;
extern int langOfMessages; extern int langOfMessages;
extern bool removeNestedIntervals; extern bool removeNestedIntervals;
extern int mpiProgram; extern int sharedMemoryParallelization;
extern int parallizeFreeLoops; extern int parallizeFreeLoops;
extern int ignoreIO; extern int ignoreIO;
extern int parseForInlining; extern int parseForInlining;

View File

@@ -35,7 +35,7 @@ int intervals_threshold = 100; // threshold for intervals
bool removeNestedIntervals = false; // nested intervals removal flag bool removeNestedIntervals = false; // nested intervals removal flag
int langOfMessages = 1; // 0 - ENG, 1 - RUS int langOfMessages = 1; // 0 - ENG, 1 - RUS
int parallizeFreeLoops = 0; // parallize free calculations 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 ignoreIO = 0; // ignore io checker for arrays (DVM IO limitations)
int parseForInlining = 0; // special regime for files parsing for inliner int parseForInlining = 0; // special regime for files parsing for inliner
int dumpIR = 0; // allow dump IR after BUILD_IR pass int dumpIR = 0; // allow dump IR after BUILD_IR pass

View File

@@ -3344,7 +3344,7 @@ SgProject* createProject(const char* proj_name,
if (detectMpiCalls(project, SPF_messages)) if (detectMpiCalls(project, SPF_messages))
{ {
mpiProgram = 1; sharedMemoryParallelization = 1;
keepDvmDirectives = 0; keepDvmDirectives = 0;
ignoreIO = 1; ignoreIO = 1;
parallizeFreeLoops = 0; parallizeFreeLoops = 0;

View File

@@ -203,7 +203,7 @@ const string printVersionAsFortranComm()
ret += "! *** consider DVMH directives\n"; ret += "! *** consider DVMH directives\n";
if (keepSpfDirs) if (keepSpfDirs)
ret += "! *** save SPF directives\n"; ret += "! *** save SPF directives\n";
if (mpiProgram) if (sharedMemoryParallelization)
ret += "! *** MPI program regime (shared memory parallelization)\n"; ret += "! *** MPI program regime (shared memory parallelization)\n";
if (ignoreIO) if (ignoreIO)
ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n"; ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n";

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2350" #define VERSION_SPF "2351"

View File

@@ -166,10 +166,10 @@ static void setOptions(const short* options, bool isBuildParallel = false, const
removeNestedIntervals = (intOptions[KEEP_LOOPS_CLOSE_NESTING] == 1); removeNestedIntervals = (intOptions[KEEP_LOOPS_CLOSE_NESTING] == 1);
showDebug = (intOptions[DEBUG_PRINT_ON] == 1); showDebug = (intOptions[DEBUG_PRINT_ON] == 1);
mpiProgram = (mpiProgram != 1) ? intOptions[MPI_PROGRAM] : mpiProgram; sharedMemoryParallelization = (sharedMemoryParallelization != 1) ? intOptions[MPI_PROGRAM] : sharedMemoryParallelization;
parallizeFreeLoops = (mpiProgram == 1) ? 0 : intOptions[PARALLIZE_FREE_LOOPS]; parallizeFreeLoops = (sharedMemoryParallelization == 1) ? 0 : intOptions[PARALLIZE_FREE_LOOPS];
ignoreIO = (mpiProgram == 1) ? 1 : intOptions[IGNORE_IO_SAPFOR]; ignoreIO = (sharedMemoryParallelization == 1) ? 1 : intOptions[IGNORE_IO_SAPFOR];
keepDvmDirectives = (mpiProgram == 1) ? 0 : intOptions[KEEP_DVM_DIRECTIVES]; keepDvmDirectives = (sharedMemoryParallelization == 1) ? 0 : intOptions[KEEP_DVM_DIRECTIVES];
parseForInlining = intOptions[PARSE_FOR_INLINE]; parseForInlining = intOptions[PARSE_FOR_INLINE];
@@ -819,7 +819,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho
runPassesForVisualizer(projName, { CREATE_TEMPLATE_LINKS }); runPassesForVisualizer(projName, { CREATE_TEMPLATE_LINKS });
else if (regime == 1) else if (regime == 1)
{ {
if (mpiProgram) if (sharedMemoryParallelization)
runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF }); runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF });
else else
runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 }); runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 });
@@ -1061,7 +1061,7 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh
throw (-5); throw (-5);
int countOfDist = 0; int countOfDist = 0;
if (mpiProgram == 0) if (sharedMemoryParallelization == 0)
{ {
map<uint64_t, vector<pair<int64_t, int64_t>>> varLens; map<uint64_t, vector<pair<int64_t, int64_t>>> varLens;
for (int i = 0, k = 0; i < *varLen; i += 3, ++k) 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::clearCache();
MessageManager::setWinHandler(winHandler); MessageManager::setWinHandler(winHandler);
ignoreArrayDistributeState = true; ignoreArrayDistributeState = true;
mpiProgram = 1; sharedMemoryParallelization = 1;
return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize, true); return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize, true);
} }