33 Int *
P, *Q, *R, *Pnum, *Offp, *Offi, *Pblock, *Pinv, *Iwork,
34 *Lip, *Uip, *Llen, *Ulen ;
35 Entry *Offx, *X, s, *Udiag ;
37 Int k1, k2, nk, k, block, oldcol, pend, oldrow,
n, lnz, unz, p, newrow,
38 nblocks, poff, nzoff, lnz_block, unz_block,
scale, max_lnz_block,
51 nblocks = Symbolic->nblocks ;
52 nzoff = Symbolic->nzoff ;
54 Pnum = Numeric->Pnum ;
55 Offp = Numeric->Offp ;
56 Offi = Numeric->Offi ;
57 Offx = (
Entry *) Numeric->Offx ;
61 Llen = Numeric->Llen ;
62 Ulen = Numeric->Ulen ;
63 LUbx = (
Unit **) Numeric->LUbx ;
64 Udiag = Numeric->Udiag ;
67 Pinv = Numeric->Pinv ;
68 X = (
Entry *) Numeric->Xwork ;
69 Iwork = Numeric->Iwork ;
71 Pblock = Iwork + 5*((
size_t) Symbolic->maxblock) ;
72 Common->nrealloc = 0 ;
73 scale = Common->scale ;
81 for (k = 0 ; k < n ; k++)
86 for (k = 0 ; k < n ; k++)
88 ASSERT (P [k] >= 0 && P [k] < n) ;
92 for (k = 0 ; k < n ; k++)
ASSERT (Pinv [k] !=
EMPTY) ;
97 Common->noffdiag = 0 ;
113 KLU_scale (scale, n, Ap, Ai, (
double *) Ax, Rs, Pnum, Common) ;
114 if (Common->status <
KLU_OK)
124 for (k = 0 ; k < n ; k++)
PRINTF ((
"Rs [%d] %g\n", k, Rs [k])) ;
132 for (block = 0 ; block < nblocks ; block++)
142 PRINTF ((
"FACTOR BLOCK %d, k1 %d k2-1 %d nk %d\n", block, k1,k2-1,nk)) ;
153 pend = Ap [oldcol+1] ;
159 for (p = Ap [oldcol] ; p < pend ; p++)
162 newrow = Pinv [oldrow] ;
165 Offi [poff] = oldrow ;
166 Offx [poff] = Ax [p] ;
172 PRINTF ((
"singleton block %d", block)) ;
185 for (p = Ap [oldcol] ; p < pend ; p++)
188 newrow = Pinv [oldrow] ;
191 Offi [poff] = oldrow ;
199 PRINTF ((
"singleton block %d ", block)) ;
212 Common->numerical_rank = k1 ;
213 Common->singular_col = oldcol ;
214 if (Common->halt_if_singular)
237 lsize = -(Common->initmem) ;
241 lsize = Common->initmem_amd * Lnz [block] + nk ;
246 lsize, &LUbx [block], Udiag + k1, Llen + k1, Ulen + k1,
247 Lip + k1, Uip + k1, Pblock, &lnz_block, &unz_block,
248 X, Iwork, k1, Pinv, Rs, Offp, Offi, Offx, Common) ;
250 if (Common->status <
KLU_OK ||
251 (Common->status ==
KLU_SINGULAR && Common->halt_if_singular))
257 PRINTF ((
"\n----------------------- L %d:\n", block)) ;
259 PRINTF ((
"\n----------------------- U %d:\n", block)) ;
268 max_lnz_block =
MAX (max_lnz_block, lnz_block) ;
269 max_unz_block =
MAX (max_unz_block, unz_block) ;
271 if (Lnz [block] ==
EMPTY)
274 Lnz [block] =
MAX (lnz_block, unz_block) ;
281 PRINTF ((
"Pnum, 1-based:\n")) ;
282 for (k = 0 ; k < nk ; k++)
285 ASSERT (Pblock [k] + k1 < n) ;
286 Pnum [k + k1] = P [Pblock [k] + k1] ;
287 PRINTF ((
"Pnum (%d + %d + 1 = %d) = %d + 1 = %d\n",
288 k, k1, k+k1+1, Pnum [k+k1], Pnum [k+k1]+1)) ;
294 ASSERT (nzoff == Offp [n]) ;
295 PRINTF ((
"\n------------------- Off diagonal entries:\n")) ;
300 Numeric->max_lnz_block = max_lnz_block ;
301 Numeric->max_unz_block = max_unz_block ;
305 for (k = 0 ; k < n ; k++)
310 for (k = 0 ; k < n ; k++)
312 ASSERT (Pnum [k] >= 0 && Pnum [k] < n) ;
313 Pinv [Pnum [k]] = k ;
316 for (k = 0 ; k < n ; k++)
ASSERT (Pinv [k] !=
EMPTY) ;
322 for (k = 0 ; k < n ; k++)
324 REAL (X [k]) = Rs [Pnum [k]] ;
326 for (k = 0 ; k < n ; k++)
328 Rs [k] =
REAL (X [k]) ;
332 PRINTF ((
"\n------------------- Off diagonal entries, old:\n")) ;
336 for (p = 0 ; p < nzoff ; p++)
338 ASSERT (Offi [p] >= 0 && Offi [p] < n) ;
339 Offi [p] = Pinv [Offi [p]] ;
342 PRINTF ((
"\n------------------- Off diagonal entries, new:\n")) ;
347 PRINTF ((
"\n ############# KLU_BTF_FACTOR done, nblocks %d\n",nblocks));
348 Entry ss, *Udiag = Numeric->Udiag ;
349 for (block = 0 ; block < nblocks && Common->status ==
KLU_OK ; block++)
354 PRINTF ((
"\n======================KLU_factor output: k1 %d k2 %d nk %d\n",k1,k2,nk)) ;
364 Int *Lip, *Uip, *Llen, *Ulen ;
366 Lip = Numeric->Lip + k1 ;
367 Llen = Numeric->Llen + k1 ;
368 LU = (
Unit *) Numeric->LUbx [block] ;
369 PRINTF ((
"\n---- L block %d\n", block));
371 Uip = Numeric->Uip + k1 ;
372 Ulen = Numeric->Ulen + k1 ;
373 PRINTF ((
"\n---- U block %d\n", block)) ;
399 Int n, nzoff, nblocks, maxblock, k, ok =
TRUE ;
402 size_t n1, nzoff1, s, b6, n3 ;
409 Common->numerical_rank =
EMPTY ;
410 Common->singular_col =
EMPTY ;
417 if (Symbolic ==
NULL)
424 nzoff = Symbolic->nzoff ;
425 nblocks = Symbolic->nblocks ;
426 maxblock = Symbolic->maxblock ;
428 PRINTF ((
"KLU_factor: n %d nzoff %d nblocks %d maxblock %d\n",
429 n, nzoff, nblocks, maxblock)) ;
435 Common->initmem_amd =
MAX (1.0, Common->initmem_amd) ;
436 Common->initmem =
MAX (1.0, Common->initmem) ;
437 Common->tol =
MIN (Common->tol, 1.0) ;
438 Common->tol =
MAX (0.0, Common->tol) ;
439 Common->memgrow =
MAX (1.0, Common->memgrow) ;
446 n1 = ((size_t) n) + 1 ;
447 nzoff1 = ((size_t) nzoff) + 1 ;
450 if (Common->status <
KLU_OK)
457 Numeric->nblocks = nblocks ;
458 Numeric->nzoff = nzoff ;
469 Numeric->LUsize =
KLU_malloc (nblocks,
sizeof (
size_t), Common) ;
472 if (Numeric->LUbx !=
NULL)
474 for (k = 0 ; k < nblocks ; k++)
476 Numeric->LUbx [k] =
NULL ;
482 if (Common->scale > 0)
484 Numeric->Rs =
KLU_malloc (n,
sizeof (
double), Common) ;
505 Numeric->Work =
KLU_malloc (Numeric->worksize, 1, Common) ;
506 Numeric->Xwork = Numeric->Work ;
507 Numeric->Iwork = (
Int *) ((
Entry *) Numeric->Xwork + n) ;
508 if (!ok || Common->status <
KLU_OK)
520 factor2 (Ap, Ai, (
Entry *) Ax, Symbolic, Numeric, Common) ;
526 if (Common->status <
KLU_OK)
533 if (Common->halt_if_singular)
541 else if (Common->status ==
KLU_OK)
544 Common->numerical_rank = n ;
545 Common->singular_col = n ;
#define KLU_kernel_factor
KLU_numeric * KLU_factor(Int Ap[], Int Ai[], double Ax[], KLU_symbolic *Symbolic, KLU_common *Common)
#define KLU_OUT_OF_MEMORY
#define ASSERT(expression)
#define SCALE_DIV_ASSIGN(a, c, s)
static void factor2(Int Ap[], Int Ai[], Entry Ax[], KLU_symbolic *Symbolic, KLU_numeric *Numeric, KLU_common *Common)