Amesos Package Browser (Single Doxygen Collection) Development
amesos_cholmod_ccolamd.c
Go to the documentation of this file.
00001 /* ========================================================================== */
00002 /* === Partition/cholmod_ccolamd ============================================ */
00003 /* ========================================================================== */
00004 
00005 /* -----------------------------------------------------------------------------
00006  * CHOLMOD/Partition Module. 
00007  * Copyright (C) 2005-2006, Univ. of Florida.  Author: Timothy A. Davis
00008  * The CHOLMOD/Partition Module is licensed under Version 2.1 of the GNU
00009  * Lesser General Public License.  See lesser.txt for a text of the license.
00010  * CHOLMOD is also available under other licenses; contact authors for details.
00011  * http://www.cise.ufl.edu/research/sparse
00012  * -------------------------------------------------------------------------- */
00013 
00014 /* CHOLMOD interface to the CCOLAMD ordering routine.  Finds a permutation
00015  * p such that the Cholesky factorization of PAA'P' is sparser than AA'.
00016  * The column etree is found and postordered, and the ccolamd ordering is then
00017  * combined with its postordering.  A must be unsymmetric.
00018  *
00019  * workspace: Iwork (MAX (nrow,ncol))
00020  *  Allocates a copy of its input matrix, which is
00021  *  then used as CCOLAMD's workspace.
00022  *
00023  * Supports any xtype (pattern, real, complex, or zomplex).
00024  */
00025 
00026 #ifndef NPARTITION
00027 
00028 #include "amesos_cholmod_internal.h"
00029 #include "amesos_ccolamd.h"
00030 #include "amesos_cholmod_partition.h"
00031 
00032 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
00033 #error "CCOLAMD v2.0 or later is required"
00034 #endif
00035 
00036 /* ========================================================================== */
00037 /* === ccolamd_interface ==================================================== */
00038 /* ========================================================================== */
00039 
00040 /* Order with ccolamd */
00041 
00042 static int ccolamd_interface
00043 (
00044     cholmod_sparse *A,
00045     size_t alen,
00046     Int *Perm,
00047     Int *Cmember,
00048     Int *fset,
00049     Int fsize,
00050     cholmod_sparse *C,
00051     cholmod_common *Common
00052 )
00053 {
00054     double knobs [CCOLAMD_KNOBS] ;
00055     Int *Cp = NULL ;
00056     Int ok, k, nrow, ncol, stats [CCOLAMD_STATS] ;
00057 
00058     nrow = A->nrow ;
00059     ncol = A->ncol ;
00060 
00061     /* ---------------------------------------------------------------------- */
00062     /* copy (and transpose) the input matrix A into the ccolamd workspace */
00063     /* ---------------------------------------------------------------------- */
00064 
00065     /* C = A (:,f)', which also packs A if needed. */
00066     /* workspace: Iwork (nrow if no fset; MAX (nrow,ncol) if fset non-NULL) */
00067     ok = CHOLMOD(transpose_unsym) (A, 0, NULL, fset, fsize, C, Common) ;
00068 
00069     /* ---------------------------------------------------------------------- */
00070     /* order the matrix (destroys the contents of C->i and C->p) */
00071     /* ---------------------------------------------------------------------- */
00072 
00073     /* get parameters */
00074 #ifdef LONG
00075     amesos_ccolamd_l_set_defaults (knobs) ;
00076 #else
00077     amesos_ccolamd_set_defaults (knobs) ;
00078 #endif
00079 
00080     if (Common->current < 0 || Common->current >= CHOLMOD_MAXMETHODS)
00081     {
00082   /* this is the CHOLMOD default, not the CCOLAMD default */
00083   knobs [CCOLAMD_DENSE_ROW] = -1 ;
00084     }
00085     else
00086     {
00087   /* get the knobs from the Common parameters */
00088   knobs [CCOLAMD_DENSE_COL] =Common->method[Common->current].prune_dense ;
00089   knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense2;
00090   knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
00091   knobs [CCOLAMD_LU]        =Common->method[Common->current].order_for_lu;
00092     }
00093 
00094     if (ok)
00095     {
00096 
00097 #ifdef LONG
00098   amesos_ccolamd_l (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
00099 #else
00100   amesos_ccolamd (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
00101 #endif
00102 
00103   ok = stats [CCOLAMD_STATUS] ;
00104 
00105   ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
00106   /* permutation returned in C->p, if the ordering succeeded */
00107   Cp = C->p ;
00108   for (k = 0 ; k < nrow ; k++)
00109   {
00110       Perm [k] = Cp [k] ;
00111   }
00112     }
00113 
00114     return (ok) ;
00115 }
00116 
00117 
00118 /* ========================================================================== */
00119 /* === cholmod_ccolamd ====================================================== */
00120 /* ========================================================================== */
00121 
00122 /* Order AA' or A(:,f)*A(:,f)' using CCOLAMD. */
00123 
00124 int CHOLMOD(ccolamd)
00125 (
00126     /* ---- input ---- */
00127     cholmod_sparse *A,  /* matrix to order */
00128     Int *fset,    /* subset of 0:(A->ncol)-1 */
00129     size_t fsize, /* size of fset */
00130     Int *Cmember, /* size A->nrow.  Cmember [i] = c if row i is in the
00131        * constraint set c.  c must be >= 0.  The # of
00132        * constraint sets is max (Cmember) + 1.  If Cmember is
00133        * NULL, then it is interpretted as Cmember [i] = 0 for
00134        * all i */
00135     /* ---- output --- */
00136     Int *Perm,    /* size A->nrow, output permutation */
00137     /* --------------- */
00138     cholmod_common *Common
00139 )
00140 {
00141     cholmod_sparse *C ;
00142     Int ok, nrow, ncol ;
00143     size_t alen ;
00144 
00145     /* ---------------------------------------------------------------------- */
00146     /* check inputs */
00147     /* ---------------------------------------------------------------------- */
00148 
00149     RETURN_IF_NULL_COMMON (FALSE) ;
00150     RETURN_IF_NULL (A, FALSE) ;
00151     RETURN_IF_NULL (Perm, FALSE) ;
00152     RETURN_IF_XTYPE_INVALID (A, CHOLMOD_PATTERN, CHOLMOD_ZOMPLEX, FALSE) ;
00153     if (A->stype != 0)
00154     {
00155   ERROR (CHOLMOD_INVALID, "matrix must be unsymmetric") ;
00156   return (FALSE) ;
00157     }
00158     Common->status = CHOLMOD_OK ;
00159 
00160     /* ---------------------------------------------------------------------- */
00161     /* get inputs */
00162     /* ---------------------------------------------------------------------- */
00163 
00164     nrow = A->nrow ;
00165     ncol = A->ncol ;
00166 
00167     /* ---------------------------------------------------------------------- */
00168     /* allocate workspace */
00169     /* ---------------------------------------------------------------------- */
00170 
00171 #ifdef LONG
00172     alen = amesos_ccolamd_l_recommended (A->nzmax, ncol, nrow) ;
00173 #else
00174     alen = amesos_ccolamd_recommended (A->nzmax, ncol, nrow) ;
00175 #endif
00176 
00177     if (alen == 0)
00178     {
00179   ERROR (CHOLMOD_TOO_LARGE, "matrix invalid or too large") ;
00180   return (FALSE) ;
00181     }
00182 
00183     CHOLMOD(allocate_work) (0, MAX (nrow,ncol), 0, Common) ;
00184     if (Common->status < CHOLMOD_OK)
00185     {
00186   return (FALSE) ;
00187     }
00188 
00189     C = CHOLMOD(allocate_sparse) (ncol, nrow, alen, TRUE, TRUE, 0,
00190       CHOLMOD_PATTERN, Common) ;
00191 
00192     /* ---------------------------------------------------------------------- */
00193     /* order with ccolamd */
00194     /* ---------------------------------------------------------------------- */
00195 
00196     ok = ccolamd_interface (A, alen, Perm, Cmember, fset, fsize, C, Common) ;
00197 
00198     /* ---------------------------------------------------------------------- */
00199     /* free the workspace and return result */
00200     /* ---------------------------------------------------------------------- */
00201 
00202     CHOLMOD(free_sparse) (&C, Common) ;
00203     return (ok) ;
00204 }
00205 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines