void umfpack_toc (double stats [2]) { /* Return the current time since the last call to umfpack_tic. */ /* On input, stats holds the values returned by umfpack_tic. */ /* On ouput, stats holds the time since the last umfpack_tic. */ double done [2] ; umfpack_tic (done) ; stats [0] = done [0] - stats [0] ; stats [1] = done [1] - stats [1] ; if (stats [0] < 0) stats [0] = 0 ; if (stats [1] < 0) stats [1] = 0 ; }
int main (int argc, char **argv) { double Info [UMFPACK_INFO], Control [UMFPACK_CONTROL], *Ax, *Cx, *Lx, *Ux, *W, t [2], *Dx, rnorm, *Rb, *y, *Rs ; double *Az, *Lz, *Uz, *Dz, *Cz, *Rbz, *yz ; int *Ap, *Ai, *Cp, *Ci, row, col, p, lnz, unz, nr, nc, *Lp, *Li, *Ui, *Up, *P, *Q, *Lj, i, j, k, anz, nfr, nchains, *Qinit, fnpiv, lnz1, unz1, nz1, status, *Front_npivcol, *Front_parent, *Chain_start, *Wi, *Pinit, n1, *Chain_maxrows, *Chain_maxcols, *Front_1strow, *Front_leftmostdesc, nzud, do_recip ; void *Symbolic, *Numeric ; /* ---------------------------------------------------------------------- */ /* initializations */ /* ---------------------------------------------------------------------- */ umfpack_tic (t) ; printf ("\nUMFPACK V%d.%d (%s) demo: _zi_ version\n", UMFPACK_MAIN_VERSION, UMFPACK_SUB_VERSION, UMFPACK_DATE) ; /* get the default control parameters */ umfpack_zi_defaults (Control) ; /* change the default print level for this demo */ /* (otherwise, nothing will print) */ Control [UMFPACK_PRL] = 6 ; /* print the license agreement */ umfpack_zi_report_status (Control, UMFPACK_OK) ; Control [UMFPACK_PRL] = 5 ; /* print the control parameters */ umfpack_zi_report_control (Control) ; /* ---------------------------------------------------------------------- */ /* print A and b, and convert A to column-form */ /* ---------------------------------------------------------------------- */ /* print the right-hand-side */ printf ("\nb: ") ; (void) umfpack_zi_report_vector (n, b, bz, Control) ; /* print the triplet form of the matrix */ printf ("\nA: ") ; (void) umfpack_zi_report_triplet (n, n, nz, Arow, Acol, Aval, Avalz, Control) ; /* convert to column form */ nz1 = MAX (nz,1) ; /* ensure arrays are not of size zero. */ Ap = (int *) malloc ((n+1) * sizeof (int)) ; Ai = (int *) malloc (nz1 * sizeof (int)) ; Ax = (double *) malloc (nz1 * sizeof (double)) ; Az = (double *) malloc (nz1 * sizeof (double)) ; if (!Ap || !Ai || !Ax || !Az) { error ("out of memory") ; } status = umfpack_zi_triplet_to_col (n, n, nz, Arow, Acol, Aval, Avalz, Ap, Ai, Ax, Az, (int *) NULL) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_triplet_to_col failed") ; } /* print the column-form of A */ printf ("\nA: ") ; (void) umfpack_zi_report_matrix (n, n, Ap, Ai, Ax, Az, 1, Control) ; /* ---------------------------------------------------------------------- */ /* symbolic factorization */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_symbolic (n, n, Ap, Ai, Ax, Az, &Symbolic, Control, Info) ; if (status < 0) { umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_symbolic failed") ; } /* print the symbolic factorization */ printf ("\nSymbolic factorization of A: ") ; (void) umfpack_zi_report_symbolic (Symbolic, Control) ; /* ---------------------------------------------------------------------- */ /* numeric factorization */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_numeric (Ap, Ai, Ax, Az, Symbolic, &Numeric, Control, Info) ; if (status < 0) { umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_numeric failed") ; } /* print the numeric factorization */ printf ("\nNumeric factorization of A: ") ; (void) umfpack_zi_report_numeric (Numeric, Control) ; /* ---------------------------------------------------------------------- */ /* solve Ax=b */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_solve (UMFPACK_A, Ap, Ai, Ax, Az, x, xz, b, bz, Numeric, Control, Info) ; umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; if (status < 0) { error ("umfpack_zi_solve failed") ; } printf ("\nx (solution of Ax=b): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (FALSE, Ap, Ai, Ax, Az) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* compute the determinant */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_get_determinant (x, xz, r, Numeric, Info) ; umfpack_zi_report_status (Control, status) ; if (status < 0) { error ("umfpack_zi_get_determinant failed") ; } printf ("determinant: (%g", x [0]) ; printf ("+ (%g)i", xz [0]) ; /* complex */ printf (") * 10^(%g)\n", r [0]) ; /* ---------------------------------------------------------------------- */ /* solve Ax=b, broken down into steps */ /* ---------------------------------------------------------------------- */ /* Rb = R*b */ Rb = (double *) malloc (n * sizeof (double)) ; Rbz = (double *) malloc (n * sizeof (double)) ; y = (double *) malloc (n * sizeof (double)) ; yz = (double *) malloc (n * sizeof (double)) ; if (!Rb || !y) error ("out of memory") ; if (!Rbz || !yz) error ("out of memory") ; status = umfpack_zi_scale (Rb, Rbz, b, bz, Numeric) ; if (status < 0) error ("umfpack_zi_scale failed") ; /* solve Ly = P*(Rb) */ status = umfpack_zi_solve (UMFPACK_Pt_L, Ap, Ai, Ax, Az, y, yz, Rb, Rbz, Numeric, Control, Info) ; if (status < 0) error ("umfpack_zi_solve failed") ; /* solve UQ'x=y */ status = umfpack_zi_solve (UMFPACK_U_Qt, Ap, Ai, Ax, Az, x, xz, y, yz, Numeric, Control, Info) ; if (status < 0) error ("umfpack_zi_solve failed") ; printf ("\nx (solution of Ax=b, solve is split into 3 steps): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (FALSE, Ap, Ai, Ax, Az) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; free (Rb) ; free (Rbz) ; free (y) ; free (yz) ; /* ---------------------------------------------------------------------- */ /* solve A'x=b */ /* ---------------------------------------------------------------------- */ /* note that this is the complex conjugate transpose, A' */ status = umfpack_zi_solve (UMFPACK_At, Ap, Ai, Ax, Az, x, xz, b, bz, Numeric, Control, Info) ; umfpack_zi_report_info (Control, Info) ; if (status < 0) { error ("umfpack_zi_solve failed") ; } printf ("\nx (solution of A'x=b): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (TRUE, Ap, Ai, Ax, Az) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* modify one numerical value in the column-form of A */ /* ---------------------------------------------------------------------- */ /* change A (1,4), look for row index 1 in column 4. */ row = 1 ; col = 4 ; for (p = Ap [col] ; p < Ap [col+1] ; p++) { if (row == Ai [p]) { printf ("\nchanging A (%d,%d) to zero\n", row, col) ; Ax [p] = 0.0 ; Az [p] = 0.0 ; break ; } } printf ("\nmodified A: ") ; (void) umfpack_zi_report_matrix (n, n, Ap, Ai, Ax, Az, 1, Control) ; /* ---------------------------------------------------------------------- */ /* redo the numeric factorization */ /* ---------------------------------------------------------------------- */ /* The pattern (Ap and Ai) hasn't changed, so the symbolic factorization */ /* doesn't have to be redone, no matter how much we change Ax. */ /* We don't need the Numeric object any more, so free it. */ umfpack_zi_free_numeric (&Numeric) ; /* Note that a memory leak would have occurred if the old Numeric */ /* had not been free'd with umfpack_zi_free_numeric above. */ status = umfpack_zi_numeric (Ap, Ai, Ax, Az, Symbolic, &Numeric, Control, Info) ; if (status < 0) { umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_numeric failed") ; } printf ("\nNumeric factorization of modified A: ") ; (void) umfpack_zi_report_numeric (Numeric, Control) ; /* ---------------------------------------------------------------------- */ /* solve Ax=b, with the modified A */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_solve (UMFPACK_A, Ap, Ai, Ax, Az, x, xz, b, bz, Numeric, Control, Info) ; umfpack_zi_report_info (Control, Info) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_solve failed") ; } printf ("\nx (with modified A): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (FALSE, Ap, Ai, Ax, Az) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* modify all of the numerical values of A, but not the pattern */ /* ---------------------------------------------------------------------- */ for (col = 0 ; col < n ; col++) { for (p = Ap [col] ; p < Ap [col+1] ; p++) { row = Ai [p] ; printf ("changing ") ; /* complex: */ printf ("real part of ") ; printf ("A (%d,%d) from %g", row, col, Ax [p]) ; Ax [p] = Ax [p] + col*10 - row ; printf (" to %g\n", Ax [p]) ; } } printf ("\ncompletely modified A (same pattern): ") ; (void) umfpack_zi_report_matrix (n, n, Ap, Ai, Ax, Az, 1, Control) ; /* ---------------------------------------------------------------------- */ /* save the Symbolic object to file, free it, and load it back in */ /* ---------------------------------------------------------------------- */ /* use the default filename, "symbolic.umf" */ printf ("\nSaving symbolic object:\n") ; status = umfpack_zi_save_symbolic (Symbolic, (char *) NULL) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_save_symbolic failed") ; } printf ("\nFreeing symbolic object:\n") ; umfpack_zi_free_symbolic (&Symbolic) ; printf ("\nLoading symbolic object:\n") ; status = umfpack_zi_load_symbolic (&Symbolic, (char *) NULL) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_load_symbolic failed") ; } printf ("\nDone loading symbolic object\n") ; /* ---------------------------------------------------------------------- */ /* redo the numeric factorization */ /* ---------------------------------------------------------------------- */ umfpack_zi_free_numeric (&Numeric) ; status = umfpack_zi_numeric (Ap, Ai, Ax, Az, Symbolic, &Numeric, Control, Info) ; if (status < 0) { umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_numeric failed") ; } printf ("\nNumeric factorization of completely modified A: ") ; (void) umfpack_zi_report_numeric (Numeric, Control) ; /* ---------------------------------------------------------------------- */ /* solve Ax=b, with the modified A */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_solve (UMFPACK_A, Ap, Ai, Ax, Az, x, xz, b, bz, Numeric, Control, Info) ; umfpack_zi_report_info (Control, Info) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_solve failed") ; } printf ("\nx (with completely modified A): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (FALSE, Ap, Ai, Ax, Az) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* free the symbolic and numeric factorization */ /* ---------------------------------------------------------------------- */ umfpack_zi_free_symbolic (&Symbolic) ; umfpack_zi_free_numeric (&Numeric) ; /* ---------------------------------------------------------------------- */ /* C = transpose of A */ /* ---------------------------------------------------------------------- */ Cp = (int *) malloc ((n+1) * sizeof (int)) ; Ci = (int *) malloc (nz1 * sizeof (int)) ; Cx = (double *) malloc (nz1 * sizeof (double)) ; Cz = (double *) malloc (nz1 * sizeof (double)) ; if (!Cp || !Ci || !Cx || !Cz) { error ("out of memory") ; } status = umfpack_zi_transpose (n, n, Ap, Ai, Ax, Az, (int *) NULL, (int *) NULL, Cp, Ci, Cx, Cz, TRUE) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_transpose failed: ") ; } printf ("\nC (transpose of A): ") ; (void) umfpack_zi_report_matrix (n, n, Cp, Ci, Cx, Cz, 1, Control) ; /* ---------------------------------------------------------------------- */ /* symbolic factorization of C */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_symbolic (n, n, Cp, Ci, Cx, Cz, &Symbolic, Control, Info) ; if (status < 0) { umfpack_zi_report_info (Control, Info) ; umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_symbolic failed") ; } printf ("\nSymbolic factorization of C: ") ; (void) umfpack_zi_report_symbolic (Symbolic, Control) ; /* ---------------------------------------------------------------------- */ /* copy the contents of Symbolic into user arrays print them */ /* ---------------------------------------------------------------------- */ printf ("\nGet the contents of the Symbolic object for C:\n") ; printf ("(compare with umfpack_zi_report_symbolic output, above)\n") ; Pinit = (int *) malloc ((n+1) * sizeof (int)) ; Qinit = (int *) malloc ((n+1) * sizeof (int)) ; Front_npivcol = (int *) malloc ((n+1) * sizeof (int)) ; Front_1strow = (int *) malloc ((n+1) * sizeof (int)) ; Front_leftmostdesc = (int *) malloc ((n+1) * sizeof (int)) ; Front_parent = (int *) malloc ((n+1) * sizeof (int)) ; Chain_start = (int *) malloc ((n+1) * sizeof (int)) ; Chain_maxrows = (int *) malloc ((n+1) * sizeof (int)) ; Chain_maxcols = (int *) malloc ((n+1) * sizeof (int)) ; if (!Pinit || !Qinit || !Front_npivcol || !Front_parent || !Chain_start || !Chain_maxrows || !Chain_maxcols || !Front_1strow || !Front_leftmostdesc) { error ("out of memory") ; } status = umfpack_zi_get_symbolic (&nr, &nc, &n1, &anz, &nfr, &nchains, Pinit, Qinit, Front_npivcol, Front_parent, Front_1strow, Front_leftmostdesc, Chain_start, Chain_maxrows, Chain_maxcols, Symbolic) ; if (status < 0) { error ("symbolic factorization invalid") ; } printf ("From the Symbolic object, C is of dimension %d-by-%d\n", nr, nc); printf (" with nz = %d, number of fronts = %d,\n", nz, nfr) ; printf (" number of frontal matrix chains = %d\n", nchains) ; printf ("\nPivot columns in each front, and parent of each front:\n") ; k = 0 ; for (i = 0 ; i < nfr ; i++) { fnpiv = Front_npivcol [i] ; printf (" Front %d: parent front: %d number of pivot cols: %d\n", i, Front_parent [i], fnpiv) ; for (j = 0 ; j < fnpiv ; j++) { col = Qinit [k] ; printf ( " %d-th pivot column is column %d in original matrix\n", k, col) ; k++ ; } } printf ("\nNote that the column ordering, above, will be refined\n") ; printf ("in the numeric factorization below. The assignment of pivot\n") ; printf ("columns to frontal matrices will always remain unchanged.\n") ; printf ("\nTotal number of pivot columns in frontal matrices: %d\n", k) ; printf ("\nFrontal matrix chains:\n") ; for (j = 0 ; j < nchains ; j++) { printf (" Frontal matrices %d to %d are factorized in a single\n", Chain_start [j], Chain_start [j+1] - 1) ; printf (" working array of size %d-by-%d\n", Chain_maxrows [j], Chain_maxcols [j]) ; } /* ---------------------------------------------------------------------- */ /* numeric factorization of C */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_numeric (Cp, Ci, Cx, Cz, Symbolic, &Numeric, Control, Info) ; if (status < 0) { error ("umfpack_zi_numeric failed") ; } printf ("\nNumeric factorization of C: ") ; (void) umfpack_zi_report_numeric (Numeric, Control) ; /* ---------------------------------------------------------------------- */ /* extract the LU factors of C and print them */ /* ---------------------------------------------------------------------- */ if (umfpack_zi_get_lunz (&lnz, &unz, &nr, &nc, &nzud, Numeric) < 0) { error ("umfpack_zi_get_lunz failed") ; } /* ensure arrays are not of zero size */ lnz1 = MAX (lnz,1) ; unz1 = MAX (unz,1) ; Lp = (int *) malloc ((n+1) * sizeof (int)) ; Lj = (int *) malloc (lnz1 * sizeof (int)) ; Lx = (double *) malloc (lnz1 * sizeof (double)) ; Lz = (double *) malloc (lnz1 * sizeof (double)) ; Up = (int *) malloc ((n+1) * sizeof (int)) ; Ui = (int *) malloc (unz1 * sizeof (int)) ; Ux = (double *) malloc (unz1 * sizeof (double)) ; Uz = (double *) malloc (unz1 * sizeof (double)) ; P = (int *) malloc (n * sizeof (int)) ; Q = (int *) malloc (n * sizeof (int)) ; Dx = (double *) NULL ; /* D vector not requested */ Dz = (double *) NULL ; Rs = (double *) malloc (n * sizeof (double)) ; if (!Lp || !Lj || !Lx || !Lz || !Up || !Ui || !Ux || !Uz || !P || !Q || !Rs) { error ("out of memory") ; } status = umfpack_zi_get_numeric (Lp, Lj, Lx, Lz, Up, Ui, Ux, Uz, P, Q, Dx, Dz, &do_recip, Rs, Numeric) ; if (status < 0) { error ("umfpack_zi_get_numeric failed") ; } printf ("\nL (lower triangular factor of C): ") ; (void) umfpack_zi_report_matrix (n, n, Lp, Lj, Lx, Lz, 0, Control) ; printf ("\nU (upper triangular factor of C): ") ; (void) umfpack_zi_report_matrix (n, n, Up, Ui, Ux, Uz, 1, Control) ; printf ("\nP: ") ; (void) umfpack_zi_report_perm (n, P, Control) ; printf ("\nQ: ") ; (void) umfpack_zi_report_perm (n, Q, Control) ; printf ("\nScale factors: row i of A is to be ") ; if (do_recip) { printf ("multiplied by the ith scale factor\n") ; } else { printf ("divided by the ith scale factor\n") ; } for (i = 0 ; i < n ; i++) printf ("%d: %g\n", i, Rs [i]) ; /* ---------------------------------------------------------------------- */ /* convert L to triplet form and print it */ /* ---------------------------------------------------------------------- */ /* Note that L is in row-form, so it is the row indices that are created */ /* by umfpack_zi_col_to_triplet. */ printf ("\nConverting L to triplet form, and printing it:\n") ; Li = (int *) malloc (lnz1 * sizeof (int)) ; if (!Li) { error ("out of memory") ; } if (umfpack_zi_col_to_triplet (n, Lp, Li) < 0) { error ("umfpack_zi_col_to_triplet failed") ; } printf ("\nL, in triplet form: ") ; (void) umfpack_zi_report_triplet (n, n, lnz, Li, Lj, Lx, Lz, Control) ; /* ---------------------------------------------------------------------- */ /* save the Numeric object to file, free it, and load it back in */ /* ---------------------------------------------------------------------- */ /* use the default filename, "numeric.umf" */ printf ("\nSaving numeric object:\n") ; status = umfpack_zi_save_numeric (Numeric, (char *) NULL) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_save_numeric failed") ; } printf ("\nFreeing numeric object:\n") ; umfpack_zi_free_numeric (&Numeric) ; printf ("\nLoading numeric object:\n") ; status = umfpack_zi_load_numeric (&Numeric, (char *) NULL) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_load_numeric failed") ; } printf ("\nDone loading numeric object\n") ; /* ---------------------------------------------------------------------- */ /* solve C'x=b */ /* ---------------------------------------------------------------------- */ status = umfpack_zi_solve (UMFPACK_At, Cp, Ci, Cx, Cz, x, xz, b, bz, Numeric, Control, Info) ; umfpack_zi_report_info (Control, Info) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_solve failed") ; } printf ("\nx (solution of C'x=b): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (TRUE, Cp, Ci, Cx, Cz) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* solve C'x=b again, using umfpack_zi_wsolve instead */ /* ---------------------------------------------------------------------- */ printf ("\nSolving C'x=b again, using umfpack_zi_wsolve instead:\n") ; Wi = (int *) malloc (n * sizeof (int)) ; W = (double *) malloc (10*n * sizeof (double)) ; if (!Wi || !W) { error ("out of memory") ; } status = umfpack_zi_wsolve (UMFPACK_At, Cp, Ci, Cx, Cz, x, xz, b, bz, Numeric, Control, Info, Wi, W) ; umfpack_zi_report_info (Control, Info) ; if (status < 0) { umfpack_zi_report_status (Control, status) ; error ("umfpack_zi_wsolve failed") ; } printf ("\nx (solution of C'x=b): ") ; (void) umfpack_zi_report_vector (n, x, xz, Control) ; rnorm = resid (TRUE, Cp, Ci, Cx, Cz) ; printf ("maxnorm of residual: %g\n\n", rnorm) ; /* ---------------------------------------------------------------------- */ /* free everything */ /* ---------------------------------------------------------------------- */ /* This is not strictly required since the process is exiting and the */ /* system will reclaim the memory anyway. It's useful, though, just as */ /* a list of what is currently malloc'ed by this program. Plus, it's */ /* always a good habit to explicitly free whatever you malloc. */ free (Ap) ; free (Ai) ; free (Ax) ; free (Az) ; free (Cp) ; free (Ci) ; free (Cx) ; free (Cz) ; free (Pinit) ; free (Qinit) ; free (Front_npivcol) ; free (Front_1strow) ; free (Front_leftmostdesc) ; free (Front_parent) ; free (Chain_start) ; free (Chain_maxrows) ; free (Chain_maxcols) ; free (Lp) ; free (Lj) ; free (Lx) ; free (Lz) ; free (Up) ; free (Ui) ; free (Ux) ; free (Uz) ; free (P) ; free (Q) ; free (Li) ; free (Wi) ; free (W) ; umfpack_zi_free_symbolic (&Symbolic) ; umfpack_zi_free_numeric (&Numeric) ; /* ---------------------------------------------------------------------- */ /* print the total time spent in this demo */ /* ---------------------------------------------------------------------- */ umfpack_toc (t) ; printf ("\numfpack_zi_demo complete.\nTotal time: %5.2f seconds" " (CPU time), %5.2f seconds (wallclock time)\n", t [1], t [0]) ; return (0) ; }
GLOBAL Int UMFPACK_numeric ( const Int Ap [ ], const Int Ai [ ], const double Ax [ ], #ifdef COMPLEX const double Az [ ], #endif void *SymbolicHandle, void **NumericHandle, const double Control [UMFPACK_CONTROL], double User_Info [UMFPACK_INFO] ) { /* ---------------------------------------------------------------------- */ /* local variables */ /* ---------------------------------------------------------------------- */ double Info2 [UMFPACK_INFO], alloc_init, relpt, relpt2, droptol, front_alloc_init, stats [2] ; double *Info ; WorkType WorkSpace, *Work ; NumericType *Numeric ; SymbolicType *Symbolic ; Int n_row, n_col, n_inner, newsize, i, status, *inew, npiv, ulen, scale ; Unit *mnew ; /* ---------------------------------------------------------------------- */ /* get the amount of time used by the process so far */ /* ---------------------------------------------------------------------- */ umfpack_tic (stats) ; /* ---------------------------------------------------------------------- */ /* initialize and check inputs */ /* ---------------------------------------------------------------------- */ #ifndef NDEBUG UMF_dump_start ( ) ; init_count = UMF_malloc_count ; DEBUGm4 (("\nUMFPACK numeric: U transpose version\n")) ; #endif /* If front_alloc_init negative then allocate that size of front in * UMF_start_front. If alloc_init negative, then allocate that initial * size of Numeric->Memory. */ relpt = GET_CONTROL (UMFPACK_PIVOT_TOLERANCE, UMFPACK_DEFAULT_PIVOT_TOLERANCE) ; relpt2 = GET_CONTROL (UMFPACK_SYM_PIVOT_TOLERANCE, UMFPACK_DEFAULT_SYM_PIVOT_TOLERANCE) ; alloc_init = GET_CONTROL (UMFPACK_ALLOC_INIT, UMFPACK_DEFAULT_ALLOC_INIT) ; front_alloc_init = GET_CONTROL (UMFPACK_FRONT_ALLOC_INIT, UMFPACK_DEFAULT_FRONT_ALLOC_INIT) ; scale = GET_CONTROL (UMFPACK_SCALE, UMFPACK_DEFAULT_SCALE) ; droptol = GET_CONTROL (UMFPACK_DROPTOL, UMFPACK_DEFAULT_DROPTOL) ; relpt = MAX (0.0, MIN (relpt, 1.0)) ; relpt2 = MAX (0.0, MIN (relpt2, 1.0)) ; droptol = MAX (0.0, droptol) ; front_alloc_init = MIN (1.0, front_alloc_init) ; if (scale != UMFPACK_SCALE_NONE && scale != UMFPACK_SCALE_MAX) { scale = UMFPACK_DEFAULT_SCALE ; } if (User_Info != (double *) NULL) { /* return Info in user's array */ Info = User_Info ; /* clear the parts of Info that are set by UMFPACK_numeric */ for (i = UMFPACK_NUMERIC_SIZE ; i <= UMFPACK_MAX_FRONT_NCOLS ; i++) { Info [i] = EMPTY ; } for (i = UMFPACK_NUMERIC_DEFRAG ; i < UMFPACK_IR_TAKEN ; i++) { Info [i] = EMPTY ; } } else { /* no Info array passed - use local one instead */ Info = Info2 ; for (i = 0 ; i < UMFPACK_INFO ; i++) { Info [i] = EMPTY ; } } Symbolic = (SymbolicType *) SymbolicHandle ; Numeric = (NumericType *) NULL ; if (!UMF_valid_symbolic (Symbolic)) { Info [UMFPACK_STATUS] = UMFPACK_ERROR_invalid_Symbolic_object ; return (UMFPACK_ERROR_invalid_Symbolic_object) ; } /* compute alloc_init automatically for AMD or other symmetric ordering */ if (/* Symbolic->ordering == UMFPACK_ORDERING_AMD */ alloc_init >= 0 && Symbolic->amd_lunz > 0) { alloc_init = (Symbolic->nz + Symbolic->amd_lunz) / Symbolic->lunz_bound; alloc_init = MIN (1.0, alloc_init) ; alloc_init *= UMF_REALLOC_INCREASE ; } n_row = Symbolic->n_row ; n_col = Symbolic->n_col ; n_inner = MIN (n_row, n_col) ; /* check for integer overflow in Numeric->Memory minimum size */ if (INT_OVERFLOW (Symbolic->dnum_mem_init_usage * sizeof (Unit))) { /* :: int overflow, initial Numeric->Memory size :: */ /* There's no hope to allocate a Numeric object big enough simply to * hold the initial matrix, so return an out-of-memory condition */ DEBUGm4 (("out of memory: numeric int overflow\n")) ; Info [UMFPACK_STATUS] = UMFPACK_ERROR_out_of_memory ; return (UMFPACK_ERROR_out_of_memory) ; } Info [UMFPACK_STATUS] = UMFPACK_OK ; Info [UMFPACK_NROW] = n_row ; Info [UMFPACK_NCOL] = n_col ; Info [UMFPACK_SIZE_OF_UNIT] = (double) (sizeof (Unit)) ; if (!Ap || !Ai || !Ax || !NumericHandle) { Info [UMFPACK_STATUS] = UMFPACK_ERROR_argument_missing ; return (UMFPACK_ERROR_argument_missing) ; } Info [UMFPACK_NZ] = Ap [n_col] ; *NumericHandle = (void *) NULL ; /* ---------------------------------------------------------------------- */ /* allocate the Work object */ /* ---------------------------------------------------------------------- */ /* (1) calls UMF_malloc 15 or 17 times, to obtain temporary workspace of * size c+1 Entry's and 2*(n_row+1) + 3*(n_col+1) + (n_col+n_inner+1) + * (nn+1) + * 3*(c+1) + 2*(r+1) + max(r,c) + (nfr+1) integers plus 2*nn * more integers if diagonal pivoting is to be done. r is the maximum * number of rows in any frontal matrix, c is the maximum number of columns * in any frontal matrix, n_inner is min (n_row,n_col), nn is * max (n_row,n_col), and nfr is the number of frontal matrices. For a * square matrix, this is c+1 Entry's and about 8n + 3c + 2r + max(r,c) + * nfr integers, plus 2n more for diagonal pivoting. */ Work = &WorkSpace ; Work->n_row = n_row ; Work->n_col = n_col ; Work->nfr = Symbolic->nfr ; Work->nb = Symbolic->nb ; Work->n1 = Symbolic->n1 ; if (!work_alloc (Work, Symbolic)) { DEBUGm4 (("out of memory: numeric work\n")) ; Info [UMFPACK_STATUS] = UMFPACK_ERROR_out_of_memory ; error (&Numeric, Work) ; return (UMFPACK_ERROR_out_of_memory) ; } ASSERT (UMF_malloc_count == init_count + 16 + 2*Symbolic->prefer_diagonal) ; /* ---------------------------------------------------------------------- */ /* allocate Numeric object */ /* ---------------------------------------------------------------------- */ /* (2) calls UMF_malloc 10 or 11 times, for a total space of * sizeof (NumericType) bytes, 4*(n_row+1) + 4*(n_row+1) integers, and * (n_inner+1) Entry's, plus n_row Entry's if row scaling is to be done. * sizeof (NumericType) is a small constant. Next, it calls UMF_malloc * once, for the variable-sized part of the Numeric object * (Numeric->Memory). The size of this object is the larger of * (Control [UMFPACK_ALLOC_INIT]) * (the approximate upper bound computed * by UMFPACK_symbolic), and the minimum required to start the numerical * factorization. * This request is reduced if it fails. */ if (!numeric_alloc (&Numeric, Symbolic, alloc_init, scale)) { DEBUGm4 (("out of memory: initial numeric\n")) ; Info [UMFPACK_STATUS] = UMFPACK_ERROR_out_of_memory ; error (&Numeric, Work) ; return (UMFPACK_ERROR_out_of_memory) ; } DEBUG0 (("malloc: init_count "ID" UMF_malloc_count "ID"\n", init_count, UMF_malloc_count)) ; ASSERT (UMF_malloc_count == init_count + (16 + 2*Symbolic->prefer_diagonal) + (11 + (scale != UMFPACK_SCALE_NONE))) ; /* set control parameters */ Numeric->relpt = relpt ; Numeric->relpt2 = relpt2 ; Numeric->droptol = droptol ; Numeric->alloc_init = alloc_init ; Numeric->front_alloc_init = front_alloc_init ; Numeric->scale = scale ; DEBUG0 (("umf relpt %g %g init %g %g inc %g red %g\n", relpt, relpt2, alloc_init, front_alloc_init, UMF_REALLOC_INCREASE, UMF_REALLOC_REDUCTION)) ; /* ---------------------------------------------------------------------- */ /* scale and factorize */ /* ---------------------------------------------------------------------- */ /* (3) During numerical factorization (inside UMF_kernel), the variable-size * block of memory is increased in size via a call to UMF_realloc if it is * found to be too small. During factorization, this block holds the * pattern and values of L and U at the top end, and the elements * (contibution blocks) and the current frontal matrix (Work->F*) at the * bottom end. The peak size of the variable-sized object is estimated in * UMFPACK_*symbolic (Info [UMFPACK_VARIABLE_PEAK_ESTIMATE]), although this * upper bound can be very loose. The size of the Symbolic object * (which is currently allocated) is in Info [UMFPACK_SYMBOLIC_SIZE], and * is between 2*n and 13*n integers. */ DEBUG0 (("Calling umf_kernel\n")) ; status = UMF_kernel (Ap, Ai, Ax, #ifdef COMPLEX Az, #endif Numeric, Work, Symbolic) ; Info [UMFPACK_STATUS] = status ; if (status < UMFPACK_OK) { /* out of memory, or pattern has changed */ error (&Numeric, Work) ; return (status) ; } Info [UMFPACK_FORCED_UPDATES] = Work->nforced ; Info [UMFPACK_VARIABLE_INIT] = Numeric->init_usage ; if (Symbolic->prefer_diagonal) { Info [UMFPACK_NOFF_DIAG] = Work->noff_diagonal ; } DEBUG0 (("malloc: init_count "ID" UMF_malloc_count "ID"\n", init_count, UMF_malloc_count)) ; npiv = Numeric->npiv ; /* = n_inner for nonsingular matrices */ ulen = Numeric->ulen ; /* = 0 for square nonsingular matrices */ /* ---------------------------------------------------------------------- */ /* free Work object */ /* ---------------------------------------------------------------------- */ /* (4) After numerical factorization all of the objects allocated in step * (1) are freed via UMF_free, except that one object of size n_col+1 is * kept if there are off-diagonal nonzeros in the last pivot row (can only * occur for singular or rectangular matrices). This is Work->Upattern, * which is transfered to Numeric->Upattern if ulen > 0. */ DEBUG0 (("malloc: init_count "ID" UMF_malloc_count "ID"\n", init_count, UMF_malloc_count)) ; free_work (Work) ; DEBUG0 (("malloc: init_count "ID" UMF_malloc_count "ID"\n", init_count, UMF_malloc_count)) ; DEBUG0 (("Numeric->ulen: "ID" scale: "ID"\n", ulen, scale)) ; ASSERT (UMF_malloc_count == init_count + (ulen > 0) + (11 + (scale != UMFPACK_SCALE_NONE))) ; /* ---------------------------------------------------------------------- */ /* reduce Lpos, Lilen, Lip, Upos, Uilen and Uip to size npiv+1 */ /* ---------------------------------------------------------------------- */ /* (5) Six components of the Numeric object are reduced in size if the * matrix is singular or rectangular. The original size is 3*(n_row+1) + * 3*(n_col+1) integers. The new size is 6*(npiv+1) integers. For * square non-singular matrices, these two sizes are the same. */ if (npiv < n_row) { /* reduce Lpos, Uilen, and Uip from size n_row+1 to size npiv */ inew = (Int *) UMF_realloc (Numeric->Lpos, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Lpos = inew ; } inew = (Int *) UMF_realloc (Numeric->Uilen, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Uilen = inew ; } inew = (Int *) UMF_realloc (Numeric->Uip, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Uip = inew ; } } if (npiv < n_col) { /* reduce Upos, Lilen, and Lip from size n_col+1 to size npiv */ inew = (Int *) UMF_realloc (Numeric->Upos, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Upos = inew ; } inew = (Int *) UMF_realloc (Numeric->Lilen, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Lilen = inew ; } inew = (Int *) UMF_realloc (Numeric->Lip, npiv+1, sizeof (Int)) ; if (inew) { Numeric->Lip = inew ; } } /* ---------------------------------------------------------------------- */ /* reduce Numeric->Upattern from size n_col+1 to size ulen+1 */ /* ---------------------------------------------------------------------- */ /* (6) The size of Numeric->Upattern (formerly Work->Upattern) is reduced * from size n_col+1 to size ulen + 1. If ulen is zero, the object does * not exist. */ DEBUG4 (("ulen: "ID" Upattern "ID"\n", ulen, (Int) Numeric->Upattern)) ; ASSERT (IMPLIES (ulen == 0, Numeric->Upattern == (Int *) NULL)) ; if (ulen > 0 && ulen < n_col) { inew = (Int *) UMF_realloc (Numeric->Upattern, ulen+1, sizeof (Int)) ; if (inew) { Numeric->Upattern = inew ; } } /* ---------------------------------------------------------------------- */ /* reduce Numeric->Memory to hold just the LU factors at the head */ /* ---------------------------------------------------------------------- */ /* (7) The variable-sized block (Numeric->Memory) is reduced to hold just L * and U, via a call to UMF_realloc, since the frontal matrices are no * longer needed. */ newsize = Numeric->ihead ; if (newsize < Numeric->size) { mnew = (Unit *) UMF_realloc (Numeric->Memory, newsize, sizeof (Unit)) ; if (mnew) { /* realloc succeeded (how can it fail since the size is reduced?) */ Numeric->Memory = mnew ; Numeric->size = newsize ; } } Numeric->ihead = Numeric->size ; Numeric->itail = Numeric->ihead ; Numeric->tail_usage = 0 ; Numeric->ibig = EMPTY ; /* UMF_mem_alloc_tail_block can no longer be called (no tail marker) */ /* ---------------------------------------------------------------------- */ /* report the results and return the Numeric object */ /* ---------------------------------------------------------------------- */ UMF_set_stats ( Info, Symbolic, (double) Numeric->max_usage, /* actual peak Numeric->Memory */ (double) Numeric->size, /* actual final Numeric->Memory */ Numeric->flops, /* actual "true flops" */ (double) Numeric->lnz + n_inner, /* actual nz in L */ (double) Numeric->unz + Numeric->nnzpiv, /* actual nz in U */ (double) Numeric->maxfrsize, /* actual largest front size */ (double) ulen, /* actual Numeric->Upattern size */ (double) npiv, /* actual # pivots found */ (double) Numeric->maxnrows, /* actual largest #rows in front */ (double) Numeric->maxncols, /* actual largest #cols in front */ scale != UMFPACK_SCALE_NONE, Symbolic->prefer_diagonal, ACTUAL) ; Info [UMFPACK_ALLOC_INIT_USED] = Numeric->alloc_init ; Info [UMFPACK_NUMERIC_DEFRAG] = Numeric->ngarbage ; Info [UMFPACK_NUMERIC_REALLOC] = Numeric->nrealloc ; Info [UMFPACK_NUMERIC_COSTLY_REALLOC] = Numeric->ncostly ; Info [UMFPACK_COMPRESSED_PATTERN] = Numeric->isize ; Info [UMFPACK_LU_ENTRIES] = Numeric->nLentries + Numeric->nUentries + Numeric->npiv ; Info [UMFPACK_UDIAG_NZ] = Numeric->nnzpiv ; Info [UMFPACK_RSMIN] = Numeric->rsmin ; Info [UMFPACK_RSMAX] = Numeric->rsmax ; Info [UMFPACK_WAS_SCALED] = Numeric->scale ; /* nz in L and U with no dropping of small entries */ Info [UMFPACK_ALL_LNZ] = Numeric->all_lnz + n_inner ; Info [UMFPACK_ALL_UNZ] = Numeric->all_unz + Numeric->nnzpiv ; Info [UMFPACK_NZDROPPED] = (Numeric->all_lnz - Numeric->lnz) + (Numeric->all_unz - Numeric->unz) ; /* estimate of the reciprocal of the condition number. */ if (SCALAR_IS_ZERO (Numeric->min_udiag) || SCALAR_IS_ZERO (Numeric->max_udiag) || SCALAR_IS_NAN (Numeric->min_udiag) || SCALAR_IS_NAN (Numeric->max_udiag)) { /* rcond is zero if there is any zero or NaN on the diagonal */ Numeric->rcond = 0.0 ; } else { /* estimate of the recipricol of the condition number. */ /* This is NaN if diagonal is zero-free, but has one or more NaN's. */ Numeric->rcond = Numeric->min_udiag / Numeric->max_udiag ; } Info [UMFPACK_UMIN] = Numeric->min_udiag ; Info [UMFPACK_UMAX] = Numeric->max_udiag ; Info [UMFPACK_RCOND] = Numeric->rcond ; if (Numeric->nnzpiv < n_inner || SCALAR_IS_ZERO (Numeric->rcond) || SCALAR_IS_NAN (Numeric->rcond)) { /* there are zeros and/or NaN's on the diagonal of U */ DEBUG0 (("Warning, matrix is singular in umfpack_numeric\n")) ; DEBUG0 (("nnzpiv "ID" n_inner "ID" rcond %g\n", Numeric->nnzpiv, n_inner, Numeric->rcond)) ; status = UMFPACK_WARNING_singular_matrix ; Info [UMFPACK_STATUS] = status ; } Numeric->valid = NUMERIC_VALID ; *NumericHandle = (void *) Numeric ; /* Numeric has 11 to 13 objects */ ASSERT (UMF_malloc_count == init_count + 11 + + (ulen > 0) /* Numeric->Upattern */ + (scale != UMFPACK_SCALE_NONE)) ; /* Numeric->Rs */ /* ---------------------------------------------------------------------- */ /* get the time used by UMFPACK_numeric */ /* ---------------------------------------------------------------------- */ umfpack_toc (stats) ; Info [UMFPACK_NUMERIC_WALLTIME] = stats [0] ; Info [UMFPACK_NUMERIC_TIME] = stats [1] ; /* return UMFPACK_OK or UMFPACK_WARNING_singular_matrix */ return (status) ; }
int main (int argc, char **argv) { int i, j, k, n, nz, *Ap, *Ai, *Ti, *Tj, status, *Pamd, nrow, ncol, rhs ; double *Ax, *b, *x, Control [UMFPACK_CONTROL], Info [UMFPACK_INFO], aij, *Tx, *r, amd_Control [AMD_CONTROL], amd_Info [AMD_INFO], tamd [2], stats [2], droptol ; void *Symbolic, *Numeric ; FILE *f, *f2 ; char s [SMAX] ; /* ---------------------------------------------------------------------- */ /* set controls */ /* ---------------------------------------------------------------------- */ printf ("\n===========================================================\n" "=== UMFPACK v%d.%d.%d ========================================\n" "===========================================================\n", UMFPACK_MAIN_VERSION, UMFPACK_SUB_VERSION, UMFPACK_SUBSUB_VERSION) ; umfpack_di_defaults (Control) ; Control [UMFPACK_PRL] = 3 ; Control [UMFPACK_BLOCK_SIZE] = 32 ; f = fopen ("tmp/control.umf4", "r") ; if (f != (FILE *) NULL) { printf ("Reading control file tmp/control.umf4\n") ; for (i = 0 ; i < UMFPACK_CONTROL ; i++) { fscanf (f, "%lg\n", & Control [i]) ; } fclose (f) ; } if (argc > 1) { char *t = argv [1] ; /* get the strategy */ if (t [0] == 'u') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_UNSYMMETRIC ; } else if (t [0] == 'a') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_AUTO ; } else if (t [0] == 's') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_SYMMETRIC ; } else if (t [0] == '2') { printf ("unrecognized strategy: %s\n", argv [1]) ; } else if (t [0] == 'U') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_UNSYMMETRIC ; Control [UMFPACK_SCALE] = UMFPACK_SCALE_MAX ; } else if (t [0] == 'A') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_AUTO ; Control [UMFPACK_SCALE] = UMFPACK_SCALE_MAX ; } else if (t [0] == 'S') { Control [UMFPACK_STRATEGY] = UMFPACK_STRATEGY_SYMMETRIC ; Control [UMFPACK_SCALE] = UMFPACK_SCALE_MAX ; } else if (t [0] == 'T') { printf ("unrecognized strategy: %s\n", argv [1]) ; } else { printf ("unrecognized strategy: %s\n", argv [1]) ; } if (t [1] == 'n') { /* no aggressive absorption */ Control [UMFPACK_AGGRESSIVE] = FALSE ; } } if (argc > 2) { /* get the drop tolerance */ sscanf (argv [2], "%lg", &droptol) ; printf ("droptol %g\n", droptol) ; Control [UMFPACK_DROPTOL] = droptol ; } umfpack_di_report_control (Control) ; /* ---------------------------------------------------------------------- */ /* open the matrix file (tmp/A) */ /* ---------------------------------------------------------------------- */ printf ("File: tmp/A\n") ; f = fopen ("tmp/A", "r") ; if (!f) { printf ("Unable to open file\n") ; exit (1) ; } /* ---------------------------------------------------------------------- */ /* get n and nz */ /* ---------------------------------------------------------------------- */ printf ("File: tmp/Asize\n") ; f2 = fopen ("tmp/Asize", "r") ; if (f2) { fscanf (f2, "%d %d %d\n", &nrow, &ncol, &nz) ; fclose (f2) ; } else { nrow = 1 ; ncol = 1 ; } nz = 0 ; while (fgets (s, SMAX, f) != (char *) NULL) { sscanf (s, "%d %d %lg", &i, &j, &aij) ; #ifdef ZERO_BASED /* matrix is zero based */ i++ ; j++ ; #endif nrow = MAX (nrow, i) ; ncol = MAX (ncol, j) ; nz++ ; } fclose (f) ; n = MAX (nrow, ncol) ; printf ("n %d nrow %d ncol %d nz %d\n", n, nrow, ncol, nz) ; /* ---------------------------------------------------------------------- */ /* allocate space for the input triplet form */ /* ---------------------------------------------------------------------- */ Ti = (int *) malloc (nz * sizeof (int)) ; Tj = (int *) malloc (nz * sizeof (int)) ; Tx = (double *) malloc (nz * sizeof (double)) ; if (!Ti || !Tj || !Tx) { printf ("out of memory for input matrix\n") ; exit (1) ; } /* ---------------------------------------------------------------------- */ /* read in the triplet form */ /* ---------------------------------------------------------------------- */ f2 = fopen ("tmp/A", "r") ; if (!f2) { printf ("Unable to open file\n") ; exit (1) ; } k = 0 ; while (fgets (s, SMAX, f2) != (char *) NULL) { sscanf (s, "%d %d %lg", &i, &j, &aij) ; #ifndef ZERO_BASED i-- ; /* convert to 0-based */ j-- ; #endif if (k >= nz) { printf ("Error! Matrix size is wrong\n") ; exit (1) ; } Ti [k] = i ; Tj [k] = j ; Tx [k] = aij ; k++ ; } fclose (f2) ; (void) umfpack_di_report_triplet (nrow, ncol, nz, Ti, Tj, Tx, Control) ; /* ---------------------------------------------------------------------- */ /* convert to column form */ /* ---------------------------------------------------------------------- */ /* convert to column form */ Ap = (int *) malloc ((n+1) * sizeof (int)) ; Ai = (int *) malloc (nz * sizeof (int)) ; Ax = (double *) malloc (nz * sizeof (double)) ; b = (double *) malloc (n * sizeof (double)) ; r = (double *) malloc (n * sizeof (double)) ; x = (double *) malloc (n * sizeof (double)) ; if (!Ap || !Ai || !Ax || !b || !r) { printf ("out of memory") ; exit (1) ; } umfpack_tic (stats) ; status = umfpack_di_triplet_to_col (nrow, ncol, nz, Ti, Tj, Tx, Ap, Ai, Ax, (int *) NULL) ; umfpack_toc (stats) ; printf ("triplet-to-col time: wall %g cpu %g\n", stats [0], stats [1]) ; if (status != UMFPACK_OK) { umfpack_di_report_status (Control, status) ; printf ("umfpack_di_triplet_to_col failed") ; exit (1) ; } /* print the column-form of A */ (void) umfpack_di_report_matrix (nrow, ncol, Ap, Ai, Ax, 1, Control) ; /* b = A * xtrue */ rhs = FALSE ; if (nrow == ncol) { f = fopen ("tmp/b", "r") ; if (f != (FILE *) NULL) { printf ("Reading tmp/b\n") ; rhs = TRUE ; for (i = 0 ; i < n ; i++) { fscanf (f, "%lg\n", &b [i]) ; } fclose (f) ; } else { Atimesx (n, Ap, Ai, Ax, b, FALSE) ; } } /* ---------------------------------------------------------------------- */ /* free the triplet form */ /* ---------------------------------------------------------------------- */ free (Ti) ; free (Tj) ; free (Tx) ; /* ---------------------------------------------------------------------- */ /* symbolic factorization */ /* ---------------------------------------------------------------------- */ status = umfpack_di_symbolic (nrow, ncol, Ap, Ai, Ax, &Symbolic, Control, Info) ; umfpack_di_report_info (Control, Info) ; if (status != UMFPACK_OK) { umfpack_di_report_status (Control, status) ; printf ("umfpack_di_symbolic failed") ; exit (1) ; } /* print the symbolic factorization */ (void) umfpack_di_report_symbolic (Symbolic, Control) ; /* ---------------------------------------------------------------------- */ /* numeric factorization */ /* ---------------------------------------------------------------------- */ status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); if (status < UMFPACK_OK) { umfpack_di_report_info (Control, Info) ; umfpack_di_report_status (Control, status) ; fprintf (stderr, "umfpack_di_numeric failed: %d\n", status) ; printf ("umfpack_di_numeric failed\n") ; exit (1) ; } /* print the numeric factorization */ (void) umfpack_di_report_numeric (Numeric, Control) ; /* ---------------------------------------------------------------------- */ /* solve Ax=b */ /* ---------------------------------------------------------------------- */ if (nrow == ncol && status == UMFPACK_OK) { status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, Control, Info) ; umfpack_di_report_info (Control, Info) ; umfpack_di_report_status (Control, status) ; if (status < UMFPACK_OK) { printf ("umfpack_di_solve failed\n") ; exit (1) ; } (void) umfpack_di_report_vector (n, x, Control) ; printf ("relative maxnorm of residual, ||Ax-b||/||b||: %g\n", resid (n, Ap, Ai, Ax, x, r, b, FALSE)) ; if (!rhs) { printf ("relative maxnorm of error, ||x-xtrue||/||xtrue||: %g\n\n", err (n, x)) ; } f = fopen ("tmp/x", "w") ; if (f != (FILE *) NULL) { printf ("Writing tmp/x\n") ; for (i = 0 ; i < n ; i++) { fprintf (f, "%30.20e\n", x [i]) ; } fclose (f) ; } else { printf ("Unable to write output x!\n") ; exit (1) ; } f = fopen ("tmp/info.umf4", "w") ; if (f != (FILE *) NULL) { printf ("Writing tmp/info.umf4\n") ; for (i = 0 ; i < UMFPACK_INFO ; i++) { fprintf (f, "%30.20e\n", Info [i]) ; } fclose (f) ; } else { printf ("Unable to write output info!\n") ; exit (1) ; } } else { /* don't solve, just report the results */ umfpack_di_report_info (Control, Info) ; umfpack_di_report_status (Control, status) ; } /* ---------------------------------------------------------------------- */ /* free the Symbolic and Numeric factorization */ /* ---------------------------------------------------------------------- */ umfpack_di_free_symbolic (&Symbolic) ; umfpack_di_free_numeric (&Numeric) ; printf ("umf4 done, strategy: %g\n", Control [UMFPACK_STRATEGY]) ; /* ---------------------------------------------------------------------- */ /* test just AMD ordering (not part of UMFPACK, but a separate test) */ /* ---------------------------------------------------------------------- */ /* first make the matrix square */ if (ncol < n) { for (j = ncol+1 ; j <= n ; j++) { Ap [j] = Ap [ncol] ; } } printf ( "\n\n===========================================================\n" "=== AMD ===================================================\n" "===========================================================\n") ; printf ("\n\n------- Now trying the AMD ordering. This not part of\n" "the UMFPACK analysis or factorization, above, but a separate\n" "test of just the AMD ordering routine.\n") ; Pamd = (int *) malloc (n * sizeof (int)) ; if (!Pamd) { printf ("out of memory\n") ; exit (1) ; } amd_defaults (amd_Control) ; amd_control (amd_Control) ; umfpack_tic (tamd) ; status = amd_order (n, Ap, Ai, Pamd, amd_Control, amd_Info) ; umfpack_toc (tamd) ; printf ("AMD ordering time: cpu %10.2f wall %10.2f\n", tamd [1], tamd [0]) ; if (status != AMD_OK) { printf ("amd failed: %d\n", status) ; exit (1) ; } amd_info (amd_Info) ; free (Pamd) ; printf ("AMD test done\n") ; free (Ap) ; free (Ai) ; free (Ax) ; free (b) ; free (r) ; free (x) ; return (0) ; }