3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CPPRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpprfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpprfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpprfs.f">
21 * SUBROUTINE CPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
22 * BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * REAL BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
40 *> CPPRFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is Hermitian positive definite
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 COMPLEX array, dimension (N*(N+1)/2)
72 *> The upper or lower triangle of the Hermitian 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)*(2n-j)/2) = A(i,j) for j<=i<=n.
81 *> AFP is COMPLEX array, dimension (N*(N+1)/2)
82 *> The triangular factor U or L from the Cholesky factorization
83 *> A = U**H*U or A = L*L**H, as computed by SPPTRF/CPPTRF,
84 *> packed columnwise in a linear array in the same format as A
90 *> B is COMPLEX array, dimension (LDB,NRHS)
91 *> The right hand side matrix B.
97 *> The leading dimension of the array B. LDB >= max(1,N).
102 *> X is COMPLEX array, dimension (LDX,NRHS)
103 *> On entry, the solution matrix X, as computed by CPPTRS.
104 *> On exit, the improved solution matrix X.
110 *> The leading dimension of the array X. LDX >= max(1,N).
115 *> FERR is REAL array, dimension (NRHS)
116 *> The estimated forward error bound for each solution vector
117 *> X(j) (the j-th column of the solution matrix X).
118 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
119 *> is an estimated upper bound for the magnitude of the largest
120 *> element in (X(j) - XTRUE) divided by the magnitude of the
121 *> largest element in X(j). The estimate is as reliable as
122 *> the estimate for RCOND, and is almost always a slight
123 *> overestimate of the true error.
128 *> BERR is REAL array, dimension (NRHS)
129 *> The componentwise relative backward error of each solution
130 *> vector X(j) (i.e., the smallest relative change in
131 *> any element of A or B that makes X(j) an exact solution).
136 *> WORK is COMPLEX array, dimension (2*N)
141 *> RWORK is REAL array, dimension (N)
147 *> = 0: successful exit
148 *> < 0: if INFO = -i, the i-th argument had an illegal value
151 *> \par Internal Parameters:
152 * =========================
155 *> ITMAX is the maximum number of steps of iterative refinement.
161 *> \author Univ. of Tennessee
162 *> \author Univ. of California Berkeley
163 *> \author Univ. of Colorado Denver
166 *> \date November 2011
168 *> \ingroup complexOTHERcomputational
170 * =====================================================================
171 SUBROUTINE CPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
172 $ BERR, WORK, RWORK, INFO )
174 * -- LAPACK computational routine (version 3.4.0) --
175 * -- LAPACK is a software package provided by Univ. of Tennessee, --
176 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
179 * .. Scalar Arguments ..
181 INTEGER INFO, LDB, LDX, N, NRHS
183 * .. Array Arguments ..
184 REAL BERR( * ), FERR( * ), RWORK( * )
185 COMPLEX AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
189 * ====================================================================
193 PARAMETER ( ITMAX = 5 )
195 PARAMETER ( ZERO = 0.0E+0 )
197 PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
199 PARAMETER ( TWO = 2.0E+0 )
201 PARAMETER ( THREE = 3.0E+0 )
203 * .. Local Scalars ..
205 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
206 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
212 * .. External Subroutines ..
213 EXTERNAL CAXPY, CCOPY, CHPMV, CLACN2, CPPTRS, XERBLA
215 * .. Intrinsic Functions ..
216 INTRINSIC ABS, AIMAG, MAX, REAL
218 * .. External Functions ..
221 EXTERNAL LSAME, SLAMCH
223 * .. Statement Functions ..
226 * .. Statement Function definitions ..
227 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
229 * .. Executable Statements ..
231 * Test the input parameters.
234 UPPER = LSAME( UPLO, 'U' )
235 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
237 ELSE IF( N.LT.0 ) THEN
239 ELSE IF( NRHS.LT.0 ) THEN
241 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
243 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
247 CALL XERBLA( 'CPPRFS', -INFO )
251 * Quick return if possible
253 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
261 * NZ = maximum number of nonzero elements in each row of A, plus 1
264 EPS = SLAMCH( 'Epsilon' )
265 SAFMIN = SLAMCH( 'Safe minimum' )
269 * Do for each right hand side
277 * Loop until stopping criterion is satisfied.
279 * Compute residual R = B - A * X
281 CALL CCOPY( N, B( 1, J ), 1, WORK, 1 )
282 CALL CHPMV( UPLO, N, -CONE, AP, X( 1, J ), 1, CONE, WORK, 1 )
284 * Compute componentwise relative backward error from formula
286 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
288 * where abs(Z) is the componentwise absolute value of the matrix
289 * or vector Z. If the i-th component of the denominator is less
290 * than SAFE2, then SAFE1 is added to the i-th components of the
291 * numerator and denominator before dividing.
294 RWORK( I ) = CABS1( B( I, J ) )
297 * Compute abs(A)*abs(X) + abs(B).
303 XK = CABS1( X( K, J ) )
306 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
307 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
310 RWORK( K ) = RWORK( K ) + ABS( REAL( AP( KK+K-1 ) ) )*
317 XK = CABS1( X( K, J ) )
318 RWORK( K ) = RWORK( K ) + ABS( REAL( AP( KK ) ) )*XK
321 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
322 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
325 RWORK( K ) = RWORK( K ) + S
331 IF( RWORK( I ).GT.SAFE2 ) THEN
332 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
334 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
335 $ ( RWORK( I )+SAFE1 ) )
340 * Test stopping criterion. Continue iterating if
341 * 1) The residual BERR(J) is larger than machine epsilon, and
342 * 2) BERR(J) decreased by at least a factor of 2 during the
343 * last iteration, and
344 * 3) At most ITMAX iterations tried.
346 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
347 $ COUNT.LE.ITMAX ) THEN
349 * Update solution and try again.
351 CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
352 CALL CAXPY( N, CONE, WORK, 1, X( 1, J ), 1 )
358 * Bound error from formula
360 * norm(X - XTRUE) / norm(X) .le. FERR =
362 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
365 * norm(Z) is the magnitude of the largest component of Z
366 * inv(A) is the inverse of A
367 * abs(Z) is the componentwise absolute value of the matrix or
369 * NZ is the maximum number of nonzeros in any row of A, plus 1
370 * EPS is machine epsilon
372 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
373 * is incremented by SAFE1 if the i-th component of
374 * abs(A)*abs(X) + abs(B) is less than SAFE2.
376 * Use CLACN2 to estimate the infinity-norm of the matrix
378 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
381 IF( RWORK( I ).GT.SAFE2 ) THEN
382 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
384 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
391 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
395 * Multiply by diag(W)*inv(A**H).
397 CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
399 WORK( I ) = RWORK( I )*WORK( I )
401 ELSE IF( KASE.EQ.2 ) THEN
403 * Multiply by inv(A)*diag(W).
406 WORK( I ) = RWORK( I )*WORK( I )
408 CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
417 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
420 $ FERR( J ) = FERR( J ) / LSTRES