17 #ifndef KLU2_ANALYZE_GIVEN_HPP
18 #define KLU2_ANALYZE_GIVEN_HPP
20 #include "klu2_internal.h"
21 #include "klu2_memory.hpp"
29 template <
typename Entry,
typename Int>
30 KLU_symbolic<Entry, Int> *KLU_alloc_symbolic
35 KLU_common<Entry, Int> *Common
38 KLU_symbolic<Entry, Int> *Symbolic ;
41 Int nz, i, j, p, pend ;
47 Common->status = KLU_OK ;
55 if (n <= 0 || Ap == NULL || Ai == NULL)
58 Common->status = KLU_INVALID ;
63 if (Ap [0] != 0 || nz < 0)
66 Common->status = KLU_INVALID ;
70 for (j = 0 ; j < n ; j++)
72 if (Ap [j] > Ap [j+1])
75 Common->status = KLU_INVALID ;
79 P = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
80 if (Common->status < KLU_OK)
83 Common->status = KLU_OUT_OF_MEMORY ;
86 for (i = 0 ; i < n ; i++)
88 P [i] = AMESOS2_KLU2_EMPTY ;
90 for (j = 0 ; j < n ; j++)
93 for (p = Ap [j] ; p < pend ; p++)
96 if (i < 0 || i >= n || P [i] == j)
99 KLU_free (P, n,
sizeof (Int), Common) ;
100 Common->status = KLU_INVALID ;
112 Symbolic = (KLU_symbolic<Entry, Int> *) KLU_malloc (
sizeof (KLU_symbolic<Entry, Int>), 1, Common) ;
113 if (Common->status < KLU_OK)
116 KLU_free (P, n,
sizeof (Int), Common) ;
117 Common->status = KLU_OUT_OF_MEMORY ;
121 Q = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
122 R = (Int *) KLU_malloc (n+1,
sizeof (Int), Common) ;
123 Lnz = (
double *) KLU_malloc (n,
sizeof (
double), Common) ;
130 Symbolic->Lnz = Lnz ;
132 if (Common->status < KLU_OK)
135 KLU_free_symbolic (&Symbolic, Common) ;
136 Common->status = KLU_OUT_OF_MEMORY ;
148 template <
typename Entry,
typename Int>
149 KLU_symbolic<Entry, Int> *KLU_analyze_given
159 KLU_common<Entry, Int> *Common
162 KLU_symbolic<Entry, Int> *Symbolic ;
164 Int nblocks, nz, block, maxblock, *P, *Q, *R, nzoff, p, pend, do_btf, k ;
170 Symbolic = KLU_alloc_symbolic (n, Ap, Ai, Common) ;
171 if (Symbolic == NULL)
178 Lnz = Symbolic->Lnz ;
185 if (Quser == (Int *) NULL)
187 for (k = 0 ; k < n ; k++)
194 for (k = 0 ; k < n ; k++)
204 do_btf = Common->btf ;
205 do_btf = (do_btf) ? TRUE : FALSE ;
206 Symbolic->ordering = 2 ;
207 Symbolic->do_btf = do_btf ;
220 Int *Pinv, *Work, *Bi, k1, k2, nk, oldcol ;
222 Work = (Int *) KLU_malloc (4*n,
sizeof (Int), Common) ;
223 Pinv = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
224 if (Puser != (Int *) NULL)
226 Bi = (Int *) KLU_malloc (nz+1,
sizeof (Int), Common) ;
233 if (Common->status < KLU_OK)
236 KLU_free (Work, 4*n,
sizeof (Int), Common) ;
237 KLU_free (Pinv, n,
sizeof (Int), Common) ;
238 if (Puser != (Int *) NULL)
240 KLU_free (Bi, nz+1,
sizeof (Int), Common) ;
242 KLU_free_symbolic (&Symbolic, Common) ;
243 Common->status = KLU_OUT_OF_MEMORY ;
251 if (Puser != (Int *) NULL)
253 for (k = 0 ; k < n ; k++)
255 Pinv [Puser [k]] = k ;
257 for (p = 0 ; p < nz ; p++)
259 Bi [p] = Pinv [Ai [p]] ;
270 nblocks = KLU_OrdinalTraits<Int>::btf_strongcomp (n, Ap, Bi, Q, P, R,
277 if (Puser != (Int *) NULL)
279 for (k = 0 ; k < n ; k++)
281 Work [k] = Puser [P [k]] ;
283 for (k = 0 ; k < n ; k++)
293 for (k = 0 ; k < n ; k++)
305 for (block = 0 ; block < nblocks ; block++)
315 PRINTF ((
"BLOCK %d, k1 %d k2-1 %d nk %d\n", block, k1, k2-1, nk)) ;
316 maxblock = MAX (maxblock, nk) ;
322 for (k = k1 ; k < k2 ; k++)
325 pend = Ap [oldcol+1] ;
326 for (p = Ap [oldcol] ; p < pend ; p++)
328 if (Pinv [Ai [p]] < k1)
336 Lnz [block] = AMESOS2_KLU2_EMPTY ;
343 KLU_free (Work, 4*n,
sizeof (Int), Common) ;
344 KLU_free (Pinv, n,
sizeof (Int), Common) ;
345 if (Puser != (Int *) NULL)
347 KLU_free (Bi, nz+1,
sizeof (Int), Common) ;
363 Lnz [0] = AMESOS2_KLU2_EMPTY ;
369 for (k = 0 ; k < n ; k++)
371 P [k] = (Puser == NULL) ? k : Puser [k] ;
379 Symbolic->nblocks = nblocks ;
380 Symbolic->maxblock = maxblock ;
381 Symbolic->lnz = AMESOS2_KLU2_EMPTY ;
382 Symbolic->unz = AMESOS2_KLU2_EMPTY ;
383 Symbolic->nzoff = nzoff ;
int Ap[]
Column offsets.
Definition: klu2_simple.cpp:52
int Ai[]
Row values.
Definition: klu2_simple.cpp:54