|
kusano |
7d535a |
/*! @file colamd.h
|
|
kusano |
7d535a |
\brief Colamd prototypes and definitions
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
==========================================================================
|
|
kusano |
7d535a |
=== colamd/symamd prototypes and definitions =============================
|
|
kusano |
7d535a |
==========================================================================
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
You must include this file (colamd.h) in any routine that uses colamd,
|
|
kusano |
7d535a |
symamd, or the related macros and definitions.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Authors:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The authors of the code itself are Stefan I. Larimore and Timothy A.
|
|
kusano |
7d535a |
Davis (davis@cise.ufl.edu), University of Florida. The algorithm was
|
|
kusano |
7d535a |
developed in collaboration with John Gilbert, Xerox PARC, and Esmond
|
|
kusano |
7d535a |
Ng, Oak Ridge National Laboratory.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Date:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
September 8, 2003. Version 2.3.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Acknowledgements:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This work was supported by the National Science Foundation, under
|
|
kusano |
7d535a |
grants DMS-9504974 and DMS-9803599.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Notice:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Copyright (c) 1998-2003 by the University of Florida.
|
|
kusano |
7d535a |
All Rights Reserved.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
|
|
kusano |
7d535a |
EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Permission is hereby granted to use, copy, modify, and/or distribute
|
|
kusano |
7d535a |
this program, provided that the Copyright, this License, and the
|
|
kusano |
7d535a |
Availability of the original version is retained on all copies and made
|
|
kusano |
7d535a |
accessible to the end-user of any code or package that includes COLAMD
|
|
kusano |
7d535a |
or any modified version of COLAMD.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Availability:
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The colamd/symamd library is available at
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
http://www.cise.ufl.edu/research/sparse/colamd/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This is the http://www.cise.ufl.edu/research/sparse/colamd/colamd.h
|
|
kusano |
7d535a |
file. It is required by the colamd.c, colamdmex.c, and symamdmex.c
|
|
kusano |
7d535a |
files, and by any C code that calls the routines whose prototypes are
|
|
kusano |
7d535a |
listed below, or that uses the colamd/symamd definitions listed below.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef COLAMD_H
|
|
kusano |
7d535a |
#define COLAMD_H
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
/* === Include files ======================================================== */
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <stdlib.h></stdlib.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
/* === Knob and statistics definitions ====================================== */
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* size of the knobs [ ] array. Only knobs [0..1] are currently used. */
|
|
kusano |
7d535a |
#define COLAMD_KNOBS 20
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* number of output statistics. Only stats [0..6] are currently used. */
|
|
kusano |
7d535a |
#define COLAMD_STATS 20
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* knobs [0] and stats [0]: dense row knob and output statistic. */
|
|
kusano |
7d535a |
#define COLAMD_DENSE_ROW 0
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* knobs [1] and stats [1]: dense column knob and output statistic. */
|
|
kusano |
7d535a |
#define COLAMD_DENSE_COL 1
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* stats [2]: memory defragmentation count output statistic */
|
|
kusano |
7d535a |
#define COLAMD_DEFRAG_COUNT 2
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* stats [3]: colamd status: zero OK, > 0 warning or notice, < 0 error */
|
|
kusano |
7d535a |
#define COLAMD_STATUS 3
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* stats [4..6]: error info, or info on jumbled columns */
|
|
kusano |
7d535a |
#define COLAMD_INFO1 4
|
|
kusano |
7d535a |
#define COLAMD_INFO2 5
|
|
kusano |
7d535a |
#define COLAMD_INFO3 6
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* error codes returned in stats [3]: */
|
|
kusano |
7d535a |
#define COLAMD_OK (0)
|
|
kusano |
7d535a |
#define COLAMD_OK_BUT_JUMBLED (1)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_A_not_present (-1)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_p_not_present (-2)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_nrow_negative (-3)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_ncol_negative (-4)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_nnz_negative (-5)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_p0_nonzero (-6)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_A_too_small (-7)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_col_length_negative (-8)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_row_index_out_of_bounds (-9)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_out_of_memory (-10)
|
|
kusano |
7d535a |
#define COLAMD_ERROR_internal_error (-999)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
/* === Row and Column structures ============================================ */
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* User code that makes use of the colamd/symamd routines need not directly */
|
|
kusano |
7d535a |
/* reference these structures. They are used only for the COLAMD_RECOMMENDED */
|
|
kusano |
7d535a |
/* macro. */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef struct Colamd_Col_struct
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int start ; /* index for A of first row in this column, or DEAD */
|
|
kusano |
7d535a |
/* if column is dead */
|
|
kusano |
7d535a |
int length ; /* number of rows in this column */
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int thickness ; /* number of original columns represented by this */
|
|
kusano |
7d535a |
/* col, if the column is alive */
|
|
kusano |
7d535a |
int parent ; /* parent in parent tree super-column structure, if */
|
|
kusano |
7d535a |
/* the column is dead */
|
|
kusano |
7d535a |
} shared1 ;
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int score ; /* the score used to maintain heap, if col is alive */
|
|
kusano |
7d535a |
int order ; /* pivot ordering of this column, if col is dead */
|
|
kusano |
7d535a |
} shared2 ;
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int headhash ; /* head of a hash bucket, if col is at the head of */
|
|
kusano |
7d535a |
/* a degree list */
|
|
kusano |
7d535a |
int hash ; /* hash value, if col is not in a degree list */
|
|
kusano |
7d535a |
int prev ; /* previous column in degree list, if col is in a */
|
|
kusano |
7d535a |
/* degree list (but not at the head of a degree list) */
|
|
kusano |
7d535a |
} shared3 ;
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int degree_next ; /* next column, if col is in a degree list */
|
|
kusano |
7d535a |
int hash_next ; /* next column, if col is in a hash list */
|
|
kusano |
7d535a |
} shared4 ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} Colamd_Col ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef struct Colamd_Row_struct
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int start ; /* index for A of first col in this row */
|
|
kusano |
7d535a |
int length ; /* number of principal columns in this row */
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int degree ; /* number of principal & non-principal columns in row */
|
|
kusano |
7d535a |
int p ; /* used as a row pointer in init_rows_cols () */
|
|
kusano |
7d535a |
} shared1 ;
|
|
kusano |
7d535a |
union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int mark ; /* for computing set differences and marking dead rows*/
|
|
kusano |
7d535a |
int first_column ;/* first column in row (used in garbage collection) */
|
|
kusano |
7d535a |
} shared2 ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} Colamd_Row ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
/* === Colamd recommended memory size ======================================= */
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
The recommended length Alen of the array A passed to colamd is given by
|
|
kusano |
7d535a |
the COLAMD_RECOMMENDED (nnz, n_row, n_col) macro. It returns -1 if any
|
|
kusano |
7d535a |
argument is negative. 2*nnz space is required for the row and column
|
|
kusano |
7d535a |
indices of the matrix. COLAMD_C (n_col) + COLAMD_R (n_row) space is
|
|
kusano |
7d535a |
required for the Col and Row arrays, respectively, which are internal to
|
|
kusano |
7d535a |
colamd. An additional n_col space is the minimal amount of "elbow room",
|
|
kusano |
7d535a |
and nnz/5 more space is recommended for run time efficiency.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This macro is not needed when using symamd.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Explicit typecast to int added Sept. 23, 2002, COLAMD version 2.2, to avoid
|
|
kusano |
7d535a |
gcc -pedantic warning messages.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define COLAMD_C(n_col) ((int) (((n_col) + 1) * sizeof (Colamd_Col) / sizeof (int)))
|
|
kusano |
7d535a |
#define COLAMD_R(n_row) ((int) (((n_row) + 1) * sizeof (Colamd_Row) / sizeof (int)))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define COLAMD_RECOMMENDED(nnz, n_row, n_col) \
|
|
kusano |
7d535a |
( \
|
|
kusano |
7d535a |
((nnz) < 0 || (n_row) < 0 || (n_col) < 0) \
|
|
kusano |
7d535a |
? \
|
|
kusano |
7d535a |
(-1) \
|
|
kusano |
7d535a |
: \
|
|
kusano |
7d535a |
(2 * (nnz) + COLAMD_C (n_col) + COLAMD_R (n_row) + (n_col) + ((nnz) / 5)) \
|
|
kusano |
7d535a |
)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
/* === Prototypes of user-callable routines ================================= */
|
|
kusano |
7d535a |
/* ========================================================================== */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int colamd_recommended /* returns recommended value of Alen, */
|
|
kusano |
7d535a |
/* or (-1) if input arguments are erroneous */
|
|
kusano |
7d535a |
(
|
|
kusano |
7d535a |
int nnz, /* nonzeros in A */
|
|
kusano |
7d535a |
int n_row, /* number of rows in A */
|
|
kusano |
7d535a |
int n_col /* number of columns in A */
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void colamd_set_defaults /* sets default parameters */
|
|
kusano |
7d535a |
( /* knobs argument is modified on output */
|
|
kusano |
7d535a |
double knobs [COLAMD_KNOBS] /* parameter settings for colamd */
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int colamd /* returns (1) if successful, (0) otherwise*/
|
|
kusano |
7d535a |
( /* A and p arguments are modified on output */
|
|
kusano |
7d535a |
int n_row, /* number of rows in A */
|
|
kusano |
7d535a |
int n_col, /* number of columns in A */
|
|
kusano |
7d535a |
int Alen, /* size of the array A */
|
|
kusano |
7d535a |
int A [], /* row indices of A, of size Alen */
|
|
kusano |
7d535a |
int p [], /* column pointers of A, of size n_col+1 */
|
|
kusano |
7d535a |
double knobs [COLAMD_KNOBS],/* parameter settings for colamd */
|
|
kusano |
7d535a |
int stats [COLAMD_STATS] /* colamd output statistics and error codes */
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int symamd /* return (1) if OK, (0) otherwise */
|
|
kusano |
7d535a |
(
|
|
kusano |
7d535a |
int n, /* number of rows and columns of A */
|
|
kusano |
7d535a |
int A [], /* row indices of A */
|
|
kusano |
7d535a |
int p [], /* column pointers of A */
|
|
kusano |
7d535a |
int perm [], /* output permutation, size n_col+1 */
|
|
kusano |
7d535a |
double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */
|
|
kusano |
7d535a |
int stats [COLAMD_STATS], /* output statistics and error codes */
|
|
kusano |
7d535a |
void * (*allocate) (size_t, size_t),
|
|
kusano |
7d535a |
/* pointer to calloc (ANSI C) or */
|
|
kusano |
7d535a |
/* mxCalloc (for MATLAB mexFunction) */
|
|
kusano |
7d535a |
void (*release) (void *)
|
|
kusano |
7d535a |
/* pointer to free (ANSI C) or */
|
|
kusano |
7d535a |
/* mxFree (for MATLAB mexFunction) */
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void colamd_report
|
|
kusano |
7d535a |
(
|
|
kusano |
7d535a |
int stats [COLAMD_STATS]
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void symamd_report
|
|
kusano |
7d535a |
(
|
|
kusano |
7d535a |
int stats [COLAMD_STATS]
|
|
kusano |
7d535a |
) ;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif /* COLAMD_H */
|