libpredict_integration: add iteration by processes_per_processor

This commit is contained in:
2026-02-21 21:31:40 +03:00
parent 2caaf1ce07
commit 611cd8014c
5 changed files with 63 additions and 39 deletions

View File

@@ -319,7 +319,6 @@ double runLibpredictCalc(const vector<size_t>& topology,
}
void runPredictScheme(SgProject& project,
vector<vector<size_t>>& topologies,
const vector<ParallelRegion*>& parallelRegions,
map<string, vector<LoopGraph*>>& loopGraph,
map<string, vector<Messages>>& SPF_messages)
@@ -363,16 +362,14 @@ void runPredictScheme(SgProject& project,
PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams(
project, parallelRegions, loopGraph, templateIdMapping);
// iterating through topologies to find most optimal one
topologies = vector<vector<size_t>>();
// iterating through topologies and processes_per_processor to find most optimal one
if (maxSizeDist) {
if (maxSizeDist > 4) {
maxSizeDist = 4;
}
// Initialize cluster
int procCount = 0;
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr, procCount);
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr);
if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster);
@@ -385,54 +382,78 @@ void runPredictScheme(SgProject& project,
return;
}
for (size_t n1 = 2; n1 <= procCount; ++n1) {
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
continue;
}
vector<size_t> best;
double bestTime = std::numeric_limits<double>::max();
for (size_t n3 = 1; n3 <= n2 && n1 * n2 * n3 <= procCount; ++n3) {
if (n3 != 1 && maxSizeDist < 3 || n3 == 1 && maxSizeDist == 3) {
for (size_t processes_per_processor = 1; processes_per_processor <= 16; ++processes_per_processor) {
int procCount = 0;
libpredict::RetInitMapping retInitMapping = libpredict::InitMapping(processes_per_processor, procCount);
if (retInitMapping != libpredict::INIT_MAPPING_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d\n",
processes_per_processor, (int)retInitMapping);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d",
processes_per_processor, (int)retInitMapping);
__spf_printToLongBuf(messageR, R211);
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1068));
continue;
}
if (procCount == 0) {
break; // No more processors available
}
__spf_print(1, "Calculate with processes_per_processor=%zu, procCount=%d\n", processes_per_processor, procCount);
for (size_t n1 = 2; n1 <= procCount; ++n1) {
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
continue;
}
for (size_t n4 = 1; n4 <= n3 && n1 * n2 * n3 * n4 <= procCount; ++n4) {
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
for (size_t n3 = 1; n3 <= n2 && n1 * n2 * n3 <= procCount; ++n3) {
if (n3 != 1 && maxSizeDist < 3 || n3 == 1 && maxSizeDist == 3) {
continue;
}
topologies.push_back(vector<size_t>{n1, n2, n3, n4});
for (size_t n4 = 1; n4 <= n3 && n1 * n2 * n3 * n4 <= procCount; ++n4) {
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
continue;
}
vector<size_t> topology = {n1, n2, n3, n4};
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
string outStr = "";
for (const auto& elem : topology) {
outStr += std::to_string(elem) + " ";
}
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
if (currTime == -1) {
continue;
}
if (currTime < bestTime) {
bestTime = currTime;
best = topology;
}
}
}
}
}
}
vector<size_t> best;
double bestTime = std::numeric_limits<double>::max();
for (auto& topology : topologies) {
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
string outStr = "";
for (const auto& elem : topology) {
if (!best.empty()) {
string outStr;
for (const auto& elem : best) {
outStr += std::to_string(elem) + " ";
}
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
if (currTime == -1) {
return;
}
if (currTime < bestTime) {
bestTime = currTime;
best = topology;
}
__spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime);
}
string outStr;
for (const auto& elem : best) {
outStr += std::to_string(elem) + " ";
}
__spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime);
} else {
__spf_print(1, "impossible to calculate best topology: project does not contain distribution directives\n");
}

View File

@@ -46,7 +46,6 @@ PrecomputedLibpredictParams precomputeLibpredictParams(
const std::map<size_t, size_t>& templateIdMapping);
void runPredictScheme(SgProject& project,
std::vector<std::vector<size_t>>& topologies,
const std::vector<ParallelRegion*>& parallelRegions,
std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Messages>>& SPF_messages);

View File

@@ -1733,7 +1733,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
}
}
else if (curr_regime == PREDICT_SCHEME)
runPredictScheme(project, topologies, parallelRegions, loopGraph, SPF_messages);
runPredictScheme(project, parallelRegions, loopGraph, SPF_messages);
else if (curr_regime == CREATE_INTER_TREE)
{
if (keepFiles)

View File

@@ -519,6 +519,8 @@ static const wchar_t* R208 = L"R208:";
static const wchar_t* R209 = L"R209:";
//1067
static const wchar_t* R210 = L"R210:";
//1068
static const wchar_t* R211 = L"R211:";
//2001
static const wchar_t *R94 = L"R94:";

View File

@@ -196,6 +196,8 @@ R208 = "Ошибка распределения массива '%s' с помо
R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
//1067
R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
//1068
R211 = "Ошибка инициализации отображения libpredict с processes_per_processor: %zu, код возврата: %d"
//2001
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"