improved planner
This commit is contained in:
@@ -132,7 +132,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int maxThreads = std::thread::hardware_concurrency();
|
const int maxThreads = std::thread::hardware_concurrency();
|
||||||
printf("total tasks count = %ld, active task count %ld, maxKernels %d, maxNeededKernels %d, maxThreads %d\n",
|
printf("total tasks count = %lu, active task count %lu, maxKernels %lu, maxNeededKernels %d, maxThreads %d\n",
|
||||||
this->getLength(), activeTasks, maxKernels, maxNeededKernels, maxThreads);
|
this->getLength(), activeTasks, maxKernels, maxNeededKernels, maxThreads);
|
||||||
|
|
||||||
if (maxKernels > maxThreads) {
|
if (maxKernels > maxThreads) {
|
||||||
@@ -161,7 +161,9 @@ public:
|
|||||||
const double total = totalProcessTasks;
|
const double total = totalProcessTasks;
|
||||||
|
|
||||||
auto timer_pause = Utils::getAbsoluteTime();
|
auto timer_pause = Utils::getAbsoluteTime();
|
||||||
|
auto timer_killed = Utils::getAbsoluteTime();
|
||||||
|
bool killed = false;
|
||||||
|
|
||||||
while (activeTasks) {
|
while (activeTasks) {
|
||||||
long oldActiveTasks = activeTasks;
|
long oldActiveTasks = activeTasks;
|
||||||
emptyKeys.clear();
|
emptyKeys.clear();
|
||||||
@@ -196,23 +198,8 @@ public:
|
|||||||
// очищаем от пустых ключей
|
// очищаем от пустых ключей
|
||||||
for (auto& empty : emptyKeys)
|
for (auto& empty : emptyKeys)
|
||||||
sortedByKernelNeeds.erase(empty);
|
sortedByKernelNeeds.erase(empty);
|
||||||
|
|
||||||
// проверяем нет ли завершившихся задач
|
checkTasksFinish(activeTaskSet, toDel, activeTasks, done, busyKernels, buf);
|
||||||
for (auto& task : activeTaskSet)
|
|
||||||
{
|
|
||||||
if (task->Check()) {
|
|
||||||
toDel.push_back(task);
|
|
||||||
activeTasks--;
|
|
||||||
done += task->getKernels();
|
|
||||||
busyKernels -= task->getKernels();
|
|
||||||
#if DEB
|
|
||||||
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
|
||||||
#endif
|
|
||||||
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
|
||||||
//copy after end of while
|
|
||||||
//task->copyResults(pathRes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// очищаем завершенные задачи
|
// очищаем завершенные задачи
|
||||||
for (auto& del : toDel)
|
for (auto& del : toDel)
|
||||||
@@ -230,20 +217,42 @@ public:
|
|||||||
|
|
||||||
// прошло больше 30 секунд, проверяем паузу
|
// прошло больше 30 секунд, проверяем паузу
|
||||||
if (Utils::getAbsoluteTime() - timer_pause > 30) {
|
if (Utils::getAbsoluteTime() - timer_pause > 30) {
|
||||||
printf("stoped\n");
|
bool hasSleep = false;
|
||||||
while (checkPause()) {
|
while (checkPause()) {
|
||||||
|
hasSleep = true;
|
||||||
|
printf("stoped, sleep 10 seconds\n");
|
||||||
Utils::Sleep(10);
|
Utils::Sleep(10);
|
||||||
}
|
}
|
||||||
timer_pause = Utils::getAbsoluteTime();
|
timer_pause = Utils::getAbsoluteTime();
|
||||||
printf("resume\n");
|
if (hasSleep)
|
||||||
|
printf("resume\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// прошло больше 10 секунд, проверяем нужно ли завершиться
|
||||||
|
if (Utils::getAbsoluteTime() - timer_killed > 10) {
|
||||||
|
if (checkKilled()) {
|
||||||
|
printf("killed\n");
|
||||||
|
|
||||||
|
while (activeTasks) {
|
||||||
|
printf("waiting for activeTasks %lu\n", activeTasks);
|
||||||
|
checkTasksFinish(activeTaskSet, toDel, activeTasks, done, busyKernels, buf);
|
||||||
|
Utils::Sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("exit for main while\n");
|
||||||
|
killed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
timer_killed = Utils::getAbsoluteTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& task : taskList)
|
if (!killed) {
|
||||||
task->copyResults(pathRes);
|
for (auto& task : taskList)
|
||||||
|
task->copyResults(pathRes);
|
||||||
|
}
|
||||||
|
|
||||||
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()));
|
||||||
}
|
}
|
||||||
@@ -254,11 +263,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void saveProgress(long long persentDone) {
|
void saveProgress(long long persentDone) {
|
||||||
/*String dump_progress = "echo '";
|
|
||||||
dump_progress = dump_progress + to_string(persentDone).c_str() + "' > progress";
|
|
||||||
|
|
||||||
system(dump_progress.getCharArray());*/
|
|
||||||
|
|
||||||
FILE* f = fopen("progress", "w");
|
FILE* f = fopen("progress", "w");
|
||||||
if (f) {
|
if (f) {
|
||||||
fprintf(f, "%lld", persentDone);
|
fprintf(f, "%lld", persentDone);
|
||||||
@@ -267,7 +271,31 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkPause() {
|
bool checkPause() const {
|
||||||
return Utils::Exists("pause");
|
return Utils::Exists("pause");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool checkKilled() const {
|
||||||
|
return Utils::Exists("kill");
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkTasksFinish(const set<T*>& activeTaskSet, vector<T*>& toDel, size_t& activeTasks,
|
||||||
|
size_t& done, int& busyKernels, string& buf) {
|
||||||
|
// проверяем нет ли завершившихся задач
|
||||||
|
for (auto& task : activeTaskSet)
|
||||||
|
{
|
||||||
|
if (task->Check()) {
|
||||||
|
toDel.push_back(task);
|
||||||
|
activeTasks--;
|
||||||
|
done += task->getKernels();
|
||||||
|
busyKernels -= task->getKernels();
|
||||||
|
#if DEB
|
||||||
|
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||||
|
#endif
|
||||||
|
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
||||||
|
//copy after end of while
|
||||||
|
//task->copyResults(pathRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -1 +1 @@
|
|||||||
16
|
17
|
||||||
Reference in New Issue
Block a user