3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZPORFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zporfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zporfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zporfs.f">
21 * SUBROUTINE ZPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
22 * LDX, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
31 * $ WORK( * ), X( LDX, * )
40 *> ZPORFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is Hermitian 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 COMPLEX*16 array, dimension (LDA,N)
72 *> The Hermitian 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 COMPLEX*16 array, dimension (LDAF,N)
90 *> The triangular factor U or L from the Cholesky factorization
91 *> A = U**H*U or A = L*L**H, as computed by ZPOTRF.
97 *> The leading dimension of the array AF. LDAF >= max(1,N).
102 *> B is COMPLEX*16 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 COMPLEX*16 array, dimension (LDX,NRHS)
115 *> On entry, the solution matrix X, as computed by ZPOTRS.
116 *> On exit, the improved solution matrix X.
122 *> The leading dimension of the array X. LDX >= max(1,N).
127 *> FERR is DOUBLE PRECISION 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 DOUBLE PRECISION 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 COMPLEX*16 array, dimension (2*N)
153 *> RWORK is DOUBLE PRECISION 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 complex16POcomputational
182 * =====================================================================
183 SUBROUTINE ZPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
184 $ LDX, FERR, BERR, WORK, RWORK, 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 ..
196 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
197 COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
198 $ WORK( * ), X( LDX, * )
201 * ====================================================================
205 PARAMETER ( ITMAX = 5 )
206 DOUBLE PRECISION ZERO
207 PARAMETER ( ZERO = 0.0D+0 )
209 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
211 PARAMETER ( TWO = 2.0D+0 )
212 DOUBLE PRECISION THREE
213 PARAMETER ( THREE = 3.0D+0 )
215 * .. Local Scalars ..
217 INTEGER COUNT, I, J, K, KASE, NZ
218 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
224 * .. External Subroutines ..
225 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZHEMV, ZLACN2, ZPOTRS
227 * .. Intrinsic Functions ..
228 INTRINSIC ABS, DBLE, DIMAG, MAX
230 * .. External Functions ..
232 DOUBLE PRECISION DLAMCH
233 EXTERNAL LSAME, DLAMCH
235 * .. Statement Functions ..
236 DOUBLE PRECISION CABS1
238 * .. Statement Function definitions ..
239 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
241 * .. Executable Statements ..
243 * Test the input parameters.
246 UPPER = LSAME( UPLO, 'U' )
247 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
249 ELSE IF( N.LT.0 ) THEN
251 ELSE IF( NRHS.LT.0 ) THEN
253 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
255 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
257 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
259 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
263 CALL XERBLA( 'ZPORFS', -INFO )
267 * Quick return if possible
269 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
277 * NZ = maximum number of nonzero elements in each row of A, plus 1
280 EPS = DLAMCH( 'Epsilon' )
281 SAFMIN = DLAMCH( 'Safe minimum' )
285 * Do for each right hand side
293 * Loop until stopping criterion is satisfied.
295 * Compute residual R = B - A * X
297 CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
298 CALL ZHEMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE, WORK, 1 )
300 * Compute componentwise relative backward error from formula
302 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
304 * where abs(Z) is the componentwise absolute value of the matrix
305 * or vector Z. If the i-th component of the denominator is less
306 * than SAFE2, then SAFE1 is added to the i-th components of the
307 * numerator and denominator before dividing.
310 RWORK( I ) = CABS1( B( I, J ) )
313 * Compute abs(A)*abs(X) + abs(B).
318 XK = CABS1( X( K, J ) )
320 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
321 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
323 RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK + S
328 XK = CABS1( X( K, J ) )
329 RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK
331 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
332 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
334 RWORK( K ) = RWORK( K ) + S
339 IF( RWORK( I ).GT.SAFE2 ) THEN
340 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
342 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
343 $ ( RWORK( I )+SAFE1 ) )
348 * Test stopping criterion. Continue iterating if
349 * 1) The residual BERR(J) is larger than machine epsilon, and
350 * 2) BERR(J) decreased by at least a factor of 2 during the
351 * last iteration, and
352 * 3) At most ITMAX iterations tried.
354 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
355 $ COUNT.LE.ITMAX ) THEN
357 * Update solution and try again.
359 CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
360 CALL ZAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
366 * Bound error from formula
368 * norm(X - XTRUE) / norm(X) .le. FERR =
370 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
373 * norm(Z) is the magnitude of the largest component of Z
374 * inv(A) is the inverse of A
375 * abs(Z) is the componentwise absolute value of the matrix or
377 * NZ is the maximum number of nonzeros in any row of A, plus 1
378 * EPS is machine epsilon
380 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
381 * is incremented by SAFE1 if the i-th component of
382 * abs(A)*abs(X) + abs(B) is less than SAFE2.
384 * Use ZLACN2 to estimate the infinity-norm of the matrix
386 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
389 IF( RWORK( I ).GT.SAFE2 ) THEN
390 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
392 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
399 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
403 * Multiply by diag(W)*inv(A**H).
405 CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
407 WORK( I ) = RWORK( I )*WORK( I )
409 ELSE IF( KASE.EQ.2 ) THEN
411 * Multiply by inv(A)*diag(W).
414 WORK( I ) = RWORK( I )*WORK( I )
416 CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
425 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
428 $ FERR( J ) = FERR( J ) / LSTRES