improved planner

This commit is contained in:
2023-12-03 16:25:42 +03:00
parent 0afbb32788
commit ed68c9b11e
3 changed files with 86 additions and 6 deletions

View File

@@ -36,6 +36,6 @@ int main(int argc, char ** argv)
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
printf("%ld\n", runSupervisor->getLength());
runSupervisor->print();
runSupervisor->Do();
runSupervisor->DoWithSchedule(maxKernels);
return 0;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <map>
#include <set>
#include <vector>
#include <queue>
#include "File.h"
@@ -131,7 +132,33 @@ public:
void DoWithSchedule(int maxKernels) {
saveState();
map<int, queue<T*>> sortedByKernelNeeds;
// подготовка тестов
while (this->state != Execution) {
for (auto& task : this->getElements()) {
switch (this->state) {
case WorkspacesCreation:
if (task->getState() == Waiting) {
task->createWorkspace();
task->setState(WorkspaceCreated);
}
break;
case Preparation:
if (task->getState() == WorkspaceCreated) {
task->prepareWorkspace();
task->createLaunchScript();
task->setState(WorkspaceReady);
}
break;
default:
//printf("id = %ld; state = %d\n", task->getId(), task->getState());
break;
}
}
changeState();
}
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
long activeTasks = 0;
for (auto& task : this->getElements()) {
@@ -141,10 +168,60 @@ public:
}
}
printf("total tasks count = %ld, active task count %ld\n", this->getLength(), activeTasks);
printf("total tasks count = %ld, active task count %ld, maxkernels %d\n", this->getLength(), activeTasks, maxKernels);
int busyKernels = 0;
set<T*> activeTaskSet;
bool ignoreCheck = true;
while (activeTasks) {
vector<int> emptyKeys;
//ставим задачи от больших к меньшему по ядрам
for (auto& elem : sortedByKernelNeeds) {
int freeKernels = maxKernels - busyKernels;
int kernelsNeeded = elem.first;
while (kernelsNeeded <= freeKernels && elem.second.size()) {
T* task = elem.second.front();
elem.second.pop();
activeTaskSet.insert(task);
task->Start(ignoreCheck);
printf("start task with %d kernels and id %ld\n", task->getKernels(), task->getId());
busyKernels += task->getKernels();
freeKernels = maxKernels - busyKernels;
}
if (elem.second.size() == 0)
emptyKeys.push_back(kernelsNeeded);
//если ядер не осталось, то нет смысла дальше смотреть
if (freeKernels == 0)
break;
}
// очищаем от пустых ключей
for (auto& empty : emptyKeys)
sortedByKernelNeeds.erase(empty);
// проверяем нет ли завершившихся задач
for (auto it = activeTaskSet.begin(); it != activeTaskSet.end(); )
{
T* task = *(it);
if (task->Check()) {
it++;
activeTaskSet.erase(task);
activeTasks--;
busyKernels -= task->getKernels();
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
continue;
}
it++;
}
}
changeState();

View File

@@ -138,7 +138,8 @@ public:
}
}
virtual void Check() {
//return 'true' if done, 'false' - if running
virtual bool Check() {
if (Utils::Exists(workspace + "/DONE"))
analyseResults();
else {
@@ -156,8 +157,10 @@ public:
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
freeKernels = Utils::max(0, maxKernels - busyKernels);
//-
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
//saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
}
return (state != Running);
}
virtual void analyseResults() {