planner_improve #1
@@ -24,7 +24,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
long getLength() const {
|
long getLength() const {
|
||||||
return elements.size();
|
return (long)elements.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get(long i) {
|
T* get(long i) {
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "CompilationSupervisor.h"
|
#include "CompilationSupervisor.h"
|
||||||
#include "RunSupervisor.h"
|
#include "RunSupervisor.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
@@ -11,7 +18,13 @@ int main(int argc, char ** argv)
|
|||||||
freeKernels = maxKernels;
|
freeKernels = maxKernels;
|
||||||
busyKernels= 0;
|
busyKernels= 0;
|
||||||
//--
|
//--
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
std::filesystem::current_path(packageWorkspace.getCharArray());
|
||||||
|
#else
|
||||||
chdir(packageWorkspace.getCharArray());
|
chdir(packageWorkspace.getCharArray());
|
||||||
|
#endif
|
||||||
|
|
||||||
userWorkspace.println();
|
userWorkspace.println();
|
||||||
packageWorkspace.println();
|
packageWorkspace.println();
|
||||||
printf("%d\n", maxKernels);
|
printf("%d\n", maxKernels);
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
String(const char* s) {
|
String(const char* s) {
|
||||||
length = strlen(s);
|
length = (long)strlen(s);
|
||||||
body = new char[length + 1];
|
body = new char[length + 1];
|
||||||
for (long i = 0; i < length; ++i)
|
for (long i = 0; i < length; ++i)
|
||||||
body[i] = s[i];
|
body[i] = s[i];
|
||||||
body[length] = '\0';
|
body[length] = '\0';
|
||||||
}
|
}
|
||||||
String(const char* s, char ps) {
|
String(const char* s, char ps) {
|
||||||
length = strlen(s);
|
length = (long)strlen(s);
|
||||||
body = new char[length + 1];
|
body = new char[length + 1];
|
||||||
for (long i = 0; i < length; ++i) {
|
for (long i = 0; i < length; ++i) {
|
||||||
body[i] = (s[i] == ps) ? '\n' : s[i];
|
body[i] = (s[i] == ps) ? '\n' : s[i];
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
@@ -56,6 +58,28 @@ public:
|
|||||||
delete packedTasks;
|
delete packedTasks;
|
||||||
delete lines;
|
delete lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void changeState() {
|
||||||
|
switch (this->state) {
|
||||||
|
case WorkspacesCreation:
|
||||||
|
this->state = Preparation;
|
||||||
|
saveState();
|
||||||
|
break;
|
||||||
|
case Preparation:
|
||||||
|
this->state = Execution;
|
||||||
|
saveState();
|
||||||
|
break;
|
||||||
|
case Execution:
|
||||||
|
Finalize();
|
||||||
|
this->state = End;
|
||||||
|
saveState();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this->state = End;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Do() {
|
void Do() {
|
||||||
saveState();
|
saveState();
|
||||||
long activeCount = 0;
|
long activeCount = 0;
|
||||||
@@ -99,34 +123,38 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("active count = %d\n", activeCount);
|
// printf("active count = %d\n", activeCount);
|
||||||
if (activeCount == 0) {
|
if (activeCount == 0)
|
||||||
switch (this->state) {
|
changeState();
|
||||||
case WorkspacesCreation:
|
|
||||||
this->state = Preparation;
|
|
||||||
saveState();
|
|
||||||
break;
|
|
||||||
case Preparation:
|
|
||||||
this->state = Execution;
|
|
||||||
saveState();
|
|
||||||
break;
|
|
||||||
case Execution:
|
|
||||||
Finalize();
|
|
||||||
this->state = End;
|
|
||||||
saveState();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this->state = End;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Utils::Sleep(2);
|
Utils::Sleep(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoWithSchedule(int maxKernels) {
|
||||||
|
saveState();
|
||||||
|
map<int, queue<T*>> sortedByKernelNeeds;
|
||||||
|
|
||||||
|
long activeTasks = 0;
|
||||||
|
for (auto& task : this->getElements()) {
|
||||||
|
if (task->getState() == WorkspaceReady) {
|
||||||
|
activeTasks++;
|
||||||
|
sortedByKernelNeeds[task->getKernels()].push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("total tasks count = %ld, active task count %ld\n", this->getLength(), activeTasks);
|
||||||
|
|
||||||
|
while (activeTasks) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
changeState();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void Finalize() {}
|
virtual void Finalize() {}
|
||||||
void saveState() {
|
void saveState() {
|
||||||
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
||||||
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||||
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
||||||
File(stateFile, Utils::getDate());
|
File tmp(stateFile, Utils::getDate());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -123,9 +123,12 @@ public:
|
|||||||
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
||||||
Utils::Chmod(launchScriptPath);
|
Utils::Chmod(launchScriptPath);
|
||||||
}
|
}
|
||||||
virtual void Start() {
|
|
||||||
|
|
||||||
if (kernels <= freeKernels) {
|
int getKernels() const { return kernels; }
|
||||||
|
|
||||||
|
virtual void Start(bool dontCheck = false) {
|
||||||
|
|
||||||
|
if (kernels <= freeKernels || dontCheck) {
|
||||||
system(getStartCommand().getCharArray());
|
system(getStartCommand().getCharArray());
|
||||||
state = Running;
|
state = Running;
|
||||||
//-
|
//-
|
||||||
@@ -134,13 +137,10 @@ public:
|
|||||||
//-
|
//-
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void analyseResults() {
|
|
||||||
state = Finished;
|
|
||||||
}
|
|
||||||
virtual void Check() {
|
virtual void Check() {
|
||||||
if (Utils::Exists(workspace + "/DONE")) {
|
if (Utils::Exists(workspace + "/DONE"))
|
||||||
analyseResults();
|
analyseResults();
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
||||||
state = AbortedByTimeout;
|
state = AbortedByTimeout;
|
||||||
@@ -150,6 +150,7 @@ public:
|
|||||||
state = AbortedByUser;
|
state = AbortedByUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state != Running) {
|
if (state != Running) {
|
||||||
//-
|
//-
|
||||||
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
||||||
@@ -158,8 +159,13 @@ public:
|
|||||||
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void analyseResults() {
|
||||||
|
state = Finished;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void saveState() {
|
virtual void saveState() {
|
||||||
String stateFile = workspace + "/TaskState";
|
String stateFile = workspace + "/TaskState";
|
||||||
File(stateFile, printState());
|
File tmp(stateFile, printState());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public:
|
|||||||
printf("text length=%ld\n", this->getLength());
|
printf("text length=%ld\n", this->getLength());
|
||||||
|
|
||||||
auto elems = this->getElements();
|
auto elems = this->getElements();
|
||||||
for (size_t i = 0; i < elems.size(); ++i) {
|
for (long i = 0; i < elems.size(); ++i) {
|
||||||
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
||||||
// elements[i]->println();
|
// elements[i]->println();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,14 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
@@ -16,31 +22,39 @@ public:
|
|||||||
return (a > b) ? b : a;
|
return (a > b) ? b : a;
|
||||||
}
|
}
|
||||||
static void Mkdir(const String& path) {
|
static void Mkdir(const String& path) {
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
std::filesystem::create_directory(path.getCharArray());
|
||||||
|
#else
|
||||||
mkdir(path.getCharArray(), 0777);
|
mkdir(path.getCharArray(), 0777);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
||||||
static void Chmod(const String& path) {
|
static void Chmod(const String& path) {
|
||||||
String command = "chmod 777 " + String::DQuotes(path);
|
String command = "chmod 777 " + String::DQuotes(path);
|
||||||
system(command.getCharArray());
|
system(command.getCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
||||||
static bool Exists(const String& path) {
|
static bool Exists(const String& path) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat(path.getCharArray(), &buffer) == 0);
|
return (stat(path.getCharArray(), &buffer) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//in seconds
|
||||||
static void Sleep(int s) {
|
static void Sleep(int s) {
|
||||||
usleep(s * 1000000);
|
std::chrono::seconds timespan(s);
|
||||||
|
std::this_thread::sleep_for(timespan);
|
||||||
}
|
}
|
||||||
static void Copy(const String& src, const String& dst) {
|
static void Copy(const String& src, const String& dst) {
|
||||||
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
||||||
system(command.getCharArray());
|
system(command.getCharArray());
|
||||||
}
|
}
|
||||||
static long getAbsoluteTime() {
|
static time_t getAbsoluteTime() {
|
||||||
return time(NULL);
|
return time(NULL);
|
||||||
}
|
}
|
||||||
static String getDate() {
|
static String getDate() {
|
||||||
long int ttime;
|
auto ttime = time(NULL);
|
||||||
ttime = time(NULL);
|
|
||||||
String res(ctime(&ttime));
|
String res(ctime(&ttime));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user