Skip to content

Commit 96c859b

Browse files
authored
boinc command (#137)
1 parent b7c33b9 commit 96c859b

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ To install or update LODA, please follow the [installation instructions](https:/
22

33
## [Unreleased]
44

5+
# v22.5.1
6+
57
### Features
68

7-
* Added option `-H` for settings the number of mining hours (useful for BOINC)
9+
* Added option `-H` for settings the number of mining hours (needed for BOINC)
10+
* Internal `boinc` command
811

912
# v22.4.17
1013

src/include/setup.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,23 @@ class Setup {
2424

2525
static MiningMode getMiningMode();
2626

27+
static void setMiningMode(MiningMode mode);
28+
2729
static std::string getMinersConfig();
2830

2931
static const std::string getSubmittedBy();
3032

33+
static void setSubmittedBy(const std::string& submited_by);
34+
3135
static void setMinersConfig(const std::string& loda_config);
3236

3337
static const std::string& getOeisHome();
3438

39+
static bool existsProgramsHome();
40+
41+
static bool cloneProgramsHome(
42+
std::string git_url = "https://github.com/loda-lang/loda-programs.git");
43+
3544
static const std::string& getProgramsHome();
3645

3746
static void setProgramsHome(const std::string& home);
@@ -58,6 +67,8 @@ class Setup {
5867

5968
static bool shouldReportCPUHours();
6069

70+
static void forceCPUHours();
71+
6172
static void runWizard();
6273

6374
private:

src/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,30 @@ void mineParallel(const Settings& settings,
129129
" minutes");
130130
}
131131

132+
void boinc(Settings settings, const std::vector<std::string>& args) {
133+
// check setup
134+
if (!hasGit()) {
135+
Log::get().error("Git not found. Please install it and try again", true);
136+
}
137+
Setup::getLodaHome();
138+
if (!Setup::existsProgramsHome()) {
139+
if (!Setup::cloneProgramsHome()) {
140+
Log::get().error("Cannot clone programs repository", true);
141+
}
142+
}
143+
// configure setup
144+
Setup::setMiningMode(MINING_MODE_CLIENT);
145+
Setup::forceCPUHours();
146+
Setup::setSubmittedBy("BOINC");
147+
// pick a random miner profile if not mining in parallel
148+
if (!settings.parallel_mining || settings.num_miner_instances == 1) {
149+
settings.miner_profile = std::to_string(Random::get().gen() % 100);
150+
}
151+
// start mining
152+
Commands commands(settings);
153+
commands.mine();
154+
}
155+
132156
int dispatch(Settings settings, const std::vector<std::string>& args) {
133157
// pre-flight checks
134158
if (args.empty()) {
@@ -182,6 +206,10 @@ int dispatch(Settings settings, const std::vector<std::string>& args) {
182206
return 1;
183207
}
184208
}
209+
// hidden boinc command
210+
else if (cmd == "boinc") {
211+
boinc(settings, args);
212+
}
185213
#ifdef _WIN64
186214
// hidden helper command for updates on windows
187215
else if (cmd == "update-windows-executable") {

src/setup.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ const std::string Setup::getSubmittedBy() {
111111
return getSetupValue("LODA_SUBMITTED_BY");
112112
}
113113

114+
void Setup::setSubmittedBy(const std::string& submited_by) {
115+
getSubmittedBy();
116+
SETUP["LODA_SUBMITTED_BY"] = submited_by;
117+
}
118+
114119
void Setup::setMinersConfig(const std::string& loda_config) {
115120
MINERS_CONFIG = loda_config;
116121
}
@@ -185,6 +190,8 @@ MiningMode Setup::getMiningMode() {
185190
return static_cast<MiningMode>(MINING_MODE);
186191
}
187192

193+
void Setup::setMiningMode(MiningMode mode) { MINING_MODE = mode; }
194+
188195
int64_t Setup::getMaxMemory() {
189196
if (MAX_MEMORY == UNDEFINED_INT) {
190197
// 1 GB default
@@ -244,6 +251,11 @@ bool Setup::shouldReportCPUHours() {
244251
getSetupFlag(LODA_SUBMIT_CPU_HOURS, false));
245252
}
246253

254+
void Setup::forceCPUHours() {
255+
getSetupFlag(LODA_SUBMIT_CPU_HOURS, false);
256+
SETUP[LODA_SUBMIT_CPU_HOURS] = "yes";
257+
}
258+
247259
void trimString(std::string& str) {
248260
while (!str.empty()) {
249261
if (str.front() == ' ') {
@@ -414,9 +426,19 @@ bool Setup::checkEnvVars() {
414426
return true;
415427
}
416428

429+
bool Setup::existsProgramsHome() {
430+
return isDir(LODA_HOME + "programs" + FILE_SEP + "oeis");
431+
}
432+
433+
bool Setup::cloneProgramsHome(std::string git_url) {
434+
const std::string git_clone =
435+
"git clone " + git_url + " \"" + getLodaHome() + "programs\"";
436+
return system(git_clone.c_str()) == 0;
437+
}
438+
417439
bool Setup::checkProgramsHome() {
418440
std::string line;
419-
if (!isDir(LODA_HOME + "programs" + FILE_SEP + "oeis")) {
441+
if (!existsProgramsHome()) {
420442
std::cout << "LODA needs to download its programs repository from GitHub."
421443
<< std::endl;
422444
std::cout << "It contains programs for more than 50,000 integer sequences."
@@ -446,9 +468,7 @@ bool Setup::checkProgramsHome() {
446468
if (!line.empty()) {
447469
git_url = line;
448470
}
449-
std::string git_clone =
450-
"git clone " + git_url + " \"" + LODA_HOME + "programs\"";
451-
if (system(git_clone.c_str()) != 0) {
471+
if (cloneProgramsHome(git_url)) {
452472
std::cout << std::endl
453473
<< "Error cloning repository. Aborting setup." << std::endl;
454474
return false;

0 commit comments

Comments
 (0)