-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
228 lines (184 loc) · 5.64 KB
/
main.cpp
File metadata and controls
228 lines (184 loc) · 5.64 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <iostream>
#ifndef TIME_LOG
#define TIME_LOG
#ifndef CSV_LOG
#define CSV_LOG
#endif
#endif
#include "sparsematrix.h"
#include "matrixoperations.h"
#include "decompositor.h"
#include <cstdlib>
#include <time.h>
using namespace std;
int main(int argc, char *argv[3])
{
if (argc < 3)
{
cout << "Need type and threads number" << endl;
return 0;
}
int type = atoi(argv[1]);
int threads = atoi(argv[2]);
#ifdef CSV_LOG
ofstream out("res.csv",ios_base::app);
#endif
if (type == 1) //Решение с разреженной матрицей
{
SparseMatrix M("matrix.txt");
#ifdef TIME_LOG
#ifdef _OPENMP
omp_set_num_threads(threads);
double t = omp_get_wtime();
double t1 = t;
double tdec, tsol, tres;
#else
time_t t = clock();
time_t t1 = t;
time_t tdec, tsol, tres;
#endif
#endif
cout << "Было ненулевых " << M.C.size()-1 << endl;
LUPS T;
MatrixOperations::LUTriang(M, T);
T.save2fileL("spL.txt");
T.save2fileU("spU.txt");
cout << "Стало ненулевых " << T.U.C.size()-1 << endl;
#ifdef TIME_LOG
#ifdef _OPENMP
tdec = omp_get_wtime() - t;
cout << "Время на разложение " << tdec << endl;
t = omp_get_wtime();
#else
tdec = double((clock()-t))/CLOCKS_PER_SEC;
cout << "Время на разложение " << tdec << endl;
t = clock();
#endif
#endif
Vector B("vector.txt"), X;
MatrixOperations::Solve(T, B, X);
#ifdef TIME_LOG
#ifdef _OPENMP
tsol = omp_get_wtime() - t;
tres = omp_get_wtime() - t1;
cout << "Время на решение " << tsol << endl;
cout << "Общее время " << tres << endl;
#else
tsol = double((clock()-t))/CLOCKS_PER_SEC;
tres = double((clock()-t1))/CLOCKS_PER_SEC;
cout << "Время на решение " << tsol << endl;
cout << "Общее время " << tres << endl;
#endif
#ifdef CSV_LOG
out << /*tdec << "; " << tsol << "; " <<*/ tres << "; " << endl;
#endif
#endif
//X.save2file("solution.txt");
cout << "Ошибка: " << MatrixOperations::MaxResidual(M, B, X) << endl << endl;
cout << X.V[1] << endl;
cout << X.V[2] << endl;
}
else if (type == 2) //Решение приведением к БДО форме
{
SparseMatrix M("matrix.txt");
Vector B("vector.txt"), X;
#ifdef TIME_LOG
#ifdef _OPENMP
omp_set_num_threads(threads);
double t = omp_get_wtime();
double t1 = t;
double tper, tdec, tsol, tres;
#else
time_t t = clock();
time_t t1 = t;
time_t tper, tdec, tsol, tres;
#endif
#endif
BBDSparseMatrix A(M);
#ifdef TIME_LOG
#ifdef _OPENMP
tper = omp_get_wtime() - t;
cout << "Время на декомпозицию " << tper << endl;
t = omp_get_wtime();
#else
tper = double((clock()-t))/CLOCKS_PER_SEC;
cout << "Время на декомпозицию " << tper << endl;
t = clock();
#endif
#endif
FactorizedBBDSparseMatrix FM;
MatrixOperations::BlockMatrixFactorization(A, FM);
#ifdef TIME_LOG
#ifdef _OPENMP
tdec = omp_get_wtime() - t;
cout << "Время на разложение " << tdec << endl;
t = omp_get_wtime();
#else
tdec = double((clock()-t))/CLOCKS_PER_SEC;
cout << "Время на разложение " << tdec << endl;
t = clock();
#endif
#endif
MatrixOperations::Solve(FM, B, X);
#ifdef TIME_LOG
#ifdef _OPENMP
tsol = omp_get_wtime() - t;
tres = omp_get_wtime() - t1;
cout << "Время на решение " << tsol << endl;
cout << "Общее время " << tres << endl;
#else
tsol = double((clock()-t))/CLOCKS_PER_SEC;
tres = double((clock()-t1))/CLOCKS_PER_SEC;
cout << "Время на решение " << tsol << endl;
cout << "Общее время " << tres << endl;
#endif
#ifdef CSV_LOG
out << /*tper << "; " << tdec << "; " << tsol << "; " <<*/ tres << "; ";
#endif
#endif
//X.save2file("solution.txt");
cout << "Ошибка: " << MatrixOperations::MaxResidual(M, B, X) << endl << endl;
//cout << X.V[1] << endl;
//cout << X.V[2] << endl;
}
else if (type == 3) //Решение с плотной матрицей
{
Matrix M("matrix.txt");
#ifdef TIME_LOG
#ifdef _OPENMP
omp_set_num_threads(threads);
double t = omp_get_wtime();
double t1 = t;
#else
time_t t = clock();
time_t t1 = t;
#endif
#endif
LUPM T;
MatrixOperations::LUTriang(M, T);
#ifdef TIME_LOG
#ifdef _OPENMP
cout << "Время на разложение " << omp_get_wtime() - t << endl;
t = omp_get_wtime();
#else
cout << "Время на разложение " << double((clock()-t))/CLOCKS_PER_SEC << endl;
t = clock();
#endif
#endif
Vector B("vector.txt"), X;
MatrixOperations::Solve(T, B, X);
#ifdef TIME_LOG
#ifdef _OPENMP
cout << "Время на решение " << omp_get_wtime() - t << endl;
cout << "Общее время " << omp_get_wtime() - t1 << endl;
#else
cout << "Время на решение " << double((clock()-t))/CLOCKS_PER_SEC << endl;
cout << "Общее время " << double((clock()-t1))/CLOCKS_PER_SEC << endl;
#endif
#endif
cout << "Ошибка: " << MatrixOperations::MaxResidual(M, B, X) << endl;
cout << X.V[1] << endl;
cout << X.V[2] << endl;
}
return 0;
}