ADPCG 1.0.0
adpcg.h
Go to the documentation of this file.
1
14#ifndef adpcg_h
15#define adpcg_h
16
17
18#include <stddef.h>
19
20#ifdef ADPCG_64
21typedef int64_t cgint;
22#define id "%lld"
23#else
24typedef int32_t cgint;
25#define id "%d"
26#endif
27
28#define cgerr(x) printf(x);
29
30/* Return code */
31#define CG_OK (0)
32#define CG_ERR (1)
33
34/* Boolean */
35#define CG_TRUE (1)
36#define CG_FALSE (0)
37
38/* Pre-conditioner */
39#define CG_PRECOND_DIAG (10)
40#define CG_PRECOND_CHOL (11)
41#define CG_NO_PRECOND (12)
42
43/* Solution status */
44#define CG_STATUS_SOLVED (100)
45#define CG_STATUS_MAXITER (101)
46#define CG_STATUS_FAILED (102)
47#define CG_STATUS_UNKNOWN (104)
48#define CG_STATUS_DIRECT (105)
49
50/* Auxiliary macros */
51#ifndef MIN
52#define MIN(a, b) (((a)<(b))?(a):(b))
53#endif /* MIN */
54#ifndef MAX
55#define MAX(a, b) (((a)>(b))?(a):(b))
56#endif /* MAX */
57
84typedef struct {
85
86 void *A;
87 void *r;
88 void *rnew;
89 void *d;
90 void *pinvr;
91 void *Ad;
92 void *x;
93 void *aux;
94 void *btmp;
95
96 cgint ptype;
97 void *chol;
98 void *diag;
99
100 double tol;
101 double rnrm;
102 double avgsvtime;
103 double avgfctime;
104 double currenttime;
105 double latesttime;
106
107 cgint n;
108 cgint niter;
109 cgint maxiter;
110 cgint status;
111 cgint reuse;
112 cgint nused;
113 cgint nmaxiter;
114 cgint restart;
115 cgint nfactors;
116 cgint nrounds;
117 cgint nsolverd;
118 cgint nsolves;
119
120 /* Vector operations */
121 void (*v_init) (void *v);
122 cgint (*v_alloc) (void *v, cgint n);
123 void (*v_free) (void *v);
124 void (*v_copy) (void *s, void *t);
125 void (*v_reset) (void *v);
126 void (*v_norm) (void *v, double *nrm);
127 void (*v_axpy) (double a, void *x, void *y);
128 void (*v_axpby) (double a, void *x, double b, void *y);
129 void (*v_zaxpby) (void *z, double a, void *x, double b, void *y);
130 void (*v_dot) (void *x, void *y, double *xTy);
131
132 /* Matrix operations */
133 cgint (*A_chol) (void *A);
134 cgint (*A_cond) (void *A);
135 void (*A_getdiag) (void *A, void *diag);
136
137 /* Matrix-vector operations */
138 cgint (*diagpcd)(void *diag, void *v);
139 cgint (*cholpcd)(void *chol, void *v, void *aux);
140 void (*Av) (void *A, void *v, void *Av);
141 cgint (*Ainv) (void *A, void *v, void *aux);
142
143} adpcg;
144
145
146#endif /* adpcg_h */
Working struct for the adaptive CG solver.
Definition: adpcg.h:84
double rnrm
Residual norm.
Definition: adpcg.h:101
void * rnew
Workspace array.
Definition: adpcg.h:88
double tol
Relative tolerance of CG.
Definition: adpcg.h:100
void * pinvr
Workspace array.
Definition: adpcg.h:90
double avgfctime
Average factorization time of previous CG solves.
Definition: adpcg.h:103
void * x
CG solution vector.
Definition: adpcg.h:92
double currenttime
Buffer of solution time in the current round.
Definition: adpcg.h:104
void * diag
Diagonal pre-conditioner.
Definition: adpcg.h:98
void * aux
CG auxiliary array.
Definition: adpcg.h:93
cgint maxiter
Maximum number of iterations.
Definition: adpcg.h:109
cgint nrounds
Number of rounds of solves.
Definition: adpcg.h:116
cgint nsolves
Number of linear systems solved.
Definition: adpcg.h:118
cgint n
Dimension of linear system.
Definition: adpcg.h:107
void * r
Residual.
Definition: adpcg.h:87
void * A
LHS data.
Definition: adpcg.h:86
void * Ad
Workspace array.
Definition: adpcg.h:91
cgint restart
Restart frequency.
Definition: adpcg.h:114
cgint nfactors
Number of factorizes performed so far.
Definition: adpcg.h:115
cgint niter
Number of iterations in most recent solve.
Definition: adpcg.h:108
cgint nsolverd
Number of solves in a round.
Definition: adpcg.h:117
void * chol
Cholesky pre-conditioner.
Definition: adpcg.h:97
cgint nmaxiter
Number of non-successfull solves.
Definition: adpcg.h:113
void(* Av)(void *A, void *v, void *Av)
Compute Av = A * v.
Definition: adpcg.h:140
cgint ptype
Pre-conditioner type.
Definition: adpcg.h:96
cgint nused
Number of rounds current Cholesky pre-conditioner is already used.
Definition: adpcg.h:112
void * d
Workspace array.
Definition: adpcg.h:89
double avgsvtime
Averate solution time of previous CG solves.
Definition: adpcg.h:102
cgint status
Solution status.
Definition: adpcg.h:110
double latesttime
Time for the latest solve.
Definition: adpcg.h:105
void * btmp
CG temporary RHS array.
Definition: adpcg.h:94
cgint reuse
Reuse Cholesky pre-conditioner.
Definition: adpcg.h:111