MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
cgtt01.f
Go to the documentation of this file.
1  SUBROUTINE cgtt01( N, DL, D, DU, DLF, DF, DUF, DU2, IPIV, WORK,
2  $ ldwork, rwork, resid )
3 *
4 * -- LAPACK test routine (version 3.1) --
5 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
6 * November 2006
7 *
8 * .. Scalar Arguments ..
9  INTEGER ldwork, n
10  REAL resid
11 * ..
12 * .. Array Arguments ..
13  INTEGER ipiv( * )
14  REAL rwork( * )
15  COMPLEX d( * ), df( * ), dl( * ), dlf( * ), du( * ),
16  $ du2( * ), duf( * ), work( ldwork, * )
17 * ..
18 *
19 * Purpose
20 * =======
21 *
22 * CGTT01 reconstructs a tridiagonal matrix A from its LU factorization
23 * and computes the residual
24 * norm(L*U - A) / ( norm(A) * EPS ),
25 * where EPS is the machine epsilon.
26 *
27 * Arguments
28 * =========
29 *
30 * N (input) INTEGTER
31 * The order of the matrix A. N >= 0.
32 *
33 * DL (input) COMPLEX array, dimension (N-1)
34 * The (n-1) sub-diagonal elements of A.
35 *
36 * D (input) COMPLEX array, dimension (N)
37 * The diagonal elements of A.
38 *
39 * DU (input) COMPLEX array, dimension (N-1)
40 * The (n-1) super-diagonal elements of A.
41 *
42 * DLF (input) COMPLEX array, dimension (N-1)
43 * The (n-1) multipliers that define the matrix L from the
44 * LU factorization of A.
45 *
46 * DF (input) COMPLEX array, dimension (N)
47 * The n diagonal elements of the upper triangular matrix U from
48 * the LU factorization of A.
49 *
50 * DUF (input) COMPLEX array, dimension (N-1)
51 * The (n-1) elements of the first super-diagonal of U.
52 *
53 * DU2 (input) COMPLEX array, dimension (N-2)
54 * The (n-2) elements of the second super-diagonal of U.
55 *
56 * IPIV (input) INTEGER array, dimension (N)
57 * The pivot indices; for 1 <= i <= n, row i of the matrix was
58 * interchanged with row IPIV(i). IPIV(i) will always be either
59 * i or i+1; IPIV(i) = i indicates a row interchange was not
60 * required.
61 *
62 * WORK (workspace) COMPLEX array, dimension (LDWORK,N)
63 *
64 * LDWORK (input) INTEGER
65 * The leading dimension of the array WORK. LDWORK >= max(1,N).
66 *
67 * RWORK (workspace) REAL array, dimension (N)
68 *
69 * RESID (output) REAL
70 * The scaled residual: norm(L*U - A) / (norm(A) * EPS)
71 *
72 * =====================================================================
73 *
74 * .. Parameters ..
75  REAL one, zero
76  parameter( one = 1.0e+0, zero = 0.0e+0 )
77 * ..
78 * .. Local Scalars ..
79  INTEGER i, ip, j, lastj
80  REAL anorm, eps
81  COMPLEX li
82 * ..
83 * .. External Functions ..
84  REAL clangt, clanhs, slamch
85  EXTERNAL clangt, clanhs, slamch
86 * ..
87 * .. Intrinsic Functions ..
88  INTRINSIC min
89 * ..
90 * .. External Subroutines ..
91  EXTERNAL caxpy, cswap
92 * ..
93 * .. Executable Statements ..
94 *
95 * Quick return if possible
96 *
97  IF( n.LE.0 ) THEN
98  resid = zero
99  return
100  END IF
101 *
102  eps = slamch( 'Epsilon' )
103 *
104 * Copy the matrix U to WORK.
105 *
106  DO 20 j = 1, n
107  DO 10 i = 1, n
108  work( i, j ) = zero
109  10 continue
110  20 continue
111  DO 30 i = 1, n
112  IF( i.EQ.1 ) THEN
113  work( i, i ) = df( i )
114  IF( n.GE.2 )
115  $ work( i, i+1 ) = duf( i )
116  IF( n.GE.3 )
117  $ work( i, i+2 ) = du2( i )
118  ELSE IF( i.EQ.n ) THEN
119  work( i, i ) = df( i )
120  ELSE
121  work( i, i ) = df( i )
122  work( i, i+1 ) = duf( i )
123  IF( i.LT.n-1 )
124  $ work( i, i+2 ) = du2( i )
125  END IF
126  30 continue
127 *
128 * Multiply on the left by L.
129 *
130  lastj = n
131  DO 40 i = n - 1, 1, -1
132  li = dlf( i )
133  CALL caxpy( lastj-i+1, li, work( i, i ), ldwork,
134  $ work( i+1, i ), ldwork )
135  ip = ipiv( i )
136  IF( ip.EQ.i ) THEN
137  lastj = min( i+2, n )
138  ELSE
139  CALL cswap( lastj-i+1, work( i, i ), ldwork, work( i+1, i ),
140  $ ldwork )
141  END IF
142  40 continue
143 *
144 * Subtract the matrix A.
145 *
146  work( 1, 1 ) = work( 1, 1 ) - d( 1 )
147  IF( n.GT.1 ) THEN
148  work( 1, 2 ) = work( 1, 2 ) - du( 1 )
149  work( n, n-1 ) = work( n, n-1 ) - dl( n-1 )
150  work( n, n ) = work( n, n ) - d( n )
151  DO 50 i = 2, n - 1
152  work( i, i-1 ) = work( i, i-1 ) - dl( i-1 )
153  work( i, i ) = work( i, i ) - d( i )
154  work( i, i+1 ) = work( i, i+1 ) - du( i )
155  50 continue
156  END IF
157 *
158 * Compute the 1-norm of the tridiagonal matrix A.
159 *
160  anorm = clangt( '1', n, dl, d, du )
161 *
162 * Compute the 1-norm of WORK, which is only guaranteed to be
163 * upper Hessenberg.
164 *
165  resid = clanhs( '1', n, work, ldwork, rwork )
166 *
167 * Compute norm(L*U - A) / (norm(A) * EPS)
168 *
169  IF( anorm.LE.zero ) THEN
170  IF( resid.NE.zero )
171  $ resid = one / eps
172  ELSE
173  resid = ( resid / anorm ) / eps
174  END IF
175 *
176  return
177 *
178 * End of CGTT01
179 *
180  END