/* nag_sparse_herm_matvec (f11xsc) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include int main(void) { /* Scalars */ Integer exit_status = 0; Integer i, j, n, nnz; /* Arrays */ char nag_enum_arg[40]; Integer *irow = 0, *icol = 0; Complex *a = 0, *x = 0, *y = 0; /* NAG types */ NagError fail; Nag_SparseSym_CheckData check; INIT_FAIL(fail); printf("nag_sparse_herm_matvec (f11xsc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n]"); /* Read order of matrix and number of non-zero entries */ scanf("%ld%*[^\n]", &n); scanf("%ld%*[^\n]", &nnz); /* Allocate memory */ if ( !(a = NAG_ALLOC(nnz, Complex)) || !(x = NAG_ALLOC(n, Complex)) || !(y = NAG_ALLOC(n, Complex)) || !(icol = NAG_ALLOC(nnz, Integer)) || !(irow = NAG_ALLOC(nnz, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Read the matrix A */ for (i = 0; i < nnz; i++) scanf(" ( %lf , %lf ) %ld%ld%*[^\n]", &a[i].re, &a[i].im, &irow[i], &icol[i] ); /* Read the vector x */ for (j = 0; j < n; j++) scanf(" ( %lf , %lf ) ", &x[j].re, &x[j].im); scanf("%*[^\n]"); /* Calculate matrix-vector product */ scanf("%s%*[^\n]", nag_enum_arg); /* Nag_SparseSym_Check */ check = (Nag_SparseSym_CheckData) nag_enum_name_to_value (nag_enum_arg); /* nag_sparse_herm_matvec (f11xsc) * Complex sparse Hermitian matrix vector multiply. */ nag_sparse_herm_matvec(n, nnz, a, irow, icol, check, x, y, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_sparse_herm_matvec (f11xsc)\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ printf(" Matrix-vector product\n"); for (j = 0; j < n; j++) printf(" (%11.4e, %11.4e)\n", y[j].re, y[j].im); END: if (a) NAG_FREE(a); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (icol) NAG_FREE(icol); if (irow) NAG_FREE(irow); return exit_status; }