Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
klu2_dump.hpp
1 /* ========================================================================== */
2 /* === KLU_dump ============================================================= */
3 /* ========================================================================== */
4 // @HEADER
5 // ***********************************************************************
6 //
7 // KLU2: A Direct Linear Solver package
8 // Copyright 2011 Sandia Corporation
9 //
10 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
11 // U.S. Government retains certain rights in this software.
12 //
13 // This library is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as
15 // published by the Free Software Foundation; either version 2.1 of the
16 // License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
26 // USA
27 // Questions? Contact Mike A. Heroux (maherou@sandia.gov)
28 //
29 // KLU2 is derived work from KLU, licensed under LGPL, and copyrighted by
30 // University of Florida. The Authors of KLU are Timothy A. Davis and
31 // Eka Palamadai. See Doc/KLU_README.txt for the licensing and copyright
32 // information for KLU.
33 //
34 // ***********************************************************************
35 // @HEADER
36 
37 /* Debug routines for klu. Only used when NDEBUGKLU2 is not defined at
38  * compile-time.
39  */
40 
41 #ifndef KLU2_DUMP_HPP
42 #define KLU2_DUMP_HPP
43 
44 #include "klu2_internal.h"
45 
46 #ifndef NDEBUGKLU2
47 
48 /* ========================================================================== */
49 /* === KLU_valid ============================================================ */
50 /* ========================================================================== */
51 
52 /* Check if a column-form matrix is valid or not. The matrix A is
53  * n-by-n. The row indices of entries in column j are in
54  * Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:
55  *
56  * n >= 0
57  * nz = Ap [n_col] >= 0 number of entries in the matrix
58  * Ap [0] == 0
59  * Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
60  * row indices in Ai [Ap [j] ... Ap [j+1]-1]
61  * must be in the range 0 to n_row-1,
62  * and no duplicate entries can exist (duplicates not checked here).
63  *
64  * Not user-callable. Only used when debugging.
65  */
66 
67 template <typename Entry, typename Int>
68 Int KLU_valid (Int n, Int Ap [ ], Int Ai [ ], Entry Ax [ ])
69 {
70  Int nz, j, p1, p2, i, p ;
71  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
72  if (n <= 0)
73  {
74  PRINTF (("n must be >= 0: %d\n", n)) ;
75  return (FALSE) ;
76  }
77  nz = Ap [n] ;
78  if (Ap [0] != 0 || nz < 0)
79  {
80  /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
81  PRINTF (("column 0 pointer bad or nz < 0\n")) ;
82  return (FALSE) ;
83  }
84  for (j = 0 ; j < n ; j++)
85  {
86  p1 = Ap [j] ;
87  p2 = Ap [j+1] ;
88  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
89  if (p1 > p2)
90  {
91  /* column pointers must be ascending */
92  PRINTF (("column %d pointer bad\n", j)) ;
93  return (FALSE) ;
94  }
95  for (p = p1 ; p < p2 ; p++)
96  {
97  i = Ai [p] ;
98  PRINTF (("row: %d", i)) ;
99  if (i < 0 || i >= n)
100  {
101  /* row index out of range */
102  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
103  return (FALSE) ;
104  }
105  if (Ax != (Entry *) NULL)
106  {
107  PRINT_ENTRY (Ax [p]) ;
108  }
109  PRINTF (("\n")) ;
110  }
111  }
112  return (TRUE) ;
113 }
114 
115 
116 /* ========================================================================== */
117 /* === KLU_valid_LU ========================================================= */
118 /* ========================================================================== */
119 
120 /* This function does the same validity tests as KLU_valid but for the
121  * LU factor storage format. The flag flag_test_start_ptr is used to
122  * test if Xip [0] = 0. This is not applicable for U. So when calling this
123  * function for U, the flag should be set to false. Only used when debugging.
124  */
125 
126 template <typename Entry, typename Int>
127 Int KLU_valid_LU (Int n, Int flag_test_start_ptr, Int Xip [ ],
128  Int Xlen [ ], Unit LU [ ])
129 {
130  Int *Xi ;
131  Entry *Xx ;
132  Int j, p1, p2, i, p, len ;
133 
134  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
135  if (n <= 0)
136  {
137  PRINTF (("n must be >= 0: %d\n", n)) ;
138  return (FALSE) ;
139  }
140  if (flag_test_start_ptr && Xip [0] != 0)
141  {
142  /* column pointers must start at Xip [0] = 0*/
143  PRINTF (("column 0 pointer bad\n")) ;
144  return (FALSE) ;
145  }
146 
147  for (j = 0 ; j < n ; j++)
148  {
149  p1 = Xip [j] ;
150  p2 = Xip [j+1] ;
151  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
152  if (p1 > p2)
153  {
154  /* column pointers must be ascending */
155  PRINTF (("column %d pointer bad\n", j)) ;
156  return (FALSE) ;
157  }
158  GET_POINTER (LU, Xip, Xlen, Xi, Xx, j, len) ;
159  for (p = 0 ; p < len ; p++)
160  {
161  i = Xi [p] ;
162  PRINTF (("row: %d", i)) ;
163  if (i < 0 || i >= n)
164  {
165  /* row index out of range */
166  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
167  return (FALSE) ;
168  }
169  if (Xx != (Entry *) NULL)
170  {
171  PRINT_ENTRY (Xx [p]) ;
172  }
173  PRINTF (("\n")) ;
174  }
175  }
176 
177  return (TRUE) ;
178 }
179 #endif
180 
181 #endif