fixed and improved #4

Merged
M merged 2 commits from planner_improve into main 2023-12-05 13:20:02 +00:00
6 changed files with 36 additions and 22 deletions

View File

@@ -8,6 +8,7 @@ public:
CompilationSupervisor() { CompilationSupervisor() {
this->init("compilationTasks", 4); this->init("compilationTasks", 4);
} }
CompilationTask* getTaskById(long task_id) { CompilationTask* getTaskById(long task_id) {
for (long i = 0; i < getLength(); ++i) { for (long i = 0; i < getLength(); ++i) {
CompilationTask* task = get(i); CompilationTask* task = get(i);
@@ -16,7 +17,8 @@ public:
} }
return NULL; return NULL;
} }
virtual String getStatePrefix() {
String getStatePrefix() override {
return String("Compilation"); return String("Compilation");
} }
}; };

View File

@@ -19,7 +19,8 @@ public:
task->printState().getCharArray()); task->printState().getCharArray());
} }
} }
virtual String getStatePrefix() {
String getStatePrefix() override {
return String("Running"); return String("Running");
} }
}; };

View File

@@ -11,7 +11,7 @@ class RunTask : public Task {
String args; String args;
CompilationTask* parent; CompilationTask* parent;
public: public:
virtual void print() const { void print() const override {
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n", printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
id, id,
maxtime, maxtime,
@@ -60,7 +60,7 @@ public:
setKernels(lines->get(offset + 7)); setKernels(lines->get(offset + 7));
} }
virtual String getLaunchScriptText() { String getLaunchScriptText() override {
String modules = userWorkspace + "/modules"; String modules = userWorkspace + "/modules";
String starterCall = modules + "/starter"; String starterCall = modules + "/starter";
String launcherCall = modules + "/launcher"; String launcherCall = modules + "/launcher";
@@ -77,7 +77,8 @@ public:
String::DQuotes("killall -SIGKILL " + binary_name) + " " + String::DQuotes("killall -SIGKILL " + binary_name) + " " +
dvm_start; dvm_start;
} }
virtual void prepareWorkspace() {
void prepareWorkspace() override {
String binary_src = parent->getWorkspace() + "/0"; String binary_src = parent->getWorkspace() + "/0";
String binary_dst = workspace + "/" + binary_name; String binary_dst = workspace + "/" + binary_name;
Utils::Copy(binary_src, binary_dst); Utils::Copy(binary_src, binary_dst);
@@ -86,14 +87,16 @@ public:
File parFile = File(parPath, usr_par); File parFile = File(parPath, usr_par);
} }
} }
virtual String getStartCommand() {
String getStartCommand() override {
String res = workspace + "/run"; String res = workspace + "/run";
if (!environments.isEmpty()) if (!environments.isEmpty())
res = environments + " " + res; res = environments + " " + res;
printf("START %ld: %s\n", id, res.getCharArray()); printf("START %ld: %s\n", id, res.getCharArray());
return res; return res;
} }
virtual String copyResults(const String& pathRes) {
String copyResults(const String& pathRes) override {
String resultPath = Task::copyResults(pathRes); String resultPath = Task::copyResults(pathRes);
if (Utils::Exists(workspace + "/sts.gz+")) { if (Utils::Exists(workspace + "/sts.gz+")) {
String stsPath(resultPath + "/statistic.txt"); String stsPath(resultPath + "/statistic.txt");

View File

@@ -29,7 +29,7 @@ public:
const char* getCharArray() const { return body.c_str(); } const char* getCharArray() const { return body.c_str(); }
const string& getBody() const { return body; } const string& getBody() const { return body; }
size_t getLength() const { return body.size(); } size_t getLength() const { return body.size(); }
bool isEmpty() const { return body.size() != 0; } bool isEmpty() const { return body.size() == 0; }
bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; } bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; }
bool operator==(const String& s) const { return body == s.getBody(); } bool operator==(const String& s) const { return body == s.getBody(); }
@@ -68,4 +68,4 @@ public:
String operator+(const String& a, const String& b) { String operator+(const String& a, const String& b) {
return String((a.getBody() + b.getBody()).c_str()); return String((a.getBody() + b.getBody()).c_str());
} }

View File

@@ -124,9 +124,13 @@ public:
Utils::Mkdir(pathRes); Utils::Mkdir(pathRes);
string buf; string buf;
vector<int> emptyKeys;
vector<T*> toDel;
while (activeTasks) { while (activeTasks) {
long oldActiveTasks = activeTasks; long oldActiveTasks = activeTasks;
vector<int> emptyKeys; emptyKeys.clear();
toDel.clear();
//ставим задачи от больших к меньшему по ядрам //ставим задачи от больших к меньшему по ядрам
for (auto& elem : sortedByKernelNeeds) { for (auto& elem : sortedByKernelNeeds) {
@@ -156,8 +160,7 @@ public:
// очищаем от пустых ключей // очищаем от пустых ключей
for (auto& empty : emptyKeys) for (auto& empty : emptyKeys)
sortedByKernelNeeds.erase(empty); sortedByKernelNeeds.erase(empty);
vector<T*> toDel;
// проверяем нет ли завершившихся задач // проверяем нет ли завершившихся задач
for (auto& task : activeTaskSet) for (auto& task : activeTaskSet)
{ {
@@ -173,6 +176,7 @@ public:
} }
} }
// очищаем завершенные задачи
for (auto& del : toDel) for (auto& del : toDel)
activeTaskSet.erase(del); activeTaskSet.erase(del);
@@ -182,7 +186,7 @@ public:
changeState(); changeState();
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() {

View File

@@ -31,19 +31,23 @@ public:
//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) {
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
std::filesystem::permissions(path.getCharArray(), std::filesystem::perms::all); std::filesystem::permissions(path.getCharArray(), std::filesystem::perms::all);
#else #else
String command = "chmod 777 " + String::DQuotes(path); String command = "chmod 777 " + String::DQuotes(path);
int i=system(command.getCharArray()); int i=system(command.getCharArray());
printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i); printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i);
#endif #endif
} }
//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) {
#if __cplusplus >= 201703L
return std::filesystem::exists(path.getCharArray());
#else
struct stat buffer; struct stat buffer;
return (stat(path.getCharArray(), &buffer) == 0); return (stat(path.getCharArray(), &buffer) == 0);
#endif
} }
//in seconds //in seconds
@@ -52,22 +56,22 @@ public:
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());
#else #else
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst); String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
int i = system(command.getCharArray()); int i = system(command.getCharArray());
printf("cp '%s' return code = %d\n",src.getCharArray(), i); printf("cp '%s' return code = %d\n",src.getCharArray(), i);
#endif #endif
} }
static void CopyDirectory(const String& src, const String& dst) { static void CopyDirectory(const String& src, const String& dst) {
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
std::filesystem::copy((src+ "/.").getCharArray(), dst.getCharArray(), std::filesystem::copy_options::recursive); std::filesystem::copy((src+ "/.").getCharArray(), dst.getCharArray(), std::filesystem::copy_options::recursive);
#else #else
String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst); String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst);
int i = system(command.getCharArray()); int i = system(command.getCharArray());
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);