Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_cholmod_l_ccolamd.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === Partition/cholmod_ccolamd ============================================ */
3 /* ========================================================================== */
4 
5 /* -----------------------------------------------------------------------------
6  * CHOLMOD/Partition Module.
7  * Copyright (C) 2005-2006, Univ. of Florida. Author: Timothy A. Davis
8  * The CHOLMOD/Partition Module is licensed under Version 2.1 of the GNU
9  * Lesser General Public License. See lesser.txt for a text of the license.
10  * CHOLMOD is also available under other licenses; contact authors for details.
11  * http://www.cise.ufl.edu/research/sparse
12  * -------------------------------------------------------------------------- */
13 
14 /* CHOLMOD interface to the CCOLAMD ordering routine. Finds a permutation
15  * p such that the Cholesky factorization of PAA'P' is sparser than AA'.
16  * The column etree is found and postordered, and the ccolamd ordering is then
17  * combined with its postordering. A must be unsymmetric.
18  *
19  * workspace: Iwork (MAX (nrow,ncol))
20  * Allocates a copy of its input matrix, which is
21  * then used as CCOLAMD's workspace.
22  *
23  * Supports any xtype (pattern, real, complex, or zomplex).
24  */
25 
26 #ifndef NPARTITION
27 
28 /* This file should make the long int version of CHOLMOD */
29 #define DLONG 1
30 
32 #include "amesos_ccolamd.h"
34 
35 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
36 #error "CCOLAMD v2.0 or later is required"
37 #endif
38 
39 /* ========================================================================== */
40 /* === ccolamd_interface ==================================================== */
41 /* ========================================================================== */
42 
43 /* Order with ccolamd */
44 
45 static int ccolamd_interface
46 (
48  size_t alen,
49  Int *Perm,
50  Int *Cmember,
51  Int *fset,
52  Int fsize,
54  cholmod_common *Common
55 )
56 {
57  double knobs [CCOLAMD_KNOBS] ;
58  Int *Cp = NULL ;
59  Int ok, k, nrow, ncol, stats [CCOLAMD_STATS] ;
60 
61  nrow = A->nrow ;
62  ncol = A->ncol ;
63 
64  /* ---------------------------------------------------------------------- */
65  /* copy (and transpose) the input matrix A into the ccolamd workspace */
66  /* ---------------------------------------------------------------------- */
67 
68  /* C = A (:,f)', which also packs A if needed. */
69  /* workspace: Iwork (nrow if no fset; MAX (nrow,ncol) if fset non-NULL) */
70  ok = CHOLMOD(transpose_unsym) (A, 0, NULL, fset, fsize, C, Common) ;
71 
72  /* ---------------------------------------------------------------------- */
73  /* order the matrix (destroys the contents of C->i and C->p) */
74  /* ---------------------------------------------------------------------- */
75 
76  /* get parameters */
77 #ifdef LONG
79 #else
81 #endif
82 
83  if (Common->current < 0 || Common->current >= CHOLMOD_MAXMETHODS)
84  {
85  /* this is the CHOLMOD default, not the CCOLAMD default */
86  knobs [CCOLAMD_DENSE_ROW] = -1 ;
87  }
88  else
89  {
90  /* get the knobs from the Common parameters */
91  knobs [CCOLAMD_DENSE_COL] =Common->method[Common->current].prune_dense ;
92  knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense2;
93  knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
94  knobs [CCOLAMD_LU] =Common->method[Common->current].order_for_lu;
95  }
96 
97  if (ok)
98  {
99 
100 #ifdef LONG
101  amesos_ccolamd_l (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
102 #else
103  amesos_ccolamd (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
104 #endif
105 
106  ok = stats [CCOLAMD_STATUS] ;
107 
108  ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
109  /* permutation returned in C->p, if the ordering succeeded */
110  Cp = C->p ;
111  for (k = 0 ; k < nrow ; k++)
112  {
113  Perm [k] = Cp [k] ;
114  }
115  }
116 
117  return (ok) ;
118 }
119 
120 
121 /* ========================================================================== */
122 /* === cholmod_ccolamd ====================================================== */
123 /* ========================================================================== */
124 
125 /* Order AA' or A(:,f)*A(:,f)' using CCOLAMD. */
126 
127 int CHOLMOD(ccolamd)
128 (
129  /* ---- input ---- */
130  cholmod_sparse *A, /* matrix to order */
131  Int *fset, /* subset of 0:(A->ncol)-1 */
132  size_t fsize, /* size of fset */
133  Int *Cmember, /* size A->nrow. Cmember [i] = c if row i is in the
134  * constraint set c. c must be >= 0. The # of
135  * constraint sets is max (Cmember) + 1. If Cmember is
136  * NULL, then it is interpretted as Cmember [i] = 0 for
137  * all i */
138  /* ---- output --- */
139  Int *Perm, /* size A->nrow, output permutation */
140  /* --------------- */
141  cholmod_common *Common
142 )
143 {
144  cholmod_sparse *C ;
145  Int ok, nrow, ncol ;
146  size_t alen ;
147 
148  /* ---------------------------------------------------------------------- */
149  /* check inputs */
150  /* ---------------------------------------------------------------------- */
151 
153  RETURN_IF_NULL (A, FALSE) ;
154  RETURN_IF_NULL (Perm, FALSE) ;
156  if (A->stype != 0)
157  {
158  ERROR (CHOLMOD_INVALID, "matrix must be unsymmetric") ;
159  return (FALSE) ;
160  }
161  Common->status = CHOLMOD_OK ;
162 
163  /* ---------------------------------------------------------------------- */
164  /* get inputs */
165  /* ---------------------------------------------------------------------- */
166 
167  nrow = A->nrow ;
168  ncol = A->ncol ;
169 
170  /* ---------------------------------------------------------------------- */
171  /* allocate workspace */
172  /* ---------------------------------------------------------------------- */
173 
174 #ifdef LONG
175  alen = amesos_ccolamd_l_recommended (A->nzmax, ncol, nrow) ;
176 #else
177  alen = amesos_ccolamd_recommended (A->nzmax, ncol, nrow) ;
178 #endif
179 
180  if (alen == 0)
181  {
182  ERROR (CHOLMOD_TOO_LARGE, "matrix invalid or too large") ;
183  return (FALSE) ;
184  }
185 
186  CHOLMOD(allocate_work) (0, MAX (nrow,ncol), 0, Common) ;
187  if (Common->status < CHOLMOD_OK)
188  {
189  return (FALSE) ;
190  }
191 
192  C = CHOLMOD(allocate_sparse) (ncol, nrow, alen, TRUE, TRUE, 0,
193  CHOLMOD_PATTERN, Common) ;
194 
195  /* ---------------------------------------------------------------------- */
196  /* order with ccolamd */
197  /* ---------------------------------------------------------------------- */
198 
199  ok = ccolamd_interface (A, alen, Perm, Cmember, fset, fsize, C, Common) ;
200 
201  /* ---------------------------------------------------------------------- */
202  /* free the workspace and return result */
203  /* ---------------------------------------------------------------------- */
204 
205  CHOLMOD(free_sparse) (&C, Common) ;
206  return (ok) ;
207 }
208 #endif
#define CCOLAMD_STATUS
#define CHOLMOD_TOO_LARGE
static int ccolamd_interface(cholmod_sparse *A, size_t alen, Int *Perm, Int *Cmember, Int *fset, Int fsize, cholmod_sparse *C, cholmod_common *Common)
void amesos_ccolamd_l_set_defaults(double knobs[CCOLAMD_KNOBS])
int CHOLMOD() transpose_unsym(cholmod_sparse *A, int values, Int *Perm, Int *fset, size_t fsize, cholmod_sparse *F, cholmod_common *Common)
#define Int
#define FALSE
#define CCOLAMD_OK_BUT_JUMBLED
#define CCOLAMD_AGGRESSIVE
#define RETURN_IF_NULL_COMMON(result)
struct cholmod_common_struct::cholmod_method_struct method[CHOLMOD_MAXMETHODS+1]
size_t amesos_ccolamd_recommended(int nnz, int n_row, int n_col)
#define CHOLMOD_PATTERN
#define CHOLMOD(name)
#define CCOLAMD_OK
#define MAX(a, b)
size_t amesos_ccolamd_l_recommended(UF_long nnz, UF_long n_row, UF_long n_col)
void amesos_ccolamd_set_defaults(double knobs[CCOLAMD_KNOBS])
int CHOLMOD() free_sparse(cholmod_sparse **AHandle, cholmod_common *Common)
#define NULL
#define CCOLAMD_KNOBS
#define CCOLAMD_DENSE_ROW
#define CCOLAMD_LU
#define CHOLMOD_INVALID
#define CHOLMOD_OK
int amesos_ccolamd(int n_row, int n_col, int Alen, int A[], int p[], double knobs[CCOLAMD_KNOBS], int stats[CCOLAMD_STATS], int cmember[])
cholmod_sparse *CHOLMOD() allocate_sparse(size_t nrow, size_t ncol, size_t nzmax, int sorted, int packed, int stype, int xtype, cholmod_common *Common)
int CHOLMOD() allocate_work(size_t nrow, size_t iworksize, size_t xworksize, cholmod_common *Common)
#define CHOLMOD_MAXMETHODS
UF_long amesos_ccolamd_l(UF_long n_row, UF_long n_col, UF_long Alen, UF_long A[], UF_long p[], double knobs[CCOLAMD_KNOBS], UF_long stats[CCOLAMD_STATS], UF_long cmember[])
#define RETURN_IF_NULL(A, result)
int CHOLMOD() ccolamd(cholmod_sparse *A, Int *fset, size_t fsize, Int *Cmember, Int *Perm, cholmod_common *Common)
#define ERROR(status, msg)
#define TRUE
#define CCOLAMD_STATS
#define RETURN_IF_XTYPE_INVALID(A, xtype1, xtype2, result)
#define CHOLMOD_ZOMPLEX
#define CCOLAMD_DENSE_COL