better condition for excluding arrays from parallelization
This commit is contained in:
@@ -92,6 +92,48 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Ar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DimConf
|
||||||
|
{
|
||||||
|
vector<pair<int, int>> dims;
|
||||||
|
|
||||||
|
DimConf(DIST::Array* a) : dims(a->GetSizes()) { }
|
||||||
|
|
||||||
|
friend bool operator<(const DimConf& l, const DimConf& r) { return l.dims < r.dims; }
|
||||||
|
};
|
||||||
|
|
||||||
|
static map<DimConf, map<FuncInfo*, set<DIST::Array*>>>::const_iterator
|
||||||
|
pickBest(const map<DimConf, map<FuncInfo*, set<DIST::Array*>>>& 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<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<std::string, vector<Directive*>>& createdDirectives,
|
||||||
map<string, vector<Messages>>& allMessages, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
map<string, vector<Messages>>& allMessages, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||||
@@ -103,7 +145,7 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
|
|||||||
funcByName[byFunc->funcName] = byFunc;
|
funcByName[byFunc->funcName] = byFunc;
|
||||||
|
|
||||||
// array(real ref) dims func array in func
|
// array(real ref) dims func array in func
|
||||||
map<DIST::Array*, map<int, map<FuncInfo*, set<DIST::Array*>>>> usedArrays;
|
map<DIST::Array*, map<DimConf, map<FuncInfo*, set<DIST::Array*>>>> usedArrays;
|
||||||
|
|
||||||
for (const auto& byFile : loopGraph)
|
for (const auto& byFile : loopGraph)
|
||||||
{
|
{
|
||||||
@@ -154,7 +196,7 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
|
|||||||
|
|
||||||
int num_of_dims = arr->GetDimSize();
|
int num_of_dims = arr->GetDimSize();
|
||||||
for(DIST::Array* ref : realRefs)
|
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, map<string, vector<FuncI
|
|||||||
DIST::Array* realRef = byRealRef.first;
|
DIST::Array* realRef = byRealRef.first;
|
||||||
auto& refferedDims = byRealRef.second;
|
auto& refferedDims = byRealRef.second;
|
||||||
|
|
||||||
// prevent from parallelization all arrays wich refers realRef and has smaller number of dims
|
// prevent from parallelization all configurations except best one
|
||||||
auto bySmallerDimSize = refferedDims.rbegin();
|
|
||||||
if(bySmallerDimSize != refferedDims.rend())
|
auto best_conf_it = pickBest(refferedDims);
|
||||||
|
|
||||||
|
for (auto by_worse_dim_conf_it = refferedDims.begin(); by_worse_dim_conf_it != refferedDims.end(); by_worse_dim_conf_it++)
|
||||||
{
|
{
|
||||||
bySmallerDimSize++;
|
if(by_worse_dim_conf_it != best_conf_it)
|
||||||
for (; bySmallerDimSize != refferedDims.rend(); bySmallerDimSize++)
|
|
||||||
{
|
{
|
||||||
for (const auto& byFunc : bySmallerDimSize->second)
|
for (const auto& byFunc : by_worse_dim_conf_it->second)
|
||||||
{
|
{
|
||||||
FuncInfo* f = byFunc.first;
|
FuncInfo* f = byFunc.first;
|
||||||
auto& to_prevent = byFunc.second;
|
auto& to_prevent = byFunc.second;
|
||||||
|
|||||||
Reference in New Issue
Block a user