LAPACK  3.5.0
LAPACK: Linear Algebra PACKage
dpstf2.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine dpstf2 (UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
 DPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Hermitian positive semi-definite matrix. More...
 

Function/Subroutine Documentation

subroutine dpstf2 ( character  UPLO,
integer  N,
double precision, dimension( lda, * )  A,
integer  LDA,
integer, dimension( n )  PIV,
integer  RANK,
double precision  TOL,
double precision, dimension( 2*n )  WORK,
integer  INFO 
)

DPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Hermitian positive semi-definite matrix.

Download DPSTF2 + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 DPSTF2 computes the Cholesky factorization with complete
 pivoting of a real symmetric positive semidefinite matrix A.

 The factorization has the form
    P**T * A * P = U**T * U ,  if UPLO = 'U',
    P**T * A * P = L  * L**T,  if UPLO = 'L',
 where U is an upper triangular matrix and L is lower triangular, and
 P is stored as vector PIV.

 This algorithm does not attempt to check that A is positive
 semidefinite. This version of the algorithm calls level 2 BLAS.
Parameters
[in]UPLO
          UPLO is CHARACTER*1
          Specifies whether the upper or lower triangular part of the
          symmetric matrix A is stored.
          = 'U':  Upper triangular
          = 'L':  Lower triangular
[in]N
          N is INTEGER
          The order of the matrix A.  N >= 0.
[in,out]A
          A is DOUBLE PRECISION array, dimension (LDA,N)
          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
          n by n upper triangular part of A contains the upper
          triangular part of the matrix A, and the strictly lower
          triangular part of A is not referenced.  If UPLO = 'L', the
          leading n by n lower triangular part of A contains the lower
          triangular part of the matrix A, and the strictly upper
          triangular part of A is not referenced.

          On exit, if INFO = 0, the factor U or L from the Cholesky
          factorization as above.
[out]PIV
          PIV is INTEGER array, dimension (N)
          PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
[out]RANK
          RANK is INTEGER
          The rank of A given by the number of steps the algorithm
          completed.
[in]TOL
          TOL is DOUBLE PRECISION
          User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) )
          will be used. The algorithm terminates at the (K-1)st step
          if the pivot <= TOL.
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,N).
[out]WORK
          WORK is DOUBLE PRECISION array, dimension (2*N)
          Work space.
[out]INFO
          INFO is INTEGER
          < 0: If INFO = -K, the K-th argument had an illegal value,
          = 0: algorithm completed successfully, and
          > 0: the matrix A is either rank deficient with computed rank
               as returned in RANK, or is indefinite.  See Section 7 of
               LAPACK Working Note #161 for further information.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Date
September 2012

Definition at line 142 of file dpstf2.f.

