-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (45 loc) · 1.54 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
#include <iostream>
#include <vector>
#include "include/primegenerator.h"
#include "include/singlethreadedprimegenerator.h"
#include "include/multithreadedprimegenerator.h"
#include "include/timer.h"
#include "include/argumentparser.h"
PrimeGenerator *setupPrimeGenerator(Config &config)
{
if (config.getMode() == "parallel")
return new MultiThreadedPrimeGenerator();
return new SingleThreadedPrimeGenerator();
}
void output(Result &result, Config &config)
{
config.printConfig();
result.printResult();
}
void run(Config &config)
{
PrimeGenerator *primeGenerator = setupPrimeGenerator(config);
Timer timer = Timer();
Result result = Result();
std::string algorithm = config.getAlgorithm();
if (algorithm == "trialDivision")
result = timer.time(&PrimeGenerator::trialDivision, primeGenerator, config);
if (algorithm == "sieveOfEratosthenes")
result = timer.time(&PrimeGenerator::sieveOfEratosthenes, primeGenerator, config);
if (algorithm == "sieveOfSundaram")
result = timer.time(&PrimeGenerator::sieveOfSundaram, primeGenerator, config);
if (algorithm == "sieveOfAtkin")
result = timer.time(&PrimeGenerator::sieveOfAtkin, primeGenerator, config);
delete primeGenerator;
result.adjust();
result.writeToFile(config.getOutputFile());
output(result, config);
}
int main(int argc, char *argv[])
{
Config config = Config();
ArgumentParser argumentParser = ArgumentParser();
if (!argumentParser.parse(argc, argv, config))
return 0;
run(config);
}