-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (92 loc) · 2.88 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
93
94
95
96
97
98
99
100
101
102
/**
* Kei Imada
* 20210120
* Sparse Lower Triangular Solve
*/
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
#include "ccs_matrix.h"
#include "dense_vector.h"
#include "matrix_operations.h"
#include "partition.h"
using namespace std;
float THRESHOLD = 1e-5;
int main(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr,
"Usage: %s [martix-market-L-filename] [martix-market-b-filename]\n",
argv[0]);
exit(1);
}
string L_filename(argv[1]);
string b_filename(argv[2]);
CCSMatrix<long double> L;
L.from_matrix_market_filepath(L_filename);
L.to_lower_triangular();
// L.fill_diag(1, true); // was initially not sure if the diagonals should be
// filled in
DenseVector<long double> b, target_x;
b.from_matrix_market_filepath(b_filename);
target_x.from_dense_vector(&b);
// original
chrono::time_point<chrono::system_clock> start, end;
start = chrono::system_clock::now();
lsolve<long double>(&L, &target_x);
end = chrono::system_clock::now();
chrono::duration<long double> elapsed_seconds = end - start;
cout << elapsed_seconds.count();
// matrix multiplication to verify the original algorithm
DenseVector<long double> y;
y.from_num_zeros(b.dimension_get());
spmv_ccs(&L, &target_x, &y);
if (!y.approx_equals(&b, THRESHOLD)) {
/**
* even if the matrix multiplication verification fails, we are measuring
* the optimizations made to the original algorithm, hence we only check if
* the output of the optimizations match the output of the original
* algorithm
*/
cerr << "matrix multiplication verification failed\n"
" the original lower triangular solve algorithm failed to solve "
"this matrix"
<< endl;
}
// naive parallelization
DenseVector<long double> x;
x.from_dense_vector(&b);
start = chrono::system_clock::now();
parallel_lsolve<long double>(&L, &x);
end = chrono::system_clock::now();
cout << ",";
// verify
if (x.approx_equals(&target_x, THRESHOLD)) {
elapsed_seconds = end - start;
cout << elapsed_seconds.count();
} else {
cerr << "parallel lower triangular solve verification failed, output does "
"not match original algorithm"
<< endl;
}
// level set partitioning parallelization
x.clear();
x.from_dense_vector(&b);
Partition partition;
partition.from_lower_triangular_matrix<long double>(&L);
start = chrono::system_clock::now();
partitioned_parallel_lsolve<long double>(&L, &x, &partition);
end = chrono::system_clock::now();
cout << ",";
// verify
if (x.approx_equals(&target_x, THRESHOLD)) {
elapsed_seconds = end - start;
cout << elapsed_seconds.count();
} else {
cerr << "level partitioned parallel lower triangular solve verification "
"failed, output does not match original algorithm"
<< endl;
}
cout << endl;
return 0;
}