fix for analysis mode

This commit is contained in:
2024-03-29 15:27:41 +03:00
parent 09d0195693
commit 66feb15714
5 changed files with 38 additions and 136 deletions

View File

@@ -65,26 +65,13 @@ static void findUsedArraysInParallelLoops(LoopGraph* loop, set<DIST::Array*>& re
}
static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Array*>& prevent,
vector<Directive*>& createdDirectives,vector<Messages>& messagesForFile)
vector<Messages>& messagesForFile)
{
if (loop->directive)
{
if (IsSetsIntersect(prevent, loop->usedArraysAll))
{
// prevent this loop
int loopLine = loop->lineNum;
for (auto dir_it = createdDirectives.begin(); dir_it != createdDirectives.end(); dir_it++)
{
if ((*dir_it)->line == loopLine)
{
delete *dir_it;
dir_it = createdDirectives.erase(dir_it);
break;
}
}
delete loop->directive;
loop->directive = NULL;
@@ -123,7 +110,7 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Ar
}
for (LoopGraph* child : loop->children)
preventLoopsFromParallelizations(child, prevent, createdDirectives, messagesForFile);
preventLoopsFromParallelizations(child, prevent, messagesForFile);
}
struct DimConf
@@ -169,9 +156,9 @@ pickBest(const map<DimConf, map<FuncInfo*, set<DIST::Array*>>>& arrs)
}
void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncInfo*>>& funcByFile,
const map<string, vector<LoopGraph*>>& loopGraph, map<std::string, vector<Directive*>>& createdDirectives,
map<string, vector<Messages>>& allMessages, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
const vector<ParallelRegion*>& regions)
const map<string, vector<LoopGraph*>>& loopGraph,
map<string, vector<Messages>>& allMessages,
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
{
map<string, FuncInfo*> funcByName;
for (const auto& byFile : funcByFile)
@@ -265,121 +252,43 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
for (const auto& byFile : loopGraph)
{
vector<Messages>& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages);
auto dirs_it = createdDirectives.find(byFile.first);
if (dirs_it != createdDirectives.end())
SgFile::switchToFile(byFile.first);
auto& loops = byFile.second;
auto file_funcs_it = funcByFile.find(byFile.first);
if (file_funcs_it == funcByFile.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile
map<FuncInfo*, set<DIST::Array*>> usedInLoops;
for (const auto& loop : loops)
{
SgFile::switchToFile(byFile.first);
SgStatement* search_func = loop->loop->GetOriginal();
auto& loops = byFile.second;
while (search_func && (!isSgProgHedrStmt(search_func)))
search_func = search_func->controlParent();
auto file_funcs_it = funcByFile.find(byFile.first);
if (!search_func)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement
if (file_funcs_it == funcByFile.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile
map<FuncInfo*, set<DIST::Array*>> usedInLoops;
for (const auto& loop : loops)
bool loop_analyzed = false;
for (const auto& byFunc : file_funcs_it->second)
{
SgStatement* search_func = loop->loop->GetOriginal();
while (search_func && (!isSgProgHedrStmt(search_func)))
search_func = search_func->controlParent();
if (!search_func)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement
bool loop_analyzed = false;
for (const auto& byFunc : file_funcs_it->second)
if (byFunc->funcPointer->GetOriginal() == search_func)
{
if (byFunc->funcPointer->GetOriginal() == search_func)
{
auto prevent_it = preventFromParallelization.find(byFunc);
if (prevent_it != preventFromParallelization.end())
preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second, fileM);
auto prevent_it = preventFromParallelization.find(byFunc);
if (prevent_it != preventFromParallelization.end())
preventLoopsFromParallelizations(loop, prevent_it->second, fileM);
loop_analyzed = true;
break;
}
}
if (!loop_analyzed)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop
}
}
}
}
void removeRegionsWithoutDirs(const map<string, vector<Directive*>>& createdDirectives,
vector<ParallelRegion*>& parallelRegions,
const map<string, vector<FuncInfo*>>& allFuncInfo,
map<string, vector<Messages>>& SPF_messages)
{
set<ParallelRegion*> empty_regs(parallelRegions.begin(), parallelRegions.end());
for (const auto& byFile : createdDirectives)
for (const auto& dir : byFile.second)
empty_regs.erase(getRegionByLine(parallelRegions, byFile.first, dir->line));
set<int> idxToDel;
for (int z = 0; z < parallelRegions.size(); ++z)
{
if (empty_regs.find(parallelRegions[z]) != empty_regs.end())
{
__spf_print(1, " no parallel directives for parallel region '%s'\n", parallelRegions[z]->GetName().c_str());
if (parallelRegions[z]->GetId() == 0) // DEFAULT
{
wstring bufE, bufR;
__spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this project");
__spf_printToLongBuf(bufR, R130);
for (auto& funcByFile : allFuncInfo)
{
vector<Messages>& fileM = getObjectForFileFromMap(funcByFile.first.c_str(), SPF_messages);
for (auto& func : funcByFile.second)
{
auto stat = func->funcPointer->GetOriginal();
if (stat->variant() == PROG_HEDR)
fileM.push_back(Messages(ERROR, stat->lineNumber(), bufR, bufE, 3010));
}
loop_analyzed = true;
break;
}
}
else
{
wstring bufE, bufR;
__spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this region");
__spf_printToLongBuf(bufR, R131);
for (auto& linesByFile : parallelRegions[z]->GetAllLines())
{
vector<Messages>& fileM = getObjectForFileFromMap(linesByFile.first.c_str(), SPF_messages);
for (auto& lines : linesByFile.second)
if (!lines.isImplicit())
fileM.push_back(Messages(ERROR, lines.lines.first, bufR, bufE, 3010));
}
}
idxToDel.insert(z);
if (!loop_analyzed)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop
}
}
vector<ParallelRegion*> newParReg;
for (int z = 0; z < parallelRegions.size(); ++z)
{
if (idxToDel.find(z) != idxToDel.end())
{
ParallelRegion* regToDel = parallelRegions[z];
#ifdef _WIN32
removeFromCollection(parallelRegions[z]);
#endif
delete parallelRegions[z];
}
else
newParReg.push_back(parallelRegions[z]);
}
parallelRegions.clear();
parallelRegions = newParReg;
if (parallelRegions.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}

View File

@@ -11,12 +11,6 @@
void SelectArrayConfForParallelization(SgProject* proj, std::map<std::string, std::vector<FuncInfo*>>& funcByFile,
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Directive*>>& createdDirectives,
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Messages>>& allMessages,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::vector<ParallelRegion*>& regions);
void removeRegionsWithoutDirs(const std::map<std::string, std::vector<Directive*>>& createdDirectives,
std::vector<ParallelRegion*>& parallelRegions,
const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
std::map<std::string, std::vector<Messages>>& SPF_messages);
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);

View File

@@ -1924,8 +1924,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == FIX_COMMON_BLOCKS)
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, SPF_messages, arrayLinksByFuncCalls);
}
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
{

View File

@@ -233,7 +233,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ GET_ALL_ARRAY_DECL, CALL_GRAPH2, CODE_CHECKER_PASSES, SUBST_EXPR_RD, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= list({ LOOP_ANALYZER_NODIST, LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH });
list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(SELECT_ARRAY_DIM_CONF) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
Pass(CHECK_ARGS_DECL) <= Pass(CREATE_TEMPLATE_LINKS);
@@ -251,7 +251,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ CORRECT_VAR_DECL, PREPROC_SPF }) <= list({ LOOP_GRAPH, CALL_GRAPH, CALL_GRAPH2 });
list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL, SELECT_ARRAY_DIM_CONF});
list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL });
list({ PREPROC_SPF, CALL_GRAPH2, FILL_PAR_REGIONS_LINES }) <= Pass(FILL_PAR_REGIONS) <= Pass(RESOLVE_PAR_REGIONS);

View File

@@ -820,7 +820,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho
else if (regime == 1)
{
if (mpiProgram)
runPassesForVisualizer(projName, { LOOP_ANALYZER_NODIST });
runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF });
else
runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 });
}