colamd.h
Go to the documentation of this file.
1 
55 #ifndef COLAMD_H
56 #define COLAMD_H
57 
58 /* ========================================================================== */
59 /* === Include files ======================================================== */
60 /* ========================================================================== */
61 
62 #include <stdlib.h>
63 
64 /* ========================================================================== */
65 /* === Knob and statistics definitions ====================================== */
66 /* ========================================================================== */
67 
68 /* size of the knobs [ ] array. Only knobs [0..1] are currently used. */
69 #define COLAMD_KNOBS 20
70 
71 /* number of output statistics. Only stats [0..6] are currently used. */
72 #define COLAMD_STATS 20
73 
74 /* knobs [0] and stats [0]: dense row knob and output statistic. */
75 #define COLAMD_DENSE_ROW 0
76 
77 /* knobs [1] and stats [1]: dense column knob and output statistic. */
78 #define COLAMD_DENSE_COL 1
79 
80 /* stats [2]: memory defragmentation count output statistic */
81 #define COLAMD_DEFRAG_COUNT 2
82 
83 /* stats [3]: colamd status: zero OK, > 0 warning or notice, < 0 error */
84 #define COLAMD_STATUS 3
85 
86 /* stats [4..6]: error info, or info on jumbled columns */
87 #define COLAMD_INFO1 4
88 #define COLAMD_INFO2 5
89 #define COLAMD_INFO3 6
90 
91 /* error codes returned in stats [3]: */
92 #define COLAMD_OK (0)
93 #define COLAMD_OK_BUT_JUMBLED (1)
94 #define COLAMD_ERROR_A_not_present (-1)
95 #define COLAMD_ERROR_p_not_present (-2)
96 #define COLAMD_ERROR_nrow_negative (-3)
97 #define COLAMD_ERROR_ncol_negative (-4)
98 #define COLAMD_ERROR_nnz_negative (-5)
99 #define COLAMD_ERROR_p0_nonzero (-6)
100 #define COLAMD_ERROR_A_too_small (-7)
101 #define COLAMD_ERROR_col_length_negative (-8)
102 #define COLAMD_ERROR_row_index_out_of_bounds (-9)
103 #define COLAMD_ERROR_out_of_memory (-10)
104 #define COLAMD_ERROR_internal_error (-999)
105 
106 /* ========================================================================== */
107 /* === Row and Column structures ============================================ */
108 /* ========================================================================== */
109 
110 /* User code that makes use of the colamd/symamd routines need not directly */
111 /* reference these structures. They are used only for the COLAMD_RECOMMENDED */
112 /* macro. */
113 
114 typedef struct Colamd_Col_struct
115 {
116  int start ; /* index for A of first row in this column, or DEAD */
117  /* if column is dead */
118  int length ; /* number of rows in this column */
119  union
120  {
121  int thickness ; /* number of original columns represented by this */
122  /* col, if the column is alive */
123  int parent ; /* parent in parent tree super-column structure, if */
124  /* the column is dead */
126  union
127  {
128  int score ; /* the score used to maintain heap, if col is alive */
129  int order ; /* pivot ordering of this column, if col is dead */
131  union
132  {
133  int headhash ; /* head of a hash bucket, if col is at the head of */
134  /* a degree list */
135  int hash ; /* hash value, if col is not in a degree list */
136  int prev ; /* previous column in degree list, if col is in a */
137  /* degree list (but not at the head of a degree list) */
139  union
140  {
141  int degree_next ; /* next column, if col is in a degree list */
142  int hash_next ; /* next column, if col is in a hash list */
144 
146 
147 typedef struct Colamd_Row_struct
148 {
149  int start ; /* index for A of first col in this row */
150  int length ; /* number of principal columns in this row */
151  union
152  {
153  int degree ; /* number of principal & non-principal columns in row */
154  int p ; /* used as a row pointer in init_rows_cols () */
156  union
157  {
158  int mark ; /* for computing set differences and marking dead rows*/
159  int first_column ;/* first column in row (used in garbage collection) */
161 
163 
164 /* ========================================================================== */
165 /* === Colamd recommended memory size ======================================= */
166 /* ========================================================================== */
167 
168 /*
169  The recommended length Alen of the array A passed to colamd is given by
170  the COLAMD_RECOMMENDED (nnz, n_row, n_col) macro. It returns -1 if any
171  argument is negative. 2*nnz space is required for the row and column
172  indices of the matrix. COLAMD_C (n_col) + COLAMD_R (n_row) space is
173  required for the Col and Row arrays, respectively, which are internal to
174  colamd. An additional n_col space is the minimal amount of "elbow room",
175  and nnz/5 more space is recommended for run time efficiency.
176 
177  This macro is not needed when using symamd.
178 
179  Explicit typecast to int added Sept. 23, 2002, COLAMD version 2.2, to avoid
180  gcc -pedantic warning messages.
181 */
182 
183 #define COLAMD_C(n_col) ((int) (((n_col) + 1) * sizeof (Colamd_Col) / sizeof (int)))
184 #define COLAMD_R(n_row) ((int) (((n_row) + 1) * sizeof (Colamd_Row) / sizeof (int)))
185 
186 #define COLAMD_RECOMMENDED(nnz, n_row, n_col) \
187 ( \
188 ((nnz) < 0 || (n_row) < 0 || (n_col) < 0) \
189 ? \
190  (-1) \
191 : \
192  (2 * (nnz) + COLAMD_C (n_col) + COLAMD_R (n_row) + (n_col) + ((nnz) / 5)) \
193 )
194 
195 /* ========================================================================== */
196 /* === Prototypes of user-callable routines ================================= */
197 /* ========================================================================== */
198 
199 int colamd_recommended /* returns recommended value of Alen, */
200  /* or (-1) if input arguments are erroneous */
201 (
202  int nnz, /* nonzeros in A */
203  int n_row, /* number of rows in A */
204  int n_col /* number of columns in A */
205 ) ;
206 
207 void colamd_set_defaults /* sets default parameters */
208 ( /* knobs argument is modified on output */
209  double knobs [COLAMD_KNOBS] /* parameter settings for colamd */
210 ) ;
211 
212 int colamd /* returns (1) if successful, (0) otherwise*/
213 ( /* A and p arguments are modified on output */
214  int n_row, /* number of rows in A */
215  int n_col, /* number of columns in A */
216  int Alen, /* size of the array A */
217  int A [], /* row indices of A, of size Alen */
218  int p [], /* column pointers of A, of size n_col+1 */
219  double knobs [COLAMD_KNOBS],/* parameter settings for colamd */
220  int stats [COLAMD_STATS] /* colamd output statistics and error codes */
221 ) ;
222 
223 int symamd /* return (1) if OK, (0) otherwise */
224 (
225  int n, /* number of rows and columns of A */
226  int A [], /* row indices of A */
227  int p [], /* column pointers of A */
228  int perm [], /* output permutation, size n_col+1 */
229  double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */
230  int stats [COLAMD_STATS], /* output statistics and error codes */
231  void * (*allocate) (size_t, size_t),
232  /* pointer to calloc (ANSI C) or */
233  /* mxCalloc (for MATLAB mexFunction) */
234  void (*release) (void *)
235  /* pointer to free (ANSI C) or */
236  /* mxFree (for MATLAB mexFunction) */
237 ) ;
238 
240 (
241  int stats [COLAMD_STATS]
242 ) ;
243 
245 (
246  int stats [COLAMD_STATS]
247 ) ;
248 
249 #endif /* COLAMD_H */
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
float * p
Definition: Tutorial_Map_using.cpp:9
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
struct Colamd_Row_struct Colamd_Row
struct Colamd_Col_struct Colamd_Col
#define COLAMD_STATS
Definition: colamd.h:72
void colamd_report(int stats[COLAMD_STATS])
void symamd_report(int stats[COLAMD_STATS])
int colamd_recommended(int nnz, int n_row, int n_col)
int symamd(int n, int A[], int p[], int perm[], double knobs[COLAMD_KNOBS], int stats[COLAMD_STATS], void *(*allocate)(size_t, size_t), void(*release)(void *))
void colamd_set_defaults(double knobs[COLAMD_KNOBS])
#define COLAMD_KNOBS
Definition: colamd.h:69
int colamd(int n_row, int n_col, int Alen, int A[], int p[], double knobs[COLAMD_KNOBS], int stats[COLAMD_STATS])
Definition: colamd.h:115
int headhash
Definition: colamd.h:133
int order
Definition: colamd.h:129
int prev
Definition: colamd.h:136
int degree_next
Definition: colamd.h:141
int start
Definition: colamd.h:116
int hash_next
Definition: colamd.h:142
union Colamd_Col_struct::@1123 shared3
union Colamd_Col_struct::@1124 shared4
int score
Definition: colamd.h:128
int thickness
Definition: colamd.h:121
int parent
Definition: colamd.h:123
int hash
Definition: colamd.h:135
int length
Definition: colamd.h:118
union Colamd_Col_struct::@1121 shared1
union Colamd_Col_struct::@1122 shared2
Definition: colamd.h:148
int mark
Definition: colamd.h:158
int degree
Definition: colamd.h:153
int start
Definition: colamd.h:149
int length
Definition: colamd.h:150
union Colamd_Row_struct::@1126 shared2
union Colamd_Row_struct::@1125 shared1
int p
Definition: colamd.h:154
int first_column
Definition: colamd.h:159