3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SSPTRF + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssptrf.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssptrf.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssptrf.f">
21 * SUBROUTINE SSPTRF( UPLO, N, AP, IPIV, INFO )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
38 *> SSPTRF computes the factorization of a real symmetric matrix A stored
39 *> in packed format using the Bunch-Kaufman diagonal pivoting method:
41 *> A = U*D*U**T or A = L*D*L**T
43 *> where U (or L) is a product of permutation and unit upper (lower)
44 *> triangular matrices, and D is symmetric and block diagonal with
45 *> 1-by-1 and 2-by-2 diagonal blocks.
53 *> UPLO is CHARACTER*1
54 *> = 'U': Upper triangle of A is stored;
55 *> = 'L': Lower triangle of A is stored.
61 *> The order of the matrix A. N >= 0.
66 *> AP is REAL array, dimension (N*(N+1)/2)
67 *> On entry, the upper or lower triangle of the symmetric matrix
68 *> A, packed columnwise in a linear array. The j-th column of A
69 *> is stored in the array AP as follows:
70 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
71 *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
73 *> On exit, the block diagonal matrix D and the multipliers used
74 *> to obtain the factor U or L, stored as a packed triangular
75 *> matrix overwriting A (see below for further details).
80 *> IPIV is INTEGER array, dimension (N)
81 *> Details of the interchanges and the block structure of D.
82 *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
83 *> interchanged and D(k,k) is a 1-by-1 diagonal block.
84 *> If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
85 *> columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
86 *> is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
87 *> IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
88 *> interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
94 *> = 0: successful exit
95 *> < 0: if INFO = -i, the i-th argument had an illegal value
96 *> > 0: if INFO = i, D(i,i) is exactly zero. The factorization
97 *> has been completed, but the block diagonal matrix D is
98 *> exactly singular, and division by zero will occur if it
99 *> is used to solve a system of equations.
105 *> \author Univ. of Tennessee
106 *> \author Univ. of California Berkeley
107 *> \author Univ. of Colorado Denver
110 *> \date November 2011
112 *> \ingroup realOTHERcomputational
114 *> \par Further Details:
115 * =====================
119 *> 5-96 - Based on modifications by J. Lewis, Boeing Computer Services
122 *> If UPLO = 'U', then A = U*D*U**T, where
123 *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
124 *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
125 *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
126 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
127 *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
128 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
131 *> U(k) = ( 0 I 0 ) s
135 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
136 *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
137 *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
139 *> If UPLO = 'L', then A = L*D*L**T, where
140 *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
141 *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
142 *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
143 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
144 *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
145 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
148 *> L(k) = ( 0 I 0 ) s
152 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
153 *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
154 *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
157 * =====================================================================
158 SUBROUTINE SSPTRF( UPLO, N, AP, IPIV, INFO )
160 * -- LAPACK computational routine (version 3.4.0) --
161 * -- LAPACK is a software package provided by Univ. of Tennessee, --
162 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
165 * .. Scalar Arguments ..
169 * .. Array Arguments ..
174 * =====================================================================
178 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
180 PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 )
182 * .. Local Scalars ..
184 INTEGER I, IMAX, J, JMAX, K, KC, KK, KNC, KP, KPC,
186 REAL ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1,
187 $ ROWMAX, T, WK, WKM1, WKP1
189 * .. External Functions ..
192 EXTERNAL LSAME, ISAMAX
194 * .. External Subroutines ..
195 EXTERNAL SSCAL, SSPR, SSWAP, XERBLA
197 * .. Intrinsic Functions ..
198 INTRINSIC ABS, MAX, SQRT
200 * .. Executable Statements ..
202 * Test the input parameters.
205 UPPER = LSAME( UPLO, 'U' )
206 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
208 ELSE IF( N.LT.0 ) THEN
212 CALL XERBLA( 'SSPTRF', -INFO )
216 * Initialize ALPHA for use in choosing pivot block size.
218 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
222 * Factorize A as U*D*U**T using the upper triangle of A
224 * K is the main loop index, decreasing from N to 1 in steps of
228 KC = ( N-1 )*N / 2 + 1
232 * If K < 1, exit from loop
238 * Determine rows and columns to be interchanged and whether
239 * a 1-by-1 or 2-by-2 pivot block will be used
241 ABSAKK = ABS( AP( KC+K-1 ) )
243 * IMAX is the row-index of the largest off-diagonal element in
244 * column K, and COLMAX is its absolute value
247 IMAX = ISAMAX( K-1, AP( KC ), 1 )
248 COLMAX = ABS( AP( KC+IMAX-1 ) )
253 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
255 * Column K is zero: set INFO and continue
261 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
263 * no interchange, use 1-by-1 pivot block
270 KX = IMAX*( IMAX+1 ) / 2 + IMAX
271 DO 20 J = IMAX + 1, K
272 IF( ABS( AP( KX ) ).GT.ROWMAX ) THEN
273 ROWMAX = ABS( AP( KX ) )
278 KPC = ( IMAX-1 )*IMAX / 2 + 1
280 JMAX = ISAMAX( IMAX-1, AP( KPC ), 1 )
281 ROWMAX = MAX( ROWMAX, ABS( AP( KPC+JMAX-1 ) ) )
284 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
286 * no interchange, use 1-by-1 pivot block
289 ELSE IF( ABS( AP( KPC+IMAX-1 ) ).GE.ALPHA*ROWMAX ) THEN
291 * interchange rows and columns K and IMAX, use 1-by-1
297 * interchange rows and columns K-1 and IMAX, use 2-by-2
310 * Interchange rows and columns KK and KP in the leading
311 * submatrix A(1:k,1:k)
313 CALL SSWAP( KP-1, AP( KNC ), 1, AP( KPC ), 1 )
315 DO 30 J = KP + 1, KK - 1
318 AP( KNC+J-1 ) = AP( KX )
322 AP( KNC+KK-1 ) = AP( KPC+KP-1 )
324 IF( KSTEP.EQ.2 ) THEN
326 AP( KC+K-2 ) = AP( KC+KP-1 )
331 * Update the leading submatrix
333 IF( KSTEP.EQ.1 ) THEN
335 * 1-by-1 pivot block D(k): column k now holds
339 * where U(k) is the k-th column of U
341 * Perform a rank-1 update of A(1:k-1,1:k-1) as
343 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
345 R1 = ONE / AP( KC+K-1 )
346 CALL SSPR( UPLO, K-1, -R1, AP( KC ), 1, AP )
348 * Store U(k) in column k
350 CALL SSCAL( K-1, R1, AP( KC ), 1 )
353 * 2-by-2 pivot block D(k): columns k and k-1 now hold
355 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
357 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
360 * Perform a rank-2 update of A(1:k-2,1:k-2) as
362 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
363 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
367 D12 = AP( K-1+( K-1 )*K / 2 )
368 D22 = AP( K-1+( K-2 )*( K-1 ) / 2 ) / D12
369 D11 = AP( K+( K-1 )*K / 2 ) / D12
370 T = ONE / ( D11*D22-ONE )
373 DO 50 J = K - 2, 1, -1
374 WKM1 = D12*( D11*AP( J+( K-2 )*( K-1 ) / 2 )-
375 $ AP( J+( K-1 )*K / 2 ) )
376 WK = D12*( D22*AP( J+( K-1 )*K / 2 )-
377 $ AP( J+( K-2 )*( K-1 ) / 2 ) )
379 AP( I+( J-1 )*J / 2 ) = AP( I+( J-1 )*J / 2 ) -
380 $ AP( I+( K-1 )*K / 2 )*WK -
381 $ AP( I+( K-2 )*( K-1 ) / 2 )*WKM1
383 AP( J+( K-1 )*K / 2 ) = WK
384 AP( J+( K-2 )*( K-1 ) / 2 ) = WKM1
392 * Store details of the interchanges in IPIV
394 IF( KSTEP.EQ.1 ) THEN
401 * Decrease K and return to the start of the main loop
409 * Factorize A as L*D*L**T using the lower triangle of A
411 * K is the main loop index, increasing from 1 to N in steps of
420 * If K > N, exit from loop
426 * Determine rows and columns to be interchanged and whether
427 * a 1-by-1 or 2-by-2 pivot block will be used
429 ABSAKK = ABS( AP( KC ) )
431 * IMAX is the row-index of the largest off-diagonal element in
432 * column K, and COLMAX is its absolute value
435 IMAX = K + ISAMAX( N-K, AP( KC+1 ), 1 )
436 COLMAX = ABS( AP( KC+IMAX-K ) )
441 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
443 * Column K is zero: set INFO and continue
449 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
451 * no interchange, use 1-by-1 pivot block
456 * JMAX is the column-index of the largest off-diagonal
457 * element in row IMAX, and ROWMAX is its absolute value
461 DO 70 J = K, IMAX - 1
462 IF( ABS( AP( KX ) ).GT.ROWMAX ) THEN
463 ROWMAX = ABS( AP( KX ) )
468 KPC = NPP - ( N-IMAX+1 )*( N-IMAX+2 ) / 2 + 1
470 JMAX = IMAX + ISAMAX( N-IMAX, AP( KPC+1 ), 1 )
471 ROWMAX = MAX( ROWMAX, ABS( AP( KPC+JMAX-IMAX ) ) )
474 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
476 * no interchange, use 1-by-1 pivot block
479 ELSE IF( ABS( AP( KPC ) ).GE.ALPHA*ROWMAX ) THEN
481 * interchange rows and columns K and IMAX, use 1-by-1
487 * interchange rows and columns K+1 and IMAX, use 2-by-2
497 $ KNC = KNC + N - K + 1
500 * Interchange rows and columns KK and KP in the trailing
501 * submatrix A(k:n,k:n)
504 $ CALL SSWAP( N-KP, AP( KNC+KP-KK+1 ), 1, AP( KPC+1 ),
507 DO 80 J = KK + 1, KP - 1
510 AP( KNC+J-KK ) = AP( KX )
514 AP( KNC ) = AP( KPC )
516 IF( KSTEP.EQ.2 ) THEN
518 AP( KC+1 ) = AP( KC+KP-K )
523 * Update the trailing submatrix
525 IF( KSTEP.EQ.1 ) THEN
527 * 1-by-1 pivot block D(k): column k now holds
531 * where L(k) is the k-th column of L
535 * Perform a rank-1 update of A(k+1:n,k+1:n) as
537 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
540 CALL SSPR( UPLO, N-K, -R1, AP( KC+1 ), 1,
543 * Store L(k) in column K
545 CALL SSCAL( N-K, R1, AP( KC+1 ), 1 )
549 * 2-by-2 pivot block D(k): columns K and K+1 now hold
551 * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
553 * where L(k) and L(k+1) are the k-th and (k+1)-th columns
558 * Perform a rank-2 update of A(k+2:n,k+2:n) as
560 * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**T
561 * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**T
563 * where L(k) and L(k+1) are the k-th and (k+1)-th
566 D21 = AP( K+1+( K-1 )*( 2*N-K ) / 2 )
567 D11 = AP( K+1+K*( 2*N-K-1 ) / 2 ) / D21
568 D22 = AP( K+( K-1 )*( 2*N-K ) / 2 ) / D21
569 T = ONE / ( D11*D22-ONE )
573 WK = D21*( D11*AP( J+( K-1 )*( 2*N-K ) / 2 )-
574 $ AP( J+K*( 2*N-K-1 ) / 2 ) )
575 WKP1 = D21*( D22*AP( J+K*( 2*N-K-1 ) / 2 )-
576 $ AP( J+( K-1 )*( 2*N-K ) / 2 ) )
579 AP( I+( J-1 )*( 2*N-J ) / 2 ) = AP( I+( J-1 )*
580 $ ( 2*N-J ) / 2 ) - AP( I+( K-1 )*( 2*N-K ) /
581 $ 2 )*WK - AP( I+K*( 2*N-K-1 ) / 2 )*WKP1
584 AP( J+( K-1 )*( 2*N-K ) / 2 ) = WK
585 AP( J+K*( 2*N-K-1 ) / 2 ) = WKP1
592 * Store details of the interchanges in IPIV
594 IF( KSTEP.EQ.1 ) THEN
601 * Increase K and return to the start of the main loop