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

Go to the source code of this file.

Functions/Subroutines

subroutine spstrf (UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
 SPSTRF More...
 

Function/Subroutine Documentation

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

SPSTRF

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

Purpose:
 SPSTRF 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 3 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 REAL 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.
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,N).
[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 REAL
          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.
[out]WORK
          WORK is REAL 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
November 2011

Definition at line 142 of file spstrf.f.

142 *
143 * -- LAPACK computational routine (version 3.4.0) --
144 * -- LAPACK is a software package provided by Univ. of Tennessee, --
145 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
146 * November 2011
147 *
148 * .. Scalar Arguments ..
149  REAL tol
150  INTEGER info, lda, n, rank
151  CHARACTER uplo
152 * ..
153 * .. Array Arguments ..
154  REAL a( lda, * ), work( 2*n )
155  INTEGER piv( n )
156 * ..
157 *
158 * =====================================================================
159 *
160 * .. Parameters ..
161  REAL one, zero
162  parameter( one = 1.0e+0, zero = 0.0e+0 )
163 * ..
164 * .. Local Scalars ..
165  REAL ajj, sstop, stemp
166  INTEGER i, itemp, j, jb, k, nb, pvt
167  LOGICAL upper
168 * ..
169 * .. External Functions ..
170  REAL slamch
171  INTEGER ilaenv
172  LOGICAL lsame, sisnan
173  EXTERNAL slamch, ilaenv, lsame, sisnan
174 * ..
175 * .. External Subroutines ..
176  EXTERNAL sgemv, spstf2, sscal, sswap, ssyrk, xerbla
177 * ..
178 * .. Intrinsic Functions ..
179  INTRINSIC max, min, sqrt, maxloc
180 * ..
181 * .. Executable Statements ..
182 *
183 * Test the input parameters.
184 *
185  info = 0
186  upper = lsame( uplo, 'U' )
187  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
188  info = -1
189  ELSE IF( n.LT.0 ) THEN
190  info = -2
191  ELSE IF( lda.LT.max( 1, n ) ) THEN
192  info = -4
193  END IF
194  IF( info.NE.0 ) THEN
195  CALL xerbla( 'SPSTRF', -info )
196  RETURN
197  END IF
198 *
199 * Quick return if possible
200 *
201  IF( n.EQ.0 )
202  $ RETURN
203 *
204 * Get block size
205 *
206  nb = ilaenv( 1, 'SPOTRF', uplo, n, -1, -1, -1 )
207  IF( nb.LE.1 .OR. nb.GE.n ) THEN
208 *
209 * Use unblocked code
210 *
211  CALL spstf2( uplo, n, a( 1, 1 ), lda, piv, rank, tol, work,
212  $ info )
213  GO TO 200
214 *
215  ELSE
216 *
217 * Initialize PIV
218 *
219  DO 100 i = 1, n
220  piv( i ) = i
221  100 CONTINUE
222 *
223 * Compute stopping value
224 *
225  pvt = 1
226  ajj = a( pvt, pvt )
227  DO i = 2, n
228  IF( a( i, i ).GT.ajj ) THEN
229  pvt = i
230  ajj = a( pvt, pvt )
231  END IF
232  END DO
233  IF( ajj.EQ.zero.OR.sisnan( ajj ) ) THEN
234  rank = 0
235  info = 1
236  GO TO 200
237  END IF
238 *
239 * Compute stopping value if not supplied
240 *
241  IF( tol.LT.zero ) THEN
242  sstop = n * slamch( 'Epsilon' ) * ajj
243  ELSE
244  sstop = tol
245  END IF
246 *
247 *
248  IF( upper ) THEN
249 *
250 * Compute the Cholesky factorization P**T * A * P = U**T * U
251 *
252  DO 140 k = 1, n, nb
253 *
254 * Account for last block not being NB wide
255 *
256  jb = min( nb, n-k+1 )
257 *
258 * Set relevant part of first half of WORK to zero,
259 * holds dot products
260 *
261  DO 110 i = k, n
262  work( i ) = 0
263  110 CONTINUE
264 *
265  DO 130 j = k, k + jb - 1
266 *
267 * Find pivot, test for exit, else swap rows and columns
268 * Update dot products, compute possible pivots which are
269 * stored in the second half of WORK
270 *
271  DO 120 i = j, n
272 *
273  IF( j.GT.k ) THEN
274  work( i ) = work( i ) + a( j-1, i )**2
275  END IF
276  work( n+i ) = a( i, i ) - work( i )
277 *
278  120 CONTINUE
279 *
280  IF( j.GT.1 ) THEN
281  itemp = maxloc( work( (n+j):(2*n) ), 1 )
282  pvt = itemp + j - 1
283  ajj = work( n+pvt )
284  IF( ajj.LE.sstop.OR.sisnan( ajj ) ) THEN
285  a( j, j ) = ajj
286  GO TO 190
287  END IF
288  END IF
289 *
290  IF( j.NE.pvt ) THEN
291 *
292 * Pivot OK, so can now swap pivot rows and columns
293 *
294  a( pvt, pvt ) = a( j, j )
295  CALL sswap( j-1, a( 1, j ), 1, a( 1, pvt ), 1 )
296  IF( pvt.LT.n )
297  $ CALL sswap( n-pvt, a( j, pvt+1 ), lda,
298  $ a( pvt, pvt+1 ), lda )
299  CALL sswap( pvt-j-1, a( j, j+1 ), lda,
300  $ a( j+1, pvt ), 1 )
301 *
302 * Swap dot products and PIV
303 *
304  stemp = work( j )
305  work( j ) = work( pvt )
306  work( pvt ) = stemp
307  itemp = piv( pvt )
308  piv( pvt ) = piv( j )
309  piv( j ) = itemp
310  END IF
311 *
312  ajj = sqrt( ajj )
313  a( j, j ) = ajj
314 *
315 * Compute elements J+1:N of row J.
316 *
317  IF( j.LT.n ) THEN
318  CALL sgemv( 'Trans', j-k, n-j, -one, a( k, j+1 ),
319  $ lda, a( k, j ), 1, one, a( j, j+1 ),
320  $ lda )
321  CALL sscal( n-j, one / ajj, a( j, j+1 ), lda )
322  END IF
323 *
324  130 CONTINUE
325 *
326 * Update trailing matrix, J already incremented
327 *
328  IF( k+jb.LE.n ) THEN
329  CALL ssyrk( 'Upper', 'Trans', n-j+1, jb, -one,
330  $ a( k, j ), lda, one, a( j, j ), lda )
331  END IF
332 *
333  140 CONTINUE
334 *
335  ELSE
336 *
337 * Compute the Cholesky factorization P**T * A * P = L * L**T
338 *
339  DO 180 k = 1, n, nb
340 *
341 * Account for last block not being NB wide
342 *
343  jb = min( nb, n-k+1 )
344 *
345 * Set relevant part of first half of WORK to zero,
346 * holds dot products
347 *
348  DO 150 i = k, n
349  work( i ) = 0
350  150 CONTINUE
351 *
352  DO 170 j = k, k + jb - 1
353 *
354 * Find pivot, test for exit, else swap rows and columns
355 * Update dot products, compute possible pivots which are
356 * stored in the second half of WORK
357 *
358  DO 160 i = j, n
359 *
360  IF( j.GT.k ) THEN
361  work( i ) = work( i ) + a( i, j-1 )**2
362  END IF
363  work( n+i ) = a( i, i ) - work( i )
364 *
365  160 CONTINUE
366 *
367  IF( j.GT.1 ) THEN
368  itemp = maxloc( work( (n+j):(2*n) ), 1 )
369  pvt = itemp + j - 1
370  ajj = work( n+pvt )
371  IF( ajj.LE.sstop.OR.sisnan( ajj ) ) THEN
372  a( j, j ) = ajj
373  GO TO 190
374  END IF
375  END IF
376 *
377  IF( j.NE.pvt ) THEN
378 *
379 * Pivot OK, so can now swap pivot rows and columns
380 *
381  a( pvt, pvt ) = a( j, j )
382  CALL sswap( j-1, a( j, 1 ), lda, a( pvt, 1 ), lda )
383  IF( pvt.LT.n )
384  $ CALL sswap( n-pvt, a( pvt+1, j ), 1,
385  $ a( pvt+1, pvt ), 1 )
386  CALL sswap( pvt-j-1, a( j+1, j ), 1, a( pvt, j+1 ),
387  $ lda )
388 *
389 * Swap dot products and PIV
390 *
391  stemp = work( j )
392  work( j ) = work( pvt )
393  work( pvt ) = stemp
394  itemp = piv( pvt )
395  piv( pvt ) = piv( j )
396  piv( j ) = itemp
397  END IF
398 *
399  ajj = sqrt( ajj )
400  a( j, j ) = ajj
401 *
402 * Compute elements J+1:N of column J.
403 *
404  IF( j.LT.n ) THEN
405  CALL sgemv( 'No Trans', n-j, j-k, -one,
406  $ a( j+1, k ), lda, a( j, k ), lda, one,
407  $ a( j+1, j ), 1 )
408  CALL sscal( n-j, one / ajj, a( j+1, j ), 1 )
409  END IF
410 *
411  170 CONTINUE
412 *
413 * Update trailing matrix, J already incremented
414 *
415  IF( k+jb.LE.n ) THEN
416  CALL ssyrk( 'Lower', 'No Trans', n-j+1, jb, -one,
417  $ a( j, k ), lda, one, a( j, j ), lda )
418  END IF
419 *
420  180 CONTINUE
421 *
422  END IF
423  END IF
424 *
425 * Ran to completion, A has full rank
426 *
427  rank = n
428 *
429  GO TO 200
430  190 CONTINUE
431 *
432 * Rank is the number of steps completed. Set INFO = 1 to signal
433 * that the factorization cannot be used to solve a system.
434 *
435  rank = j - 1
436  info = 1
437 *
438  200 CONTINUE
439  RETURN
440 *
441 * End of SPSTRF
442 *
subroutine spstf2(UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
SPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Herm...
Definition: spstf2.f:142
subroutine sswap(N, SX, INCX, SY, INCY)
SSWAP
Definition: sswap.f:53
subroutine ssyrk(UPLO, TRANS, N, K, ALPHA, A, LDA, BETA, C, LDC)
SSYRK
Definition: ssyrk.f:171
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine sgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
SGEMV
Definition: sgemv.f:158
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:69
integer function ilaenv(ISPEC, NAME, OPTS, N1, N2, N3, N4)
Definition: tstiee.f:83
logical function sisnan(SIN)
SISNAN tests input for NaN.
Definition: sisnan.f:61
subroutine sscal(N, SA, SX, INCX)
SSCAL
Definition: sscal.f:55

Here is the call graph for this function:

Here is the caller graph for this function: