1 /* ========================================================================== */
2 /* === UMF_set_stats ======================================================== */
3 /* ========================================================================== */
4 
5 /* -------------------------------------------------------------------------- */
6 /* UMFPACK Copyright (c) Timothy A. Davis, CISE,                              */
7 /* Univ. of Florida.  All Rights Reserved.  See ../Doc/License for License.   */
8 /* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
9 /* -------------------------------------------------------------------------- */
10 
11 /*
12     Sets statistics in Info array.  Calculates everything in double precision,
13     rather than Int or size_t, so that usage estimates can be computed even if
14     the problem is so large that it would cause integer overflow.
15 
16     This routine has many double relop's, but the NaN case is ignored.
17 */
18 
19 #include "umf_internal.h"
20 #include "umf_set_stats.h"
21 #include "umf_symbolic_usage.h"
22 
UMF_set_stats(double Info[],SymbolicType * Symbolic,double max_usage,double num_mem_size,double flops,double lnz,double unz,double maxfrsize,double ulen,double npiv,double maxnrows,double maxncols,Int scale,Int prefer_diagonal,Int what)23 GLOBAL void UMF_set_stats
24 (
25     double Info [ ],
26     SymbolicType *Symbolic,
27     double max_usage,		/* peak size of Numeric->Memory, in Units */
28     double num_mem_size,	/* final size of Numeric->Memory, in Units */
29     double flops,		/* "true flops" */
30     double lnz,			/* nz in L */
31     double unz,			/* nz in U */
32     double maxfrsize,		/* largest front size */
33     double ulen,		/* size of Numeric->Upattern */
34     double npiv,		/* number of pivots found */
35     double maxnrows,		/* largest #rows in front */
36     double maxncols,		/* largest #cols in front */
37     Int scale,			/* true if scaling the rows of A */
38     Int prefer_diagonal,	/* true if diagonal pivoting (only square A) */
39     Int what			/* ESTIMATE or ACTUAL */
40 )
41 {
42 
43     double sym_size, work_usage, nn, n_row, n_col, n_inner, num_On_size1,
44 	num_On_size2, num_usage, sym_maxncols, sym_maxnrows, elen, n1 ;
45 
46     n_col = Symbolic->n_col ;
47     n_row = Symbolic->n_row ;
48     n1 = Symbolic->n1 ;
49     nn = MAX (n_row, n_col) ;
50     n_inner = MIN (n_row, n_col) ;
51     sym_maxncols = MIN (Symbolic->maxncols + Symbolic->nb, n_col) ;
52     sym_maxnrows = MIN (Symbolic->maxnrows + Symbolic->nb, n_row) ;
53     elen = (n_col - n1) + (n_row - n1) + MIN (n_col - n1, n_row - n1) + 1 ;
54 
55     /* final Symbolic object size */
56     sym_size = UMF_symbolic_usage (Symbolic->n_row, Symbolic->n_col,
57 	Symbolic->nchains, Symbolic->nfr, Symbolic->esize, prefer_diagonal) ;
58 
59     /* size of O(n) part of Numeric object during factorization, */
60     /* except Numeric->Memory and Numeric->Upattern */
61     num_On_size1 =
62 	DUNITS (NumericType, 1)		/* Numeric structure */
63 	+ DUNITS (Entry, n_inner+1)	/* D */
64 	+ 4 * DUNITS (Int, n_row+1)	/* Rperm, Lpos, Uilen, Uip */
65 	+ 4 * DUNITS (Int, n_col+1)	/* Cperm, Upos, Lilen, Lip */
66 	+ (scale ? DUNITS (Entry, n_row) : 0) ;   /* Rs, row scale factors */
67 
68     /* size of O(n) part of Numeric object after factorization, */
69     /* except Numeric->Memory and Numeric->Upattern */
70     num_On_size2 =
71 	DUNITS (NumericType, 1)		/* Numeric structure */
72 	+ DUNITS (Entry, n_inner+1)	/* D */
73 	+ DUNITS (Int, n_row+1)		/* Rperm */
74 	+ DUNITS (Int, n_col+1)		/* Cperm */
75 	+ 6 * DUNITS (Int, npiv+1)	/* Lpos, Uilen, Uip, Upos, Lilen, Lip */
76 	+ (scale ? DUNITS (Entry, n_row) : 0) ;	    /* Rs, row scale factors */
77 
78     DEBUG1 (("num O(n) size2: %g\n", num_On_size2)) ;
79 
80     /* peak size of Numeric->Memory, including LU factors, current frontal
81      * matrix, elements, and tuple lists.  */
82     Info [UMFPACK_VARIABLE_PEAK + what] = max_usage ;
83 
84     /* final size of Numeric->Memory (LU factors only) */
85     Info [UMFPACK_VARIABLE_FINAL + what] = num_mem_size ;
86 
87     /* final size of Numeric object, including Numeric->Memory and ->Upattern */
88     Info [UMFPACK_NUMERIC_SIZE + what] =
89 	num_On_size2
90 	+ num_mem_size		/* final Numeric->Memory size */
91 	+ DUNITS (Int, ulen+1) ;/* Numeric->Upattern (from Work->Upattern) */
92 
93     DEBUG1 (("num mem size: %g\n", num_mem_size)) ;
94     DEBUG1 (("ulen units %g\n", DUNITS (Int, ulen))) ;
95     DEBUG1 (("numeric size %g\n", Info [UMFPACK_NUMERIC_SIZE + what])) ;
96 
97     /* largest front size (working array size, or actual size used) */
98     Info [UMFPACK_MAX_FRONT_SIZE + what] = maxfrsize ;
99     Info [UMFPACK_MAX_FRONT_NROWS + what] = maxnrows ;
100     Info [UMFPACK_MAX_FRONT_NCOLS + what] = maxncols ;
101     DEBUGm4 (("maxnrows %g maxncols %g\n", maxnrows, maxncols)) ;
102     DEBUGm4 (("maxfrsize %g\n", maxfrsize)) ;
103 
104     /* UMF_kernel usage, from work_alloc routine in umf_kernel.c */
105     work_usage =
106 	/* Work-> arrays, except for current frontal matrix which is allocated
107 	 * inside Numeric->Memory. */
108 	2 * DUNITS (Entry, sym_maxnrows + 1)	/* Wx, Wy */
109 	+ 2 * DUNITS (Int, n_row+1)		/* Frpos, Lpattern */
110 	+ 2 * DUNITS (Int, n_col+1)		/* Fcpos, Upattern */
111 	+ DUNITS (Int, nn + 1)			/* Wp */
112 	+ DUNITS (Int, MAX (n_col, sym_maxnrows) + 1)	/* Wrp */
113 	+ 2 * DUNITS (Int, sym_maxnrows + 1)	/* Frows, Wm */
114 	+ 3 * DUNITS (Int, sym_maxncols + 1)	/* Fcols, Wio, Woi */
115 	+ DUNITS (Int, MAX (sym_maxnrows, sym_maxncols) + 1)	/* Woo */
116 	+ DUNITS (Int, elen)			/* E */
117 	+ DUNITS (Int, Symbolic->nfr + 1)	/* Front_new1strow */
118 	+ ((n_row == n_col) ? (2 * DUNITS (Int, nn)) : 0) ;  /* Diag map,imap */
119 
120     /* Peak memory for just UMFPACK_numeric. */
121     num_usage =
122 	sym_size	/* size of Symbolic object */
123 	+ num_On_size1	/* O(n) part of Numeric object (excl. Upattern) */
124 	+ work_usage	/* Work-> arrays (including Upattern) */
125 	+ max_usage ;	/* peak size of Numeric->Memory */
126 
127     /* peak memory usage for both UMFPACK_*symbolic and UMFPACK_numeric. */
128     Info [UMFPACK_PEAK_MEMORY + what] =
129 	MAX (Symbolic->peak_sym_usage, num_usage) ;
130 
131     Info [UMFPACK_FLOPS + what] = flops ;
132     Info [UMFPACK_LNZ + what] = lnz ;
133     Info [UMFPACK_UNZ + what] = unz ;
134 }
135