#include #include #include #include "mkl.h" #include "mkl_types.h" #include "mkl_spblas.h" #include "mmio.h" // mkl_?csrgemv y := A*x one based // void mkl_dcsrgemv (char *transa, MKL_INT *m, double *a, MKL_INT *ia, MKL_INT *ja, double *x, double *y); // mkl_cspblas_?csrgemv y := A*x zero based // void mkl_cspblas_dcsrgemv (char *transa, MKL_INT *m, double *a, MKL_INT *ia, MKL_INT *ja, double *x, double *y); // mkl_?csrmv y := alpha*A*x + beta*y // void mkl_dcsrmv (char *transa, MKL_INT *m, MKL_INT *k, double *alpha, char *matdescra, double *val, MKL_INT *indx, MKL_INT *pntrb, MKL_INT *pntre, double *x, double *beta, double *y); // trans='n' int main(int argc, char* argv[]) { int ret_code; MM_typecode matcode; FILE *f; int M, N, nz; int i, *I, *J; double *val; if (argc != 5) { fprintf(stderr, "Usage: %s [martix-market-filename] [nworker] [num repeat] [null|row/col permutation file]\n", argv[0]); exit(1); } else { if ((f = fopen(argv[1], "r")) == NULL) exit(1); } int nworker = atoi(argv[2]); int num_repeat = atoi(argv[3]); char* fnrcperm = argv[4]; if (mm_read_banner(f, &matcode) != 0) { printf("Could not process Matrix Market banner.\n"); exit(1); } /* This is how one can screen matrix types if their application */ /* only supports a subset of the Matrix Market data types. */ if (mm_is_complex(matcode) && mm_is_matrix(matcode) && mm_is_sparse(matcode) ) { printf("Sorry, this application does not support "); printf("Market Market type: [%s]\n", mm_typecode_to_str(matcode)); exit(1); } /* find out size of sparse matrix .... */ if ((ret_code = mm_read_mtx_crd_size(f, &M, &N, &nz)) !=0) exit(1); /* reseve memory for matrices */ I = (int *) malloc((mm_is_symmetric(matcode) ? 2*nz : nz) * sizeof(int)); J = (int *) malloc((mm_is_symmetric(matcode) ? 2*nz : nz) * sizeof(int)); val = (double *) malloc((mm_is_symmetric(matcode) ? 2*nz : nz) * sizeof(double)); /* 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) */ int realnnz = 0; for (i=0; imaxdiff){ printf("%g\t%g\t%g\n", diff, vecout[i], vecoutcpu[i]); } } printf("\n"); printf("%s %d %d %g %d %s\n", argv[1], nworker, max_threads, s_elapsed, num_repeat, fnrcperm); // mkl_free(A); return 0; }