LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
spstrf.f
Go to the documentation of this file.
1 *> \brief \b SPSTRF
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SPSTRF + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/spstrf.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/spstrf.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/spstrf.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * REAL TOL
25 * INTEGER INFO, LDA, N, RANK
26 * CHARACTER UPLO
27 * ..
28 * .. Array Arguments ..
29 * REAL A( LDA, * ), WORK( 2*N )
30 * INTEGER PIV( N )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
39 *> SPSTRF computes the Cholesky factorization with complete
40 *> pivoting of a real symmetric positive semidefinite matrix A.
41 *>
42 *> The factorization has the form
43 *> P**T * A * P = U**T * U , if UPLO = 'U',
44 *> P**T * A * P = L * L**T, if UPLO = 'L',
45 *> where U is an upper triangular matrix and L is lower triangular, and
46 *> P is stored as vector PIV.
47 *>
48 *> This algorithm does not attempt to check that A is positive
49 *> semidefinite. This version of the algorithm calls level 3 BLAS.
50 *> \endverbatim
51 *
52 * Arguments:
53 * ==========
54 *
55 *> \param[in] UPLO
56 *> \verbatim
57 *> UPLO is CHARACTER*1
58 *> Specifies whether the upper or lower triangular part of the
59 *> symmetric matrix A is stored.
60 *> = 'U': Upper triangular
61 *> = 'L': Lower triangular
62 *> \endverbatim
63 *>
64 *> \param[in] N
65 *> \verbatim
66 *> N is INTEGER
67 *> The order of the matrix A. N >= 0.
68 *> \endverbatim
69 *>
70 *> \param[in,out] A
71 *> \verbatim
72 *> A is REAL array, dimension (LDA,N)
73 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
74 *> n by n upper triangular part of A contains the upper
75 *> triangular part of the matrix A, and the strictly lower
76 *> triangular part of A is not referenced. If UPLO = 'L', the
77 *> leading n by n lower triangular part of A contains the lower
78 *> triangular part of the matrix A, and the strictly upper
79 *> triangular part of A is not referenced.
80 *>
81 *> On exit, if INFO = 0, the factor U or L from the Cholesky
82 *> factorization as above.
83 *> \endverbatim
84 *>
85 *> \param[in] LDA
86 *> \verbatim
87 *> LDA is INTEGER
88 *> The leading dimension of the array A. LDA >= max(1,N).
89 *> \endverbatim
90 *>
91 *> \param[out] PIV
92 *> \verbatim
93 *> PIV is INTEGER array, dimension (N)
94 *> PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
95 *> \endverbatim
96 *>
97 *> \param[out] RANK
98 *> \verbatim
99 *> RANK is INTEGER
100 *> The rank of A given by the number of steps the algorithm
101 *> completed.
102 *> \endverbatim
103 *>
104 *> \param[in] TOL
105 *> \verbatim
106 *> TOL is REAL
107 *> User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) )
108 *> will be used. The algorithm terminates at the (K-1)st step
109 *> if the pivot <= TOL.
110 *> \endverbatim
111 *>
112 *> \param[out] WORK
113 *> \verbatim
114 *> WORK is REAL array, dimension (2*N)
115 *> Work space.
116 *> \endverbatim
117 *>
118 *> \param[out] INFO
119 *> \verbatim
120 *> INFO is INTEGER
121 *> < 0: If INFO = -K, the K-th argument had an illegal value,
122 *> = 0: algorithm completed successfully, and
123 *> > 0: the matrix A is either rank deficient with computed rank
124 *> as returned in RANK, or is indefinite. See Section 7 of
125 *> LAPACK Working Note #161 for further information.
126 *> \endverbatim
127 *
128 * Authors:
129 * ========
130 *
131 *> \author Univ. of Tennessee
132 *> \author Univ. of California Berkeley
133 *> \author Univ. of Colorado Denver
134 *> \author NAG Ltd.
135 *
136 *> \date November 2011
137 *
138 *> \ingroup realOTHERcomputational
139 *
140 * =====================================================================
141  SUBROUTINE spstrf( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
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 *
443  END