3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZHPRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhprfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhprfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhprfs.f">
21 * SUBROUTINE ZHPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX,
22 * FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
30 * DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
31 * COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
41 *> ZHPRFS improves the computed solution to a system of linear
42 *> equations when the coefficient matrix is Hermitian indefinite
43 *> and packed, and provides error bounds and backward error estimates
52 *> UPLO is CHARACTER*1
53 *> = 'U': Upper triangle of A is stored;
54 *> = 'L': Lower triangle of A is stored.
60 *> The order of the matrix A. N >= 0.
66 *> The number of right hand sides, i.e., the number of columns
67 *> of the matrices B and X. NRHS >= 0.
72 *> AP is COMPLEX*16 array, dimension (N*(N+1)/2)
73 *> The upper or lower triangle of the Hermitian matrix A, packed
74 *> columnwise in a linear array. The j-th column of A is stored
75 *> in the array AP as follows:
76 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
77 *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
82 *> AFP is COMPLEX*16 array, dimension (N*(N+1)/2)
83 *> The factored form of the matrix A. AFP contains the block
84 *> diagonal matrix D and the multipliers used to obtain the
85 *> factor U or L from the factorization A = U*D*U**H or
86 *> A = L*D*L**H as computed by ZHPTRF, stored as a packed
92 *> IPIV is INTEGER array, dimension (N)
93 *> Details of the interchanges and the block structure of D
94 *> as determined by ZHPTRF.
99 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
100 *> The right hand side matrix B.
106 *> The leading dimension of the array B. LDB >= max(1,N).
111 *> X is COMPLEX*16 array, dimension (LDX,NRHS)
112 *> On entry, the solution matrix X, as computed by ZHPTRS.
113 *> On exit, the improved solution matrix X.
119 *> The leading dimension of the array X. LDX >= max(1,N).
124 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
125 *> The estimated forward error bound for each solution vector
126 *> X(j) (the j-th column of the solution matrix X).
127 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
128 *> is an estimated upper bound for the magnitude of the largest
129 *> element in (X(j) - XTRUE) divided by the magnitude of the
130 *> largest element in X(j). The estimate is as reliable as
131 *> the estimate for RCOND, and is almost always a slight
132 *> overestimate of the true error.
137 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
138 *> The componentwise relative backward error of each solution
139 *> vector X(j) (i.e., the smallest relative change in
140 *> any element of A or B that makes X(j) an exact solution).
145 *> WORK is COMPLEX*16 array, dimension (2*N)
150 *> RWORK is DOUBLE PRECISION array, dimension (N)
156 *> = 0: successful exit
157 *> < 0: if INFO = -i, the i-th argument had an illegal value
160 *> \par Internal Parameters:
161 * =========================
164 *> ITMAX is the maximum number of steps of iterative refinement.
170 *> \author Univ. of Tennessee
171 *> \author Univ. of California Berkeley
172 *> \author Univ. of Colorado Denver
175 *> \date November 2011
177 *> \ingroup complex16OTHERcomputational
179 * =====================================================================
180 SUBROUTINE ZHPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX,
181 $ FERR, BERR, WORK, RWORK, INFO )
183 * -- LAPACK computational routine (version 3.4.0) --
184 * -- LAPACK is a software package provided by Univ. of Tennessee, --
185 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
188 * .. Scalar Arguments ..
190 INTEGER INFO, LDB, LDX, N, NRHS
192 * .. Array Arguments ..
194 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
195 COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
199 * =====================================================================
203 PARAMETER ( ITMAX = 5 )
204 DOUBLE PRECISION ZERO
205 PARAMETER ( ZERO = 0.0D+0 )
207 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
209 PARAMETER ( TWO = 2.0D+0 )
210 DOUBLE PRECISION THREE
211 PARAMETER ( THREE = 3.0D+0 )
213 * .. Local Scalars ..
215 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
216 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
222 * .. External Subroutines ..
223 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZHPMV, ZHPTRS, ZLACN2
225 * .. Intrinsic Functions ..
226 INTRINSIC ABS, DBLE, DIMAG, MAX
228 * .. External Functions ..
230 DOUBLE PRECISION DLAMCH
231 EXTERNAL LSAME, DLAMCH
233 * .. Statement Functions ..
234 DOUBLE PRECISION CABS1
236 * .. Statement Function definitions ..
237 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
239 * .. Executable Statements ..
241 * Test the input parameters.
244 UPPER = LSAME( UPLO, 'U' )
245 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
247 ELSE IF( N.LT.0 ) THEN
249 ELSE IF( NRHS.LT.0 ) THEN
251 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
253 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
257 CALL XERBLA( 'ZHPRFS', -INFO )
261 * Quick return if possible
263 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
271 * NZ = maximum number of nonzero elements in each row of A, plus 1
274 EPS = DLAMCH( 'Epsilon' )
275 SAFMIN = DLAMCH( 'Safe minimum' )
279 * Do for each right hand side
287 * Loop until stopping criterion is satisfied.
289 * Compute residual R = B - A * X
291 CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
292 CALL ZHPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK, 1 )
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 RWORK( I ) = CABS1( B( I, J ) )
307 * Compute abs(A)*abs(X) + abs(B).
313 XK = CABS1( X( K, J ) )
316 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
317 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
320 RWORK( K ) = RWORK( K ) + ABS( DBLE( AP( KK+K-1 ) ) )*
327 XK = CABS1( X( K, J ) )
328 RWORK( K ) = RWORK( K ) + ABS( DBLE( AP( KK ) ) )*XK
331 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
332 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
335 RWORK( K ) = RWORK( K ) + S
341 IF( RWORK( I ).GT.SAFE2 ) THEN
342 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
344 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
345 $ ( RWORK( I )+SAFE1 ) )
350 * Test stopping criterion. Continue iterating if
351 * 1) The residual BERR(J) is larger than machine epsilon, and
352 * 2) BERR(J) decreased by at least a factor of 2 during the
353 * last iteration, and
354 * 3) At most ITMAX iterations tried.
356 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
357 $ COUNT.LE.ITMAX ) THEN
359 * Update solution and try again.
361 CALL ZHPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO )
362 CALL ZAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
368 * Bound error from formula
370 * norm(X - XTRUE) / norm(X) .le. FERR =
372 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
375 * norm(Z) is the magnitude of the largest component of Z
376 * inv(A) is the inverse of A
377 * abs(Z) is the componentwise absolute value of the matrix or
379 * NZ is the maximum number of nonzeros in any row of A, plus 1
380 * EPS is machine epsilon
382 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
383 * is incremented by SAFE1 if the i-th component of
384 * abs(A)*abs(X) + abs(B) is less than SAFE2.
386 * Use ZLACN2 to estimate the infinity-norm of the matrix
388 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
391 IF( RWORK( I ).GT.SAFE2 ) THEN
392 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
394 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
401 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
405 * Multiply by diag(W)*inv(A**H).
407 CALL ZHPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO )
409 WORK( I ) = RWORK( I )*WORK( I )
411 ELSE IF( KASE.EQ.2 ) THEN
413 * Multiply by inv(A)*diag(W).
416 WORK( I ) = RWORK( I )*WORK( I )
418 CALL ZHPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO )
427 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
430 $ FERR( J ) = FERR( J ) / LSTRES