~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to KLU/User/klu_l_cholmod.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ========================================================================== */
 
2
/* === klu_cholmod ========================================================== */
 
3
/* ========================================================================== */
 
4
 
 
5
/* klu_l_cholmod: user-defined ordering function to interface KLU to CHOLMOD.
 
6
 *
 
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)):
 
9
 *      0 if error,
 
10
 *      -1 if OK, but estimate of max (nnz(L),nnz(U)) not computed
 
11
 *      > 0 if OK and estimate computed.
 
12
 *
 
13
 * This function can be assigned to KLU's Common->user_order function pointer.
 
14
 */
 
15
 
 
16
#include "klu_cholmod.h"
 
17
#include "cholmod.h"
 
18
#define TRUE 1
 
19
#define FALSE 0
 
20
 
 
21
UF_long klu_l_cholmod
 
22
(
 
23
    /* inputs */
 
24
    UF_long n,              /* A is n-by-n */
 
25
    UF_long Ap [ ],                 /* column pointers */
 
26
    UF_long Ai [ ],                 /* row indices */
 
27
    /* outputs */
 
28
    UF_long Perm [ ],       /* fill-reducing permutation */
 
29
    /* user-defined */
 
30
    klu_l_common *Common    /* user-defined data is in Common->user_data */
 
31
)
 
32
{
 
33
    double one [2] = {1,0}, zero [2] = {0,0}, lnz = 0 ;
 
34
    cholmod_sparse Amatrix, *A, *AT, *S ;
 
35
    cholmod_factor *L ;
 
36
    cholmod_common cm ;
 
37
    UF_long *P ;
 
38
    UF_long k, symmetric ;
 
39
 
 
40
    if (Ap == NULL || Ai == NULL || Perm == NULL || n < 0)
 
41
    {
 
42
        /* invalid inputs */
 
43
        return (0) ;
 
44
    }
 
45
 
 
46
    /* start CHOLMOD */
 
47
    cholmod_l_start (&cm) ;
 
48
    cm.supernodal = CHOLMOD_SIMPLICIAL ;
 
49
    cm.print = 0 ;
 
50
 
 
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 ;
 
56
 
 
57
    /* construct a CHOLMOD version of the input matrix A */
 
58
    A = &Amatrix ;
 
59
    A->nrow = n ;                   /* A is n-by-n */
 
60
    A->ncol = 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 ;
 
67
    A->nz = NULL ;
 
68
    A->p = Ap ;                     /* column pointers */
 
69
    A->i = Ai ;                     /* row indices */
 
70
    A->x = NULL ;                   /* no numerical values */
 
71
    A->z = NULL ;
 
72
    A->sorted = FALSE ;             /* columns of A are not sorted */
 
73
 
 
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) ;
 
77
 
 
78
    /* AT = pattern of A' */
 
79
    AT = cholmod_l_transpose (A, 0, &cm) ;
 
80
    if (symmetric)
 
81
    {
 
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) ;
 
85
        if (S != NULL)
 
86
        {
 
87
            S->stype = 1 ;
 
88
        }
 
89
    }
 
90
    else
 
91
    {
 
92
        /* S = A'.  CHOLMOD will order S*S', which is A'*A */
 
93
        S = AT ;
 
94
    }
 
95
 
 
96
    /* order and analyze S or S*S' */
 
97
    L = cholmod_l_analyze (S, &cm) ;
 
98
 
 
99
    /* copy the permutation from L to the output */
 
100
    if (L != NULL)
 
101
    {
 
102
        P = L->Perm ;
 
103
        for (k = 0 ; k < n ; k++)
 
104
        {
 
105
            Perm [k] = P [k] ;
 
106
        }
 
107
        lnz = cm.lnz ;
 
108
    }
 
109
 
 
110
    cholmod_l_free_sparse (&S, &cm) ;
 
111
    cholmod_l_free_factor (&L, &cm) ;
 
112
    cholmod_l_finish (&cm) ;
 
113
    return (lnz) ;
 
114
}