diff --git a/Makefile b/Makefile index c88f533..ed0f94d 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,24 @@ CC=gcc LD=${CC} COVFLAGS = -fprofile-arcs -ftest-coverage #CFLAGS+=-Wall -Werror -pedantic -O3 -fopenmp -fPIC ${COVFLAGS} -Wfatal-errors -g -Werror=unused-but-set-variable CFLAGS+=-Wall -pedantic -O3 -fopenmp -fPIC ${COVFLAGS} -g -pg LDFLAGS+=-lm -fopenmp ${COVFLAGS} -g -pg -OBJS=blas.o cg.o cg_blas.o mmio.o util.o +OBJS=blas.o cg.o util.o cg_blas.o mmio.o all: conjugategradient conjugategradient: $(OBJS) $(LD) $(OBJS) $(LDFLAGS) -o $@ #coverage study coverage: ./conjugategradient matrix3x3.mtx vector3.mtx gcov *.c lcov --capture --directory . --output-file coverage.info genhtml coverage.info --output-directory out_html clean: rm -Rf conjugategradient *.o *~ *.gcda *.gcov *.gcno out_html coverage.info gmon.out diff --git a/blas.h b/blas.h index d912e86..4a87b51 100644 --- a/blas.h +++ b/blas.h @@ -1,33 +1,30 @@ #ifndef SIMPLEBLAS_H_ #define SIMPLEBLAS_H_ #include "mmio.h" +#include "parameters.h" #define BLAS_INT int #define CBLAS_LAYOUT int #define CBLAS_TRANSPOSE int #ifdef INTEL_MKL #define BLAS_INT INTEL_MKL #endif - +/* struct size_m { int m; int n; }; - +*/ void cblas_dcopy (const BLAS_INT n, const double *x, const BLAS_INT incx, double *y, const BLAS_INT incy); double cblas_ddot (const BLAS_INT n, const double *x, const BLAS_INT incx, const double *y, const BLAS_INT incy); void cblas_daxpy (const BLAS_INT n, const double a, const double *x, const BLAS_INT incx, double *y, const BLAS_INT incy); void cblas_dgemv (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE trans, const BLAS_INT m, const BLAS_INT n, const double alpha, const double *a, const BLAS_INT lda, const double *x, const BLAS_INT incx, const double beta, double *y, const BLAS_INT incy); double cblas_dnrm2(const int n, const double *x, const int incx); void cblas_dadd(const int n, double *x, double alpha, double *y, double beta, double *z); void cblas_dtra(const int m, const int n, const double *a, double *b); -void print_mat( char title[], double *A, int m, int n ); -double* read_mat(const char * restrict fn); -struct size_m get_size(const char * restrict fn); - #endif /*SIMPLEBLAS_H_*/ diff --git a/cg_blas.c b/cg_blas.c index 9fbb757..ec4e187 100644 --- a/cg_blas.c +++ b/cg_blas.c @@ -1,68 +1,65 @@ #include #include #include #include #include #include "blas.h" +#include "util.h" #include "cg.h" #include "parameters.h" +/* - -/* - main function - reads the matrix entered as argument. - using mmio.h (from matrix market) */ int main ( int argc, char **argv ) { double * A; double * b; double * x; double * x0; int m,n; struct size_m sA,sb; 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; x = (double*) malloc(n * sizeof(double)); x0 = (double*) malloc(n * sizeof(double)); - printf("Call cgsolver()\n"); + 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/mmio.c b/mmio.c index c250ff2..4b0ab17 100644 --- a/mmio.c +++ b/mmio.c @@ -1,511 +1,511 @@ /* * Matrix Market I/O library for ANSI C * * See http://math.nist.gov/MatrixMarket for details. * * */ #include #include #include #include #include "mmio.h" int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_) { FILE *f; MM_typecode matcode; int M, N, nz; int i; double *val; int *I, *J; if ((f = fopen(fname, "r")) == NULL) return -1; if (mm_read_banner(f, &matcode) != 0) { printf("mm_read_unsymetric: Could not process Matrix Market banner "); printf(" in file [%s]\n", fname); return -1; } if ( !(mm_is_real(matcode) && mm_is_matrix(matcode) && mm_is_sparse(matcode))) { fprintf(stderr, "Sorry, this application does not support "); fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode)); return -1; } /* find out size of sparse matrix: M, N, nz .... */ if (mm_read_mtx_crd_size(f, &M, &N, &nz) !=0) { fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n"); return -1; } *M_ = M; *N_ = N; *nz_ = nz; /* reseve memory for matrices */ I = (int *) malloc(nz * sizeof(int)); J = (int *) malloc(nz * sizeof(int)); val = (double *) malloc(nz * sizeof(double)); *val_ = val; *I_ = I; *J_ = J; /* NOTE: when reading in doubles, ANSI C requires the use of the "l" */ /* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */ /* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */ for (i=0; i