amd_dump.c 6.0 KB

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