/* nag_superlu_column_permutation (f11mdc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include int main(void) { Integer exit_status=0, i, n, nnz; Integer *icolzp=0, *iprm=0, *irowix=0; /* Nag types */ Nag_ColumnPermutationType ispec; NagError fail; INIT_FAIL(fail); Vprintf( "nag_superlu_column_permutation (f11mdc) Example Program Results" "\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read order of matrix */ Vscanf("%ld%*[^\n] ", &n); if ( !(icolzp = NAG_ALLOC(n+1, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read the matrix A */ for (i = 1; i <= n+1; ++i) Vscanf("%ld%*[^\n] ", &icolzp[i - 1]); nnz = icolzp[n] - 1; if ( !(irowix = NAG_ALLOC(nnz, Integer)) || !(iprm = NAG_ALLOC(7*n, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nnz; ++i) Vscanf("%ld%*[^\n] ", &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; } /* Output results */ Vprintf("\n"); Vprintf("%s\n", "COLAMD Permutation"); for (i = 1; i <= n; ++i) Vprintf("%6ld%s", iprm[i - 1], i%10 == 0 || i == n ?"\n":" "); /* Calculate user permutation */ ispec = Nag_Sparse_User; iprm[0] = 4; iprm[1] = 3; iprm[2] = 2; iprm[3] = 1; iprm[4] = 0; /* nag_superlu_column_permutation (f11mdc), see above. */ 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; } /* Output results */ Vprintf("\n"); Vprintf("%s", "User Permutation"); Vprintf("\n"); for (i = 1; i <= n; ++i) Vprintf("%6ld%s", iprm[i - 1], i%10 == 0 || i == n ?"\n":" "); /* Calculate natural permutation */ ispec = Nag_Sparse_Identity; /* nag_superlu_column_permutation (f11mdc), see above. */ 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; } /* Output results */ Vprintf("\n"); Vprintf("%s\n", "Natural Permutation"); for (i = 1; i <= n; ++i) Vprintf("%6ld%s", iprm[i - 1], i%10 == 0 || i == n ?"\n":" "); Vprintf("\n"); END: if (icolzp) NAG_FREE(icolzp); if (iprm) NAG_FREE(iprm); if (irowix) NAG_FREE(irowix); return exit_status; }