fixed shared memory parallelization, moved messages to single file

This commit is contained in:
ALEXks
2025-06-14 12:50:04 +03:00
parent 10636427ed
commit 9e777ceeab
8 changed files with 133 additions and 70 deletions

View File

@@ -455,15 +455,7 @@ namespace Distribution
} }
if (needPrint) if (needPrint)
{ sendMessage_2lvl(4, k, (int)AllCycles.size());
#if _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(k + 1) + L"/" + std::to_wstring(AllCycles.size());
#else
wstring treeM = L"conflict resolution, processing group " + std::to_wstring(k + 1) + L"/" + std::to_wstring(AllCycles.size());
#endif
sendMessage_2lvl(treeM);
}
auto timeR = steady_clock::now(); auto timeR = steady_clock::now();
if (countConflicts != 0) if (countConflicts != 0)
@@ -516,7 +508,7 @@ namespace Distribution
} }
if (needPrint) if (needPrint)
sendMessage_2lvl(L""); sendMessage_2lvl(2);
return make_pair(allOnlySecondType, globalSum); return make_pair(allOnlySecondType, globalSum);
} }
@@ -572,13 +564,7 @@ namespace Distribution
for (int z = 0; z < arraysV.size(); ++z) for (int z = 0; z < arraysV.size(); ++z)
{ {
const DIST::Array *array = arraysV[z]; const DIST::Array *array = arraysV[z];
sendMessage_2lvl(5, z, (int)arrays.size());
#ifdef _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(z + 1) + L"/" + std::to_wstring(arrays.size());
#else
wstring treeM = L"conflict resolution, processing array " + std::to_wstring(z + 1) + L"/" + std::to_wstring(arrays.size());
#endif
sendMessage_2lvl(treeM);
vector<vType> verts; vector<vType> verts;
@@ -605,7 +591,7 @@ namespace Distribution
} }
} }
} }
sendMessage_2lvl(L""); sendMessage_2lvl(2);
} }
else else
{ {

View File

@@ -830,13 +830,13 @@ namespace Distribution
color[k] = WHITE; color[k] = WHITE;
findFrom = currentV; findFrom = currentV;
#ifdef _WIN32 /*#ifdef _WIN32
if (needPrint) if (needPrint)
{ {
wstring vertexM = std::to_wstring(k + 1) + L"/" + std::to_wstring(vertByTrees[t].size()); wstring vertexM = std::to_wstring(k + 1) + L"/" + std::to_wstring(vertByTrees[t].size());
sendMessage_2lvl(wstring(L"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ") + wstring(treeM.begin(), treeM.end()) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + wstring(vertexM.begin(), vertexM.end())); sendMessage_2lvl(wstring(L"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ") + wstring(treeM.begin(), treeM.end()) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + wstring(vertexM.begin(), vertexM.end()));
} }
#endif #endif*/
__spf_print(PRINT_TIMES && needPrint, "v (tree %d) = %d (with neighb %d) ", t, i, neighbors[i + 1] - neighbors[i]); __spf_print(PRINT_TIMES && needPrint, "v (tree %d) = %d (with neighb %d) ", t, i, neighbors[i + 1] - neighbors[i]);
activeV[activeCounter++] = currentV; activeV[activeCounter++] = currentV;
FindLoop(cyclesTmp[t], currentV, currentV, numbers); FindLoop(cyclesTmp[t], currentV, currentV, numbers);
@@ -847,8 +847,8 @@ namespace Distribution
maxLoopDim = wasMaxLoopDim; maxLoopDim = wasMaxLoopDim;
} }
if (needPrint) /*if (needPrint)
sendMessage_2lvl(L""); sendMessage_2lvl(2);*/
} }
catch (int code) catch (int code)
{ {

View File

@@ -1633,17 +1633,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
createNeededException(); createNeededException();
string fName = file->functions(i)->symbol()->identifier(); string fName = file->functions(i)->symbol()->identifier();
#if _WIN32 sendMessage_2lvl(0, (file->functions(i)->variant() != MODULE_STMT), fName);
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<SgSymbol*> delcsSymbViewed;
set<SgStatement*> delcsStatViewed; set<SgStatement*> delcsStatViewed;
@@ -2188,11 +2178,8 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (!skipDeps) if (!skipDeps)
{ {
string fName = file->functions(i)->symbol()->identifier(); string fName = file->functions(i)->symbol()->identifier();
#ifdef _WIN32 sendMessage_2lvl(1, idx, (int)convertedLoopInfo.size());
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); tryToFindDependencies(loop.first, allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace);
} }
} }
@@ -2340,7 +2327,7 @@ 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);
} }
sendMessage_2lvl(L""); sendMessage_2lvl(2);
} }
else if (regime == COMP_DISTR) else if (regime == COMP_DISTR)
{ {

View File

@@ -294,11 +294,8 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
} }
} }
#ifdef _WIN32 sendMessage_2lvl(3, file);
sendMessage_2lvl(L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> '" + to_wstring(file) + L"'");
#else
sendMessage_2lvl(L" processing file '" + to_wstring(file) + L"'");
#endif
StdCapture::Init(); StdCapture::Init();
string errorMessage = ""; string errorMessage = "";
try try
@@ -578,11 +575,8 @@ static void parseFiles(int& iters, vector<string>& errors, vector<FileInfo>& lis
do do
{ {
#ifdef _WIN32 sendMessage_1lvl(0, iters + 1);
sendMessage_1lvl(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring((iters + 1)) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
#else
sendMessage_1lvl(L"running " + std::to_wstring((iters + 1)) + L" iteration of syntax analisys");
#endif
errors = parseList(listOfProject, iters != 0, parseForInlining, mapModuleDeps, moduleDelc, modDirectOrder, isFromConsole); errors = parseList(listOfProject, iters != 0, parseForInlining, mapModuleDeps, moduleDelc, modDirectOrder, isFromConsole);
changed = createMapOfUse(errors, listOfProject, mapModuleDeps); changed = createMapOfUse(errors, listOfProject, mapModuleDeps);
if (iters != 0) if (iters != 0)

View File

@@ -398,11 +398,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
__spf_print(DEBUG_LVL1, "RUN PASS with name %s\n", passNames[curr_regime]); __spf_print(DEBUG_LVL1, "RUN PASS with name %s\n", passNames[curr_regime]);
auto toSendStrMessage = string(passNames[curr_regime]); auto toSendStrMessage = string(passNames[curr_regime]);
#ifdef _WIN32 sendMessage_1lvl(1, toSendStrMessage);
sendMessage_1lvl(wstring(L"выполняется проход '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#else
sendMessage_1lvl(wstring(L"running pass '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#endif
const int n = project.numberOfFiles(); const int n = project.numberOfFiles();
bool verifyOK = true; bool verifyOK = true;
@@ -450,11 +446,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
SgFile *file = &(project.file(i)); SgFile *file = &(project.file(i));
toSendStrMessage = file->filename(); toSendStrMessage = file->filename();
#ifdef _WIN32 sendMessage_2lvl(3, toSendStrMessage);
sendMessage_2lvl(wstring(L"обработка файла '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#else
sendMessage_2lvl(wstring(L"processing file '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#endif
sendMessage_progress(std::to_wstring((int)(((double)(n - i) / n) * 100))); sendMessage_progress(std::to_wstring((int)(((double)(n - i) / n) * 100)));
const char *file_name = file->filename(); const char *file_name = file->filename();
@@ -1057,7 +1049,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
throw -11; throw -11;
} }
sendMessage_2lvl(wstring(L"")); sendMessage_2lvl(2);
// ********************************** /// // ********************************** ///
/// SECOND AGGREGATION STEP /// /// SECOND AGGREGATION STEP ///
// ********************************** /// // ********************************** ///
@@ -1928,7 +1920,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.; const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
__spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal); __spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal);
sendMessage_2lvl(wstring(L"")); sendMessage_2lvl(2);
if (internalExit != 0) if (internalExit != 0)
throw -1; throw -1;

View File

@@ -1776,11 +1776,8 @@ static bool inliner(const string& fileName_in, const string& funcName, const int
point.currCall = func->funcName; point.currCall = func->funcName;
__spf_print(1, " INLINE %s - ", func->funcName.c_str()); __spf_print(1, " INLINE %s - ", func->funcName.c_str());
#ifdef _WIN32 sendMessage_2lvl(6, func->funcName);
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(func->funcName.begin(), func->funcName.end()) + L"'");
#else
sendMessage_2lvl(wstring(L"inlinig of function '") + wstring(func->funcName.begin(), func->funcName.end()) + L"'");
#endif
//1 level //1 level
bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks); bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks);
__spf_print(1, "%s\n", isInlined ? "done" : "fault"); __spf_print(1, "%s\n", isInlined ? "done" : "fault");

View File

@@ -144,10 +144,116 @@ static int decodeMessage(const string& message, vector<string>& pars, int &winH,
return 0; return 0;
} }
void sendMessage_1lvl(const wstring& toSend) { MessageManager::sendFirstLvl (toSend); } static void sendMessage_1lvl(const wstring& toSend) { MessageManager::sendFirstLvl (toSend); }
void sendMessage_2lvl(const wstring& toSend) { MessageManager::sendSecondLvl(toSend); } static void sendMessage_2lvl(const wstring& toSend) { MessageManager::sendSecondLvl(toSend); }
void sendMessage_progress(const wstring& toSend) { MessageManager::sendProgress (toSend); } void sendMessage_progress(const wstring& toSend) { MessageManager::sendProgress (toSend); }
void sendMessage_1lvl(int kind, ...)
{
va_list list;
va_start(list, kind);
if (kind == 0)
{
int iters = va_arg(list, int);
#ifdef _WIN32
sendMessage_1lvl(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(iters) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
#else
sendMessage_1lvl(L"running " + std::to_wstring(iters) + L" iteration of syntax analisys");
#endif
}
else if (kind == 1)
{
string str = va_arg(list, string);
#ifdef _WIN32
sendMessage_1lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(str.begin(), str.end()) + L"'");
#else
sendMessage_1lvl(wstring(L"running pass '") + wstring(str.begin(), str.end()) + L"'");
#endif
}
va_end(list);
}
void sendMessage_2lvl(int kind, ...)
{
va_list list;
va_start(list, kind);
if (kind == 0)
{
bool isFunction = va_arg(list, int);
string fName = va_arg(list, string);
#if _WIN32
if (isFunction)
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + to_wstring(fName) + L"'");
else
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + to_wstring(fName) + L"'");
#else
if (isFunction)
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
}
else if (kind == 1)
{
int idx = va_arg(list, int);
int all = va_arg(list, int);
#ifdef _WIN32
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> ") + std::to_wstring(idx) + L"/" + std::to_wstring(all));
#else
sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(all));
#endif
}
else if (kind == 2)
{
sendMessage_2lvl(L"");
}
else if (kind == 3)
{
string file = va_arg(list, string);
#ifdef _WIN32
sendMessage_2lvl(L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> '" + to_wstring(file) + L"'");
#else
sendMessage_2lvl(L" processing file '" + to_wstring(file) + L"'");
#endif
}
else if (kind == 4)
{
int k = va_arg(list, int);
int all = va_arg(list, int);
#if _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(k + 1) + L"/" + std::to_wstring(all);
#else
wstring treeM = L"conflict resolution, processing group " + std::to_wstring(k + 1) + L"/" + std::to_wstring(all);
#endif
sendMessage_2lvl(treeM);
}
else if (kind == 5)
{
int z = va_arg(list, int);
int all = va_arg(list, int);
#ifdef _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(z + 1) + L"/" + std::to_wstring(all);
#else
wstring treeM = L"conflict resolution, processing array " + std::to_wstring(z + 1) + L"/" + std::to_wstring(all);
#endif
sendMessage_2lvl(treeM);
}
else if (kind == 6)
{
string funcName = va_arg(list, string);
#ifdef _WIN32
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + to_wstring(funcName) + L"'");
#else
sendMessage_2lvl(wstring(L"inlinig of function '") + to_wstring(funcName) + L"'");
#endif
}
va_end(list);
}
static string utf8_encode(const wstring& wstr) static string utf8_encode(const wstring& wstr)
{ {
if (wstr.empty()) if (wstr.empty())

View File

@@ -32,7 +32,8 @@ public:
static int init(); static int init();
}; };
void sendMessage_1lvl(const std::wstring& toSend); void sendMessage_1lvl(int kind, ...);
void sendMessage_2lvl(const std::wstring& toSend); void sendMessage_2lvl(int kind, ...);
void sendMessage_progress(const std::wstring& toSend); void sendMessage_progress(const std::wstring& toSend);
unsigned int GetPid(); unsigned int GetPid();