forked from preda/gpuowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
92 lines (78 loc) · 2.45 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// GpuOwl Mersenne primality tester; Copyright Mihai Preda.
#include "Args.h"
#include "Task.h"
#include "Worktodo.h"
#include "common.h"
#include "File.h"
#include "version.h"
#include "AllocTrac.h"
#include "typeName.h"
#include "log.h"
#include <cstdio>
#include <filesystem>
extern string globalCpuName;
namespace fs = std::filesystem;
static void readConfig(Args& args, const fs::path& path, bool doLog) {
if (auto file = File::openRead(path)) {
// log("reading %s\n", path.c_str());
while (true) {
if (string line = file.readLine(); !line.empty()) {
line = rstripNewline(line);
if (doLog) { log("config: %s\n", line.c_str()); }
args.parse(line);
} else {
break;
}
}
} else {
if (doLog) { log("Note: not found '%s'\n", path.string().c_str()); }
}
}
int main(int argc, char **argv) {
initLog();
log("GpuOwl VERSION %s\n", VERSION);
int exitCode = 0;
try {
string mainLine = Args::mergeArgs(argc, argv);
{
Args args;
args.parse(mainLine);
if (!args.dir.empty()) { fs::current_path(args.dir); }
initLog("gpuowl.log");
}
log("GpuOwl VERSION %s\n", VERSION);
fs::path poolDir = [&mainLine](){
Args args;
readConfig(args, "config.txt", false);
args.parse(mainLine);
return args.masterDir;
}();
Args args;
if (!poolDir.empty()) { readConfig(args, poolDir / "config.txt", true); }
readConfig(args, "config.txt", true);
if (!mainLine.empty()) {
log("config: %s\n", mainLine.c_str());
args.parse(mainLine);
}
args.setDefaults();
if (!args.cpu.empty()) { globalCpuName = args.cpu; }
if (args.maxAlloc) { AllocTrac::setMaxAlloc(args.maxAlloc); }
if (args.prpExp) {
Worktodo::makePRP(args, args.prpExp).execute(args);
} else if (!args.verifyPath.empty()) {
Worktodo::makeVerify(args, args.verifyPath).execute(args);
} else {
while (auto task = Worktodo::getTask(args)) { task->execute(args); }
}
} catch (const char *mes) {
log("Exiting because \"%s\"\n", mes);
} catch (const std::exception& e) {
log("Exception %s: %s\n", typeName(e), e.what());
} catch (...) {
log("Unexpected exception\n");
}
// background.wait();
// if (factorFoundForExp) { Worktodo::deletePRP(factorFoundForExp); }
log("Bye\n");
return exitCode; // not used yet.
}