/* nag_superlu_matrix_product (f11mkc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include /* Table of constant values */ static double alpha = 1.; static double beta = 0.; int main(void) { Integer exit_status=0, i, j, m, n, nnz; double *a=0, *b=0, *c=0; Integer *icolzp=0, *irowix=0; /* Nag types */ NagError fail; Nag_OrderType order = Nag_ColMajor; Nag_MatrixType matrix = Nag_GeneralMatrix; Nag_DiagType diag = Nag_NonUnitDiag; Nag_TransType trans; INIT_FAIL(fail); Vprintf( "nag_superlu_matrix_product (f11mkc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read order of matrix */ Vscanf("%ld%ld%*[^\n] ", &n, &m); /* Read the matrix A */ if ( !(icolzp = NAG_ALLOC(n+1, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n + 1; ++i) Vscanf("%ld%*[^\n] ", &icolzp[i - 1]); nnz = icolzp[n] - 1; /* Allocate memory */ if ( !(irowix = NAG_ALLOC(nnz, Integer)) || !(a = NAG_ALLOC(nnz, double)) || !(b = NAG_ALLOC(n * m, double)) || !(c = NAG_ALLOC(n * m, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nnz; ++i) Vscanf("%lf%ld%*[^\n] ", &a[i - 1], &irowix[i - 1]); /* Read the matrix B */ for (j = 1; j <= m; ++j) { for (i = 1; i <= n; ++i) { Vscanf("%lf", &b[j*n + i - n - 1]); c[j*n + i - n - 1] = 0. ; } Vscanf("%*[^\n] "); } /* Calculate matrix-matrix product */ trans = Nag_NoTrans; /* nag_superlu_matrix_product (f11mkc). * Real sparse nonsymmetric matrix matrix multiply, * compressed column storage */ nag_superlu_matrix_product(order, trans, n, m, alpha, icolzp, irowix, a, b, n, beta, c, n, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_matrix_product (f11mkc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ Vprintf("\n"); /* nag_gen_real_mat_print (x04cac). * Print real general matrix (easy-to-use) */ nag_gen_real_mat_print(order, matrix, diag, n, m, c, n, "Matrix-vector product", NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Calculate transposed matrix-matrix product */ trans = Nag_Trans; /* nag_superlu_matrix_product (f11mkc), see above. */ nag_superlu_matrix_product(order, trans, n, m, alpha, icolzp, irowix, a, b, n, beta, c, n, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_matrix_product (f11mkc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ Vprintf("\n"); /* nag_gen_real_mat_print (x04cac), see above. */ nag_gen_real_mat_print(order, matrix, diag, n, m, c, n, "Transposed matrix-vector product", NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (a) NAG_FREE(a); if (b) NAG_FREE(b); if (c) NAG_FREE(c); if (icolzp) NAG_FREE(icolzp); if (irowix) NAG_FREE(irowix); return exit_status; }