planner_improve #1
@@ -36,6 +36,6 @@ int main(int argc, char ** argv)
|
|||||||
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
||||||
printf("%ld\n", runSupervisor->getLength());
|
printf("%ld\n", runSupervisor->getLength());
|
||||||
runSupervisor->print();
|
runSupervisor->print();
|
||||||
runSupervisor->Do();
|
runSupervisor->DoWithSchedule(maxKernels);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
@@ -131,7 +132,33 @@ public:
|
|||||||
|
|
||||||
void DoWithSchedule(int maxKernels) {
|
void DoWithSchedule(int maxKernels) {
|
||||||
saveState();
|
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;
|
long activeTasks = 0;
|
||||||
for (auto& task : this->getElements()) {
|
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) {
|
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();
|
changeState();
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Check() {
|
//return 'true' if done, 'false' - if running
|
||||||
|
virtual bool Check() {
|
||||||
if (Utils::Exists(workspace + "/DONE"))
|
if (Utils::Exists(workspace + "/DONE"))
|
||||||
analyseResults();
|
analyseResults();
|
||||||
else {
|
else {
|
||||||
@@ -156,8 +157,10 @@ public:
|
|||||||
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
||||||
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
||||||
//-
|
//-
|
||||||
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
//saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (state != Running);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void analyseResults() {
|
virtual void analyseResults() {
|
||||||
|
|||||||
Reference in New Issue
Block a user