improved planner
This commit is contained in:
@@ -9,6 +9,13 @@
|
||||
#include "File.h"
|
||||
#include "Task.h"
|
||||
#include "Array.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
enum SupervisorState {
|
||||
WorkspacesCreation, //0
|
||||
@@ -16,11 +23,12 @@ enum SupervisorState {
|
||||
Execution, //2
|
||||
End //3
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class Supervisor : public Array <T> {
|
||||
protected:
|
||||
SupervisorState state;
|
||||
|
||||
public:
|
||||
virtual String getStatePrefix() {
|
||||
return String("");
|
||||
@@ -108,11 +116,13 @@ public:
|
||||
|
||||
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
|
||||
size_t activeTasks = 0;
|
||||
size_t totalProcessTasks = 0;
|
||||
int maxNeededKernels = 0;
|
||||
|
||||
for (auto& task : this->getElements()) {
|
||||
if (task->getState() == WorkspaceReady) {
|
||||
activeTasks++;
|
||||
totalProcessTasks += task->getKernels();
|
||||
sortedByKernelNeeds[task->getKernels()].push(task);
|
||||
if (maxNeededKernels < task->getKernels())
|
||||
maxNeededKernels = task->getKernels();
|
||||
@@ -145,9 +155,10 @@ public:
|
||||
vector<T*> toDel;
|
||||
|
||||
size_t done = 0;
|
||||
size_t step = ceil(activeTasks * 0.01); // step == 1%
|
||||
const double total = activeTasks;
|
||||
size_t step = ceil(totalProcessTasks * 0.01); // step == 1%
|
||||
const double total = totalProcessTasks;
|
||||
|
||||
auto timer_start = Utils::getAbsoluteTime();
|
||||
while (activeTasks) {
|
||||
long oldActiveTasks = activeTasks;
|
||||
emptyKeys.clear();
|
||||
@@ -189,7 +200,7 @@ public:
|
||||
if (task->Check()) {
|
||||
toDel.push_back(task);
|
||||
activeTasks--;
|
||||
done++;
|
||||
done += task->getKernels();
|
||||
busyKernels -= task->getKernels();
|
||||
#if DEB
|
||||
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||
@@ -212,6 +223,16 @@ public:
|
||||
saveProgress(persentDone);
|
||||
}
|
||||
}
|
||||
|
||||
// прошло больше 10 секунд, проверяем паузу
|
||||
if (Utils::getAbsoluteTime() - timer_start > 30) {
|
||||
printf("stoped\n");
|
||||
while (checkPause()) {
|
||||
Utils::Sleep(10);
|
||||
}
|
||||
timer_start = Utils::getAbsoluteTime();
|
||||
printf("resume\n");
|
||||
}
|
||||
}
|
||||
|
||||
changeState();
|
||||
@@ -219,10 +240,12 @@ public:
|
||||
String outFile(pathRes + "/" + getStatePrefix() + "Info.txt");
|
||||
File tmp(outFile, String(buf.c_str()));
|
||||
}
|
||||
|
||||
void saveState() {
|
||||
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||
File tmp(stateFile, Utils::getDate());
|
||||
}
|
||||
|
||||
void saveProgress(long long persentDone) {
|
||||
FILE *f = fopen("progress", "w");
|
||||
if (f) {
|
||||
@@ -230,4 +253,13 @@ public:
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkPause() {
|
||||
FILE* f = fopen("pause", "w");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user