fixed merge

This commit is contained in:
2023-12-03 18:02:15 +03:00
6 changed files with 110 additions and 79 deletions

View File

@@ -5,7 +5,8 @@
#include <vector>
#include <queue>
#include "File.h"
#include "Task.h"
#include "Task.h"
#include "Array.h"
enum SupervisorState {
WorkspacesCreation, //0
@@ -87,8 +88,8 @@ public:
//todo обязательно убрать отладочную печать.
printf("tasks count = %ld\n", this->getLength());
while (this->state != End) {
// printf("state=%d\n", this->state);
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
// printf("state=%d\n", this->state);
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
activeCount = 0;
for (long i = 0; i < this->getLength(); ++i) {
T* task = this->get(i);
@@ -111,6 +112,7 @@ public:
case Execution:
if (task->getState() == WorkspaceReady) {
activeCount++;
task->start_time = Utils::getAbsoluteTime();
task->Start();
}
else if (task->getState() == Running) {
@@ -119,17 +121,18 @@ public:
}
break;
default:
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
break;
}
}
// printf("active count = %d\n", activeCount);
// printf("active count = %d\n", activeCount);
if (activeCount == 0)
changeState();
Utils::Sleep(2);
}
}
void DoWithSchedule(int maxKernels) {
saveState();
@@ -162,7 +165,7 @@ public:
long activeTasks = 0;
long done = 0;
for (auto& task : this->getElements()) {
for (auto& task : this->getElements()) {
if (task->getState() == WorkspaceReady) {
activeTasks++;
sortedByKernelNeeds[task->getKernels()].push(task);
@@ -183,7 +186,7 @@ public:
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();
@@ -201,18 +204,18 @@ public:
//если ядер не осталось, то нет смысла дальше смотреть
if (freeKernels == 0)
break;
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);
@@ -225,7 +228,7 @@ public:
}
it++;
}
if (oldActiveTasks != activeTasks)
printf("done %ld / %ld\n", done, this->getLength());
}
@@ -234,10 +237,11 @@ public:
}
virtual void Finalize() {}
void saveState() {
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
//printf("stateFile=<%s>\n", stateFile.getCharArray());
File tmp(stateFile, Utils::getDate());
File(stateFile, Utils::getDate());
}
};