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

Go to the source code of this file.

Functions/Subroutines

subroutine cpstrf (UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
 CPSTRF More...
 

Function/Subroutine Documentation

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

CPSTRF

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

Purpose:
 CPSTRF computes the Cholesky factorization with complete
 pivoting of a complex Hermitian positive semidefinite matrix A.

 The factorization has the form
    P**T * A * P = U**H * U ,  if UPLO = 'U',
    P**T * A * P = L  * L**H,  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 COMPLEX 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 143 of file cpstrf.f.

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

Here is the call graph for this function:

Here is the caller graph for this function: