Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_cholmod_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 
29 #include "amesos_ccolamd.h"
31 
32 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
33 #error "CCOLAMD v2.0 or later is required"
34 #endif
35 
36 /* ========================================================================== */
37 /* === ccolamd_interface ==================================================== */
38 /* ========================================================================== */
39 
40 /* Order with ccolamd */
41 
42 static int ccolamd_interface
43 (
45  size_t alen,
46  Int *Perm,
47  Int *Cmember,
48  Int *fset,
49  Int fsize,
51  cholmod_common *Common
52 )
53 {
54  double knobs [CCOLAMD_KNOBS] ;
55  Int *Cp = NULL ;
56  Int ok, k, nrow, ncol, stats [CCOLAMD_STATS] ;
57 
58  nrow = A->nrow ;
59  ncol = A->ncol ;
60 
61  /* ---------------------------------------------------------------------- */
62  /* copy (and transpose) the input matrix A into the ccolamd workspace */
63  /* ---------------------------------------------------------------------- */
64 
65  /* C = A (:,f)', which also packs A if needed. */
66  /* workspace: Iwork (nrow if no fset; MAX (nrow,ncol) if fset non-NULL) */
67  ok = CHOLMOD(transpose_unsym) (A, 0, NULL, fset, fsize, C, Common) ;
68 
69  /* ---------------------------------------------------------------------- */
70  /* order the matrix (destroys the contents of C->i and C->p) */
71  /* ---------------------------------------------------------------------- */
72 
73  /* get parameters */
74 #ifdef LONG
76 #else
78 #endif
79 
80  if (Common->current < 0 || Common->current >= CHOLMOD_MAXMETHODS)
81  {
82  /* this is the CHOLMOD default, not the CCOLAMD default */
83  knobs [CCOLAMD_DENSE_ROW] = -1 ;
84  }
85  else
86  {
87  /* get the knobs from the Common parameters */
88  knobs [CCOLAMD_DENSE_COL] =Common->method[Common->current].prune_dense ;
89  knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense2;
90  knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
91  knobs [CCOLAMD_LU] =Common->method[Common->current].order_for_lu;
92  }
93 
94  if (ok)
95  {
96 
97 #ifdef LONG
98  amesos_ccolamd_l (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
99 #else
100  amesos_ccolamd (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
101 #endif
102 
103  ok = stats [CCOLAMD_STATUS] ;
104 
105  ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
106  /* permutation returned in C->p, if the ordering succeeded */
107  Cp = C->p ;
108  for (k = 0 ; k < nrow ; k++)
109  {
110  Perm [k] = Cp [k] ;
111  }
112  }
113 
114  return (ok) ;
115 }
116 
117 
118 /* ========================================================================== */
119 /* === cholmod_ccolamd ====================================================== */
120 /* ========================================================================== */
121 
122 /* Order AA' or A(:,f)*A(:,f)' using CCOLAMD. */
123 
124 int CHOLMOD(ccolamd)
125 (
126  /* ---- input ---- */
127  cholmod_sparse *A, /* matrix to order */
128  Int *fset, /* subset of 0:(A->ncol)-1 */
129  size_t fsize, /* size of fset */
130  Int *Cmember, /* size A->nrow. Cmember [i] = c if row i is in the
131  * constraint set c. c must be >= 0. The # of
132  * constraint sets is max (Cmember) + 1. If Cmember is
133  * NULL, then it is interpretted as Cmember [i] = 0 for
134  * all i */
135  /* ---- output --- */
136  Int *Perm, /* size A->nrow, output permutation */
137  /* --------------- */
138  cholmod_common *Common
139 )
140 {
141  cholmod_sparse *C ;
142  Int ok, nrow, ncol ;
143  size_t alen ;
144 
145  /* ---------------------------------------------------------------------- */
146  /* check inputs */
147  /* ---------------------------------------------------------------------- */
148 
150  RETURN_IF_NULL (A, FALSE) ;
151  RETURN_IF_NULL (Perm, FALSE) ;
153  if (A->stype != 0)
154  {
155  ERROR (CHOLMOD_INVALID, "matrix must be unsymmetric") ;
156  return (FALSE) ;
157  }
158  Common->status = CHOLMOD_OK ;
159 
160  /* ---------------------------------------------------------------------- */
161  /* get inputs */
162  /* ---------------------------------------------------------------------- */
163 
164  nrow = A->nrow ;
165  ncol = A->ncol ;
166 
167  /* ---------------------------------------------------------------------- */
168  /* allocate workspace */
169  /* ---------------------------------------------------------------------- */
170 
171 #ifdef LONG
172  alen = amesos_ccolamd_l_recommended (A->nzmax, ncol, nrow) ;
173 #else
174  alen = amesos_ccolamd_recommended (A->nzmax, ncol, nrow) ;
175 #endif
176 
177  if (alen == 0)
178  {
179  ERROR (CHOLMOD_TOO_LARGE, "matrix invalid or too large") ;
180  return (FALSE) ;
181  }
182 
183  CHOLMOD(allocate_work) (0, MAX (nrow,ncol), 0, Common) ;
184  if (Common->status < CHOLMOD_OK)
185  {
186  return (FALSE) ;
187  }
188 
189  C = CHOLMOD(allocate_sparse) (ncol, nrow, alen, TRUE, TRUE, 0,
190  CHOLMOD_PATTERN, Common) ;
191 
192  /* ---------------------------------------------------------------------- */
193  /* order with ccolamd */
194  /* ---------------------------------------------------------------------- */
195 
196  ok = ccolamd_interface (A, alen, Perm, Cmember, fset, fsize, C, Common) ;
197 
198  /* ---------------------------------------------------------------------- */
199  /* free the workspace and return result */
200  /* ---------------------------------------------------------------------- */
201 
202  CHOLMOD(free_sparse) (&C, Common) ;
203  return (ok) ;
204 }
205 #endif
#define CCOLAMD_STATUS
#define CHOLMOD_TOO_LARGE
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
int CHOLMOD() ccolamd(cholmod_sparse *A, Int *fset, size_t fsize, Int *Cmember, Int *Perm, cholmod_common *Common)
#define CCOLAMD_DENSE_ROW
#define CCOLAMD_LU
#define CHOLMOD_INVALID
static int ccolamd_interface(cholmod_sparse *A, size_t alen, Int *Perm, Int *Cmember, Int *fset, Int fsize, cholmod_sparse *C, cholmod_common *Common)
#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)
#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