improved planner
This commit is contained in:
@@ -9,6 +9,13 @@
|
|||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
enum SupervisorState {
|
enum SupervisorState {
|
||||||
WorkspacesCreation, //0
|
WorkspacesCreation, //0
|
||||||
@@ -21,6 +28,7 @@ template <class T>
|
|||||||
class Supervisor : public Array <T> {
|
class Supervisor : public Array <T> {
|
||||||
protected:
|
protected:
|
||||||
SupervisorState state;
|
SupervisorState state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual String getStatePrefix() {
|
virtual String getStatePrefix() {
|
||||||
return String("");
|
return String("");
|
||||||
@@ -108,11 +116,13 @@ public:
|
|||||||
|
|
||||||
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
|
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
|
||||||
size_t activeTasks = 0;
|
size_t activeTasks = 0;
|
||||||
|
size_t totalProcessTasks = 0;
|
||||||
int maxNeededKernels = 0;
|
int maxNeededKernels = 0;
|
||||||
|
|
||||||
for (auto& task : this->getElements()) {
|
for (auto& task : this->getElements()) {
|
||||||
if (task->getState() == WorkspaceReady) {
|
if (task->getState() == WorkspaceReady) {
|
||||||
activeTasks++;
|
activeTasks++;
|
||||||
|
totalProcessTasks += task->getKernels();
|
||||||
sortedByKernelNeeds[task->getKernels()].push(task);
|
sortedByKernelNeeds[task->getKernels()].push(task);
|
||||||
if (maxNeededKernels < task->getKernels())
|
if (maxNeededKernels < task->getKernels())
|
||||||
maxNeededKernels = task->getKernels();
|
maxNeededKernels = task->getKernels();
|
||||||
@@ -145,9 +155,10 @@ public:
|
|||||||
vector<T*> toDel;
|
vector<T*> toDel;
|
||||||
|
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
size_t step = ceil(activeTasks * 0.01); // step == 1%
|
size_t step = ceil(totalProcessTasks * 0.01); // step == 1%
|
||||||
const double total = activeTasks;
|
const double total = totalProcessTasks;
|
||||||
|
|
||||||
|
auto timer_start = Utils::getAbsoluteTime();
|
||||||
while (activeTasks) {
|
while (activeTasks) {
|
||||||
long oldActiveTasks = activeTasks;
|
long oldActiveTasks = activeTasks;
|
||||||
emptyKeys.clear();
|
emptyKeys.clear();
|
||||||
@@ -189,7 +200,7 @@ public:
|
|||||||
if (task->Check()) {
|
if (task->Check()) {
|
||||||
toDel.push_back(task);
|
toDel.push_back(task);
|
||||||
activeTasks--;
|
activeTasks--;
|
||||||
done++;
|
done += task->getKernels();
|
||||||
busyKernels -= task->getKernels();
|
busyKernels -= task->getKernels();
|
||||||
#if DEB
|
#if DEB
|
||||||
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||||
@@ -212,6 +223,16 @@ public:
|
|||||||
saveProgress(persentDone);
|
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();
|
changeState();
|
||||||
@@ -219,10 +240,12 @@ public:
|
|||||||
String outFile(pathRes + "/" + getStatePrefix() + "Info.txt");
|
String outFile(pathRes + "/" + getStatePrefix() + "Info.txt");
|
||||||
File tmp(outFile, String(buf.c_str()));
|
File tmp(outFile, String(buf.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveState() {
|
void saveState() {
|
||||||
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||||
File tmp(stateFile, Utils::getDate());
|
File tmp(stateFile, Utils::getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveProgress(long long persentDone) {
|
void saveProgress(long long persentDone) {
|
||||||
FILE *f = fopen("progress", "w");
|
FILE *f = fopen("progress", "w");
|
||||||
if (f) {
|
if (f) {
|
||||||
@@ -230,4 +253,13 @@ public:
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool checkPause() {
|
||||||
|
FILE* f = fopen("pause", "w");
|
||||||
|
if (f) {
|
||||||
|
fclose(f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
std::chrono::seconds timespan(s);
|
std::chrono::seconds timespan(s);
|
||||||
std::this_thread::sleep_for(timespan);
|
std::this_thread::sleep_for(timespan);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Copy(const String& src, const String& dst) {
|
static void Copy(const String& src, const String& dst) {
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
std::filesystem::copy(src.getCharArray(), dst.getCharArray());
|
std::filesystem::copy(src.getCharArray(), dst.getCharArray());
|
||||||
@@ -73,9 +74,11 @@ public:
|
|||||||
//printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
|
//printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static time_t getAbsoluteTime() {
|
static time_t getAbsoluteTime() {
|
||||||
return time(NULL);
|
return time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getDate() {
|
static String getDate() {
|
||||||
auto ttime = time(NULL);
|
auto ttime = time(NULL);
|
||||||
String res(ctime(&ttime));
|
String res(ctime(&ttime));
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ using namespace std;
|
|||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "CompilationSupervisor.h"
|
#include "CompilationSupervisor.h"
|
||||||
#include "RunSupervisor.h"
|
#include "RunSupervisor.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
|
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
|
||||||
void hdl(int sig)
|
void hdl(int sig)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
3
|
4
|
||||||
Reference in New Issue
Block a user