001:       SUBROUTINE SLATRD( UPLO, N, NB, A, LDA, E, TAU, W, LDW )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          UPLO
010:       INTEGER            LDA, LDW, N, NB
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               A( LDA, * ), E( * ), TAU( * ), W( LDW, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  SLATRD reduces NB rows and columns of a real symmetric matrix A to
020: *  symmetric tridiagonal form by an orthogonal 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', SLATRD reduces the last NB rows and columns of a
025: *  matrix, of which the upper triangle is supplied;
026: *  if UPLO = 'L', SLATRD 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 SSYTRD.
030: *
031: *  Arguments
032: *  =========
033: *
034: *  UPLO    (input) CHARACTER*1
035: *          Specifies whether the upper or lower triangular part of the
036: *          symmetric 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) REAL array, dimension (LDA,N)
047: *          On entry, the symmetric 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 orthogonal 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  orthogonal 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 >= (1,N).
069: *
070: *  E       (output) REAL 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) REAL 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) REAL 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 real scalar, and v is a real 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 real scalar, and v is a real 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 symmetric 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:       REAL               ZERO, ONE, HALF
141:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0, HALF = 0.5E+0 )
142: *     ..
143: *     .. Local Scalars ..
144:       INTEGER            I, IW
145:       REAL               ALPHA
146: *     ..
147: *     .. External Subroutines ..
148:       EXTERNAL           SAXPY, SGEMV, SLARFG, SSCAL, SSYMV
149: *     ..
150: *     .. External Functions ..
151:       LOGICAL            LSAME
152:       REAL               SDOT
153:       EXTERNAL           LSAME, SDOT
154: *     ..
155: *     .. Intrinsic Functions ..
156:       INTRINSIC          MIN
157: *     ..
158: *     .. Executable Statements ..
159: *
160: *     Quick return if possible
161: *
162:       IF( N.LE.0 )
163:      $   RETURN
164: *
165:       IF( LSAME( UPLO, 'U' ) ) THEN
166: *
167: *        Reduce last NB columns of upper triangle
168: *
169:          DO 10 I = N, N - NB + 1, -1
170:             IW = I - N + NB
171:             IF( I.LT.N ) THEN
172: *
173: *              Update A(1:i,i)
174: *
175:                CALL SGEMV( 'No transpose', I, N-I, -ONE, A( 1, I+1 ),
176:      $                     LDA, W( I, IW+1 ), LDW, ONE, A( 1, I ), 1 )
177:                CALL SGEMV( 'No transpose', I, N-I, -ONE, W( 1, IW+1 ),
178:      $                     LDW, A( I, I+1 ), LDA, ONE, A( 1, I ), 1 )
179:             END IF
180:             IF( I.GT.1 ) THEN
181: *
182: *              Generate elementary reflector H(i) to annihilate
183: *              A(1:i-2,i)
184: *
185:                CALL SLARFG( I-1, A( I-1, I ), A( 1, I ), 1, TAU( I-1 ) )
186:                E( I-1 ) = A( I-1, I )
187:                A( I-1, I ) = ONE
188: *
189: *              Compute W(1:i-1,i)
190: *
191:                CALL SSYMV( 'Upper', I-1, ONE, A, LDA, A( 1, I ), 1,
192:      $                     ZERO, W( 1, IW ), 1 )
193:                IF( I.LT.N ) THEN
194:                   CALL SGEMV( 'Transpose', I-1, N-I, ONE, W( 1, IW+1 ),
195:      $                        LDW, A( 1, I ), 1, ZERO, W( I+1, IW ), 1 )
196:                   CALL SGEMV( 'No transpose', I-1, N-I, -ONE,
197:      $                        A( 1, I+1 ), LDA, W( I+1, IW ), 1, ONE,
198:      $                        W( 1, IW ), 1 )
199:                   CALL SGEMV( 'Transpose', I-1, N-I, ONE, A( 1, I+1 ),
200:      $                        LDA, A( 1, I ), 1, ZERO, W( I+1, IW ), 1 )
201:                   CALL SGEMV( 'No transpose', I-1, N-I, -ONE,
202:      $                        W( 1, IW+1 ), LDW, W( I+1, IW ), 1, ONE,
203:      $                        W( 1, IW ), 1 )
204:                END IF
205:                CALL SSCAL( I-1, TAU( I-1 ), W( 1, IW ), 1 )
206:                ALPHA = -HALF*TAU( I-1 )*SDOT( I-1, W( 1, IW ), 1,
207:      $                 A( 1, I ), 1 )
208:                CALL SAXPY( I-1, ALPHA, A( 1, I ), 1, W( 1, IW ), 1 )
209:             END IF
210: *
211:    10    CONTINUE
212:       ELSE
213: *
214: *        Reduce first NB columns of lower triangle
215: *
216:          DO 20 I = 1, NB
217: *
218: *           Update A(i:n,i)
219: *
220:             CALL SGEMV( 'No transpose', N-I+1, I-1, -ONE, A( I, 1 ),
221:      $                  LDA, W( I, 1 ), LDW, ONE, A( I, I ), 1 )
222:             CALL SGEMV( 'No transpose', N-I+1, I-1, -ONE, W( I, 1 ),
223:      $                  LDW, A( I, 1 ), LDA, ONE, A( I, I ), 1 )
224:             IF( I.LT.N ) THEN
225: *
226: *              Generate elementary reflector H(i) to annihilate
227: *              A(i+2:n,i)
228: *
229:                CALL SLARFG( N-I, A( I+1, I ), A( MIN( I+2, N ), I ), 1,
230:      $                      TAU( I ) )
231:                E( I ) = A( I+1, I )
232:                A( I+1, I ) = ONE
233: *
234: *              Compute W(i+1:n,i)
235: *
236:                CALL SSYMV( 'Lower', N-I, ONE, A( I+1, I+1 ), LDA,
237:      $                     A( I+1, I ), 1, ZERO, W( I+1, I ), 1 )
238:                CALL SGEMV( 'Transpose', N-I, I-1, ONE, W( I+1, 1 ), LDW,
239:      $                     A( I+1, I ), 1, ZERO, W( 1, I ), 1 )
240:                CALL SGEMV( 'No transpose', N-I, I-1, -ONE, A( I+1, 1 ),
241:      $                     LDA, W( 1, I ), 1, ONE, W( I+1, I ), 1 )
242:                CALL SGEMV( 'Transpose', N-I, I-1, ONE, A( I+1, 1 ), LDA,
243:      $                     A( I+1, I ), 1, ZERO, W( 1, I ), 1 )
244:                CALL SGEMV( 'No transpose', N-I, I-1, -ONE, W( I+1, 1 ),
245:      $                     LDW, W( 1, I ), 1, ONE, W( I+1, I ), 1 )
246:                CALL SSCAL( N-I, TAU( I ), W( I+1, I ), 1 )
247:                ALPHA = -HALF*TAU( I )*SDOT( N-I, W( I+1, I ), 1,
248:      $                 A( I+1, I ), 1 )
249:                CALL SAXPY( N-I, ALPHA, A( I+1, I ), 1, W( I+1, I ), 1 )
250:             END IF
251: *
252:    20    CONTINUE
253:       END IF
254: *
255:       RETURN
256: *
257: *     End of SLATRD
258: *
259:       END
260: