/* nag_superlu_lu_factorise (f11mec) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include /* Table of constant values */ static Integer c__1 = 1; static Integer c__10 = 10; static Integer c__80 = 80; static Integer c__4 = 4; int main(void) { double flop, thresh; Integer exit_status=0, i, n, nnz, nnzl, nnzu, nzlmx, nzlumx, nzumx; double *a=0, *lval=0, *uval=0; Integer *icolzp=0, *il=0, *iprm=0, *irowix=0, *iu=0; /* Nag types */ NagError fail; Nag_ColumnPermutationType ispec; Nag_OrderType order = Nag_ColMajor; Nag_MatrixType matrix = Nag_GeneralMatrix; Nag_DiagType diag = Nag_NonUnitDiag; INIT_FAIL(fail); /* nag_superlu_lu_factorize (f11mec). * LU factorization of real sparse matrix */ Vprintf( "nag_superlu_lu_factorize (f11mec) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read order of matrix */ Vscanf("%ld%*[^\n] ", &n); /* Read the matrix A */ /* Allocate memory */ 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)) || !(il = NAG_ALLOC(7*n+8*nnz+4, Integer)) || !(iu= NAG_ALLOC(2*n+8*nnz+1, Integer)) || !(uval = NAG_ALLOC(8*nnz, double)) || !(lval = NAG_ALLOC(8*nnz, double)) || !(iprm = NAG_ALLOC(7*n, Integer)) ) { 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]); /* Calculate COLAMD permutation */ ispec = Nag_Sparse_Colamd; /* nag_superlu_column_permutation (f11mdc). * Real sparse nonsymmetric linear systems, setup for * nag_superlu_lu_factorize (f11mec) */ nag_superlu_column_permutation (ispec, n, icolzp, irowix, iprm, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_column_permutation (f11mdc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Factorise */ thresh = 1.; nzlmx = 8*nnz; nzlumx = 8*nnz; nzumx = 8*nnz; /* nag_superlu_lu_factorize (f11mec), see above. */ nag_superlu_lu_factorize(n, irowix, a, iprm, thresh, nzlmx, &nzlumx, nzumx, il, lval, iu, uval, &nnzl, &nnzu, &flop, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_lu_factorize (f11mec).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ Vprintf("\n"); Vprintf("%s\n", "Number of nonzeros in factors (excluding unit diagonal)"); Vprintf("%8ld\n", nnzl + nnzu - n ); Vprintf("\n"); /* nag_gen_real_mat_print_comp (x04cbc). * Print real general matrix (comprehensive) */ nag_gen_real_mat_print_comp(order, matrix, diag, c__1, c__10, lval, c__1, "%6.2f", "Factor elements in LVAL", Nag_NoLabels, NULL, Nag_NoLabels, NULL, c__80, c__1, NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); /* nag_gen_real_mat_print_comp (x04cbc), see above. */ nag_gen_real_mat_print_comp(order, matrix, diag, c__1, c__4, uval, c__1, "%6.2f", "Factor elements in LVAL", Nag_NoLabels, NULL, Nag_NoLabels, NULL, c__80, c__1, NULL, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (a) NAG_FREE(a); if (lval) NAG_FREE(lval); if (uval) NAG_FREE(uval); if (icolzp) NAG_FREE(icolzp); if (il) NAG_FREE(il); if (iprm) NAG_FREE(iprm); if (irowix) NAG_FREE(irowix); if (iu) NAG_FREE(iu); return exit_status; }