17 #ifndef KLU2_ANALYZE_HPP
18 #define KLU2_ANALYZE_HPP
20 #include "klu2_internal.h"
21 #include "klu2_analyze_given.hpp"
22 #include "klu2_memory.hpp"
28 template <
typename Entry,
typename Int>
29 static Int analyze_worker
54 KLU_symbolic<Entry, Int> *Symbolic,
55 KLU_common<Entry, Int> *Common
58 double amd_Info [TRILINOS_AMD_INFO], lnz, lnz1, flops, flops1 ;
59 Int k1, k2, nk, k, block, oldcol, pend, newcol, result, pc, p, newrow,
60 maxnz, nzoff, cstats [TRILINOS_COLAMD_STATS], ok, err = KLU_INVALID ;
65 for (k = 0 ; k < TRILINOS_AMD_INFO ; k++)
72 for (k = 0 ; k < n ; k++)
74 P [k] = AMESOS2_KLU2_EMPTY ;
75 Q [k] = AMESOS2_KLU2_EMPTY ;
76 Pinv [k] = AMESOS2_KLU2_EMPTY ;
79 for (k = 0 ; k < n ; k++)
81 ASSERT (Pbtf [k] >= 0 && Pbtf [k] < n) ;
85 for (k = 0 ; k < n ; k++) ASSERT (Pinv [k] != AMESOS2_KLU2_EMPTY) ;
91 Symbolic->symmetry = AMESOS2_KLU2_EMPTY ;
97 for (block = 0 ; block < nblocks ; block++)
107 PRINTF ((
"BLOCK %d, k1 %d k2-1 %d nk %d\n", block, k1, k2-1, nk)) ;
113 Lnz [block] = AMESOS2_KLU2_EMPTY ;
115 for (k = k1 ; k < k2 ; k++)
120 pend =
Ap [oldcol+1] ;
121 for (p =
Ap [oldcol] ; p < pend ; p++)
123 newrow = Pinv [
Ai [p]] ;
131 ASSERT (newrow < k2) ;
138 maxnz = MAX (maxnz, pc) ;
139 ASSERT (KLU_valid (nk, Cp, Ci, NULL)) ;
152 for (k = 0 ; k < nk ; k++)
156 lnz1 = nk * (nk + 1) / 2 ;
157 flops1 = nk * (nk - 1) / 2 + (nk-1)*nk*(2*nk-1) / 6 ;
161 else if (ordering == 0)
169 result = KLU_OrdinalTraits<Int>::amd_order (nk, Cp, Ci, Pblk,
171 ok = (result >= TRILINOS_AMD_OK) ;
172 if (result == TRILINOS_AMD_OUT_OF_MEMORY)
174 err = KLU_OUT_OF_MEMORY ;
178 Common->mempeak = ( size_t) (MAX (Common->mempeak,
179 Common->memusage + amd_Info [TRILINOS_AMD_MEMORY])) ;
182 lnz1 = (Int) (amd_Info [TRILINOS_AMD_LNZ]) + nk ;
183 flops1 = 2 * amd_Info [TRILINOS_AMD_NMULTSUBS_LU] + amd_Info [TRILINOS_AMD_NDIV] ;
187 Symbolic->symmetry = amd_Info [TRILINOS_AMD_SYMMETRY] ;
191 else if (ordering == 1)
203 ok = KLU_OrdinalTraits<Int>::colamd (nk, nk, Cilen, Ci, Cp,
205 lnz1 = AMESOS2_KLU2_EMPTY ;
206 flops1 = AMESOS2_KLU2_EMPTY ;
209 for (k = 0 ; k < nk ; k++)
222 lnz1 = (Common->user_order) (nk, Cp, Ci, Pblk, Common) ;
223 flops1 = AMESOS2_KLU2_EMPTY ;
237 lnz = (lnz == AMESOS2_KLU2_EMPTY || lnz1 == AMESOS2_KLU2_EMPTY) ? AMESOS2_KLU2_EMPTY : (lnz + lnz1) ;
238 flops = (flops == AMESOS2_KLU2_EMPTY || flops1 == AMESOS2_KLU2_EMPTY) ? AMESOS2_KLU2_EMPTY : (flops + flops1) ;
244 PRINTF ((
"Pblk, 1-based:\n")) ;
245 for (k = 0 ; k < nk ; k++)
247 ASSERT (k + k1 < n) ;
248 ASSERT (Pblk [k] + k1 < n) ;
249 Q [k + k1] = Qbtf [Pblk [k] + k1] ;
251 for (k = 0 ; k < nk ; k++)
253 ASSERT (k + k1 < n) ;
254 ASSERT (Pblk [k] + k1 < n) ;
255 P [k + k1] = Pbtf [Pblk [k] + k1] ;
259 PRINTF ((
"nzoff %d Ap[n] %d\n", nzoff,
Ap [n])) ;
260 ASSERT (nzoff >= 0 && nzoff <=
Ap [n]) ;
263 Symbolic->lnz = lnz ;
264 Symbolic->unz = lnz ;
265 Symbolic->nzoff = nzoff ;
266 Symbolic->est_flops = flops ;
279 template <
typename Entry,
typename Int>
280 static KLU_symbolic<Entry, Int> *order_and_analyze
288 KLU_common<Entry, Int> *Common
292 KLU_symbolic<Entry, Int> *Symbolic ;
294 Int *Qbtf, *Cp, *Ci, *Pinv, *Pblk, *Pbtf, *P, *Q, *R ;
295 Int nblocks, nz, block, maxblock, k1, k2, nk, do_btf, ordering, k, Cilen,
302 Symbolic = KLU_alloc_symbolic (n, Ap, Ai, Common) ;
303 if (Symbolic == NULL)
310 Lnz = Symbolic->Lnz ;
313 ordering = Common->ordering ;
319 Cilen = KLU_OrdinalTraits<Int>::colamd_recommended (nz, n, n) ;
321 else if (ordering == 0 || (ordering == 3 && Common->user_order != NULL))
329 Common->status = KLU_INVALID ;
330 KLU_free_symbolic (&Symbolic, Common) ;
335 trilinos_amd_malloc = Common->malloc_memory ;
336 trilinos_amd_free = Common->free_memory ;
337 trilinos_amd_calloc = Common->calloc_memory ;
338 trilinos_amd_realloc = Common->realloc_memory ;
344 Pbtf = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
345 Qbtf = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
346 if (Common->status < KLU_OK)
348 KLU_free (Pbtf, n,
sizeof (Int), Common) ;
349 KLU_free (Qbtf, n,
sizeof (Int), Common) ;
350 KLU_free_symbolic (&Symbolic, Common) ;
358 do_btf = Common->btf ;
359 do_btf = (do_btf) ? TRUE : FALSE ;
360 Symbolic->ordering = ordering ;
361 Symbolic->do_btf = do_btf ;
362 Symbolic->structural_rank = AMESOS2_KLU2_EMPTY ;
373 Work = (Int *) KLU_malloc (5*n,
sizeof (Int), Common) ;
374 if (Common->status < KLU_OK)
377 KLU_free (Pbtf, n,
sizeof (Int), Common) ;
378 KLU_free (Qbtf, n,
sizeof (Int), Common) ;
379 KLU_free_symbolic (&Symbolic, Common) ;
386 nblocks = KLU_OrdinalTraits<Int>::btf_order (n, Ap, Ai,
387 Common->maxwork, &work, Pbtf, Qbtf, R,
388 &(Symbolic->structural_rank), Work) ;
389 Common->structural_rank = Symbolic->structural_rank ;
390 Common->work += work ;
392 KLU_free (Work, 5*n,
sizeof (Int), Common) ;
395 if (Symbolic->structural_rank < n)
397 for (k = 0 ; k < n ; k++)
399 Qbtf [k] = TRILINOS_BTF_UNFLIP (Qbtf [k]) ;
405 for (block = 0 ; block < nblocks ; block++)
410 PRINTF ((
"block %d size %d\n", block, nk)) ;
411 maxblock = MAX (maxblock, nk) ;
421 for (k = 0 ; k < n ; k++)
428 Symbolic->nblocks = nblocks ;
430 PRINTF ((
"maxblock size %d\n", maxblock)) ;
431 Symbolic->maxblock = maxblock ;
437 Pblk = (Int *) KLU_malloc (maxblock,
sizeof (Int), Common) ;
438 Cp = (Int *) KLU_malloc (maxblock + 1,
sizeof (Int), Common) ;
439 Ci = (Int *) KLU_malloc (MAX (Cilen, nz+1),
sizeof (Int), Common) ;
440 Pinv = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
446 if (Common->status == KLU_OK)
448 PRINTF ((
"calling analyze_worker\n")) ;
449 Common->status = analyze_worker (n, Ap, Ai, nblocks, Pbtf, Qbtf, R,
450 ordering, P, Q, Lnz, Pblk, Cp, Ci, Cilen, Pinv, Symbolic, Common) ;
451 PRINTF ((
"analyze_worker done\n")) ;
458 KLU_free (Pblk, maxblock,
sizeof (Int), Common) ;
459 KLU_free (Cp, maxblock+1,
sizeof (Int), Common) ;
460 KLU_free (Ci, MAX (Cilen, nz+1),
sizeof (Int), Common) ;
461 KLU_free (Pinv, n,
sizeof (Int), Common) ;
462 KLU_free (Pbtf, n,
sizeof (Int), Common) ;
463 KLU_free (Qbtf, n,
sizeof (Int), Common) ;
469 if (Common->status < KLU_OK)
471 KLU_free_symbolic (&Symbolic, Common) ;
481 template <
typename Entry,
typename Int>
482 KLU_symbolic<Entry, Int> *KLU_analyze
490 KLU_common<Entry, Int> *Common
502 Common->status = KLU_OK ;
503 Common->structural_rank = AMESOS2_KLU2_EMPTY ;
509 if (Common->ordering == 2)
515 return (KLU_analyze_given (n, Ap, Ai, dummy, dummy, Common)) ;
520 return (order_and_analyze (n, Ap, Ai, Common)) ;
int Ap[]
Column offsets.
Definition: klu2_simple.cpp:52
int Ai[]
Row values.
Definition: klu2_simple.cpp:54