28
28
int Perm [ ], /* fill-reducing permutation */
30
void *user_datap /* this is KLU's Common->user_data, unchanged.
31
* You may use this to pass additional parameters
32
* to your ordering routine. KLU does not access
33
* Common->user_data, except to pass it here. */
30
klu_common *Common /* user-defined data is in Common->user_data */
36
double one [2] = {1,0}, zero [2] = {0,0} ;
37
cholmod_sparse *A, *AT, *S ;
33
double one [2] = {1,0}, zero [2] = {0,0}, lnz = 0 ;
34
cholmod_sparse Amatrix, *A, *AT, *S ;
38
35
cholmod_factor *L ;
39
cholmod_common *cm, Common ;
40
if (Ap == NULL || Ai == NULL || Perm == NULL || n < 0)
43
46
/* start CHOLMOD */
46
cm->supernodal = CHOLMOD_SIMPLICIAL ;
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 ;
50
57
/* construct a CHOLMOD version of the input matrix A */
51
A = cholmod_malloc (1, sizeof (cholmod_sparse), cm) ;
57
59
A->nrow = n ; /* A is n-by-n */
59
61
A->nzmax = Ap [n] ; /* with nzmax entries */
70
72
A->sorted = FALSE ; /* columns of A are not sorted */
72
/* cholmod_print_sparse (A, "A for user order", cm) ; */
74
/* get the user_data */
75
user_data = user_datap ;
76
symmetric = (user_data == NULL) ? TRUE : (user_data [0] != 0) ;
74
/* get the user_data; default is symmetric if user_data is NULL */
75
symmetric = (Common->user_data == NULL) ? TRUE :
76
(((int *) (Common->user_data)) [0] != 0) ;
78
78
/* AT = pattern of A' */
79
AT = cholmod_transpose (A, 0, cm) ;
79
AT = cholmod_transpose (A, 0, &cm) ;
83
82
/* S = the symmetric pattern of A+A' */
84
S = cholmod_add (A, AT, one, zero, FALSE, FALSE, cm) ;
85
cholmod_free_sparse (&AT, cm) ;
83
S = cholmod_add (A, AT, one, zero, FALSE, FALSE, &cm) ;
84
cholmod_free_sparse (&AT, &cm) ;
93
/* free the header for A, but not Ap and Ai */
96
cholmod_free_sparse (&A, cm) ;
109
/* cholmod_print_sparse (S, "S", cm) ; */
114
cm->method [0].ordering = CHOLMOD_AMD ;
115
cm->method [0].ordering = CHOLMOD_METIS ;
116
cm->method [0].ordering = CHOLMOD_NESDIS ;
119
96
/* order and analyze S or S*S' */
120
L = cholmod_analyze (S, cm) ;
127
printf ("L->ordering %d\n", L->ordering) ;
130
/* cholmod_print_factor (L, "L, symbolic analysis only", cm) ; */
97
L = cholmod_analyze (S, &cm) ;
132
99
/* copy the permutation from L to the output */
134
for (k = 0 ; k < n ; k++)
103
for (k = 0 ; k < n ; k++)
139
/* cholmod_print_perm (Perm, n, n, "Final permutation", cm) ; */
141
cholmod_free_sparse (&S, cm) ;
142
cholmod_free_factor (&L, cm) ;
143
cholmod_finish (cm) ;
146
if (n > 100) cholmod_print_common ("Final statistics", cm) ;
147
if (cm->malloc_count != 0) printf ("CHOLMOD memory leak!") ;
149
return ((int) (cm->lnz)) ;
110
cholmod_free_sparse (&S, &cm) ;
111
cholmod_free_factor (&L, &cm) ;
112
cholmod_finish (&cm) ;