-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (81 loc) · 2.75 KB
/
main.cpp
File metadata and controls
100 lines (81 loc) · 2.75 KB
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
93
94
95
96
97
98
99
100
#ifdef USE_LIKWID
#include <likwid-marker.h>
#endif
#include "common.hpp"
#include "methods/bicgstab.hpp"
#include "methods/cg.hpp"
#include "methods/gauss_seidel.hpp"
#include "methods/gmres.hpp"
#include "methods/jacobi.hpp"
#include "postprocessing.hpp"
#include "preprocessing.hpp"
#include "solver_harness.hpp"
#include "utilities/utilities.hpp"
void run(Args *cli_args, Timers *timers) {
// Declare solver object
Solver *solver;
switch (cli_args->method) {
case SolverType::Jacobi:
solver = new JacobiSolver(cli_args);
break;
case SolverType::GaussSeidel:
solver = new GaussSeidelSolver(cli_args);
break;
case SolverType::SymmetricGaussSeidel:
solver = new SymmetricGaussSeidelSolver(cli_args);
break;
case SolverType::ConjugateGradient:
solver = new ConjugateGradientSolver(cli_args);
break;
case SolverType::GMRES:
solver = new GMRESSolver(cli_args);
break;
case SolverType::BiCGSTAB:
solver = new BiCGSTABSolver(cli_args);
break;
default:
std::cerr << "Error: Unknown or unsupported solver type.\n";
exit(EXIT_FAILURE);
}
// Read or generate matrix A to solve for x in: Ax = b
std::unique_ptr<MatrixCOO> mtx = std::make_unique<MatrixCOO>();
#ifdef USE_SCAMAC
IF_DEBUG_MODE(printf("Generating SCAMAC Matrix\n"))
mtx->scamac_make_mtx(cli_args->matrix_file_name);
#else
IF_DEBUG_MODE(printf("Reading .mtx Matrix\n"))
mtx->read_from_mtx(cli_args->matrix_file_name);
#endif
IF_DEBUG_MODE(printf("Converting COO matrix to CRS\n"))
std::unique_ptr<MatrixCRS> A = std::make_unique<MatrixCRS>();
convert_coo_to_crs(mtx.get(), A.get());
// Allocate and init needed structs
TIME(timers->preprocessing, preprocessing(cli_args, solver, timers, A))
// Use the selected solver until convergence
TIME(timers->solve, solve(cli_args, solver, timers))
// Record solution and print summary
TIME(timers->postprocessing, postprocessing(cli_args, solver, timers))
delete solver;
}
int main(int argc, char *argv[]) {
#ifdef USE_LIKWID
LIKWID_MARKER_INIT;
register_likwid_markers();
#endif
// Declare and initialize timers
Timers *timers = new Timers;
init_timers(timers);
// Collect matrix file path and options from command line
Args *cli_args = new Args;
parse_cli(cli_args, argc, argv);
// Execute all phases of the solver
TIME(timers->total, run(cli_args, timers))
// Print timer information to stdout
print_timers(cli_args, timers);
#ifdef USE_LIKWID
LIKWID_MARKER_CLOSE;
#endif
delete timers;
delete cli_args;
return 0;
}