src/amd/amd_dump.c
changeset 1 c445c931472f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/amd/amd_dump.c	Mon Dec 06 13:09:21 2010 +0100
     1.3 @@ -0,0 +1,180 @@
     1.4 +/* ========================================================================= */
     1.5 +/* === AMD_dump ============================================================ */
     1.6 +/* ========================================================================= */
     1.7 +
     1.8 +/* ------------------------------------------------------------------------- */
     1.9 +/* AMD, Copyright (c) Timothy A. Davis,                                      */
    1.10 +/* Patrick R. Amestoy, and Iain S. Duff.  See ../README.txt for License.     */
    1.11 +/* email: davis at cise.ufl.edu    CISE Department, Univ. of Florida.        */
    1.12 +/* web: http://www.cise.ufl.edu/research/sparse/amd                          */
    1.13 +/* ------------------------------------------------------------------------- */
    1.14 +
    1.15 +/* Debugging routines for AMD.  Not used if NDEBUG is not defined at compile-
    1.16 + * time (the default).  See comments in amd_internal.h on how to enable
    1.17 + * debugging.  Not user-callable.
    1.18 + */
    1.19 +
    1.20 +#include "amd_internal.h"
    1.21 +
    1.22 +#ifndef NDEBUG
    1.23 +
    1.24 +/* This global variable is present only when debugging */
    1.25 +GLOBAL Int AMD_debug = -999 ;           /* default is no debug printing */
    1.26 +
    1.27 +/* ========================================================================= */
    1.28 +/* === AMD_debug_init ====================================================== */
    1.29 +/* ========================================================================= */
    1.30 +
    1.31 +/* Sets the debug print level, by reading the file debug.amd (if it exists) */
    1.32 +
    1.33 +GLOBAL void AMD_debug_init ( char *s )
    1.34 +{
    1.35 +    FILE *f ;
    1.36 +    f = fopen ("debug.amd", "r") ;
    1.37 +    if (f == (FILE *) NULL)
    1.38 +    {
    1.39 +        AMD_debug = -999 ;
    1.40 +    }
    1.41 +    else
    1.42 +    {
    1.43 +        fscanf (f, ID, &AMD_debug) ;
    1.44 +        fclose (f) ;
    1.45 +    }
    1.46 +    if (AMD_debug >= 0)
    1.47 +    {
    1.48 +        printf ("%s: AMD_debug_init, D= "ID"\n", s, AMD_debug) ;
    1.49 +    }
    1.50 +}
    1.51 +
    1.52 +/* ========================================================================= */
    1.53 +/* === AMD_dump ============================================================ */
    1.54 +/* ========================================================================= */
    1.55 +
    1.56 +/* Dump AMD's data structure, except for the hash buckets.  This routine
    1.57 + * cannot be called when the hash buckets are non-empty.
    1.58 + */
    1.59 +
    1.60 +GLOBAL void AMD_dump (
    1.61 +    Int n,          /* A is n-by-n */
    1.62 +    Int Pe [ ],     /* pe [0..n-1]: index in iw of start of row i */
    1.63 +    Int Iw [ ],     /* workspace of size iwlen, iwlen [0..pfree-1]
    1.64 +                     * holds the matrix on input */
    1.65 +    Int Len [ ],    /* len [0..n-1]: length for row i */
    1.66 +    Int iwlen,      /* length of iw */
    1.67 +    Int pfree,      /* iw [pfree ... iwlen-1] is empty on input */
    1.68 +    Int Nv [ ],     /* nv [0..n-1] */
    1.69 +    Int Next [ ],   /* next [0..n-1] */
    1.70 +    Int Last [ ],   /* last [0..n-1] */
    1.71 +    Int Head [ ],   /* head [0..n-1] */
    1.72 +    Int Elen [ ],   /* size n */
    1.73 +    Int Degree [ ], /* size n */
    1.74 +    Int W [ ],      /* size n */
    1.75 +    Int nel
    1.76 +)
    1.77 +{
    1.78 +    Int i, pe, elen, nv, len, e, p, k, j, deg, w, cnt, ilast ;
    1.79 +
    1.80 +    if (AMD_debug < 0) return ;
    1.81 +    ASSERT (pfree <= iwlen) ;
    1.82 +    AMD_DEBUG3 (("\nAMD dump, pfree: "ID"\n", pfree)) ;
    1.83 +    for (i = 0 ; i < n ; i++)
    1.84 +    {
    1.85 +        pe = Pe [i] ;
    1.86 +        elen = Elen [i] ;
    1.87 +        nv = Nv [i] ;
    1.88 +        len = Len [i] ;
    1.89 +        w = W [i] ;
    1.90 +
    1.91 +        if (elen >= EMPTY)
    1.92 +        {
    1.93 +            if (nv == 0)
    1.94 +            {
    1.95 +                AMD_DEBUG3 (("\nI "ID": nonprincipal:    ", i)) ;
    1.96 +                ASSERT (elen == EMPTY) ;
    1.97 +                if (pe == EMPTY)
    1.98 +                {
    1.99 +                    AMD_DEBUG3 ((" dense node\n")) ;
   1.100 +                    ASSERT (w == 1) ;
   1.101 +                }
   1.102 +                else
   1.103 +                {
   1.104 +                    ASSERT (pe < EMPTY) ;
   1.105 +                    AMD_DEBUG3 ((" i "ID" -> parent "ID"\n", i, FLIP (Pe[i])));
   1.106 +                }
   1.107 +            }
   1.108 +            else
   1.109 +            {
   1.110 +                AMD_DEBUG3 (("\nI "ID": active principal supervariable:\n",i));
   1.111 +                AMD_DEBUG3 (("   nv(i): "ID"  Flag: %d\n", nv, (nv < 0))) ;
   1.112 +                ASSERT (elen >= 0) ;
   1.113 +                ASSERT (nv > 0 && pe >= 0) ;
   1.114 +                p = pe ;
   1.115 +                AMD_DEBUG3 (("   e/s: ")) ;
   1.116 +                if (elen == 0) AMD_DEBUG3 ((" : ")) ;
   1.117 +                ASSERT (pe + len <= pfree) ;
   1.118 +                for (k = 0 ; k < len ; k++)
   1.119 +                {
   1.120 +                    j = Iw [p] ;
   1.121 +                    AMD_DEBUG3 (("  "ID"", j)) ;
   1.122 +                    ASSERT (j >= 0 && j < n) ;
   1.123 +                    if (k == elen-1) AMD_DEBUG3 ((" : ")) ;
   1.124 +                    p++ ;
   1.125 +                }
   1.126 +                AMD_DEBUG3 (("\n")) ;
   1.127 +            }
   1.128 +        }
   1.129 +        else
   1.130 +        {
   1.131 +            e = i ;
   1.132 +            if (w == 0)
   1.133 +            {
   1.134 +                AMD_DEBUG3 (("\nE "ID": absorbed element: w "ID"\n", e, w)) ;
   1.135 +                ASSERT (nv > 0 && pe < 0) ;
   1.136 +                AMD_DEBUG3 ((" e "ID" -> parent "ID"\n", e, FLIP (Pe [e]))) ;
   1.137 +            }
   1.138 +            else
   1.139 +            {
   1.140 +                AMD_DEBUG3 (("\nE "ID": unabsorbed element: w "ID"\n", e, w)) ;
   1.141 +                ASSERT (nv > 0 && pe >= 0) ;
   1.142 +                p = pe ;
   1.143 +                AMD_DEBUG3 ((" : ")) ;
   1.144 +                ASSERT (pe + len <= pfree) ;
   1.145 +                for (k = 0 ; k < len ; k++)
   1.146 +                {
   1.147 +                    j = Iw [p] ;
   1.148 +                    AMD_DEBUG3 (("  "ID"", j)) ;
   1.149 +                    ASSERT (j >= 0 && j < n) ;
   1.150 +                    p++ ;
   1.151 +                }
   1.152 +                AMD_DEBUG3 (("\n")) ;
   1.153 +            }
   1.154 +        }
   1.155 +    }
   1.156 +
   1.157 +    /* this routine cannot be called when the hash buckets are non-empty */
   1.158 +    AMD_DEBUG3 (("\nDegree lists:\n")) ;
   1.159 +    if (nel >= 0)
   1.160 +    {
   1.161 +        cnt = 0 ;
   1.162 +        for (deg = 0 ; deg < n ; deg++)
   1.163 +        {
   1.164 +            if (Head [deg] == EMPTY) continue ;
   1.165 +            ilast = EMPTY ;
   1.166 +            AMD_DEBUG3 ((ID": \n", deg)) ;
   1.167 +            for (i = Head [deg] ; i != EMPTY ; i = Next [i])
   1.168 +            {
   1.169 +                AMD_DEBUG3 (("   "ID" : next "ID" last "ID" deg "ID"\n",
   1.170 +                    i, Next [i], Last [i], Degree [i])) ;
   1.171 +                ASSERT (i >= 0 && i < n && ilast == Last [i] &&
   1.172 +                    deg == Degree [i]) ;
   1.173 +                cnt += Nv [i] ;
   1.174 +                ilast = i ;
   1.175 +            }
   1.176 +            AMD_DEBUG3 (("\n")) ;
   1.177 +        }
   1.178 +        ASSERT (cnt == n - nel) ;
   1.179 +    }
   1.180 +
   1.181 +}
   1.182 +
   1.183 +#endif