1 *> \brief \b DPSTRF computes the Cholesky factorization with complete pivoting of a real symmetric positive semidefinite matrix.
4 * =========== DOCUMENTATION ===========
6 * Online html documentation available at
7 * http://www.netlib.org/lapack/explore-html/
10 *> Download DPSTRF + dependencies
11 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpstrf.f">
13 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpstrf.f">
15 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpstrf.f">
22 * SUBROUTINE DPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
24 * .. Scalar Arguments ..
25 * DOUBLE PRECISION TOL
26 * INTEGER INFO, LDA, N, RANK
29 * .. Array Arguments ..
30 * DOUBLE PRECISION A( LDA, * ), WORK( 2*N )
40 *> DPSTRF computes the Cholesky factorization with complete
41 *> pivoting of a real symmetric positive semidefinite matrix A.
43 *> The factorization has the form
44 *> P**T * A * P = U**T * U , if UPLO = 'U',
45 *> P**T * A * P = L * L**T, if UPLO = 'L',
46 *> where U is an upper triangular matrix and L is lower triangular, and
47 *> P is stored as vector PIV.
49 *> This algorithm does not attempt to check that A is positive
50 *> semidefinite. This version of the algorithm calls level 3 BLAS.
58 *> UPLO is CHARACTER*1
59 *> Specifies whether the upper or lower triangular part of the
60 *> symmetric matrix A is stored.
61 *> = 'U': Upper triangular
62 *> = 'L': Lower triangular
68 *> The order of the matrix A. N >= 0.
73 *> A is DOUBLE PRECISION array, dimension (LDA,N)
74 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
75 *> n by n upper triangular part of A contains the upper
76 *> triangular part of the matrix A, and the strictly lower
77 *> triangular part of A is not referenced. If UPLO = 'L', the
78 *> leading n by n lower triangular part of A contains the lower
79 *> triangular part of the matrix A, and the strictly upper
80 *> triangular part of A is not referenced.
82 *> On exit, if INFO = 0, the factor U or L from the Cholesky
83 *> factorization as above.
89 *> The leading dimension of the array A. LDA >= max(1,N).
94 *> PIV is INTEGER array, dimension (N)
95 *> PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
101 *> The rank of A given by the number of steps the algorithm
107 *> TOL is DOUBLE PRECISION
108 *> User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) )
109 *> will be used. The algorithm terminates at the (K-1)st step
110 *> if the pivot <= TOL.
115 *> WORK is DOUBLE PRECISION array, dimension (2*N)
122 *> < 0: If INFO = -K, the K-th argument had an illegal value,
123 *> = 0: algorithm completed successfully, and
124 *> > 0: the matrix A is either rank deficient with computed rank
125 *> as returned in RANK, or is not positive semidefinite. See
126 *> Section 7 of LAPACK Working Note #161 for further
133 *> \author Univ. of Tennessee
134 *> \author Univ. of California Berkeley
135 *> \author Univ. of Colorado Denver
138 *> \date November 2015
140 *> \ingroup doubleOTHERcomputational
142 * =====================================================================
143 SUBROUTINE DPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
145 * -- LAPACK computational routine (version 3.6.0) --
146 * -- LAPACK is a software package provided by Univ. of Tennessee, --
147 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
150 * .. Scalar Arguments ..
152 INTEGER INFO, LDA, N, RANK
155 * .. Array Arguments ..
156 DOUBLE PRECISION A( LDA, * ), WORK( 2*N )
160 * =====================================================================
163 DOUBLE PRECISION ONE, ZERO
164 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
166 * .. Local Scalars ..
167 DOUBLE PRECISION AJJ, DSTOP, DTEMP
168 INTEGER I, ITEMP, J, JB, K, NB, PVT
171 * .. External Functions ..
172 DOUBLE PRECISION DLAMCH
174 LOGICAL LSAME, DISNAN
175 EXTERNAL DLAMCH, ILAENV, LSAME, DISNAN
177 * .. External Subroutines ..
178 EXTERNAL DGEMV, DPSTF2, DSCAL, DSWAP, DSYRK, XERBLA
180 * .. Intrinsic Functions ..
181 INTRINSIC MAX, MIN, SQRT, MAXLOC
183 * .. Executable Statements ..
185 * Test the input parameters.
188 UPPER = LSAME( UPLO, 'U' )
189 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
191 ELSE IF( N.LT.0 ) THEN
193 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
197 CALL XERBLA( 'DPSTRF', -INFO )
201 * Quick return if possible
208 NB = ILAENV( 1, 'DPOTRF', UPLO, N, -1, -1, -1 )
209 IF( NB.LE.1 .OR. NB.GE.N ) THEN
213 CALL DPSTF2( UPLO, N, A( 1, 1 ), LDA, PIV, RANK, TOL, WORK,
225 * Compute stopping value
230 IF( A( I, I ).GT.AJJ ) THEN
235 IF( AJJ.LE.ZERO.OR.DISNAN( AJJ ) ) THEN
241 * Compute stopping value if not supplied
243 IF( TOL.LT.ZERO ) THEN
244 DSTOP = N * DLAMCH( 'Epsilon' ) * AJJ
252 * Compute the Cholesky factorization P**T * A * P = U**T * U
256 * Account for last block not being NB wide
258 JB = MIN( NB, N-K+1 )
260 * Set relevant part of first half of WORK to zero,
267 DO 130 J = K, K + JB - 1
269 * Find pivot, test for exit, else swap rows and columns
270 * Update dot products, compute possible pivots which are
271 * stored in the second half of WORK
276 WORK( I ) = WORK( I ) + A( J-1, I )**2
278 WORK( N+I ) = A( I, I ) - WORK( I )
283 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
286 IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
294 * Pivot OK, so can now swap pivot rows and columns
296 A( PVT, PVT ) = A( J, J )
297 CALL DSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
299 $ CALL DSWAP( N-PVT, A( J, PVT+1 ), LDA,
300 $ A( PVT, PVT+1 ), LDA )
301 CALL DSWAP( PVT-J-1, A( J, J+1 ), LDA,
304 * Swap dot products and PIV
307 WORK( J ) = WORK( PVT )
310 PIV( PVT ) = PIV( J )
317 * Compute elements J+1:N of row J.
320 CALL DGEMV( 'Trans', J-K, N-J, -ONE, A( K, J+1 ),
321 $ LDA, A( K, J ), 1, ONE, A( J, J+1 ),
323 CALL DSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
328 * Update trailing matrix, J already incremented
331 CALL DSYRK( 'Upper', 'Trans', N-J+1, JB, -ONE,
332 $ A( K, J ), LDA, ONE, A( J, J ), LDA )
339 * Compute the Cholesky factorization P**T * A * P = L * L**T
343 * Account for last block not being NB wide
345 JB = MIN( NB, N-K+1 )
347 * Set relevant part of first half of WORK to zero,
354 DO 170 J = K, K + JB - 1
356 * Find pivot, test for exit, else swap rows and columns
357 * Update dot products, compute possible pivots which are
358 * stored in the second half of WORK
363 WORK( I ) = WORK( I ) + A( I, J-1 )**2
365 WORK( N+I ) = A( I, I ) - WORK( I )
370 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
373 IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
381 * Pivot OK, so can now swap pivot rows and columns
383 A( PVT, PVT ) = A( J, J )
384 CALL DSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
386 $ CALL DSWAP( N-PVT, A( PVT+1, J ), 1,
387 $ A( PVT+1, PVT ), 1 )
388 CALL DSWAP( PVT-J-1, A( J+1, J ), 1, A( PVT, J+1 ),
391 * Swap dot products and PIV
394 WORK( J ) = WORK( PVT )
397 PIV( PVT ) = PIV( J )
404 * Compute elements J+1:N of column J.
407 CALL DGEMV( 'No Trans', N-J, J-K, -ONE,
408 $ A( J+1, K ), LDA, A( J, K ), LDA, ONE,
410 CALL DSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
415 * Update trailing matrix, J already incremented
418 CALL DSYRK( 'Lower', 'No Trans', N-J+1, JB, -ONE,
419 $ A( J, K ), LDA, ONE, A( J, J ), LDA )
427 * Ran to completion, A has full rank
434 * Rank is the number of steps completed. Set INFO = 1 to signal
435 * that the factorization cannot be used to solve a system.