Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_cholmod_l_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 
27 /* This file should make the long int version of CHOLMOD */
28 #define DLONG 1
29 
31 #include "amesos_ccolamd.h"
33 
34 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
35 #error "CCOLAMD v2.0 or later is required"
36 #endif
37 
38 /* ========================================================================== */
39 /* === cholmod_csymamd ====================================================== */
40 /* ========================================================================== */
41 
42 int CHOLMOD(csymamd)
43 (
44  /* ---- input ---- */
45  cholmod_sparse *A, /* matrix to order */
46  /* ---- output --- */
47  Int *Cmember, /* size nrow. see cholmod_ccolamd.c for description */
48  Int *Perm, /* size A->nrow, output permutation */
49  /* --------------- */
50  cholmod_common *Common
51 )
52 {
53  double knobs [CCOLAMD_KNOBS] ;
54  Int *perm, *Head ;
55  Int ok, i, nrow, stats [CCOLAMD_STATS] ;
56 
57  /* ---------------------------------------------------------------------- */
58  /* check inputs */
59  /* ---------------------------------------------------------------------- */
60 
62  RETURN_IF_NULL (A, FALSE) ;
63  RETURN_IF_NULL (Perm, FALSE) ;
65  Common->status = CHOLMOD_OK ;
66 
67  if (A->nrow != A->ncol || !(A->packed))
68  {
69  ERROR (CHOLMOD_INVALID, "matrix must be square and packed") ;
70  return (FALSE) ;
71  }
72 
73  /* ---------------------------------------------------------------------- */
74  /* get inputs */
75  /* ---------------------------------------------------------------------- */
76 
77  nrow = A->nrow ;
78 
79  /* ---------------------------------------------------------------------- */
80  /* allocate workspace */
81  /* ---------------------------------------------------------------------- */
82 
83  CHOLMOD(allocate_work) (nrow, 0, 0, Common) ;
84  if (Common->status < CHOLMOD_OK)
85  {
86  return (FALSE) ;
87  }
88 
89  /* ---------------------------------------------------------------------- */
90  /* order the matrix (does not affect A->p or A->i) */
91  /* ---------------------------------------------------------------------- */
92 
93  perm = Common->Head ; /* size nrow+1 (i/l/l) */
94 
95  /* get parameters */
96 #ifdef LONG
98 #else
100 #endif
101  if (Common->current >= 0 && Common->current < CHOLMOD_MAXMETHODS)
102  {
103  /* get the knobs from the Common parameters */
104  knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense ;
105  knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
106  }
107 
108  {
109 #ifdef LONG
110  amesos_csymamd_l (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
111  Common->free_memory, Cmember, A->stype) ;
112 #else
113  amesos_csymamd (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
114  Common->free_memory, Cmember, A->stype) ;
115 #endif
116  ok = stats [CCOLAMD_STATUS] ;
117  }
118 
119  if (ok == CCOLAMD_ERROR_out_of_memory)
120  {
121  ERROR (CHOLMOD_OUT_OF_MEMORY, "out of memory") ;
122  }
123  ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
124 
125  /* ---------------------------------------------------------------------- */
126  /* free the workspace and return result */
127  /* ---------------------------------------------------------------------- */
128 
129  /* permutation returned in perm [0..n-1] */
130  for (i = 0 ; i < nrow ; i++)
131  {
132  Perm [i] = perm [i] ;
133  }
134 
135  /* clear Head workspace (used for perm, in csymamd): */
136  Head = Common->Head ;
137  for (i = 0 ; i <= nrow ; i++)
138  {
139  Head [i] = EMPTY ;
140  }
141 
142  return (ok) ;
143 }
144 #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
int CHOLMOD() csymamd(cholmod_sparse *A, Int *Cmember, Int *Perm, cholmod_common *Common)
#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