Amesos Package Browser (Single Doxygen Collection) Development
amesos_cholmod_l_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 /* This file should make the long int version of CHOLMOD */
00029 #define DLONG 1
00030 
00031 #include "amesos_cholmod_internal.h"
00032 #include "amesos_ccolamd.h"
00033 #include "amesos_cholmod_partition.h"
00034 
00035 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
00036 #error "CCOLAMD v2.0 or later is required"
00037 #endif
00038 
00039 /* ========================================================================== */
00040 /* === ccolamd_interface ==================================================== */
00041 /* ========================================================================== */
00042 
00043 /* Order with ccolamd */
00044 
00045 static int ccolamd_interface
00046 (
00047     cholmod_sparse *A,
00048     size_t alen,
00049     Int *Perm,
00050     Int *Cmember,
00051     Int *fset,
00052     Int fsize,
00053     cholmod_sparse *C,
00054     cholmod_common *Common
00055 )
00056 {
00057     double knobs [CCOLAMD_KNOBS] ;
00058     Int *Cp = NULL ;
00059     Int ok, k, nrow, ncol, stats [CCOLAMD_STATS] ;
00060 
00061     nrow = A->nrow ;
00062     ncol = A->ncol ;
00063 
00064     /* ---------------------------------------------------------------------- */
00065     /* copy (and transpose) the input matrix A into the ccolamd workspace */
00066     /* ---------------------------------------------------------------------- */
00067 
00068     /* C = A (:,f)', which also packs A if needed. */
00069     /* workspace: Iwork (nrow if no fset; MAX (nrow,ncol) if fset non-NULL) */
00070     ok = CHOLMOD(transpose_unsym) (A, 0, NULL, fset, fsize, C, Common) ;
00071 
00072     /* ---------------------------------------------------------------------- */
00073     /* order the matrix (destroys the contents of C->i and C->p) */
00074     /* ---------------------------------------------------------------------- */
00075 
00076     /* get parameters */
00077 #ifdef LONG
00078     amesos_ccolamd_l_set_defaults (knobs) ;
00079 #else
00080     amesos_ccolamd_set_defaults (knobs) ;
00081 #endif
00082 
00083     if (Common->current < 0 || Common->current >= CHOLMOD_MAXMETHODS)
00084     {
00085   /* this is the CHOLMOD default, not the CCOLAMD default */
00086   knobs [CCOLAMD_DENSE_ROW] = -1 ;
00087     }
00088     else
00089     {
00090   /* get the knobs from the Common parameters */
00091   knobs [CCOLAMD_DENSE_COL] =Common->method[Common->current].prune_dense ;
00092   knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense2;
00093   knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
00094   knobs [CCOLAMD_LU]        =Common->method[Common->current].order_for_lu;
00095     }
00096 
00097     if (ok)
00098     {
00099 
00100 #ifdef LONG
00101   amesos_ccolamd_l (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
00102 #else
00103   amesos_ccolamd (ncol, nrow, alen, C->i, C->p, knobs, stats, Cmember) ;
00104 #endif
00105 
00106   ok = stats [CCOLAMD_STATUS] ;
00107 
00108   ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
00109   /* permutation returned in C->p, if the ordering succeeded */
00110   Cp = C->p ;
00111   for (k = 0 ; k < nrow ; k++)
00112   {
00113       Perm [k] = Cp [k] ;
00114   }
00115     }
00116 
00117     return (ok) ;
00118 }
00119 
00120 
00121 /* ========================================================================== */
00122 /* === cholmod_ccolamd ====================================================== */
00123 /* ========================================================================== */
00124 
00125 /* Order AA' or A(:,f)*A(:,f)' using CCOLAMD. */
00126 
00127 int CHOLMOD(ccolamd)
00128 (
00129     /* ---- input ---- */
00130     cholmod_sparse *A,  /* matrix to order */
00131     Int *fset,    /* subset of 0:(A->ncol)-1 */
00132     size_t fsize, /* size of fset */
00133     Int *Cmember, /* size A->nrow.  Cmember [i] = c if row i is in the
00134        * constraint set c.  c must be >= 0.  The # of
00135        * constraint sets is max (Cmember) + 1.  If Cmember is
00136        * NULL, then it is interpretted as Cmember [i] = 0 for
00137        * all i */
00138     /* ---- output --- */
00139     Int *Perm,    /* size A->nrow, output permutation */
00140     /* --------------- */
00141     cholmod_common *Common
00142 )
00143 {
00144     cholmod_sparse *C ;
00145     Int ok, nrow, ncol ;
00146     size_t alen ;
00147 
00148     /* ---------------------------------------------------------------------- */
00149     /* check inputs */
00150     /* ---------------------------------------------------------------------- */
00151 
00152     RETURN_IF_NULL_COMMON (FALSE) ;
00153     RETURN_IF_NULL (A, FALSE) ;
00154     RETURN_IF_NULL (Perm, FALSE) ;
00155     RETURN_IF_XTYPE_INVALID (A, CHOLMOD_PATTERN, CHOLMOD_ZOMPLEX, FALSE) ;
00156     if (A->stype != 0)
00157     {
00158   ERROR (CHOLMOD_INVALID, "matrix must be unsymmetric") ;
00159   return (FALSE) ;
00160     }
00161     Common->status = CHOLMOD_OK ;
00162 
00163     /* ---------------------------------------------------------------------- */
00164     /* get inputs */
00165     /* ---------------------------------------------------------------------- */
00166 
00167     nrow = A->nrow ;
00168     ncol = A->ncol ;
00169 
00170     /* ---------------------------------------------------------------------- */
00171     /* allocate workspace */
00172     /* ---------------------------------------------------------------------- */
00173 
00174 #ifdef LONG
00175     alen = amesos_ccolamd_l_recommended (A->nzmax, ncol, nrow) ;
00176 #else
00177     alen = amesos_ccolamd_recommended (A->nzmax, ncol, nrow) ;
00178 #endif
00179 
00180     if (alen == 0)
00181     {
00182   ERROR (CHOLMOD_TOO_LARGE, "matrix invalid or too large") ;
00183   return (FALSE) ;
00184     }
00185 
00186     CHOLMOD(allocate_work) (0, MAX (nrow,ncol), 0, Common) ;
00187     if (Common->status < CHOLMOD_OK)
00188     {
00189   return (FALSE) ;
00190     }
00191 
00192     C = CHOLMOD(allocate_sparse) (ncol, nrow, alen, TRUE, TRUE, 0,
00193       CHOLMOD_PATTERN, Common) ;
00194 
00195     /* ---------------------------------------------------------------------- */
00196     /* order with ccolamd */
00197     /* ---------------------------------------------------------------------- */
00198 
00199     ok = ccolamd_interface (A, alen, Perm, Cmember, fset, fsize, C, Common) ;
00200 
00201     /* ---------------------------------------------------------------------- */
00202     /* free the workspace and return result */
00203     /* ---------------------------------------------------------------------- */
00204 
00205     CHOLMOD(free_sparse) (&C, Common) ;
00206     return (ok) ;
00207 }
00208 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines