1
/* ========================================================================== */
2
/* === klu_cholmod ========================================================== */
3
/* ========================================================================== */
5
/* klu_l_cholmod: user-defined ordering function to interface KLU to CHOLMOD.
7
* This routine is an example of a user-provided ordering function for KLU.
8
* Its return value is klu_l_cholmod's estimate of max (nnz(L),nnz(U)):
10
* -1 if OK, but estimate of max (nnz(L),nnz(U)) not computed
11
* > 0 if OK and estimate computed.
13
* This function can be assigned to KLU's Common->user_order function pointer.
16
#include "klu_cholmod.h"
24
UF_long n, /* A is n-by-n */
25
UF_long Ap [ ], /* column pointers */
26
UF_long Ai [ ], /* row indices */
28
UF_long Perm [ ], /* fill-reducing permutation */
30
klu_l_common *Common /* user-defined data is in Common->user_data */
33
double one [2] = {1,0}, zero [2] = {0,0}, lnz = 0 ;
34
cholmod_sparse Amatrix, *A, *AT, *S ;
38
UF_long k, symmetric ;
40
if (Ap == NULL || Ai == NULL || Perm == NULL || n < 0)
47
cholmod_l_start (&cm) ;
48
cm.supernodal = CHOLMOD_SIMPLICIAL ;
51
/* use KLU memory management routines for CHOLMOD */
52
cm.malloc_memory = Common->malloc_memory ;
53
cm.realloc_memory = Common->realloc_memory ;
54
cm.calloc_memory = Common->calloc_memory ;
55
cm.free_memory = Common->free_memory ;
57
/* construct a CHOLMOD version of the input matrix A */
59
A->nrow = n ; /* A is n-by-n */
61
A->nzmax = Ap [n] ; /* with nzmax entries */
62
A->packed = TRUE ; /* there is no A->nz array */
63
A->stype = 0 ; /* A is unsymmetric */
64
A->itype = CHOLMOD_INT ;
65
A->xtype = CHOLMOD_PATTERN ;
66
A->dtype = CHOLMOD_DOUBLE ;
68
A->p = Ap ; /* column pointers */
69
A->i = Ai ; /* row indices */
70
A->x = NULL ; /* no numerical values */
72
A->sorted = FALSE ; /* columns of A are not sorted */
74
/* get the user_data; default is symmetric if user_data is NULL */
75
symmetric = (Common->user_data == NULL) ? TRUE :
76
(((UF_long *) (Common->user_data)) [0] != 0) ;
78
/* AT = pattern of A' */
79
AT = cholmod_l_transpose (A, 0, &cm) ;
82
/* S = the symmetric pattern of A+A' */
83
S = cholmod_l_add (A, AT, one, zero, FALSE, FALSE, &cm) ;
84
cholmod_l_free_sparse (&AT, &cm) ;
92
/* S = A'. CHOLMOD will order S*S', which is A'*A */
96
/* order and analyze S or S*S' */
97
L = cholmod_l_analyze (S, &cm) ;
99
/* copy the permutation from L to the output */
103
for (k = 0 ; k < n ; k++)
110
cholmod_l_free_sparse (&S, &cm) ;
111
cholmod_l_free_factor (&L, &cm) ;
112
cholmod_l_finish (&cm) ;