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

« back to all changes in this revision

Viewing changes to KLU/User/klu_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:
27
27
    /* outputs */
28
28
    int Perm [ ],           /* fill-reducing permutation */
29
29
    /* user-defined */
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 */
34
31
)
35
32
{
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
 
    int *P, *user_data ;
 
36
    cholmod_common cm ;
 
37
    int *P ;
41
38
    int k, symmetric ;
42
39
 
 
40
    if (Ap == NULL || Ai == NULL || Perm == NULL || n < 0)
 
41
    {
 
42
        /* invalid inputs */
 
43
        return (0) ;
 
44
    }
 
45
 
43
46
    /* start CHOLMOD */
44
 
    cm = &Common ;
45
 
    cholmod_start (cm) ;
46
 
    cm->supernodal = CHOLMOD_SIMPLICIAL ;
 
47
    cholmod_start (&cm) ;
 
48
    cm.supernodal = CHOLMOD_SIMPLICIAL ;
 
49
    cm.print = 0 ;
47
50
 
48
 
    /* cm->print = 5 ; */
 
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 ;
49
56
 
50
57
    /* construct a CHOLMOD version of the input matrix A */
51
 
    A = cholmod_malloc (1, sizeof (cholmod_sparse), cm) ;
52
 
    if (A == NULL)
53
 
    {
54
 
        /* out of memory */
55
 
        return (0) ;
56
 
    }
 
58
    A = &Amatrix ;
57
59
    A->nrow = n ;                   /* A is n-by-n */
58
60
    A->ncol = n ;
59
61
    A->nzmax = Ap [n] ;             /* with nzmax entries */
69
71
    A->z = NULL ;
70
72
    A->sorted = FALSE ;             /* columns of A are not sorted */
71
73
 
72
 
    /* cholmod_print_sparse (A, "A for user order", cm) ; */
73
 
 
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) ;
77
77
 
78
78
    /* AT = pattern of A' */
79
 
    AT = cholmod_transpose (A, 0, cm) ;
80
 
 
 
79
    AT = cholmod_transpose (A, 0, &cm) ;
81
80
    if (symmetric)
82
81
    {
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) ;
 
85
        if (S != NULL)
 
86
        {
 
87
            S->stype = 1 ;
 
88
        }
86
89
    }
87
90
    else
88
91
    {
90
93
        S = AT ;
91
94
    }
92
95
 
93
 
    /* free the header for A, but not Ap and Ai */
94
 
    A->p = NULL ;
95
 
    A->i = NULL ;
96
 
    cholmod_free_sparse (&A, cm) ;
97
 
 
98
 
    if (S == NULL)
99
 
    {
100
 
        /* out of memory */
101
 
        return (0) ;
102
 
    }
103
 
 
104
 
    if (symmetric)
105
 
    {
106
 
        S->stype = 1 ;
107
 
    }
108
 
 
109
 
    /* cholmod_print_sparse (S, "S", cm) ; */
110
 
 
111
 
    cm->nmethods = 10 ;
112
 
    /*
113
 
    cm->nmethods = 1 ;
114
 
    cm->method [0].ordering = CHOLMOD_AMD ;
115
 
    cm->method [0].ordering = CHOLMOD_METIS ;
116
 
    cm->method [0].ordering = CHOLMOD_NESDIS ;
117
 
    */
118
 
 
119
96
    /* order and analyze S or S*S' */
120
 
    L = cholmod_analyze (S, cm) ;
121
 
    if (L == NULL)
122
 
    {
123
 
        return (0) ;
124
 
    }
125
 
 
126
 
/*
127
 
printf ("L->ordering %d\n", L->ordering) ; 
128
 
*/
129
 
 
130
 
    /* cholmod_print_factor (L, "L, symbolic analysis only", cm) ; */
 
97
    L = cholmod_analyze (S, &cm) ;
131
98
 
132
99
    /* copy the permutation from L to the output */
133
 
    P = L->Perm ;
134
 
    for (k = 0 ; k < n ; k++)
 
100
    if (L != NULL)
135
101
    {
136
 
        Perm [k] = P [k] ;
 
102
        P = L->Perm ;
 
103
        for (k = 0 ; k < n ; k++)
 
104
        {
 
105
            Perm [k] = P [k] ;
 
106
        }
 
107
        lnz = cm.lnz ;
137
108
    }
138
109
 
139
 
    /* cholmod_print_perm (Perm, n, n, "Final permutation", cm) ; */
140
 
 
141
 
    cholmod_free_sparse (&S, cm) ;
142
 
    cholmod_free_factor (&L, cm) ;
143
 
    cholmod_finish (cm) ;
144
 
 
145
 
    /*
146
 
    if (n > 100) cholmod_print_common ("Final statistics", cm) ;
147
 
    if (cm->malloc_count != 0) printf ("CHOLMOD memory leak!") ;
148
 
    */
149
 
    return ((int) (cm->lnz)) ;
 
110
    cholmod_free_sparse (&S, &cm) ;
 
111
    cholmod_free_factor (&L, &cm) ;
 
112
    cholmod_finish (&cm) ;
 
113
    return (lnz) ;
150
114
}