Improvements of shared memory parallelization #34

Merged
Alexander_KS merged 6 commits from selecct_array_conf_pass into master 2024-03-30 16:28:03 +00:00
9 changed files with 47 additions and 140 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, static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Array*>& prevent,
vector<Directive*>& createdDirectives,vector<Messages>& messagesForFile) vector<Messages>& messagesForFile)
{ {
if (loop->directive) if (loop->directive)
{ {
if (IsSetsIntersect(prevent, loop->usedArraysAll)) if (IsSetsIntersect(prevent, loop->usedArraysAll))
{ {
// prevent this loop // 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; delete loop->directive;
loop->directive = NULL; loop->directive = NULL;
@@ -123,7 +110,7 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Ar
} }
for (LoopGraph* child : loop->children) for (LoopGraph* child : loop->children)
preventLoopsFromParallelizations(child, prevent, createdDirectives, messagesForFile); preventLoopsFromParallelizations(child, prevent, messagesForFile);
} }
struct DimConf 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, void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncInfo*>>& funcByFile,
const map<string, vector<LoopGraph*>>& loopGraph, map<std::string, vector<Directive*>>& createdDirectives, const map<string, vector<LoopGraph*>>& loopGraph,
map<string, vector<Messages>>& allMessages, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls, map<string, vector<Messages>>& allMessages,
const vector<ParallelRegion*>& regions) const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
{ {
map<string, FuncInfo*> funcByName; map<string, FuncInfo*> funcByName;
for (const auto& byFile : funcByFile) for (const auto& byFile : funcByFile)
@@ -265,121 +252,43 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
for (const auto& byFile : loopGraph) for (const auto& byFile : loopGraph)
{ {
vector<Messages>& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages); vector<Messages>& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages);
auto dirs_it = createdDirectives.find(byFile.first); SgFile::switchToFile(byFile.first);
if (dirs_it != createdDirectives.end())
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()) bool loop_analyzed = false;
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile for (const auto& byFunc : file_funcs_it->second)
map<FuncInfo*, set<DIST::Array*>> usedInLoops;
for (const auto& loop : loops)
{ {
SgStatement* search_func = loop->loop->GetOriginal(); if (byFunc->funcPointer->GetOriginal() == search_func)
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) auto prevent_it = preventFromParallelization.find(byFunc);
{ if (prevent_it != preventFromParallelization.end())
auto prevent_it = preventFromParallelization.find(byFunc); preventLoopsFromParallelizations(loop, prevent_it->second, fileM);
if (prevent_it != preventFromParallelization.end())
preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second, fileM);
loop_analyzed = true; loop_analyzed = true;
break; 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));
}
} }
} }
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()) if (!loop_analyzed)
{ printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop
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);
} }
} }
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, void SelectArrayConfForParallelization(SgProject* proj, std::map<std::string, std::vector<FuncInfo*>>& funcByFile,
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph, const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Directive*>>& createdDirectives,
std::map<std::string, std::vector<Messages>>& allMessages, std::map<std::string, std::vector<Messages>>& allMessages,
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::vector<ParallelRegion*>& regions); const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
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);

View File

@@ -207,6 +207,12 @@ static inline bool hasGoto(SgStatement *begin, SgStatement *end,
has = true; has = true;
} }
if (curr->variant() == RETURN_STAT)
{
linesOfIntGoTo.push_back(curr->lineNumber());
has = true;
}
if (curr->variant() == CYCLE_STMT) if (curr->variant() == CYCLE_STMT)
cycleStmts.push_back(curr->lineNumber()); cycleStmts.push_back(curr->lineNumber());
curr = curr->lexNext(); curr = curr->lexNext();

View File

@@ -1,4 +1,4 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>

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) else if (curr_regime == FIX_COMMON_BLOCKS)
fixCommonBlocks(allFuncInfo, commonBlocks, &project); fixCommonBlocks(allFuncInfo, commonBlocks, &project);
else if (curr_regime == SELECT_ARRAY_DIM_CONF) { else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions); SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, SPF_messages, arrayLinksByFuncCalls);
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
} }
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST) else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
{ {
@@ -2154,8 +2153,6 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName); runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName);
runPass(CONVERT_LOOP_TO_ASSIGN, proj_name, folderName); runPass(CONVERT_LOOP_TO_ASSIGN, proj_name, folderName);
runPass(SELECT_ARRAY_DIM_CONF, proj_name, folderName);
runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName); runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName);

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({ 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); 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({ 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); list({ PREPROC_SPF, CALL_GRAPH2, FILL_PAR_REGIONS_LINES }) <= Pass(FILL_PAR_REGIONS) <= Pass(RESOLVE_PAR_REGIONS);

View File

@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <string> #include <string>
#include <cstdint>
struct DataDirective; struct DataDirective;
namespace Distribution namespace Distribution

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2296" #define VERSION_SPF "2298"

View File

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