Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_cholmod_csymamd.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === Partition/cholmod_csymamd ============================================ */
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 CSYMAMD ordering routine. Finds a permutation
15  * p such that the Cholesky factorization of PAP' is sparser than A.
16  * The column etree is found and postordered, and the CSYMAMD
17  * ordering is then combined with its postordering. If A is unsymmetric,
18  * A+A' is ordered (A must be square).
19  *
20  * workspace: Head (nrow+1)
21  *
22  * Supports any xtype (pattern, real, complex, or zomplex).
23  */
24 
25 #ifndef NPARTITION
26 
28 #include "amesos_ccolamd.h"
30 
31 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
32 #error "CCOLAMD v2.0 or later is required"
33 #endif
34 
35 /* ========================================================================== */
36 /* === cholmod_csymamd ====================================================== */
37 /* ========================================================================== */
38 
39 int CHOLMOD(csymamd)
40 (
41  /* ---- input ---- */
42  cholmod_sparse *A, /* matrix to order */
43  /* ---- output --- */
44  Int *Cmember, /* size nrow. see cholmod_ccolamd.c for description */
45  Int *Perm, /* size A->nrow, output permutation */
46  /* --------------- */
47  cholmod_common *Common
48 )
49 {
50  double knobs [CCOLAMD_KNOBS] ;
51  Int *perm, *Head ;
52  Int ok, i, nrow, stats [CCOLAMD_STATS] ;
53 
54  /* ---------------------------------------------------------------------- */
55  /* check inputs */
56  /* ---------------------------------------------------------------------- */
57 
59  RETURN_IF_NULL (A, FALSE) ;
60  RETURN_IF_NULL (Perm, FALSE) ;
62  Common->status = CHOLMOD_OK ;
63 
64  if (A->nrow != A->ncol || !(A->packed))
65  {
66  ERROR (CHOLMOD_INVALID, "matrix must be square and packed") ;
67  return (FALSE) ;
68  }
69 
70  /* ---------------------------------------------------------------------- */
71  /* get inputs */
72  /* ---------------------------------------------------------------------- */
73 
74  nrow = A->nrow ;
75 
76  /* ---------------------------------------------------------------------- */
77  /* allocate workspace */
78  /* ---------------------------------------------------------------------- */
79 
80  CHOLMOD(allocate_work) (nrow, 0, 0, Common) ;
81  if (Common->status < CHOLMOD_OK)
82  {
83  return (FALSE) ;
84  }
85 
86  /* ---------------------------------------------------------------------- */
87  /* order the matrix (does not affect A->p or A->i) */
88  /* ---------------------------------------------------------------------- */
89 
90  perm = Common->Head ; /* size nrow+1 (i/l/l) */
91 
92  /* get parameters */
93 #ifdef LONG
95 #else
97 #endif
98  if (Common->current >= 0 && Common->current < CHOLMOD_MAXMETHODS)
99  {
100  /* get the knobs from the Common parameters */
101  knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense ;
102  knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
103  }
104 
105  {
106 #ifdef LONG
107  amesos_csymamd_l (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
108  Common->free_memory, Cmember, A->stype) ;
109 #else
110  amesos_csymamd (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
111  Common->free_memory, Cmember, A->stype) ;
112 #endif
113  ok = stats [CCOLAMD_STATUS] ;
114  }
115 
116  if (ok == CCOLAMD_ERROR_out_of_memory)
117  {
118  ERROR (CHOLMOD_OUT_OF_MEMORY, "out of memory") ;
119  }
120  ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
121 
122  /* ---------------------------------------------------------------------- */
123  /* free the workspace and return result */
124  /* ---------------------------------------------------------------------- */
125 
126  /* permutation returned in perm [0..n-1] */
127  for (i = 0 ; i < nrow ; i++)
128  {
129  Perm [i] = perm [i] ;
130  }
131 
132  /* clear Head workspace (used for perm, in csymamd): */
133  Head = Common->Head ;
134  for (i = 0 ; i <= nrow ; i++)
135  {
136  Head [i] = EMPTY ;
137  }
138 
139  return (ok) ;
140 }
141 #endif
#define CCOLAMD_STATUS
void amesos_ccolamd_l_set_defaults(double knobs[CCOLAMD_KNOBS])
#define EMPTY
#define Int
#define FALSE
#define CCOLAMD_OK_BUT_JUMBLED
#define CCOLAMD_AGGRESSIVE
#define RETURN_IF_NULL_COMMON(result)
#define CHOLMOD_PATTERN
#define CHOLMOD(name)
#define CCOLAMD_OK
UF_long amesos_csymamd_l(UF_long n, UF_long A[], UF_long p[], UF_long perm[], double knobs[CCOLAMD_KNOBS], UF_long stats[CCOLAMD_STATS], void *(*allocate)(size_t, size_t), void(*release)(void *), UF_long cmember[], UF_long stype)
void amesos_ccolamd_set_defaults(double knobs[CCOLAMD_KNOBS])
#define CCOLAMD_KNOBS
#define CCOLAMD_DENSE_ROW
int amesos_csymamd(int n, int A[], int p[], int perm[], double knobs[CCOLAMD_KNOBS], int stats[CCOLAMD_STATS], void *(*allocate)(size_t, size_t), void(*release)(void *), int cmember[], int stype)
#define CHOLMOD_INVALID
#define CHOLMOD_OK
#define CHOLMOD_OUT_OF_MEMORY
int CHOLMOD() allocate_work(size_t nrow, size_t iworksize, size_t xworksize, cholmod_common *Common)
#define CHOLMOD_MAXMETHODS
#define RETURN_IF_NULL(A, result)
#define ERROR(status, msg)
#define CCOLAMD_STATS
#define CCOLAMD_ERROR_out_of_memory
#define RETURN_IF_XTYPE_INVALID(A, xtype1, xtype2, result)
#define CHOLMOD_ZOMPLEX
int CHOLMOD() csymamd(cholmod_sparse *A, Int *Cmember, Int *Perm, cholmod_common *Common)