From 83f5fee8cd36c7c585398b50ecb5ae810916a687 Mon Sep 17 00:00:00 2001 From: mkoch Date: Wed, 27 Sep 2023 20:27:03 +0300 Subject: [PATCH] better condition for excluding arrays from parallelization --- .../_src/GraphCall/select_array_conf.cpp | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp index 9ec630e..f5ce3ab 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp @@ -92,6 +92,48 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set> dims; + + DimConf(DIST::Array* a) : dims(a->GetSizes()) { } + + friend bool operator<(const DimConf& l, const DimConf& r) { return l.dims < r.dims; } +}; + +static map>>::const_iterator +pickBest(const map>>& arrs) +{ + const int undefined = -1; + int max_elems = undefined; + auto best_it = arrs.begin(); + + for (auto it = arrs.begin(); it != arrs.end(); it++) + { + int elems = 1; + for (const auto& p : it->first.dims) + { + if(p.first >= 0 && p.second >= p.first) + { + elems *= p.second - p.first; + } + else + { + elems = undefined; + break; + } + } + + if (elems > max_elems) + { + max_elems = elems; + best_it = it; + } + } + + return best_it; +} + void SelectArrayConfForParallelization(SgProject* proj, map>& funcByFile, const map>& loopGraph, map>& createdDirectives, map>& allMessages, const map>& arrayLinksByFuncCalls, @@ -103,7 +145,7 @@ void SelectArrayConfForParallelization(SgProject* proj, mapfuncName] = byFunc; // array(real ref) dims func array in func - map>>> usedArrays; + map>>> usedArrays; for (const auto& byFile : loopGraph) { @@ -154,7 +196,7 @@ void SelectArrayConfForParallelization(SgProject* proj, mapGetDimSize(); for(DIST::Array* ref : realRefs) - usedArrays[ref][num_of_dims][byFunc.first].insert(arr); + usedArrays[ref][DimConf(arr)][byFunc.first].insert(arr); } } } @@ -166,14 +208,15 @@ void SelectArrayConfForParallelization(SgProject* proj, mapsecond) + for (const auto& byFunc : by_worse_dim_conf_it->second) { FuncInfo* f = byFunc.first; auto& to_prevent = byFunc.second; -- 2.49.1