Amesos Package Browser (Single Doxygen Collection) Development
amesos_cholmod_csymamd.c
Go to the documentation of this file.
00001 /* ========================================================================== */
00002 /* === Partition/cholmod_csymamd ============================================ */
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 CSYMAMD ordering routine.  Finds a permutation
00015  * p such that the Cholesky factorization of PAP' is sparser than A.
00016  * The column etree is found and postordered, and the CSYMAMD
00017  * ordering is then combined with its postordering.  If A is unsymmetric,
00018  * A+A' is ordered (A must be square).
00019  *
00020  * workspace: Head (nrow+1)
00021  *
00022  * Supports any xtype (pattern, real, complex, or zomplex).
00023  */
00024 
00025 #ifndef NPARTITION
00026 
00027 #include "amesos_cholmod_internal.h"
00028 #include "amesos_ccolamd.h"
00029 #include "amesos_cholmod_partition.h"
00030 
00031 #if (CCOLAMD_VERSION < CCOLAMD_VERSION_CODE (2,5))
00032 #error "CCOLAMD v2.0 or later is required"
00033 #endif
00034 
00035 /* ========================================================================== */
00036 /* === cholmod_csymamd ====================================================== */
00037 /* ========================================================================== */
00038 
00039 int CHOLMOD(csymamd)
00040 (
00041     /* ---- input ---- */
00042     cholmod_sparse *A,  /* matrix to order */
00043     /* ---- output --- */
00044     Int *Cmember, /* size nrow.  see cholmod_ccolamd.c for description */
00045     Int *Perm,    /* size A->nrow, output permutation */
00046     /* --------------- */
00047     cholmod_common *Common
00048 )
00049 {
00050     double knobs [CCOLAMD_KNOBS] ;
00051     Int *perm, *Head ;
00052     Int ok, i, nrow, stats [CCOLAMD_STATS] ;
00053 
00054     /* ---------------------------------------------------------------------- */
00055     /* check inputs */
00056     /* ---------------------------------------------------------------------- */
00057 
00058     RETURN_IF_NULL_COMMON (FALSE) ;
00059     RETURN_IF_NULL (A, FALSE) ;
00060     RETURN_IF_NULL (Perm, FALSE) ;
00061     RETURN_IF_XTYPE_INVALID (A, CHOLMOD_PATTERN, CHOLMOD_ZOMPLEX, FALSE) ;
00062     Common->status = CHOLMOD_OK ;
00063 
00064     if (A->nrow != A->ncol || !(A->packed))
00065     {
00066   ERROR (CHOLMOD_INVALID, "matrix must be square and packed") ;
00067   return (FALSE) ;
00068     }
00069 
00070     /* ---------------------------------------------------------------------- */
00071     /* get inputs */
00072     /* ---------------------------------------------------------------------- */
00073 
00074     nrow = A->nrow ;
00075 
00076     /* ---------------------------------------------------------------------- */
00077     /* allocate workspace */
00078     /* ---------------------------------------------------------------------- */
00079 
00080     CHOLMOD(allocate_work) (nrow, 0, 0, Common) ;
00081     if (Common->status < CHOLMOD_OK)
00082     {
00083   return (FALSE) ;
00084     }
00085 
00086     /* ---------------------------------------------------------------------- */
00087     /* order the matrix (does not affect A->p or A->i) */
00088     /* ---------------------------------------------------------------------- */
00089 
00090     perm = Common->Head ; /* size nrow+1 (i/l/l) */
00091 
00092     /* get parameters */
00093 #ifdef LONG
00094     amesos_ccolamd_l_set_defaults (knobs) ;
00095 #else
00096     amesos_ccolamd_set_defaults (knobs) ;
00097 #endif
00098     if (Common->current >= 0 && Common->current < CHOLMOD_MAXMETHODS)
00099     {
00100   /* get the knobs from the Common parameters */
00101   knobs [CCOLAMD_DENSE_ROW] =Common->method[Common->current].prune_dense ;
00102   knobs [CCOLAMD_AGGRESSIVE]=Common->method[Common->current].aggressive ;
00103     }
00104 
00105     {
00106 #ifdef LONG
00107   amesos_csymamd_l (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
00108     Common->free_memory, Cmember, A->stype) ;
00109 #else
00110   amesos_csymamd (nrow, A->i, A->p, perm, knobs, stats, Common->calloc_memory,
00111     Common->free_memory, Cmember, A->stype) ;
00112 #endif
00113   ok = stats [CCOLAMD_STATUS] ;
00114     }
00115 
00116     if (ok == CCOLAMD_ERROR_out_of_memory)
00117     {
00118   ERROR (CHOLMOD_OUT_OF_MEMORY, "out of memory") ; 
00119     }
00120     ok = (ok == CCOLAMD_OK || ok == CCOLAMD_OK_BUT_JUMBLED) ;
00121 
00122     /* ---------------------------------------------------------------------- */
00123     /* free the workspace and return result */
00124     /* ---------------------------------------------------------------------- */
00125 
00126     /* permutation returned in perm [0..n-1] */
00127     for (i = 0 ; i < nrow ; i++)
00128     {
00129   Perm [i] = perm [i] ;
00130     }
00131 
00132     /* clear Head workspace (used for perm, in csymamd): */
00133     Head = Common->Head ;
00134     for (i = 0 ; i <= nrow ; i++)
00135     {
00136   Head [i] = EMPTY ;
00137     }
00138 
00139     return (ok) ;
00140 }
00141 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines