-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg_omp.h
32 lines (25 loc) · 939 Bytes
/
cg_omp.h
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
/*
Large Scale Computing
solve Ax=b
Conjugate Gradient Method
General Sparse Matrix A
solve_cg solve Ax=b with CG method
this returns the number of iterations, or negative if failed.
Note: A must be symmetric and positive-defined matrix
*/
#ifndef __CG_OMP_H__
#define __CG_OMP_H__
#include<iostream>
#include<cmath>
#include <omp.h>
int solve_cg_OMP(int dim, /* dimension */
int nnz, /* # of non-zeros in the matrix */
double *nzval, /* array of nonzero values */
int *colidx, /* array of column indices of the nonzeros */
int *rowptr, /* the first column of nonzero in each row */
/* rowptr[j] stores the location of nzval[] and colidx[], */
/* which starts row j. This has dim+1 entry that is nnz */
double *x, /* solition */
double *b, /* right hand side */
double tol); /* tolerance */
#endif // __CG_OMP_H__