planner_improve #1
@@ -3,42 +3,35 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Array {
|
class Array {
|
||||||
protected:
|
private:
|
||||||
long length;
|
std::vector<T*> elements;
|
||||||
T** elements;
|
|
||||||
public:
|
public:
|
||||||
Array() {
|
Array() { }
|
||||||
length = 0;
|
|
||||||
elements = NULL;
|
|
||||||
}
|
|
||||||
virtual ~Array() {
|
virtual ~Array() {
|
||||||
if (elements != NULL) {
|
for (auto& elem : elements)
|
||||||
for (long i = 0; i < length; ++i)
|
delete elem;
|
||||||
delete elements[i];
|
elements.clear();
|
||||||
delete[] elements;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(T* new_line) {
|
void add(T* new_line) {
|
||||||
T** buf = new T * [length + 1];
|
elements.push_back(new_line);
|
||||||
for (long i = 0; i < length; ++i) {
|
|
||||||
buf[i] = elements[i];
|
|
||||||
}
|
}
|
||||||
buf[length] = new_line;
|
|
||||||
length++;
|
long getLength() const {
|
||||||
delete[] elements;
|
return elements.size();
|
||||||
elements = buf;
|
|
||||||
buf = NULL;
|
|
||||||
}
|
|
||||||
long getLength() {
|
|
||||||
return length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get(long i) {
|
T* get(long i) {
|
||||||
return elements[i];
|
return elements[i];
|
||||||
}
|
}
|
||||||
T** getElements() {
|
|
||||||
|
const std::vector<T*>& getElements() const {
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,7 @@ public:
|
|||||||
this->init("compilationTasks", 4);
|
this->init("compilationTasks", 4);
|
||||||
}
|
}
|
||||||
CompilationTask* getTaskById(long task_id) {
|
CompilationTask* getTaskById(long task_id) {
|
||||||
for (long i = 0; i < length; ++i) {
|
for (long i = 0; i < getLength(); ++i) {
|
||||||
CompilationTask* task = get(i);
|
CompilationTask* task = get(i);
|
||||||
if (task->getId() == task_id)
|
if (task->getId() == task_id)
|
||||||
return task;
|
return task;
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ public:
|
|||||||
void setMakefileText(String* makefile_text_in) {
|
void setMakefileText(String* makefile_text_in) {
|
||||||
makefile_text = String(makefile_text_in->getCharArray(), '|');
|
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,
|
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
|
||||||
test_id.getCharArray());
|
test_id.getCharArray());
|
||||||
printf("makefile_text=%s\n", makefile_text.getCharArray());
|
printf("makefile_text=%s\n", makefile_text.getCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
|
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
|
||||||
setTestId(lines->get(offset + 2));
|
setTestId(lines->get(offset + 2));
|
||||||
setMakefileText(lines->get(offset + 3));
|
setMakefileText(lines->get(offset + 3));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public:
|
|||||||
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
|
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
|
||||||
this->init("runTasks", 8);
|
this->init("runTasks", 8);
|
||||||
//проверить отмененные задачи.
|
//проверить отмененные задачи.
|
||||||
for (long i = 0; i < this->length; ++i) {
|
for (long i = 0; i < getLength(); ++i) {
|
||||||
RunTask* task = this->get(i);
|
RunTask* task = this->get(i);
|
||||||
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
|
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
|
||||||
task->setState((parent->getState() == Done) ? Waiting : Canceled);
|
task->setState((parent->getState() == Done) ? Waiting : Canceled);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class RunTask : public Task {
|
|||||||
String args;
|
String args;
|
||||||
CompilationTask* parent;
|
CompilationTask* parent;
|
||||||
public:
|
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",
|
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
|
||||||
id,
|
id,
|
||||||
maxtime,
|
maxtime,
|
||||||
|
|||||||
@@ -38,18 +38,19 @@ public:
|
|||||||
}
|
}
|
||||||
//-
|
//-
|
||||||
void print() {
|
void print() {
|
||||||
for (long i = 0; i < this->length; ++i)
|
for (auto& elem : this->getElements())
|
||||||
this->elements[i]->print();
|
elem->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(const char* fileName, int recordSize) {
|
void init(const char* fileName, int recordSize) {
|
||||||
state = WorkspacesCreation;
|
state = WorkspacesCreation;
|
||||||
File* packedTasks = new File(fileName);
|
File* packedTasks = new File(fileName);
|
||||||
Text* lines = packedTasks->readLines();
|
Text* lines = packedTasks->readLines();
|
||||||
this->length = lines->getLength() / recordSize;
|
|
||||||
this->elements = new T * [this->length];
|
const long length = lines->getLength() / recordSize;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (int i = 0; i < this->length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
this->elements[i] = new T(lines, offset);
|
this->add(new T(lines, offset));
|
||||||
offset += recordSize;
|
offset += recordSize;
|
||||||
}
|
}
|
||||||
delete packedTasks;
|
delete packedTasks;
|
||||||
@@ -59,13 +60,13 @@ public:
|
|||||||
saveState();
|
saveState();
|
||||||
long activeCount = 0;
|
long activeCount = 0;
|
||||||
//todo обязательно убрать отладочную печать.
|
//todo обязательно убрать отладочную печать.
|
||||||
printf("tasks count = %ld\n", this->length);
|
printf("tasks count = %ld\n", this->getLength());
|
||||||
while (this->state != End) {
|
while (this->state != End) {
|
||||||
// printf("state=%d\n", this->state);
|
// printf("state=%d\n", this->state);
|
||||||
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
||||||
activeCount = 0;
|
activeCount = 0;
|
||||||
for (long i = 0; i < this->length; ++i) {
|
for (long i = 0; i < this->getLength(); ++i) {
|
||||||
T* task = this->elements[i];
|
T* task = this->get(i);
|
||||||
switch (this->state) {
|
switch (this->state) {
|
||||||
case WorkspacesCreation:
|
case WorkspacesCreation:
|
||||||
if (task->getState() == Waiting) {
|
if (task->getState() == Waiting) {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public:
|
|||||||
setMaxtime(lines->get(offset + 1));
|
setMaxtime(lines->get(offset + 1));
|
||||||
workspace = packageWorkspace + "/" + String(id);
|
workspace = packageWorkspace + "/" + String(id);
|
||||||
}
|
}
|
||||||
virtual void print() = 0;
|
virtual void print() const = 0;
|
||||||
//-
|
//-
|
||||||
virtual void prepareWorkspace() {}
|
virtual void prepareWorkspace() {}
|
||||||
virtual String getLaunchScriptText() = 0;
|
virtual String getLaunchScriptText() = 0;
|
||||||
|
|||||||
@@ -5,18 +5,20 @@
|
|||||||
|
|
||||||
class Text : public Array<String> {
|
class Text : public Array<String> {
|
||||||
public:
|
public:
|
||||||
void Print() {
|
void Print() const {
|
||||||
printf("text length=%ld\n", length);
|
printf("text length=%ld\n", this->getLength());
|
||||||
|
|
||||||
for (long i = 0; i < length; ++i) {
|
auto elems = this->getElements();
|
||||||
printf("i=%ld; [%s]\n", i, elements[i]->getCharArray());
|
for (size_t i = 0; i < elems.size(); ++i) {
|
||||||
|
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
||||||
// elements[i]->println();
|
// elements[i]->println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool hasMatch(const String& s) {
|
|
||||||
|
|
||||||
for (long i = 0; i < length; ++i) {
|
bool hasMatch(const String& s) const {
|
||||||
if (s.contains(*elements[i])) {
|
|
||||||
|
for (auto& elem : this->getElements()) {
|
||||||
|
if (s.contains(*elem)) {
|
||||||
//printf("match: [%s]\n", elements[i]->getCharArray());
|
//printf("match: [%s]\n", elements[i]->getCharArray());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user