142 *
143 * -- LAPACK computational routine (version 3.4.2) --
144 * -- LAPACK is a software package provided by Univ. of Tennessee, --
145 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
146 * September 2012
147 *
148 * .. Scalar Arguments ..
149  DOUBLE PRECISION tol
150  INTEGER info, lda, n, rank
151  CHARACTER uplo
152 * ..
153 * .. Array Arguments ..
154  DOUBLE PRECISION a( lda, * ), work( 2*n )
155  INTEGER piv( n )
156 * ..
157 *
158 * =====================================================================
159 *
160 * .. Parameters ..
161  DOUBLE PRECISION one, zero
162  parameter( one = 1.0d+0, zero = 0.0d+0 )
163 * ..
164 * .. Local Scalars ..
165  DOUBLE PRECISION ajj, dstop, dtemp
166  INTEGER i, itemp, j, pvt
167  LOGICAL upper
168 * ..
169 * .. External Functions ..
170  DOUBLE PRECISION dlamch
171  LOGICAL lsame, disnan
172  EXTERNAL dlamch, lsame, disnan
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL dgemv, dscal, dswap, xerbla
176 * ..
177 * .. Intrinsic Functions ..
178  INTRINSIC max, sqrt, maxloc
179 * ..
180 * .. Executable Statements ..
181 *
182 * Test the input parameters
183 *
184  info = 0
185  upper = lsame( uplo, 'U' )
186  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
187  info = -1
188  ELSE IF( n.LT.0 ) THEN
189  info = -2
190  ELSE IF( lda.LT.max( 1, n ) ) THEN
191  info = -4
192  END IF
193  IF( info.NE.0 ) THEN
194  CALL xerbla( 'DPSTF2', -info )
195  RETURN
196  END IF
197 *
198 * Quick return if possible
199 *
200  IF( n.EQ.0 )
201  $ RETURN
202 *
203 * Initialize PIV
204 *
205  DO 100 i = 1, n
206  piv( i ) = i
207  100 CONTINUE
208 *
209 * Compute stopping value
210 *
211  pvt = 1
212  ajj = a( pvt, pvt )
213  DO i = 2, n
214  IF( a( i, i ).GT.ajj ) THEN
215  pvt = i
216  ajj = a( pvt, pvt )
217  END IF
218  END DO
219  IF( ajj.EQ.zero.OR.disnan( ajj ) ) THEN
220  rank = 0
221  info = 1
222  GO TO 170
223  END IF
224 *
225 * Compute stopping value if not supplied
226 *
227  IF( tol.LT.zero ) THEN
228  dstop = n * dlamch( 'Epsilon' ) * ajj
229  ELSE
230  dstop = tol
231  END IF
232 *
233 * Set first half of WORK to zero, holds dot products
234 *
235  DO 110 i = 1, n
236  work( i ) = 0
237  110 CONTINUE
238 *
239  IF( upper ) THEN
240 *
241 * Compute the Cholesky factorization P**T * A * P = U**T * U
242 *
243  DO 130 j = 1, n
244 *
245 * Find pivot, test for exit, else swap rows and columns
246 * Update dot products, compute possible pivots which are
247 * stored in the second half of WORK
248 *
249  DO 120 i = j, n
250 *
251  IF( j.GT.1 ) THEN
252  work( i ) = work( i ) + a( j-1, i )**2
253  END IF
254  work( n+i ) = a( i, i ) - work( i )
255 *
256  120 CONTINUE
257 *
258  IF( j.GT.1 ) THEN
259  itemp = maxloc( work( (n+j):(2*n) ), 1 )
260  pvt = itemp + j - 1
261  ajj = work( n+pvt )
262  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
263  a( j, j ) = ajj
264  GO TO 160
265  END IF
266  END IF
267 *
268  IF( j.NE.pvt ) THEN
269 *
270 * Pivot OK, so can now swap pivot rows and columns
271 *
272  a( pvt, pvt ) = a( j, j )
273  CALL dswap( j-1, a( 1, j ), 1, a( 1, pvt ), 1 )
274  IF( pvt.LT.n )
275  $ CALL dswap( n-pvt, a( j, pvt+1 ), lda,
276  $ a( pvt, pvt+1 ), lda )
277  CALL dswap( pvt-j-1, a( j, j+1 ), lda, a( j+1, pvt ), 1 )
278 *
279 * Swap dot products and PIV
280 *
281  dtemp = work( j )
282  work( j ) = work( pvt )
283  work( pvt ) = dtemp
284  itemp = piv( pvt )
285  piv( pvt ) = piv( j )
286  piv( j ) = itemp
287  END IF
288 *
289  ajj = sqrt( ajj )
290  a( j, j ) = ajj
291 *
292 * Compute elements J+1:N of row J
293 *
294  IF( j.LT.n ) THEN
295  CALL dgemv( 'Trans', j-1, n-j, -one, a( 1, j+1 ), lda,
296  $ a( 1, j ), 1, one, a( j, j+1 ), lda )
297  CALL dscal( n-j, one / ajj, a( j, j+1 ), lda )
298  END IF
299 *
300  130 CONTINUE
301 *
302  ELSE
303 *
304 * Compute the Cholesky factorization P**T * A * P = L * L**T
305 *
306  DO 150 j = 1, n
307 *
308 * Find pivot, test for exit, else swap rows and columns
309 * Update dot products, compute possible pivots which are
310 * stored in the second half of WORK
311 *
312  DO 140 i = j, n
313 *
314  IF( j.GT.1 ) THEN
315  work( i ) = work( i ) + a( i, j-1 )**2
316  END IF
317  work( n+i ) = a( i, i ) - work( i )
318 *
319  140 CONTINUE
320 *
321  IF( j.GT.1 ) THEN
322  itemp = maxloc( work( (n+j):(2*n) ), 1 )
323  pvt = itemp + j - 1
324  ajj = work( n+pvt )
325  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
326  a( j, j ) = ajj
327  GO TO 160
328  END IF
329  END IF
330 *
331  IF( j.NE.pvt ) THEN
332 *
333 * Pivot OK, so can now swap pivot rows and columns
334 *
335  a( pvt, pvt ) = a( j, j )
336  CALL dswap( j-1, a( j, 1 ), lda, a( pvt, 1 ), lda )
337  IF( pvt.LT.n )
338  $ CALL dswap( n-pvt, a( pvt+1, j ), 1, a( pvt+1, pvt ),
339  $ 1 )
340  CALL dswap( pvt-j-1, a( j+1, j ), 1, a( pvt, j+1 ), lda )
341 *
342 * Swap dot products and PIV
343 *
344  dtemp = work( j )
345  work( j ) = work( pvt )
346  work( pvt ) = dtemp
347  itemp = piv( pvt )
348  piv( pvt ) = piv( j )
349  piv( j ) = itemp
350  END IF
351 *
352  ajj = sqrt( ajj )
353  a( j, j ) = ajj
354 *
355 * Compute elements J+1:N of column J
356 *
357  IF( j.LT.n ) THEN
358  CALL dgemv( 'No Trans', n-j, j-1, -one, a( j+1, 1 ), lda,
359  $ a( j, 1 ), lda, one, a( j+1, j ), 1 )
360  CALL dscal( n-j, one / ajj, a( j+1, j ), 1 )
361  END IF
362 *
363  150 CONTINUE
364 *
365  END IF
366 *
367 * Ran to completion, A has full rank
368 *
369  rank = n
370 *
371  GO TO 170
372  160 CONTINUE
373 *
374 * Rank is number of steps completed. Set INFO = 1 to signal
375 * that the factorization cannot be used to solve a system.
376 *
377  rank = j - 1
378  info = 1
379 *
380  170 CONTINUE
381  RETURN
382 *
383 * End of DPSTF2
384 *
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine dscal(N, DA, DX, INCX)
DSCAL
Definition: dscal.f:55
double precision function dlamch(CMACH)
DLAMCH
Definition: dlamch.f:65
subroutine dswap(N, DX, INCX, DY, INCY)
DSWAP
Definition: dswap.f:53
subroutine dgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
DGEMV
Definition: dgemv.f:158
logical function disnan(DIN)
DISNAN tests input for NaN.
Definition: disnan.f:61

Here is the call graph for this function:

Here is the caller graph for this function: