planner_improve #1

Merged
M merged 10 commits from planner_improve into main 2023-12-03 16:20:11 +00:00
8 changed files with 42 additions and 45 deletions
Showing only changes of commit c4b8e2dd7a - Show all commits

View File

@@ -3,42 +3,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
template <class T>
class Array {
protected:
long length;
T** elements;
private:
std::vector<T*> elements;
public:
Array() {
length = 0;
elements = NULL;
}
Array() { }
virtual ~Array() {
if (elements != NULL) {
for (long i = 0; i < length; ++i)
delete elements[i];
delete[] elements;
}
for (auto& elem : elements)
delete elem;
elements.clear();
}
void add(T* new_line) {
T** buf = new T * [length + 1];
for (long i = 0; i < length; ++i) {
buf[i] = elements[i];
elements.push_back(new_line);
}
buf[length] = new_line;
length++;
delete[] elements;
elements = buf;
buf = NULL;
}
long getLength() {
return length;
long getLength() const {
return elements.size();
}
T* get(long i) {
return elements[i];
}
T** getElements() {
const std::vector<T*>& getElements() const {
return elements;
}
};

View File

@@ -9,7 +9,7 @@ public:
this->init("compilationTasks", 4);
}
CompilationTask* getTaskById(long task_id) {
for (long i = 0; i < length; ++i) {
for (long i = 0; i < getLength(); ++i) {
CompilationTask* task = get(i);
if (task->getId() == task_id)
return task;

View File

@@ -13,11 +13,12 @@ public:
void setMakefileText(String* makefile_text_in) {
makefile_text = String(makefile_text_in->getCharArray(), '|');
}
virtual void print() {
virtual void print() const {
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
test_id.getCharArray());
printf("makefile_text=%s\n", makefile_text.getCharArray());
}
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
setTestId(lines->get(offset + 2));
setMakefileText(lines->get(offset + 3));

View File

@@ -8,7 +8,7 @@ public:
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
this->init("runTasks", 8);
//проверить отмененные задачи.
for (long i = 0; i < this->length; ++i) {
for (long i = 0; i < getLength(); ++i) {
RunTask* task = this->get(i);
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
task->setState((parent->getState() == Done) ? Waiting : Canceled);

View File

@@ -11,7 +11,7 @@ class RunTask : public Task {
String args;
CompilationTask* parent;
public:
virtual void print() {
virtual void print() const {
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
id,
maxtime,

View File

@@ -38,18 +38,19 @@ public:
}
//-
void print() {
for (long i = 0; i < this->length; ++i)
this->elements[i]->print();
for (auto& elem : this->getElements())
elem->print();
}
void init(const char* fileName, int recordSize) {
state = WorkspacesCreation;
File* packedTasks = new File(fileName);
Text* lines = packedTasks->readLines();
this->length = lines->getLength() / recordSize;
this->elements = new T * [this->length];
const long length = lines->getLength() / recordSize;
int offset = 0;
for (int i = 0; i < this->length; ++i) {
this->elements[i] = new T(lines, offset);
for (int i = 0; i < length; ++i) {
this->add(new T(lines, offset));
offset += recordSize;
}
delete packedTasks;
@@ -59,13 +60,13 @@ public:
saveState();
long activeCount = 0;
//todo обязательно убрать отладочную печать.
printf("tasks count = %ld\n", this->length);
printf("tasks count = %ld\n", this->getLength());
while (this->state != End) {
// printf("state=%d\n", this->state);
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
activeCount = 0;
for (long i = 0; i < this->length; ++i) {
T* task = this->elements[i];
for (long i = 0; i < this->getLength(); ++i) {
T* task = this->get(i);
switch (this->state) {
case WorkspacesCreation:
if (task->getState() == Waiting) {

View File

@@ -104,7 +104,7 @@ public:
setMaxtime(lines->get(offset + 1));
workspace = packageWorkspace + "/" + String(id);
}
virtual void print() = 0;
virtual void print() const = 0;
//-
virtual void prepareWorkspace() {}
virtual String getLaunchScriptText() = 0;

View File

@@ -5,18 +5,20 @@
class Text : public Array<String> {
public:
void Print() {
printf("text length=%ld\n", length);
void Print() const {
printf("text length=%ld\n", this->getLength());
for (long i = 0; i < length; ++i) {
printf("i=%ld; [%s]\n", i, elements[i]->getCharArray());
auto elems = this->getElements();
for (size_t i = 0; i < elems.size(); ++i) {
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
// elements[i]->println();
}
}
bool hasMatch(const String& s) {
for (long i = 0; i < length; ++i) {
if (s.contains(*elements[i])) {
bool hasMatch(const String& s) const {
for (auto& elem : this->getElements()) {
if (s.contains(*elem)) {
//printf("match: [%s]\n", elements[i]->getCharArray());
return true;
}