umfpack_report_numeric.c
16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/* ========================================================================== */
/* === UMFPACK_report_numeric =============================================== */
/* ========================================================================== */
/* -------------------------------------------------------------------------- */
/* UMFPACK Copyright (c) Timothy A. Davis, CISE, */
/* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
/* -------------------------------------------------------------------------- */
/*
User-callable. Prints the Numeric object.
See umfpack_report_numeric.h for details.
Dynamic memory usage: Allocates a size n*sizeof(Int) workspace via a single
call to UMF_malloc and then frees all of it via UMF_free on return. The
workspace is not allocated if an early error return occurs before the
workspace is needed.
*/
#include "umf_internal.h"
#include "umf_valid_numeric.h"
#include "umf_report_perm.h"
#include "umf_report_vector.h"
#include "umf_malloc.h"
#include "umf_free.h"
PRIVATE Int report_L
(
NumericType *Numeric,
Int Pattern [ ],
Int prl
) ;
PRIVATE Int report_U
(
NumericType *Numeric,
Int Pattern [ ],
Int prl
) ;
/* ========================================================================== */
/* === UMFPACK_report_numeric =============================================== */
/* ========================================================================== */
GLOBAL Int UMFPACK_report_numeric
(
void *NumericHandle,
const double Control [UMFPACK_CONTROL]
)
{
Int prl, *W, nn, n_row, n_col, n_inner, num_fixed_size, numeric_size,
npiv ;
NumericType *Numeric ;
prl = GET_CONTROL (UMFPACK_PRL, UMFPACK_DEFAULT_PRL) ;
if (prl <= 2)
{
return (UMFPACK_OK) ;
}
PRINTF (("Numeric object: ")) ;
Numeric = (NumericType *) NumericHandle ;
if (!UMF_valid_numeric (Numeric))
{
PRINTF (("ERROR: LU factors invalid\n\n")) ;
return (UMFPACK_ERROR_invalid_Numeric_object) ;
}
n_row = Numeric->n_row ;
n_col = Numeric->n_col ;
nn = MAX (n_row, n_col) ;
n_inner = MIN (n_row, n_col) ;
npiv = Numeric->npiv ;
DEBUG1 (("n_row "ID" n_col "ID" nn "ID" n_inner "ID" npiv "ID"\n",
n_row, n_col, nn, n_inner, npiv)) ;
/* size of Numeric object, except Numeric->Memory and Numeric->Upattern */
/* see also UMF_set_stats */
num_fixed_size =
UNITS (NumericType, 1) /* Numeric structure */
+ UNITS (Entry, n_inner+1) /* D */
+ UNITS (Int, n_row+1) /* Rperm */
+ UNITS (Int, n_col+1) /* Cperm */
+ 6 * UNITS (Int, npiv+1) /* Lpos, Uilen, Uip, Upos, Lilen, Lip */
+ ((Numeric->scale != UMFPACK_SCALE_NONE) ?
UNITS (Entry, n_row) : 0) ; /* Rs */
DEBUG1 (("num fixed size: "ID"\n", num_fixed_size)) ;
DEBUG1 (("Numeric->size "ID"\n", Numeric->size)) ;
DEBUG1 (("ulen units "ID"\n", UNITS (Int, Numeric->ulen))) ;
/* size of Numeric->Memory is Numeric->size */
/* size of Numeric->Upattern is Numeric->ulen */
numeric_size = num_fixed_size + Numeric->size
+ UNITS (Int, Numeric->ulen) ;
DEBUG1 (("numeric total size "ID"\n", numeric_size)) ;
if (prl >= 4)
{
PRINTF (("\n n_row: "ID" n_col: "ID"\n", n_row, n_col)) ;
PRINTF ((" relative pivot tolerance used: %g\n",
Numeric->relpt)) ;
PRINTF ((" relative symmetric pivot tolerance used: %g\n",
Numeric->relpt2)) ;
PRINTF ((" matrix scaled: ")) ;
if (Numeric->scale == UMFPACK_SCALE_NONE)
{
PRINTF (("no")) ;
}
else if (Numeric->scale == UMFPACK_SCALE_SUM)
{
PRINTF (("yes (divided each row by sum abs value in each row)\n")) ;
PRINTF ((" minimum sum (abs (rows of A)): %.5e\n",
Numeric->rsmin)) ;
PRINTF ((" maximum sum (abs (rows of A)): %.5e",
Numeric->rsmax)) ;
}
else if (Numeric->scale == UMFPACK_SCALE_MAX)
{
PRINTF (("yes (divided each row by max abs value in each row)\n")) ;
PRINTF ((" minimum max (abs (rows of A)): %.5e\n",
Numeric->rsmin)) ;
PRINTF ((" maximum max (abs (rows of A)): %.5e",
Numeric->rsmax)) ;
}
PRINTF (("\n")) ;
PRINTF ((" initial allocation parameter used: %g\n",
Numeric->alloc_init)) ;
PRINTF ((" frontal matrix allocation parameter used: %g\n",
Numeric->front_alloc_init)) ;
PRINTF ((" final total size of Numeric object (Units): "ID"\n",
numeric_size)) ;
PRINTF ((" final total size of Numeric object (MBytes): %.1f\n",
MBYTES (numeric_size))) ;
PRINTF ((" peak size of variable-size part (Units): "ID"\n",
Numeric->max_usage)) ;
PRINTF ((" peak size of variable-size part (MBytes): %.1f\n",
MBYTES (Numeric->max_usage))) ;
PRINTF ((" largest actual frontal matrix size: "ID"\n",
Numeric->maxfrsize)) ;
PRINTF ((" memory defragmentations: "ID"\n",
Numeric->ngarbage)) ;
PRINTF ((" memory reallocations: "ID"\n",
Numeric->nrealloc)) ;
PRINTF ((" costly memory reallocations: "ID"\n",
Numeric->ncostly)) ;
PRINTF ((" entries in compressed pattern (L and U): "ID"\n",
Numeric->isize)) ;
PRINTF ((" number of nonzeros in L (excl diag): "ID"\n",
Numeric->lnz)) ;
PRINTF ((" number of entries stored in L (excl diag): "ID"\n",
Numeric->nLentries)) ;
PRINTF ((" number of nonzeros in U (excl diag): "ID"\n",
Numeric->unz)) ;
PRINTF ((" number of entries stored in U (excl diag): "ID"\n",
Numeric->nUentries)) ;
PRINTF ((" factorization floating-point operations: %g\n",
Numeric->flops)) ;
PRINTF ((" number of nonzeros on diagonal of U: "ID"\n",
Numeric->nnzpiv)) ;
PRINTF ((" min abs. value on diagonal of U: %.5e\n",
Numeric->min_udiag)) ;
PRINTF ((" max abs. value on diagonal of U: %.5e\n",
Numeric->max_udiag)) ;
PRINTF ((" reciprocal condition number estimate: %.2e\n",
Numeric->rcond)) ;
}
W = (Int *) UMF_malloc (nn, sizeof (Int)) ;
if (!W)
{
PRINTF ((" ERROR: out of memory to check Numeric object\n\n")) ;
return (UMFPACK_ERROR_out_of_memory) ;
}
if (Numeric->Rs)
{
#ifndef NRECIPROCAL
if (Numeric->do_recip)
{
PRINTF4 (("\nScale factors applied via multiplication\n")) ;
}
else
#endif
{
PRINTF4 (("\nScale factors applied via division\n")) ;
}
PRINTF4 (("Scale factors, Rs: ")) ;
(void) UMF_report_vector (n_row, Numeric->Rs, (double *) NULL,
prl, FALSE, TRUE) ;
}
else
{
PRINTF4 (("Scale factors, Rs: (not present)\n")) ;
}
PRINTF4 (("\nP: row ")) ;
if (UMF_report_perm (n_row, Numeric->Rperm, W, prl, 0) != UMFPACK_OK)
{
(void) UMF_free ((void *) W) ;
return (UMFPACK_ERROR_invalid_Numeric_object) ;
}
PRINTF4 (("\nQ: column ")) ;
if (UMF_report_perm (n_col, Numeric->Cperm, W, prl, 0) != UMFPACK_OK)
{
(void) UMF_free ((void *) W) ;
return (UMFPACK_ERROR_invalid_Numeric_object) ;
}
if (!report_L (Numeric, W, prl))
{
(void) UMF_free ((void *) W) ;
PRINTF ((" ERROR: L factor invalid\n\n")) ;
return (UMFPACK_ERROR_invalid_Numeric_object) ;
}
if (!report_U (Numeric, W, prl))
{
(void) UMF_free ((void *) W) ;
PRINTF ((" ERROR: U factor invalid\n\n")) ;
return (UMFPACK_ERROR_invalid_Numeric_object) ;
}
/* The diagonal of U is in "merged" (Entry) form, not "split" form. */
PRINTF4 (("\ndiagonal of U: ")) ;
(void) UMF_report_vector (n_inner, (double *) Numeric->D, (double *) NULL,
prl, FALSE, FALSE) ;
(void) UMF_free ((void *) W) ;
PRINTF4 ((" Numeric object: ")) ;
PRINTF (("OK\n\n")) ;
return (UMFPACK_OK) ;
}
/* ========================================================================== */
/* === report_L ============================================================= */
/* ========================================================================== */
PRIVATE Int report_L
(
NumericType *Numeric,
Int Pattern [ ],
Int prl
)
{
Int k, deg, *ip, j, row, n_row, *Lpos, *Lilen, valid, k1,
*Lip, newLchain, llen, prl1, pos, lp, p, npiv, n1, *Li ;
Entry *xp, *Lval ;
/* ---------------------------------------------------------------------- */
ASSERT (prl >= 3) ;
n_row = Numeric->n_row ;
npiv = Numeric->npiv ;
n1 = Numeric->n1 ;
Lpos = Numeric->Lpos ;
Lilen = Numeric->Lilen ;
Lip = Numeric->Lip ;
prl1 = prl ;
deg = 0 ;
PRINTF4 ((
"\nL in Numeric object, in column-oriented compressed-pattern form:\n"
" Diagonal entries are all equal to 1.0 (not stored)\n")) ;
ASSERT (Pattern != (Int *) NULL) ;
/* ---------------------------------------------------------------------- */
/* print L */
/* ---------------------------------------------------------------------- */
k1 = 12 ;
/* ---------------------------------------------------------------------- */
/* print the singleton columns of L */
/* ---------------------------------------------------------------------- */
for (k = 0 ; k < n1 ; k++)
{
if (k1 > 0)
{
prl = prl1 ;
}
lp = Lip [k] ;
deg = Lilen [k] ;
Li = (Int *) (Numeric->Memory + lp) ;
lp += UNITS (Int, deg) ;
Lval = (Entry *) (Numeric->Memory + lp) ;
if (k1-- > 0)
{
prl = prl1 ;
}
else if (prl == 4)
{
PRINTF ((" ...\n")) ;
prl-- ;
}
PRINTF4 (("\n column "ID":", INDEX (k))) ;
PRINTF4 ((" length "ID".\n", deg)) ;
for (j = 0 ; j < deg ; j++)
{
row = Li [j] ;
PRINTF4 (("\trow "ID" : ", INDEX (row))) ;
if (prl >= 4) PRINT_ENTRY (Lval [j]) ;
if (row <= k || row >= n_row)
{
return (FALSE) ;
}
PRINTF4 (("\n")) ;
/* truncate printout, but continue to check L */
if (prl == 4 && j == 9 && deg > 10)
{
PRINTF (("\t...\n")) ;
prl-- ;
}
}
}
/* ---------------------------------------------------------------------- */
/* print the regular columns of L */
/* ---------------------------------------------------------------------- */
for (k = n1 ; k < npiv ; k++)
{
/* if prl is 4, print the first 10 entries of the first 10 columns */
if (k1 > 0)
{
prl = prl1 ;
}
lp = Lip [k] ;
newLchain = (lp < 0) ;
if (newLchain)
{
lp = -lp ;
deg = 0 ;
}
if (k1-- > 0)
{
prl = prl1 ;
}
else if (prl == 4)
{
PRINTF ((" ...\n")) ;
prl-- ;
}
PRINTF4 (("\n column "ID":", INDEX (k))) ;
/* ------------------------------------------------------------------ */
/* make column of L in Pattern [0..deg-1] */
/* ------------------------------------------------------------------ */
/* remove pivot row */
pos = Lpos [k] ;
if (pos != EMPTY)
{
PRINTF4 ((" remove row "ID" at position "ID".",
INDEX (Pattern [pos]), INDEX (pos))) ;
valid = (!newLchain) && (deg > 0) && (pos < deg) && (pos >= 0)
&& (Pattern [pos] == k) ;
if (!valid)
{
return (FALSE) ;
}
Pattern [pos] = Pattern [--deg] ;
}
/* concatenate the pattern */
llen = Lilen [k] ;
if (llen < 0)
{
return (FALSE) ;
}
p = lp + UNITS (Int, llen) ;
xp = (Entry *) (Numeric->Memory + p) ;
if ((llen > 0 || deg > 0)
&& (p + (Int) UNITS (Entry, deg) > Numeric->size))
{
return (FALSE) ;
}
if (llen > 0)
{
PRINTF4 ((" add "ID" entries.", llen)) ;
ip = (Int *) (Numeric->Memory + lp) ;
for (j = 0 ; j < llen ; j++)
{
Pattern [deg++] = *ip++ ;
}
}
/* ------------------------------------------------------------------ */
/* print column k of L */
/* ------------------------------------------------------------------ */
PRINTF4 ((" length "ID".", deg)) ;
if (newLchain)
{
PRINTF4 ((" Start of Lchain.")) ;
}
PRINTF4 (("\n")) ;
for (j = 0 ; j < deg ; j++)
{
row = Pattern [j] ;
PRINTF4 (("\trow "ID" : ", INDEX (row))) ;
if (prl >= 4) PRINT_ENTRY (*xp) ;
if (row <= k || row >= n_row)
{
return (FALSE) ;
}
PRINTF4 (("\n")) ;
xp++ ;
/* truncate printout, but continue to check L */
if (prl == 4 && j == 9 && deg > 10)
{
PRINTF (("\t...\n")) ;
prl-- ;
}
}
}
PRINTF4 (("\n")) ;
return (TRUE) ;
}
/* ========================================================================== */
/* === report_U ============================================================= */
/* ========================================================================== */
PRIVATE Int report_U
(
NumericType *Numeric,
Int Pattern [ ],
Int prl
)
{
/* ---------------------------------------------------------------------- */
Int k, deg, j, *ip, col, *Upos, *Uilen, k1, prl1, pos,
*Uip, n_col, ulen, p, newUchain, up, npiv, n1, *Ui ;
Entry *xp, *Uval ;
/* ---------------------------------------------------------------------- */
ASSERT (prl >= 3) ;
n_col = Numeric->n_col ;
npiv = Numeric->npiv ;
n1 = Numeric->n1 ;
Upos = Numeric->Upos ;
Uilen = Numeric->Uilen ;
Uip = Numeric->Uip ;
prl1 = prl ;
PRINTF4 ((
"\nU in Numeric object, in row-oriented compressed-pattern form:\n"
" Diagonal is stored separately.\n")) ;
ASSERT (Pattern != (Int *) NULL) ;
k1 = 12 ;
/* ---------------------------------------------------------------------- */
/* print the sparse part of U */
/* ---------------------------------------------------------------------- */
deg = Numeric->ulen ;
if (deg > 0)
{
/* make last pivot row of U (singular matrices only) */
for (j = 0 ; j < deg ; j++)
{
Pattern [j] = Numeric->Upattern [j] ;
}
}
PRINTF4 (("\n row "ID": length "ID". End of Uchain.\n", INDEX (npiv-1),
deg)) ;
for (k = npiv-1 ; k >= n1 ; k--)
{
/* ------------------------------------------------------------------ */
/* print row k of U */
/* ------------------------------------------------------------------ */
/* if prl is 3, print the first 10 entries of the first 10 columns */
if (k1 > 0)
{
prl = prl1 ;
}
up = Uip [k] ;
ulen = Uilen [k] ;
if (ulen < 0)
{
return (FALSE) ;
}
newUchain = (up < 0) ;
if (newUchain)
{
up = -up ;
p = up + UNITS (Int, ulen) ;
}
else
{
p = up ;
}
xp = (Entry *) (Numeric->Memory + p) ;
if (deg > 0 && (p + (Int) UNITS (Entry, deg) > Numeric->size))
{
return (FALSE) ;
}
for (j = 0 ; j < deg ; j++)
{
col = Pattern [j] ;
PRINTF4 (("\tcol "ID" :", INDEX (col))) ;
if (prl >= 4) PRINT_ENTRY (*xp) ;
if (col <= k || col >= n_col)
{
return (FALSE) ;
}
PRINTF4 (("\n")) ;
xp++ ;
/* truncate printout, but continue to check U */
if (prl == 4 && j == 9 && deg > 10)
{
PRINTF (("\t...\n")) ;
prl-- ;
}
}
/* ------------------------------------------------------------------ */
/* make row k-1 of U in Pattern [0..deg-1] */
/* ------------------------------------------------------------------ */
if (k1-- > 0)
{
prl = prl1 ;
}
else if (prl == 4)
{
PRINTF ((" ...\n")) ;
prl-- ;
}
if (k > 0)
{
PRINTF4 (("\n row "ID": ", INDEX (k-1))) ;
}
if (newUchain)
{
/* next row is a new Uchain */
if (k > 0)
{
deg = ulen ;
PRINTF4 (("length "ID". End of Uchain.\n", deg)) ;
if (up + (Int) UNITS (Int, ulen) > Numeric->size)
{
return (FALSE) ;
}
ip = (Int *) (Numeric->Memory + up) ;
for (j = 0 ; j < deg ; j++)
{
Pattern [j] = *ip++ ;
}
}
}
else
{
if (ulen > 0)
{
PRINTF4 (("remove "ID" entries. ", ulen)) ;
}
deg -= ulen ;
if (deg < 0)
{
return (FALSE) ;
}
pos = Upos [k] ;
if (pos != EMPTY)
{
/* add the pivot column */
PRINTF4 (("add column "ID" at position "ID". ",
INDEX (k), INDEX (pos))) ;
if (pos < 0 || pos > deg)
{
return (FALSE) ;
}
Pattern [deg++] = Pattern [pos] ;
Pattern [pos] = k ;
}
PRINTF4 (("length "ID".\n", deg)) ;
}
}
/* ---------------------------------------------------------------------- */
/* print the singleton rows of U */
/* ---------------------------------------------------------------------- */
for (k = n1 - 1 ; k >= 0 ; k--)
{
if (k1 > 0)
{
prl = prl1 ;
}
up = Uip [k] ;
deg = Uilen [k] ;
Ui = (Int *) (Numeric->Memory + up) ;
up += UNITS (Int, deg) ;
Uval = (Entry *) (Numeric->Memory + up) ;
if (k1-- > 0)
{
prl = prl1 ;
}
else if (prl == 4)
{
PRINTF ((" ...\n")) ;
prl-- ;
}
PRINTF4 (("\n row "ID":", INDEX (k))) ;
PRINTF4 ((" length "ID".\n", deg)) ;
for (j = 0 ; j < deg ; j++)
{
col = Ui [j] ;
PRINTF4 (("\tcol "ID" : ", INDEX (col))) ;
if (prl >= 4) PRINT_ENTRY (Uval [j]) ;
if (col <= k || col >= n_col)
{
return (FALSE) ;
}
PRINTF4 (("\n")) ;
/* truncate printout, but continue to check U */
if (prl == 4 && j == 9 && deg > 10)
{
PRINTF (("\t...\n")) ;
prl-- ;
}
}
}
prl = prl1 ;
PRINTF4 (("\n")) ;
return (TRUE) ;
}