/* nag_superlu_matrix_product (f11mkc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include #include /* Table of constant values */ static double alpha = 1.; static double beta = 0.; int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *outfile = 0; 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); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "nag_superlu_matrix_product (f11mkc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read order of matrix */ fscanf(fpin, "%ld%ld%*[^\n] ", &n, &m); /* Read the matrix A */ if (!(icolzp = NAG_ALLOC(n+1, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < n + 1; ++i) fscanf(fpin, "%ld%*[^\n] ", &icolzp[i]); 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))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < nnz; ++i) fscanf(fpin, "%lf%ld%*[^\n] ", &a[i], &irowix[i]); /* Read the matrix B */ for (j = 0; j < m; ++j) { for (i = 0; i < n; ++i) { fscanf(fpin, "%lf", &b[j*n + i]); c[j*n + i] = 0.0; } fscanf(fpin, "%*[^\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) { fprintf(fpout, "Error from nag_superlu_matrix_product (f11mkc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ fprintf(fpout, "\n"); /* nag_gen_real_mat_print (x04cac). * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, matrix, diag, n, m, c, n, "Matrix-vector product", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "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) { fprintf(fpout, "Error from nag_superlu_matrix_product (f11mkc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ fprintf(fpout, "\n"); /* nag_gen_real_mat_print (x04cac), see above. */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, matrix, diag, n, m, c, n, "Transposed matrix-vector product", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); 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; }