improved planner

This commit is contained in:
ALEXks
2025-03-13 20:47:20 +03:00
parent 8fc70d48ad
commit cb7360ae86
2 changed files with 59 additions and 31 deletions

View File

@@ -132,7 +132,7 @@ public:
}
const int maxThreads = std::thread::hardware_concurrency();
printf("total tasks count = %ld, active task count %ld, maxKernels %d, maxNeededKernels %d, maxThreads %d\n",
printf("total tasks count = %lu, active task count %lu, maxKernels %lu, maxNeededKernels %d, maxThreads %d\n",
this->getLength(), activeTasks, maxKernels, maxNeededKernels, maxThreads);
if (maxKernels > maxThreads) {
@@ -161,7 +161,9 @@ public:
const double total = totalProcessTasks;
auto timer_pause = Utils::getAbsoluteTime();
auto timer_killed = Utils::getAbsoluteTime();
bool killed = false;
while (activeTasks) {
long oldActiveTasks = activeTasks;
emptyKeys.clear();
@@ -196,23 +198,8 @@ public:
// очищаем от пустых ключей
for (auto& empty : emptyKeys)
sortedByKernelNeeds.erase(empty);
// проверяем нет ли завершившихся задач
for (auto& task : activeTaskSet)
{
if (task->Check()) {
toDel.push_back(task);
activeTasks--;
done += task->getKernels();
busyKernels -= task->getKernels();
#if DEB
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
#endif
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
//copy after end of while
//task->copyResults(pathRes);
}
}
checkTasksFinish(activeTaskSet, toDel, activeTasks, done, busyKernels, buf);
// очищаем завершенные задачи
for (auto& del : toDel)
@@ -230,20 +217,42 @@ public:
// прошло больше 30 секунд, проверяем паузу
if (Utils::getAbsoluteTime() - timer_pause > 30) {
printf("stoped\n");
bool hasSleep = false;
while (checkPause()) {
hasSleep = true;
printf("stoped, sleep 10 seconds\n");
Utils::Sleep(10);
}
timer_pause = Utils::getAbsoluteTime();
printf("resume\n");
if (hasSleep)
printf("resume\n");
}
// прошло больше 10 секунд, проверяем нужно ли завершиться
if (Utils::getAbsoluteTime() - timer_killed > 10) {
if (checkKilled()) {
printf("killed\n");
while (activeTasks) {
printf("waiting for activeTasks %lu\n", activeTasks);
checkTasksFinish(activeTaskSet, toDel, activeTasks, done, busyKernels, buf);
Utils::Sleep(5);
}
printf("exit for main while\n");
killed = true;
break;
}
timer_killed = Utils::getAbsoluteTime();
}
}
for (auto& task : taskList)
task->copyResults(pathRes);
if (!killed) {
for (auto& task : taskList)
task->copyResults(pathRes);
}
changeState();
String outFile(pathRes + "/" + getStatePrefix() + "Info.txt");
File tmp(outFile, String(buf.c_str()));
}
@@ -254,11 +263,6 @@ public:
}
void saveProgress(long long persentDone) {
/*String dump_progress = "echo '";
dump_progress = dump_progress + to_string(persentDone).c_str() + "' > progress";
system(dump_progress.getCharArray());*/
FILE* f = fopen("progress", "w");
if (f) {
fprintf(f, "%lld", persentDone);
@@ -267,7 +271,31 @@ public:
}
}
bool checkPause() {
bool checkPause() const {
return Utils::Exists("pause");
}
bool checkKilled() const {
return Utils::Exists("kill");
}
void checkTasksFinish(const set<T*>& activeTaskSet, vector<T*>& toDel, size_t& activeTasks,
size_t& done, int& busyKernels, string& buf) {
// проверяем нет ли завершившихся задач
for (auto& task : activeTaskSet)
{
if (task->Check()) {
toDel.push_back(task);
activeTasks--;
done += task->getKernels();
busyKernels -= task->getKernels();
#if DEB
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
#endif
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
//copy after end of while
//task->copyResults(pathRes);
}
}
}
};

View File

@@ -1 +1 @@
16
17