From ee42b7e9ffe15deb27489a1c620e332d30cb59e6 Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Mon, 2 May 2022 20:12:02 +0200 Subject: [PATCH 1/2] report progress to BOINC wrapper --- CHANGELOG.md | 1 + src/boinc.cpp | 16 +++++++----- src/include/miner.hpp | 11 +++++++- src/miner.cpp | 59 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd972cc..5e804892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ To install or update LODA, please follow the [installation instructions](https:/ * Use shared project directory when running in BOINC * Extract user name from BOINC metadata +* Report progress to BOINC wrapper app # v22.5.1 diff --git a/src/boinc.cpp b/src/boinc.cpp index dbbbaf20..3393864b 100644 --- a/src/boinc.cpp +++ b/src/boinc.cpp @@ -38,6 +38,16 @@ void Boinc::run() { Log::get().error("Git not found. Please install it and try again", true); } + // pick a random miner profile if not mining in parallel + if (!settings.parallel_mining || settings.num_miner_instances == 1) { + settings.miner_profile = std::to_string(Random::get().gen() % 100); + } + + // create initial progress file + Miner miner(settings); + miner.progress_file = slot_dir + "fraction_done"; + miner.reportProgress(); + // clone programs repository if necessary if (!Setup::existsProgramsHome()) { FolderLock lock(project_dir); @@ -46,13 +56,7 @@ void Boinc::run() { } } - // pick a random miner profile if not mining in parallel - if (!settings.parallel_mining || settings.num_miner_instances == 1) { - settings.miner_profile = std::to_string(Random::get().gen() % 100); - } - // start mining! - Miner miner(settings); miner.mine(); } diff --git a/src/include/miner.hpp b/src/include/miner.hpp index 251105b6..398dca1c 100644 --- a/src/include/miner.hpp +++ b/src/include/miner.hpp @@ -30,6 +30,10 @@ class Miner { void submit(const std::string &path, std::string id); + void reportProgress(); + + std::string progress_file; + private: bool checkRegularTasks(); @@ -39,6 +43,10 @@ class Miner { void updateSubmittedBy(Program &program); + void reportCPUHour(); + + int64_t getElapsedMinutes() const; + static const std::string ANONYMOUS; static const int64_t PROGRAMS_TO_FETCH; static const int64_t NUM_MUTATIONS; @@ -58,7 +66,8 @@ class Miner { int64_t num_new; int64_t num_updated; int64_t num_removed; - int64_t num_hours; + int64_t num_reported_hours; int64_t current_fetch; std::map num_received_per_profile; + std::chrono::steady_clock::time_point start_time; }; diff --git a/src/miner.cpp b/src/miner.cpp index 313ee1c4..7a008026 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -30,8 +30,9 @@ Miner::Miner(const Settings &settings) num_new(0), num_updated(0), num_removed(0), - num_hours(0), - current_fetch(0) {} + num_reported_hours(0), + current_fetch(0), + start_time(std::chrono::steady_clock::now()) {} void Miner::reload() { api_client.reset(new ApiClient()); @@ -54,11 +55,12 @@ void Miner::mine() { std::stack progs; Sequence norm_seq; Program program; - const auto start_time = std::chrono::steady_clock::now(); // load manager + reportProgress(); if (!manager) { reload(); + reportProgress(); } // print info @@ -152,6 +154,11 @@ void Miner::mine() { } } + // report remaining cpu hours + while (num_reported_hours < settings.num_mine_hours) { + reportCPUHour(); + } + // finish with log message auto cur_time = std::chrono::steady_clock::now(); int64_t mins = @@ -163,7 +170,7 @@ void Miner::mine() { bool Miner::checkRegularTasks() { bool result = true; - // regular task: log info about generated programs + // regular task: log info if (log_scheduler.isTargetReached()) { log_scheduler.reset(); if (num_processed) { @@ -173,6 +180,14 @@ bool Miner::checkRegularTasks() { } else { Log::get().warn("Slow processing of programs"); } + + // regular task: report progress and check termination + if (settings.num_mine_hours > 0) { + if (getElapsedMinutes() >= settings.num_mine_hours * 60) { + result = false; + } + reportProgress(); + } } // regular task: fetch programs from API server @@ -181,7 +196,7 @@ bool Miner::checkRegularTasks() { current_fetch += PROGRAMS_TO_FETCH; } - // regular task: log info and publish metrics + // regular task: publish metrics if (metrics_scheduler.isTargetReached()) { metrics_scheduler.reset(); std::vector entries; @@ -207,13 +222,7 @@ bool Miner::checkRegularTasks() { // regular task: report CPU hours if (cpuhours_scheduler.isTargetReached()) { cpuhours_scheduler.reset(); - if (Setup::shouldReportCPUHours() && settings.report_cpu_hours) { - api_client->postCPUHour(); - } - num_hours++; - if (settings.num_mine_hours > 0 && num_hours >= settings.num_mine_hours) { - result = false; - } + reportCPUHour(); } // regular task: reload oeis manager and generators @@ -225,6 +234,32 @@ bool Miner::checkRegularTasks() { return result; } +void Miner::reportCPUHour() { + if (Setup::shouldReportCPUHours() && settings.report_cpu_hours) { + api_client->postCPUHour(); + } + num_reported_hours++; +} + +void Miner::reportProgress() { + if (settings.num_mine_hours > 0 && !progress_file.empty()) { + double progress = static_cast(getElapsedMinutes()) / + static_cast(settings.num_mine_hours * 60); + if (progress > 1.0) { + progress = 1.0; + } + std::ofstream out(progress_file); + out.precision(6); + out << std::fixed << progress << std::endl; + } +} + +int64_t Miner::getElapsedMinutes() const { + const auto cur_time = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(cur_time - start_time) + .count(); +} + void Miner::submit(const std::string &path, std::string id) { Parser parser; auto program = parser.parse(path); From 14ae94b7eb38a81a468029b835f564cafef2639e Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Tue, 3 May 2022 18:00:44 +0200 Subject: [PATCH 2/2] boinc fixes --- CHANGELOG.md | 8 ++++++++ src/boinc.cpp | 6 ++++-- src/setup.cpp | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e804892..ca1872c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ To install or update LODA, please follow the [installation instructions](https:/ ## [Unreleased] +# v22.5.3 + +### Bugfixes + +* Fixes setup issues when runing in BOINC + +# v22.5.2 + ### Enhancements * Use shared project directory when running in BOINC diff --git a/src/boinc.cpp b/src/boinc.cpp index 3393864b..9d282a2f 100644 --- a/src/boinc.cpp +++ b/src/boinc.cpp @@ -51,8 +51,10 @@ void Boinc::run() { // clone programs repository if necessary if (!Setup::existsProgramsHome()) { FolderLock lock(project_dir); - if (!Setup::cloneProgramsHome()) { - Log::get().error("Cannot clone programs repository", true); + if (!Setup::existsProgramsHome()) { // need to check again here + if (!Setup::cloneProgramsHome()) { + Log::get().error("Cannot clone programs repository", true); + } } } diff --git a/src/setup.cpp b/src/setup.cpp index 399399e3..c907156a 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -59,6 +59,9 @@ MiningMode convertStrToMiningMode(const std::string& str) { } std::string Setup::getLodaHomeNoCheck() { + if (!LODA_HOME.empty()) { + return LODA_HOME; + } auto loda_home = std::getenv("LODA_HOME"); std::string result; if (loda_home) {