001:       SUBROUTINE ZLATRD( UPLO, N, NB, A, LDA, E, TAU, W, LDW )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          UPLO
009:       INTEGER            LDA, LDW, N, NB
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   E( * )
013:       COMPLEX*16         A( LDA, * ), TAU( * ), W( LDW, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  ZLATRD reduces NB rows and columns of a complex Hermitian matrix A to
020: *  Hermitian tridiagonal form by a unitary similarity
021: *  transformation Q' * A * Q, and returns the matrices V and W which are
022: *  needed to apply the transformation to the unreduced part of A.
023: *
024: *  If UPLO = 'U', ZLATRD reduces the last NB rows and columns of a
025: *  matrix, of which the upper triangle is supplied;
026: *  if UPLO = 'L', ZLATRD reduces the first NB rows and columns of a
027: *  matrix, of which the lower triangle is supplied.
028: *
029: *  This is an auxiliary routine called by ZHETRD.
030: *
031: *  Arguments
032: *  =========
033: *
034: *  UPLO    (input) CHARACTER*1
035: *          Specifies whether the upper or lower triangular part of the
036: *          Hermitian matrix A is stored:
037: *          = 'U': Upper triangular
038: *          = 'L': Lower triangular
039: *
040: *  N       (input) INTEGER
041: *          The order of the matrix A.
042: *
043: *  NB      (input) INTEGER
044: *          The number of rows and columns to be reduced.
045: *
046: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
047: *          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
048: *          n-by-n upper triangular part of A contains the upper
049: *          triangular part of the matrix A, and the strictly lower
050: *          triangular part of A is not referenced.  If UPLO = 'L', the
051: *          leading n-by-n lower triangular part of A contains the lower
052: *          triangular part of the matrix A, and the strictly upper
053: *          triangular part of A is not referenced.
054: *          On exit:
055: *          if UPLO = 'U', the last NB columns have been reduced to
056: *            tridiagonal form, with the diagonal elements overwriting
057: *            the diagonal elements of A; the elements above the diagonal
058: *            with the array TAU, represent the unitary matrix Q as a
059: *            product of elementary reflectors;
060: *          if UPLO = 'L', the first NB columns have been reduced to
061: *            tridiagonal form, with the diagonal elements overwriting
062: *            the diagonal elements of A; the elements below the diagonal
063: *            with the array TAU, represent the  unitary matrix Q as a
064: *            product of elementary reflectors.
065: *          See Further Details.
066: *
067: *  LDA     (input) INTEGER
068: *          The leading dimension of the array A.  LDA >= max(1,N).
069: *
070: *  E       (output) DOUBLE PRECISION array, dimension (N-1)
071: *          If UPLO = 'U', E(n-nb:n-1) contains the superdiagonal
072: *          elements of the last NB columns of the reduced matrix;
073: *          if UPLO = 'L', E(1:nb) contains the subdiagonal elements of
074: *          the first NB columns of the reduced matrix.
075: *
076: *  TAU     (output) COMPLEX*16 array, dimension (N-1)
077: *          The scalar factors of the elementary reflectors, stored in
078: *          TAU(n-nb:n-1) if UPLO = 'U', and in TAU(1:nb) if UPLO = 'L'.
079: *          See Further Details.
080: *
081: *  W       (output) COMPLEX*16 array, dimension (LDW,NB)
082: *          The n-by-nb matrix W required to update the unreduced part
083: *          of A.
084: *
085: *  LDW     (input) INTEGER
086: *          The leading dimension of the array W. LDW >= max(1,N).
087: *
088: *  Further Details
089: *  ===============
090: *
091: *  If UPLO = 'U', the matrix Q is represented as a product of elementary
092: *  reflectors
093: *
094: *     Q = H(n) H(n-1) . . . H(n-nb+1).
095: *
096: *  Each H(i) has the form
097: *
098: *     H(i) = I - tau * v * v'
099: *
100: *  where tau is a complex scalar, and v is a complex vector with
101: *  v(i:n) = 0 and v(i-1) = 1; v(1:i-1) is stored on exit in A(1:i-1,i),
102: *  and tau in TAU(i-1).
103: *
104: *  If UPLO = 'L', the matrix Q is represented as a product of elementary
105: *  reflectors
106: *
107: *     Q = H(1) H(2) . . . H(nb).
108: *
109: *  Each H(i) has the form
110: *
111: *     H(i) = I - tau * v * v'
112: *
113: *  where tau is a complex scalar, and v is a complex vector with
114: *  v(1:i) = 0 and v(i+1) = 1; v(i+1:n) is stored on exit in A(i+1:n,i),
115: *  and tau in TAU(i).
116: *
117: *  The elements of the vectors v together form the n-by-nb matrix V
118: *  which is needed, with W, to apply the transformation to the unreduced
119: *  part of the matrix, using a Hermitian rank-2k update of the form:
120: *  A := A - V*W' - W*V'.
121: *
122: *  The contents of A on exit are illustrated by the following examples
123: *  with n = 5 and nb = 2:
124: *
125: *  if UPLO = 'U':                       if UPLO = 'L':
126: *
127: *    (  a   a   a   v4  v5 )              (  d                  )
128: *    (      a   a   v4  v5 )              (  1   d              )
129: *    (          a   1   v5 )              (  v1  1   a          )
130: *    (              d   1  )              (  v1  v2  a   a      )
131: *    (                  d  )              (  v1  v2  a   a   a  )
132: *
133: *  where d denotes a diagonal element of the reduced matrix, a denotes
134: *  an element of the original matrix that is unchanged, and vi denotes
135: *  an element of the vector defining H(i).
136: *
137: *  =====================================================================
138: *
139: *     .. Parameters ..
140:       COMPLEX*16         ZERO, ONE, HALF
141:       PARAMETER          ( ZERO = ( 0.0D+0, 0.0D+0 ),
142:      $                   ONE = ( 1.0D+0, 0.0D+0 ),
143:      $                   HALF = ( 0.5D+0, 0.0D+0 ) )
144: *     ..
145: *     .. Local Scalars ..
146:       INTEGER            I, IW
147:       COMPLEX*16         ALPHA
148: *     ..
149: *     .. External Subroutines ..
150:       EXTERNAL           ZAXPY, ZGEMV, ZHEMV, ZLACGV, ZLARFG, ZSCAL
151: *     ..
152: *     .. External Functions ..
153:       LOGICAL            LSAME
154:       COMPLEX*16         ZDOTC
155:       EXTERNAL           LSAME, ZDOTC
156: *     ..
157: *     .. Intrinsic Functions ..
158:       INTRINSIC          DBLE, MIN
159: *     ..
160: *     .. Executable Statements ..
161: *
162: *     Quick return if possible
163: *
164:       IF( N.LE.0 )
165:      $   RETURN
166: *
167:       IF( LSAME( UPLO, 'U' ) ) THEN
168: *
169: *        Reduce last NB columns of upper triangle
170: *
171:          DO 10 I = N, N - NB + 1, -1
172:             IW = I - N + NB
173:             IF( I.LT.N ) THEN
174: *
175: *              Update A(1:i,i)
176: *
177:                A( I, I ) = DBLE( A( I, I ) )
178:                CALL ZLACGV( N-I, W( I, IW+1 ), LDW )
179:                CALL ZGEMV( 'No transpose', I, N-I, -ONE, A( 1, I+1 ),
180:      $                     LDA, W( I, IW+1 ), LDW, ONE, A( 1, I ), 1 )
181:                CALL ZLACGV( N-I, W( I, IW+1 ), LDW )
182:                CALL ZLACGV( N-I, A( I, I+1 ), LDA )
183:                CALL ZGEMV( 'No transpose', I, N-I, -ONE, W( 1, IW+1 ),
184:      $                     LDW, A( I, I+1 ), LDA, ONE, A( 1, I ), 1 )
185:                CALL ZLACGV( N-I, A( I, I+1 ), LDA )
186:                A( I, I ) = DBLE( A( I, I ) )
187:             END IF
188:             IF( I.GT.1 ) THEN
189: *
190: *              Generate elementary reflector H(i) to annihilate
191: *              A(1:i-2,i)
192: *
193:                ALPHA = A( I-1, I )
194:                CALL ZLARFG( I-1, ALPHA, A( 1, I ), 1, TAU( I-1 ) )
195:                E( I-1 ) = ALPHA
196:                A( I-1, I ) = ONE
197: *
198: *              Compute W(1:i-1,i)
199: *
200:                CALL ZHEMV( 'Upper', I-1, ONE, A, LDA, A( 1, I ), 1,
201:      $                     ZERO, W( 1, IW ), 1 )
202:                IF( I.LT.N ) THEN
203:                   CALL ZGEMV( 'Conjugate transpose', I-1, N-I, ONE,
204:      $                        W( 1, IW+1 ), LDW, A( 1, I ), 1, ZERO,
205:      $                        W( I+1, IW ), 1 )
206:                   CALL ZGEMV( 'No transpose', I-1, N-I, -ONE,
207:      $                        A( 1, I+1 ), LDA, W( I+1, IW ), 1, ONE,
208:      $                        W( 1, IW ), 1 )
209:                   CALL ZGEMV( 'Conjugate transpose', I-1, N-I, ONE,
210:      $                        A( 1, I+1 ), LDA, A( 1, I ), 1, ZERO,
211:      $                        W( I+1, IW ), 1 )
212:                   CALL ZGEMV( 'No transpose', I-1, N-I, -ONE,
213:      $                        W( 1, IW+1 ), LDW, W( I+1, IW ), 1, ONE,
214:      $                        W( 1, IW ), 1 )
215:                END IF
216:                CALL ZSCAL( I-1, TAU( I-1 ), W( 1, IW ), 1 )
217:                ALPHA = -HALF*TAU( I-1 )*ZDOTC( I-1, W( 1, IW ), 1,
218:      $                 A( 1, I ), 1 )
219:                CALL ZAXPY( I-1, ALPHA, A( 1, I ), 1, W( 1, IW ), 1 )
220:             END IF
221: *
222:    10    CONTINUE
223:       ELSE
224: *
225: *        Reduce first NB columns of lower triangle
226: *
227:          DO 20 I = 1, NB
228: *
229: *           Update A(i:n,i)
230: *
231:             A( I, I ) = DBLE( A( I, I ) )
232:             CALL ZLACGV( I-1, W( I, 1 ), LDW )
233:             CALL ZGEMV( 'No transpose', N-I+1, I-1, -ONE, A( I, 1 ),
234:      $                  LDA, W( I, 1 ), LDW, ONE, A( I, I ), 1 )
235:             CALL ZLACGV( I-1, W( I, 1 ), LDW )
236:             CALL ZLACGV( I-1, A( I, 1 ), LDA )
237:             CALL ZGEMV( 'No transpose', N-I+1, I-1, -ONE, W( I, 1 ),
238:      $                  LDW, A( I, 1 ), LDA, ONE, A( I, I ), 1 )
239:             CALL ZLACGV( I-1, A( I, 1 ), LDA )
240:             A( I, I ) = DBLE( A( I, I ) )
241:             IF( I.LT.N ) THEN
242: *
243: *              Generate elementary reflector H(i) to annihilate
244: *              A(i+2:n,i)
245: *
246:                ALPHA = A( I+1, I )
247:                CALL ZLARFG( N-I, ALPHA, A( MIN( I+2, N ), I ), 1,
248:      $                      TAU( I ) )
249:                E( I ) = ALPHA
250:                A( I+1, I ) = ONE
251: *
252: *              Compute W(i+1:n,i)
253: *
254:                CALL ZHEMV( 'Lower', N-I, ONE, A( I+1, I+1 ), LDA,
255:      $                     A( I+1, I ), 1, ZERO, W( I+1, I ), 1 )
256:                CALL ZGEMV( 'Conjugate transpose', N-I, I-1, ONE,
257:      $                     W( I+1, 1 ), LDW, A( I+1, I ), 1, ZERO,
258:      $                     W( 1, I ), 1 )
259:                CALL ZGEMV( 'No transpose', N-I, I-1, -ONE, A( I+1, 1 ),
260:      $                     LDA, W( 1, I ), 1, ONE, W( I+1, I ), 1 )
261:                CALL ZGEMV( 'Conjugate transpose', N-I, I-1, ONE,
262:      $                     A( I+1, 1 ), LDA, A( I+1, I ), 1, ZERO,
263:      $                     W( 1, I ), 1 )
264:                CALL ZGEMV( 'No transpose', N-I, I-1, -ONE, W( I+1, 1 ),
265:      $                     LDW, W( 1, I ), 1, ONE, W( I+1, I ), 1 )
266:                CALL ZSCAL( N-I, TAU( I ), W( I+1, I ), 1 )
267:                ALPHA = -HALF*TAU( I )*ZDOTC( N-I, W( I+1, I ), 1,
268:      $                 A( I+1, I ), 1 )
269:                CALL ZAXPY( N-I, ALPHA, A( I+1, I ), 1, W( I+1, I ), 1 )
270:             END IF
271: *
272:    20    CONTINUE
273:       END IF
274: *
275:       RETURN
276: *
277: *     End of ZLATRD
278: *
279:       END
280: