1 /* ========================================================================= */
2 /* === CAMD_dump =========================================================== */
3 /* ========================================================================= */
4 
5 /* ------------------------------------------------------------------------- */
6 /* CAMD Version 2.0, Copyright (c) 2006 by Timothy A. Davis, Yanqing Chen,   */
7 /* Patrick R. Amestoy, and Iain S. Duff.  See ../README.txt for License.     */
8 /* email: davis at cise.ufl.edu    CISE Department, Univ. of Florida.        */
9 /* web: http://www.cise.ufl.edu/research/sparse/camd                         */
10 /* ------------------------------------------------------------------------- */
11 
12 /* Debugging routines for CAMD.  Not used if NDEBUG is not defined at compile-
13  * time (the default).  See comments in camd_internal.h on how to enable
14  * debugging.  Not user-callable.
15  */
16 
17 #include "camd_internal.h"
18 
19 #ifndef NDEBUG
20 
21 /* This global variable is present only when debugging */
22 GLOBAL Int CAMD_debug = -999 ;		/* default is no debug printing */
23 
24 /* ========================================================================= */
25 /* === CAMD_debug_init ===================================================== */
26 /* ========================================================================= */
27 
28 /* Sets the debug print level, by reading the file debug.camd (if it exists) */
29 
CAMD_debug_init(char * s)30 GLOBAL void CAMD_debug_init ( char *s )
31 {
32     FILE *f ;
33     f = fopen ("debug.camd", "r") ;
34     if (f == (FILE *) NULL)
35     {
36 	CAMD_debug = -999 ;
37     }
38     else
39     {
40 	fscanf (f, ID, &CAMD_debug) ;
41 	fclose (f) ;
42     }
43     if (CAMD_debug >= 0) printf ("%s: CAMD_debug_init, D= "ID"\n", s, CAMD_debug);
44 }
45 
46 /* ========================================================================= */
47 /* === CAMD_dump =========================================================== */
48 /* ========================================================================= */
49 
50 /* Dump CAMD's data structure, except for the hash buckets.  This routine
51  * cannot be called when the hash buckets are non-empty.
52  */
53 
CAMD_dump(Int n,Int Pe[],Int Iw[],Int Len[],Int iwlen,Int pfree,Int Nv[],Int Next[],Int Last[],Int Head[],Int Elen[],Int Degree[],Int W[],Int nel,Int BucketSet[],const Int C[],Int CurC)54 GLOBAL void CAMD_dump (
55     Int n,	    /* A is n-by-n */
56     Int Pe [ ],	    /* pe [0..n-1]: index in iw of start of row i */
57     Int Iw [ ],	    /* workspace of size iwlen, iwlen [0..pfree-1]
58 		     * holds the matrix on input */
59     Int Len [ ],    /* len [0..n-1]: length for row i */
60     Int iwlen,	    /* length of iw */
61     Int pfree,	    /* iw [pfree ... iwlen-1] is empty on input */
62     Int Nv [ ],	    /* nv [0..n-1] */
63     Int Next [ ],   /* next [0..n-1] */
64     Int Last [ ],   /* last [0..n-1] */
65     Int Head [ ],   /* head [0..n-1] */
66     Int Elen [ ],   /* size n */
67     Int Degree [ ], /* size n */
68     Int W [ ],	    /* size n */
69     Int nel,
70     Int BucketSet [ ],
71     const Int C [ ],
72     Int CurC
73 )
74 {
75     Int i, pe, elen, nv, len, e, p, k, j, deg, w, cnt, ilast ;
76 
77     if (CAMD_debug < 0) return ;
78     ASSERT (pfree <= iwlen) ;
79     CAMD_DEBUG3 (("\nCAMD dump, pfree: "ID"\n", pfree)) ;
80     for (i = 0 ; i < n ; i++)
81     {
82 	pe = Pe [i] ;
83 	elen = Elen [i] ;
84 	nv = Nv [i] ;
85 	len = Len [i] ;
86 	w = W [i] ;
87 
88 	if (elen >= EMPTY)
89 	{
90 	    if (nv == 0)
91 	    {
92 		CAMD_DEBUG3 (("\nI "ID": nonprincipal:    ", i)) ;
93 		ASSERT (elen == EMPTY) ;
94 		if (pe == FLIP(n))
95 		{
96 		    CAMD_DEBUG3 ((" dense node\n")) ;
97 		    ASSERT (w == 1) ;
98 		}
99 		else
100 		{
101 		    ASSERT (pe < EMPTY) ;
102 		    CAMD_DEBUG3 ((" i "ID" -> parent "ID"\n", i, FLIP (Pe[i])));
103 		}
104 	    }
105 	    else
106 	    {
107 		CAMD_DEBUG3 (("\nI "ID": active principal supervariable:\n",i));
108 		CAMD_DEBUG3 (("   nv(i): "ID"  Flag: %d\n", nv, (nv < 0))) ;
109 		ASSERT (elen >= 0) ;
110 		ASSERT (nv > 0 && pe >= 0) ;
111 		p = pe ;
112 		CAMD_DEBUG3 (("   e/s: ")) ;
113 		if (elen == 0) CAMD_DEBUG3 ((" : ")) ;
114 		ASSERT (pe + len <= pfree) ;
115 		for (k = 0 ; k < len ; k++)
116 		{
117 		    j = Iw [p] ;
118 		    CAMD_DEBUG3 (("  "ID"", j)) ;
119 		    ASSERT (j >= 0 && j < n) ;
120 		    if (k == elen-1) CAMD_DEBUG3 ((" : ")) ;
121 		    p++ ;
122 		}
123 		CAMD_DEBUG3 (("\n")) ;
124 	    }
125 	}
126 	else
127 	{
128 	    e = i ;
129 	    if (w == 0)
130 	    {
131 		CAMD_DEBUG3 (("\nE "ID": absorbed element: w "ID"\n", e, w)) ;
132 		ASSERT (nv > 0 && pe < 0) ;
133 		CAMD_DEBUG3 ((" e "ID" -> parent "ID"\n", e, FLIP (Pe [e]))) ;
134 	    }
135 	    else
136 	    {
137 		CAMD_DEBUG3 (("\nE "ID": unabsorbed element: w "ID"\n", e, w)) ;
138 		ASSERT (nv > 0 && pe >= 0) ;
139 		p = pe ;
140 		CAMD_DEBUG3 ((" : ")) ;
141 		ASSERT (pe + len <= pfree) ;
142 		for (k = 0 ; k < len ; k++)
143 		{
144 		    j = Iw [p] ;
145 		    CAMD_DEBUG3 (("  "ID"", j)) ;
146 		    ASSERT (j >= 0 && j < n) ;
147 		    p++ ;
148 		}
149 		CAMD_DEBUG3 (("\n")) ;
150 	    }
151 	}
152 	CAMD_DEBUG3 (("C[i] is :"ID"\n", (C == NULL) ? 0 : C [i]));
153     }
154 
155     /* this routine cannot be called when the hash buckets are non-empty */
156     CAMD_DEBUG3 (("\nDegree lists:\n")) ;
157     if (nel >= 0)
158     {
159 	cnt = 0 ;
160 	for (deg = 0 ; deg < n ; deg++)
161 	{
162 	    if (Head [deg] == EMPTY) continue ;
163 	    ilast = EMPTY ;
164 	    CAMD_DEBUG3 ((ID": \n", deg)) ;
165 	    for (i = Head [deg] ; i != EMPTY ; i = Next [i])
166 	    {
167 		CAMD_DEBUG3 (("   "ID" : next "ID" last "ID" deg "ID"\n",
168 		    i, Next [i], Last [i], Degree [i])) ;
169 		ASSERT (i >= 0 && i < n && ilast == Last [i] &&
170 		    deg == Degree [i]) ;
171 		cnt += Nv [i] ;
172 		ilast = i ;
173 	    }
174 	    CAMD_DEBUG3 (("\n")) ;
175 	}
176     }
177 
178     CAMD_DEBUG3(("\nCurrent C[i] is "ID". current Buckets are:\n", CurC)) ;
179     for (i = 0 ; i < n ; i++)
180     {
181 	if ((C == NULL) ? 1 : (C [BucketSet [i]] <= CurC))
182             CAMD_DEBUG3((ID",",BucketSet [i]));
183     }
184     CAMD_DEBUG3 (("\n")) ;
185 }
186 
187 #endif
188