-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpcg_runner.c
87 lines (63 loc) · 3 KB
/
hpcg_runner.c
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
#include "hpcg_runner.h"
void setupProblem(double a, SparseMatrix & A, Vector & b, Vector & x, Vector & xexact, bool distributed) {
int size, rank;
int numThreads = 1, pz = 0, zl = 0, zu = 0, npx = 0, npy = 0, npz = 0;
if (distributed) {
MPI_Comm_size(MPI_COMM_WORLD, & size);
MPI_Comm_rank(MPI_COMM_WORLD, & rank);
}
else {
size = 1;
rank = 0;
}
local_int_t nx,ny,nz;
nx = (local_int_t) a;
ny = (local_int_t) a;
nz = (local_int_t) a;
// Construct the geometry and linear system
Geometry * geom = new Geometry;
GenerateGeometry(size, rank, numThreads, pz, zl, zu, nx, ny, nz, npx, npy, npz, geom);
printf("Size: %d\tRank: %d\tNum Threads: %d\tpz: %d\tzl: %d\tzu: %d\tnx: %d\tny: %d\tnz: %d\tnpx: %d\tnpy: %d\tnpz: %d\n", size, rank, numThreads, pz, zl, zu, geom->nx, geom->ny, geom->nz, geom->npx, geom->npy, geom->npz);
InitializeSparseMatrix(A, geom);
// printf("Number of Rows: %d\tNumber of Columns: %d\tTotal Number of Non-Zeros: %lld\n", A.localNumberOfRows, A.localNumberOfColumns, A.totalNumberOfNonzeros);
GenerateProblem(A, &b, &x, &xexact);
SetupHalo(A);
// printf("Number of Rows: %d\tNumber of Columns: %d\tTotal Number of Non-Zeros: %lld\n", A.localNumberOfRows, A.localNumberOfColumns, A.totalNumberOfNonzeros);
FillRandomVector(x);
}
void setupSPMV(double a, SparseMatrix & A, Vector & b, Vector & x, Vector & xexact) {
// printf("Setting up SPMV\n");
// printf("The value of a is: %.4f\n", a);
bool distributed = false;
setupProblem(a, A, b, x, xexact, distributed);
}
void runSPMV(SparseMatrix & A, Vector & x, Vector & b) {
// printf("Running SPMV\n");
// printf("Number of Rows: %d\tNumber of Columns: %d\tTotal Number of Non-Zeros: %lld\n", A.localNumberOfRows, A.localNumberOfColumns, A.totalNumberOfNonzeros);
int ierr = ComputeSPMV_ref(A, x, b); // b = A*x
if (ierr) printf("Error in call to SpMV: %d\n", ierr);
}
void resetSPMV(Vector & x, Vector & b) {
FillRandomVector(x);
FillRandomVector(b);
}
void setupHPCG(double a, SparseMatrix & A, Vector & b, Vector & x, Vector & xexact, CGData & data){
// printf("Setting up HPCG\n");
// printf("The value of a is: %.4f\n", a);
bool distributed = true;
setupProblem(a, A, b, x, xexact, distributed);
InitializeSparseCGData(A, data);
}
void runHPCG(SparseMatrix & A, Vector & x, Vector & b, CGData & data, int max_iter){
// printf("Running HPCG\n");
// printf("Number of Rows: %d\tNumber of Columns: %d\tTotal Number of Non-Zeros: %lld\n", A.localNumberOfRows, A.localNumberOfColumns, A.totalNumberOfNonzeros);
std::vector<double> opt_times(9,0.0);
int niter = 0;
double tolerance = 0.0, normr = 0.0, normr0 = 0.0;
bool doPreconditioning = true;
CG_ref(A, data, b, x, max_iter, tolerance, niter, normr, normr0, & opt_times[0], doPreconditioning);
}
void resetHPCG(Vector & x, Vector & xorig, CGData & data, CGData & data_orig) {
x = xorig;
data = data_orig;
}