diff --git a/cg_blas.c b/cg_blas.c index 7f8c021..fc30ea0 100644 --- a/cg_blas.c +++ b/cg_blas.c @@ -1,71 +1,72 @@ #include #include #include #include #include #include "cg.h" #include "util.h" #include "parameters.h" + /* Implementation of a simple CG solver using matrix in the mtx format (Matrix market) Any matrix in that format can be used to test the code */ int main ( int argc, char **argv ) { double * A; double * b; double * x; double * x0; int m,n; struct size_m sA,sb; double h; if (argc < 2) { fprintf(stderr, "Usage: %s [martix-market-filename]\n", argv[0]); exit(1); } else { A = read_mat(argv[1]); sA = get_size(argv[1]); // b = read_mat(argv[2]); // sb = get_size(argv[2]); } m = sA.m; n = sA.n; h = 1./(double)n; b = init_source_term(n,h); x = (double*) malloc(n * sizeof(double)); x0 = (double*) malloc(n * sizeof(double)); printf("Call cgsolver() on matrix size (%d x %d) times vector size (%d x %d)\n",m,n,sb.m,sb.n); cgsolver( A, b, x, m, n ); printf("Solves A x = b\n"); // print_mat( "\nSolution :", x,1,n ); cblas_dgemv (1, 0, m, n, 1., A, 1., x, 1., 0., x0, 1.); print_first( "\nCheck AX:\n", x0,1, n, 4); print_first( "\nCheck b:\n", b,1, n, 4); free(A); free(b); free(x); free(x0); return 0; } diff --git a/util.h b/util.h index c28655e..e0a8888 100644 --- a/util.h +++ b/util.h @@ -1,14 +1,15 @@ #ifndef SIMPLEUTIL_H_ #define SIMPLEUTIL_H_ #include #include #include "parameters.h" #include "mmio.h" + void print_mat( char title[], double *A, int m, int n ); void print_first( char title[], double *A, int m, int n, int d ); double* read_mat(const char * restrict fn); struct size_m get_size(const char * restrict fn); #endif /*SIMPLEUTIL_H_*/