3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SPORFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sporfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sporfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sporfs.f">
21 * SUBROUTINE SPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
22 * LDX, FERR, BERR, WORK, IWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
30 * REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
31 * $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
40 *> SPORFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is symmetric positive definite,
42 *> and provides error bounds and backward error estimates for the
51 *> UPLO is CHARACTER*1
52 *> = 'U': Upper triangle of A is stored;
53 *> = 'L': Lower triangle of A is stored.
59 *> The order of the matrix A. N >= 0.
65 *> The number of right hand sides, i.e., the number of columns
66 *> of the matrices B and X. NRHS >= 0.
71 *> A is REAL array, dimension (LDA,N)
72 *> The symmetric matrix A. If UPLO = 'U', the leading N-by-N
73 *> upper triangular part of A contains the upper triangular part
74 *> of the matrix A, and the strictly lower triangular part of A
75 *> is not referenced. If UPLO = 'L', the leading N-by-N lower
76 *> triangular part of A contains the lower triangular part of
77 *> the matrix A, and the strictly upper triangular part of A is
84 *> The leading dimension of the array A. LDA >= max(1,N).
89 *> AF is REAL array, dimension (LDAF,N)
90 *> The triangular factor U or L from the Cholesky factorization
91 *> A = U**T*U or A = L*L**T, as computed by SPOTRF.
97 *> The leading dimension of the array AF. LDAF >= max(1,N).
102 *> B is REAL array, dimension (LDB,NRHS)
103 *> The right hand side matrix B.
109 *> The leading dimension of the array B. LDB >= max(1,N).
114 *> X is REAL array, dimension (LDX,NRHS)
115 *> On entry, the solution matrix X, as computed by SPOTRS.
116 *> On exit, the improved solution matrix X.
122 *> The leading dimension of the array X. LDX >= max(1,N).
127 *> FERR is REAL array, dimension (NRHS)
128 *> The estimated forward error bound for each solution vector
129 *> X(j) (the j-th column of the solution matrix X).
130 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
131 *> is an estimated upper bound for the magnitude of the largest
132 *> element in (X(j) - XTRUE) divided by the magnitude of the
133 *> largest element in X(j). The estimate is as reliable as
134 *> the estimate for RCOND, and is almost always a slight
135 *> overestimate of the true error.
140 *> BERR is REAL array, dimension (NRHS)
141 *> The componentwise relative backward error of each solution
142 *> vector X(j) (i.e., the smallest relative change in
143 *> any element of A or B that makes X(j) an exact solution).
148 *> WORK is REAL array, dimension (3*N)
153 *> IWORK is INTEGER array, dimension (N)
159 *> = 0: successful exit
160 *> < 0: if INFO = -i, the i-th argument had an illegal value
163 *> \par Internal Parameters:
164 * =========================
167 *> ITMAX is the maximum number of steps of iterative refinement.
173 *> \author Univ. of Tennessee
174 *> \author Univ. of California Berkeley
175 *> \author Univ. of Colorado Denver
178 *> \date November 2011
180 *> \ingroup realPOcomputational
182 * =====================================================================
183 SUBROUTINE SPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
184 $ LDX, FERR, BERR, WORK, IWORK, INFO )
186 * -- LAPACK computational routine (version 3.4.0) --
187 * -- LAPACK is a software package provided by Univ. of Tennessee, --
188 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
191 * .. Scalar Arguments ..
193 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
195 * .. Array Arguments ..
197 REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
198 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
201 * =====================================================================
205 PARAMETER ( ITMAX = 5 )
207 PARAMETER ( ZERO = 0.0E+0 )
209 PARAMETER ( ONE = 1.0E+0 )
211 PARAMETER ( TWO = 2.0E+0 )
213 PARAMETER ( THREE = 3.0E+0 )
215 * .. Local Scalars ..
217 INTEGER COUNT, I, J, K, KASE, NZ
218 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
223 * .. External Subroutines ..
224 EXTERNAL SAXPY, SCOPY, SLACN2, SPOTRS, SSYMV, XERBLA
226 * .. Intrinsic Functions ..
229 * .. External Functions ..
232 EXTERNAL LSAME, SLAMCH
234 * .. Executable Statements ..
236 * Test the input parameters.
239 UPPER = LSAME( UPLO, 'U' )
240 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
242 ELSE IF( N.LT.0 ) THEN
244 ELSE IF( NRHS.LT.0 ) THEN
246 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
248 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
250 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
252 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
256 CALL XERBLA( 'SPORFS', -INFO )
260 * Quick return if possible
262 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
270 * NZ = maximum number of nonzero elements in each row of A, plus 1
273 EPS = SLAMCH( 'Epsilon' )
274 SAFMIN = SLAMCH( 'Safe minimum' )
278 * Do for each right hand side
286 * Loop until stopping criterion is satisfied.
288 * Compute residual R = B - A * X
290 CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
291 CALL SSYMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
294 * Compute componentwise relative backward error from formula
296 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
298 * where abs(Z) is the componentwise absolute value of the matrix
299 * or vector Z. If the i-th component of the denominator is less
300 * than SAFE2, then SAFE1 is added to the i-th components of the
301 * numerator and denominator before dividing.
304 WORK( I ) = ABS( B( I, J ) )
307 * Compute abs(A)*abs(X) + abs(B).
312 XK = ABS( X( K, J ) )
314 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
315 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
317 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
322 XK = ABS( X( K, J ) )
323 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
325 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
326 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
328 WORK( K ) = WORK( K ) + S
333 IF( WORK( I ).GT.SAFE2 ) THEN
334 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
336 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
337 $ ( WORK( I )+SAFE1 ) )
342 * Test stopping criterion. Continue iterating if
343 * 1) The residual BERR(J) is larger than machine epsilon, and
344 * 2) BERR(J) decreased by at least a factor of 2 during the
345 * last iteration, and
346 * 3) At most ITMAX iterations tried.
348 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
349 $ COUNT.LE.ITMAX ) THEN
351 * Update solution and try again.
353 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
354 CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
360 * Bound error from formula
362 * norm(X - XTRUE) / norm(X) .le. FERR =
364 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
367 * norm(Z) is the magnitude of the largest component of Z
368 * inv(A) is the inverse of A
369 * abs(Z) is the componentwise absolute value of the matrix or
371 * NZ is the maximum number of nonzeros in any row of A, plus 1
372 * EPS is machine epsilon
374 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
375 * is incremented by SAFE1 if the i-th component of
376 * abs(A)*abs(X) + abs(B) is less than SAFE2.
378 * Use SLACN2 to estimate the infinity-norm of the matrix
380 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
383 IF( WORK( I ).GT.SAFE2 ) THEN
384 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
386 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
392 CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
397 * Multiply by diag(W)*inv(A**T).
399 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
401 WORK( N+I ) = WORK( I )*WORK( N+I )
403 ELSE IF( KASE.EQ.2 ) THEN
405 * Multiply by inv(A)*diag(W).
408 WORK( N+I ) = WORK( I )*WORK( N+I )
410 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
419 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
422 $ FERR( J ) = FERR( J ) / LSTRES