3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSPRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsprfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsprfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsprfs.f">
21 * SUBROUTINE DSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX,
22 * FERR, BERR, WORK, IWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * INTEGER IPIV( * ), IWORK( * )
30 * DOUBLE PRECISION AFP( * ), AP( * ), B( LDB, * ), BERR( * ),
31 * $ FERR( * ), WORK( * ), X( LDX, * )
40 *> DSPRFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is symmetric indefinite
42 *> and packed, and provides error bounds and backward error estimates
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 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
72 *> The upper or lower triangle of the symmetric matrix A, packed
73 *> columnwise in a linear array. The j-th column of A is stored
74 *> in the array AP as follows:
75 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
76 *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
81 *> AFP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
82 *> The factored form of the matrix A. AFP contains the block
83 *> diagonal matrix D and the multipliers used to obtain the
84 *> factor U or L from the factorization A = U*D*U**T or
85 *> A = L*D*L**T as computed by DSPTRF, stored as a packed
91 *> IPIV is INTEGER array, dimension (N)
92 *> Details of the interchanges and the block structure of D
93 *> as determined by DSPTRF.
98 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
99 *> The right hand side matrix B.
105 *> The leading dimension of the array B. LDB >= max(1,N).
110 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
111 *> On entry, the solution matrix X, as computed by DSPTRS.
112 *> On exit, the improved solution matrix X.
118 *> The leading dimension of the array X. LDX >= max(1,N).
123 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
124 *> The estimated forward error bound for each solution vector
125 *> X(j) (the j-th column of the solution matrix X).
126 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
127 *> is an estimated upper bound for the magnitude of the largest
128 *> element in (X(j) - XTRUE) divided by the magnitude of the
129 *> largest element in X(j). The estimate is as reliable as
130 *> the estimate for RCOND, and is almost always a slight
131 *> overestimate of the true error.
136 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
137 *> The componentwise relative backward error of each solution
138 *> vector X(j) (i.e., the smallest relative change in
139 *> any element of A or B that makes X(j) an exact solution).
144 *> WORK is DOUBLE PRECISION array, dimension (3*N)
149 *> IWORK is INTEGER array, dimension (N)
155 *> = 0: successful exit
156 *> < 0: if INFO = -i, the i-th argument had an illegal value
159 *> \par Internal Parameters:
160 * =========================
163 *> ITMAX is the maximum number of steps of iterative refinement.
169 *> \author Univ. of Tennessee
170 *> \author Univ. of California Berkeley
171 *> \author Univ. of Colorado Denver
174 *> \date November 2011
176 *> \ingroup doubleOTHERcomputational
178 * =====================================================================
179 SUBROUTINE DSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX,
180 $ FERR, BERR, WORK, IWORK, INFO )
182 * -- LAPACK computational routine (version 3.4.0) --
183 * -- LAPACK is a software package provided by Univ. of Tennessee, --
184 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
187 * .. Scalar Arguments ..
189 INTEGER INFO, LDB, LDX, N, NRHS
191 * .. Array Arguments ..
192 INTEGER IPIV( * ), IWORK( * )
193 DOUBLE PRECISION AFP( * ), AP( * ), B( LDB, * ), BERR( * ),
194 $ FERR( * ), WORK( * ), X( LDX, * )
197 * =====================================================================
201 PARAMETER ( ITMAX = 5 )
202 DOUBLE PRECISION ZERO
203 PARAMETER ( ZERO = 0.0D+0 )
205 PARAMETER ( ONE = 1.0D+0 )
207 PARAMETER ( TWO = 2.0D+0 )
208 DOUBLE PRECISION THREE
209 PARAMETER ( THREE = 3.0D+0 )
211 * .. Local Scalars ..
213 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
214 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
219 * .. External Subroutines ..
220 EXTERNAL DAXPY, DCOPY, DLACN2, DSPMV, DSPTRS, XERBLA
222 * .. Intrinsic Functions ..
225 * .. External Functions ..
227 DOUBLE PRECISION DLAMCH
228 EXTERNAL LSAME, DLAMCH
230 * .. Executable Statements ..
232 * Test the input parameters.
235 UPPER = LSAME( UPLO, 'U' )
236 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
238 ELSE IF( N.LT.0 ) THEN
240 ELSE IF( NRHS.LT.0 ) THEN
242 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
244 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
248 CALL XERBLA( 'DSPRFS', -INFO )
252 * Quick return if possible
254 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
262 * NZ = maximum number of nonzero elements in each row of A, plus 1
265 EPS = DLAMCH( 'Epsilon' )
266 SAFMIN = DLAMCH( 'Safe minimum' )
270 * Do for each right hand side
278 * Loop until stopping criterion is satisfied.
280 * Compute residual R = B - A * X
282 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
283 CALL DSPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK( N+1 ),
286 * Compute componentwise relative backward error from formula
288 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
290 * where abs(Z) is the componentwise absolute value of the matrix
291 * or vector Z. If the i-th component of the denominator is less
292 * than SAFE2, then SAFE1 is added to the i-th components of the
293 * numerator and denominator before dividing.
296 WORK( I ) = ABS( B( I, J ) )
299 * Compute abs(A)*abs(X) + abs(B).
305 XK = ABS( X( K, J ) )
308 WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
309 S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
312 WORK( K ) = WORK( K ) + ABS( AP( KK+K-1 ) )*XK + S
318 XK = ABS( X( K, J ) )
319 WORK( K ) = WORK( K ) + ABS( AP( KK ) )*XK
322 WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
323 S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
326 WORK( K ) = WORK( K ) + S
332 IF( WORK( I ).GT.SAFE2 ) THEN
333 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
335 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
336 $ ( WORK( I )+SAFE1 ) )
341 * Test stopping criterion. Continue iterating if
342 * 1) The residual BERR(J) is larger than machine epsilon, and
343 * 2) BERR(J) decreased by at least a factor of 2 during the
344 * last iteration, and
345 * 3) At most ITMAX iterations tried.
347 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
348 $ COUNT.LE.ITMAX ) THEN
350 * Update solution and try again.
352 CALL DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N, INFO )
353 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
359 * Bound error from formula
361 * norm(X - XTRUE) / norm(X) .le. FERR =
363 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
366 * norm(Z) is the magnitude of the largest component of Z
367 * inv(A) is the inverse of A
368 * abs(Z) is the componentwise absolute value of the matrix or
370 * NZ is the maximum number of nonzeros in any row of A, plus 1
371 * EPS is machine epsilon
373 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
374 * is incremented by SAFE1 if the i-th component of
375 * abs(A)*abs(X) + abs(B) is less than SAFE2.
377 * Use DLACN2 to estimate the infinity-norm of the matrix
379 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
382 IF( WORK( I ).GT.SAFE2 ) THEN
383 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
385 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
391 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
396 * Multiply by diag(W)*inv(A**T).
398 CALL DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N,
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 DSPTRS( UPLO, N, 1, AFP, IPIV, WORK( N+1 ), N,
420 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
423 $ FERR( J ) = FERR( J ) / LSTRES