aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/glpk-4.65/src/amd/amd_dump.c
blob: 39bbe1d8ece714d5c7f2ce6ff8361aeba4f543a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* ========================================================================= */
/* === AMD_dump ============================================================ */
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* AMD, Copyright (c) Timothy A. Davis,                                      */
/* Patrick R. Amestoy, and Iain S. Duff.  See ../README.txt for License.     */
/* email: davis at cise.ufl.edu    CISE Department, Univ. of Florida.        */
/* web: http://www.cise.ufl.edu/research/sparse/amd                          */
/* ------------------------------------------------------------------------- */

/* Debugging routines for AMD.  Not used if NDEBUG is not defined at compile-
 * time (the default).  See comments in amd_internal.h on how to enable
 * debugging.  Not user-callable.
 */

#include "amd_internal.h"

#ifndef NDEBUG

/* This global variable is present only when debugging */
GLOBAL Int AMD_debug = -999 ;           /* default is no debug printing */

/* ========================================================================= */
/* === AMD_debug_init ====================================================== */
/* ========================================================================= */

/* Sets the debug print level, by reading the file debug.amd (if it exists) */

GLOBAL void AMD_debug_init ( char *s )
{
    FILE *f ;
    f = fopen ("debug.amd", "r") ;
    if (f == (FILE *) NULL)
    {
        AMD_debug = -999 ;
    }
    else
    {
        fscanf (f, ID, &AMD_debug) ;
        fclose (f) ;
    }
    if (AMD_debug >= 0)
    {
        printf ("%s: AMD_debug_init, D= "ID"\n", s, AMD_debug) ;
    }
}

/* ========================================================================= */
/* === AMD_dump ============================================================ */
/* ========================================================================= */

/* Dump AMD's data structure, except for the hash buckets.  This routine
 * cannot be called when the hash buckets are non-empty.
 */

GLOBAL void AMD_dump (
    Int n,          /* A is n-by-n */
    Int Pe [ ],     /* pe [0..n-1]: index in iw of start of row i */
    Int Iw [ ],     /* workspace of size iwlen, iwlen [0..pfree-1]
                     * holds the matrix on input */
    Int Len [ ],    /* len [0..n-1]: length for row i */
    Int iwlen,      /* length of iw */
    Int pfree,      /* iw [pfree ... iwlen-1] is empty on input */
    Int Nv [ ],     /* nv [0..n-1] */
    Int Next [ ],   /* next [0..n-1] */
    Int Last [ ],   /* last [0..n-1] */
    Int Head [ ],   /* head [0..n-1] */
    Int Elen [ ],   /* size n */
    Int Degree [ ], /* size n */
    Int W [ ],      /* size n */
    Int nel
)
{
    Int i, pe, elen, nv, len, e, p, k, j, deg, w, cnt, ilast ;

    if (AMD_debug < 0) return ;
    ASSERT (pfree <= iwlen) ;
    AMD_DEBUG3 (("\nAMD dump, pfree: "ID"\n", pfree)) ;
    for (i = 0 ; i < n ; i++)
    {
        pe = Pe [i] ;
        elen = Elen [i] ;
        nv = Nv [i] ;
        len = Len [i] ;
        w = W [i] ;

        if (elen >= EMPTY)
        {
            if (nv == 0)
            {
                AMD_DEBUG3 (("\nI "ID": nonprincipal:    ", i)) ;
                ASSERT (elen == EMPTY) ;
                if (pe == EMPTY)
                {
                    AMD_DEBUG3 ((" dense node\n")) ;
                    ASSERT (w == 1) ;
                }
                else
                {
                    ASSERT (pe < EMPTY) ;
                    AMD_DEBUG3 ((" i "ID" -> parent "ID"\n", i, FLIP (Pe[i])));
                }
            }
            else
            {
                AMD_DEBUG3 (("\nI "ID": active principal supervariable:\n",i));
                AMD_DEBUG3 (("   nv(i): "ID"  Flag: %d\n", nv, (nv < 0))) ;
                ASSERT (elen >= 0) ;
                ASSERT (nv > 0 && pe >= 0) ;
                p = pe ;
                AMD_DEBUG3 (("   e/s: ")) ;
                if (elen == 0) AMD_DEBUG3 ((" : ")) ;
                ASSERT (pe + len <= pfree) ;
                for (k = 0 ; k < len ; k++)
                {
                    j = Iw [p] ;
                    AMD_DEBUG3 (("  "ID"", j)) ;
                    ASSERT (j >= 0 && j < n) ;
                    if (k == elen-1) AMD_DEBUG3 ((" : ")) ;
                    p++ ;
                }
                AMD_DEBUG3 (("\n")) ;
            }
        }
        else
        {
            e = i ;
            if (w == 0)
            {
                AMD_DEBUG3 (("\nE "ID": absorbed element: w "ID"\n", e, w)) ;
                ASSERT (nv > 0 && pe < 0) ;
                AMD_DEBUG3 ((" e "ID" -> parent "ID"\n", e, FLIP (Pe [e]))) ;
            }
            else
            {
                AMD_DEBUG3 (("\nE "ID": unabsorbed element: w "ID"\n", e, w)) ;
                ASSERT (nv > 0 && pe >= 0) ;
                p = pe ;
                AMD_DEBUG3 ((" : ")) ;
                ASSERT (pe + len <= pfree) ;
                for (k = 0 ; k < len ; k++)
                {
                    j = Iw [p] ;
                    AMD_DEBUG3 (("  "ID"", j)) ;
                    ASSERT (j >= 0 && j < n) ;
                    p++ ;
                }
                AMD_DEBUG3 (("\n")) ;
            }
        }
    }

    /* this routine cannot be called when the hash buckets are non-empty */
    AMD_DEBUG3 (("\nDegree lists:\n")) ;
    if (nel >= 0)
    {
        cnt = 0 ;
        for (deg = 0 ; deg < n ; deg++)
        {
            if (Head [deg] == EMPTY) continue ;
            ilast = EMPTY ;
            AMD_DEBUG3 ((ID": \n", deg)) ;
            for (i = Head [deg] ; i != EMPTY ; i = Next [i])
            {
                AMD_DEBUG3 (("   "ID" : next "ID" last "ID" deg "ID"\n",
                    i, Next [i], Last [i], Degree [i])) ;
                ASSERT (i >= 0 && i < n && ilast == Last [i] &&
                    deg == Degree [i]) ;
                cnt += Nv [i] ;
                ilast = i ;
            }
            AMD_DEBUG3 (("\n")) ;
        }
        ASSERT (cnt == n - nel) ;
    }

}

#endif