-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcg_solver.hpp
70 lines (56 loc) · 1.31 KB
/
pcg_solver.hpp
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
#ifndef __PCG_SOLVER_HPP__
#define __PCG_SOLVER_HPP__
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cusparse.h>
class PCGsolver
{
private:
cublasHandle_t cubHandle;
cusparseHandle_t cusHandle;
cusparseMatDescr_t descr_A;
cusparseMatDescr_t descr_L;
// device data
int N;
int nonzero;
double *d_ic=0; // nz
double *d_x=0; // N
double *d_y=0; // N
double *d_z=0; // N
double *d_r=0; // N
double *d_rt=0; // N
double *d_xt=0; // N
double *d_q=0; // N
double *d_p=0; // N
double alpha;
double beta;
double alpha1 = 1.0;
double beta0 = 0.0;
double rTr;
double pTq;
double rho;
double rhot;
// device data size
int d_N = 0;
int d_nz = 0;
// constant
int max_iter;
double tolerance;
public:
PCGsolver(int max_iter=1000, double tol=1e-12);
~PCGsolver();
void solve_gpumem(int N, int nz,
double *d_A, int *d_rowIdx, int *d_colIdx,
double *d_b, double *d_guess);
void convert_coo2csr(const int N, const int nonzero, const int *cooRowIdx, int *csrRowIdx);
double *get_device_x();
private:
void check_and_resize();
void free_memory();
};
#endif