LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zpprfs.f
Go to the documentation of this file.
1*> \brief \b ZPPRFS
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZPPRFS + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zpprfs.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zpprfs.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zpprfs.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
20* BERR, WORK, RWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER UPLO
24* INTEGER INFO, LDB, LDX, N, NRHS
25* ..
26* .. Array Arguments ..
27* DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
28* COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
29* $ X( LDX, * )
30* ..
31*
32*
33*> \par Purpose:
34* =============
35*>
36*> \verbatim
37*>
38*> ZPPRFS improves the computed solution to a system of linear
39*> equations when the coefficient matrix is Hermitian positive definite
40*> and packed, and provides error bounds and backward error estimates
41*> for the solution.
42*> \endverbatim
43*
44* Arguments:
45* ==========
46*
47*> \param[in] UPLO
48*> \verbatim
49*> UPLO is CHARACTER*1
50*> = 'U': Upper triangle of A is stored;
51*> = 'L': Lower triangle of A is stored.
52*> \endverbatim
53*>
54*> \param[in] N
55*> \verbatim
56*> N is INTEGER
57*> The order of the matrix A. N >= 0.
58*> \endverbatim
59*>
60*> \param[in] NRHS
61*> \verbatim
62*> NRHS is INTEGER
63*> The number of right hand sides, i.e., the number of columns
64*> of the matrices B and X. NRHS >= 0.
65*> \endverbatim
66*>
67*> \param[in] AP
68*> \verbatim
69*> AP is COMPLEX*16 array, dimension (N*(N+1)/2)
70*> The upper or lower triangle of the Hermitian matrix A, packed
71*> columnwise in a linear array. The j-th column of A is stored
72*> in the array AP as follows:
73*> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
74*> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
75*> \endverbatim
76*>
77*> \param[in] AFP
78*> \verbatim
79*> AFP is COMPLEX*16 array, dimension (N*(N+1)/2)
80*> The triangular factor U or L from the Cholesky factorization
81*> A = U**H*U or A = L*L**H, as computed by DPPTRF/ZPPTRF,
82*> packed columnwise in a linear array in the same format as A
83*> (see AP).
84*> \endverbatim
85*>
86*> \param[in] B
87*> \verbatim
88*> B is COMPLEX*16 array, dimension (LDB,NRHS)
89*> The right hand side matrix B.
90*> \endverbatim
91*>
92*> \param[in] LDB
93*> \verbatim
94*> LDB is INTEGER
95*> The leading dimension of the array B. LDB >= max(1,N).
96*> \endverbatim
97*>
98*> \param[in,out] X
99*> \verbatim
100*> X is COMPLEX*16 array, dimension (LDX,NRHS)
101*> On entry, the solution matrix X, as computed by ZPPTRS.
102*> On exit, the improved solution matrix X.
103*> \endverbatim
104*>
105*> \param[in] LDX
106*> \verbatim
107*> LDX is INTEGER
108*> The leading dimension of the array X. LDX >= max(1,N).
109*> \endverbatim
110*>
111*> \param[out] FERR
112*> \verbatim
113*> FERR is DOUBLE PRECISION array, dimension (NRHS)
114*> The estimated forward error bound for each solution vector
115*> X(j) (the j-th column of the solution matrix X).
116*> If XTRUE is the true solution corresponding to X(j), FERR(j)
117*> is an estimated upper bound for the magnitude of the largest
118*> element in (X(j) - XTRUE) divided by the magnitude of the
119*> largest element in X(j). The estimate is as reliable as
120*> the estimate for RCOND, and is almost always a slight
121*> overestimate of the true error.
122*> \endverbatim
123*>
124*> \param[out] BERR
125*> \verbatim
126*> BERR is DOUBLE PRECISION array, dimension (NRHS)
127*> The componentwise relative backward error of each solution
128*> vector X(j) (i.e., the smallest relative change in
129*> any element of A or B that makes X(j) an exact solution).
130*> \endverbatim
131*>
132*> \param[out] WORK
133*> \verbatim
134*> WORK is COMPLEX*16 array, dimension (2*N)
135*> \endverbatim
136*>
137*> \param[out] RWORK
138*> \verbatim
139*> RWORK is DOUBLE PRECISION array, dimension (N)
140*> \endverbatim
141*>
142*> \param[out] INFO
143*> \verbatim
144*> INFO is INTEGER
145*> = 0: successful exit
146*> < 0: if INFO = -i, the i-th argument had an illegal value
147*> \endverbatim
148*
149*> \par Internal Parameters:
150* =========================
151*>
152*> \verbatim
153*> ITMAX is the maximum number of steps of iterative refinement.
154*> \endverbatim
155*
156* Authors:
157* ========
158*
159*> \author Univ. of Tennessee
160*> \author Univ. of California Berkeley
161*> \author Univ. of Colorado Denver
162*> \author NAG Ltd.
163*
164*> \ingroup pprfs
165*
166* =====================================================================
167 SUBROUTINE zpprfs( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX,
168 $ FERR,
169 $ BERR, WORK, RWORK, INFO )
170*
171* -- LAPACK computational routine --
172* -- LAPACK is a software package provided by Univ. of Tennessee, --
173* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
174*
175* .. Scalar Arguments ..
176 CHARACTER UPLO
177 INTEGER INFO, LDB, LDX, N, NRHS
178* ..
179* .. Array Arguments ..
180 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
181 COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
182 $ x( ldx, * )
183* ..
184*
185* ====================================================================
186*
187* .. Parameters ..
188 INTEGER ITMAX
189 PARAMETER ( ITMAX = 5 )
190 DOUBLE PRECISION ZERO
191 parameter( zero = 0.0d+0 )
192 COMPLEX*16 CONE
193 parameter( cone = ( 1.0d+0, 0.0d+0 ) )
194 DOUBLE PRECISION TWO
195 parameter( two = 2.0d+0 )
196 DOUBLE PRECISION THREE
197 parameter( three = 3.0d+0 )
198* ..
199* .. Local Scalars ..
200 LOGICAL UPPER
201 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
202 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
203 COMPLEX*16 ZDUM
204* ..
205* .. Local Arrays ..
206 INTEGER ISAVE( 3 )
207* ..
208* .. External Subroutines ..
209 EXTERNAL xerbla, zaxpy, zcopy, zhpmv, zlacn2,
210 $ zpptrs
211* ..
212* .. Intrinsic Functions ..
213 INTRINSIC abs, dble, dimag, max
214* ..
215* .. External Functions ..
216 LOGICAL LSAME
217 DOUBLE PRECISION DLAMCH
218 EXTERNAL lsame, dlamch
219* ..
220* .. Statement Functions ..
221 DOUBLE PRECISION CABS1
222* ..
223* .. Statement Function definitions ..
224 cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
225* ..
226* .. Executable Statements ..
227*
228* Test the input parameters.
229*
230 info = 0
231 upper = lsame( uplo, 'U' )
232 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
233 info = -1
234 ELSE IF( n.LT.0 ) THEN
235 info = -2
236 ELSE IF( nrhs.LT.0 ) THEN
237 info = -3
238 ELSE IF( ldb.LT.max( 1, n ) ) THEN
239 info = -7
240 ELSE IF( ldx.LT.max( 1, n ) ) THEN
241 info = -9
242 END IF
243 IF( info.NE.0 ) THEN
244 CALL xerbla( 'ZPPRFS', -info )
245 RETURN
246 END IF
247*
248* Quick return if possible
249*
250 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
251 DO 10 j = 1, nrhs
252 ferr( j ) = zero
253 berr( j ) = zero
254 10 CONTINUE
255 RETURN
256 END IF
257*
258* NZ = maximum number of nonzero elements in each row of A, plus 1
259*
260 nz = n + 1
261 eps = dlamch( 'Epsilon' )
262 safmin = dlamch( 'Safe minimum' )
263 safe1 = nz*safmin
264 safe2 = safe1 / eps
265*
266* Do for each right hand side
267*
268 DO 140 j = 1, nrhs
269*
270 count = 1
271 lstres = three
272 20 CONTINUE
273*
274* Loop until stopping criterion is satisfied.
275*
276* Compute residual R = B - A * X
277*
278 CALL zcopy( n, b( 1, j ), 1, work, 1 )
279 CALL zhpmv( uplo, n, -cone, ap, x( 1, j ), 1, cone, work,
280 $ 1 )
281*
282* Compute componentwise relative backward error from formula
283*
284* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
285*
286* where abs(Z) is the componentwise absolute value of the matrix
287* or vector Z. If the i-th component of the denominator is less
288* than SAFE2, then SAFE1 is added to the i-th components of the
289* numerator and denominator before dividing.
290*
291 DO 30 i = 1, n
292 rwork( i ) = cabs1( b( i, j ) )
293 30 CONTINUE
294*
295* Compute abs(A)*abs(X) + abs(B).
296*
297 kk = 1
298 IF( upper ) THEN
299 DO 50 k = 1, n
300 s = zero
301 xk = cabs1( x( k, j ) )
302 ik = kk
303 DO 40 i = 1, k - 1
304 rwork( i ) = rwork( i ) + cabs1( ap( ik ) )*xk
305 s = s + cabs1( ap( ik ) )*cabs1( x( i, j ) )
306 ik = ik + 1
307 40 CONTINUE
308 rwork( k ) = rwork( k ) + abs( dble( ap( kk+k-1 ) ) )*
309 $ xk + s
310 kk = kk + k
311 50 CONTINUE
312 ELSE
313 DO 70 k = 1, n
314 s = zero
315 xk = cabs1( x( k, j ) )
316 rwork( k ) = rwork( k ) + abs( dble( ap( kk ) ) )*xk
317 ik = kk + 1
318 DO 60 i = k + 1, n
319 rwork( i ) = rwork( i ) + cabs1( ap( ik ) )*xk
320 s = s + cabs1( ap( ik ) )*cabs1( x( i, j ) )
321 ik = ik + 1
322 60 CONTINUE
323 rwork( k ) = rwork( k ) + s
324 kk = kk + ( n-k+1 )
325 70 CONTINUE
326 END IF
327 s = zero
328 DO 80 i = 1, n
329 IF( rwork( i ).GT.safe2 ) THEN
330 s = max( s, cabs1( work( i ) ) / rwork( i ) )
331 ELSE
332 s = max( s, ( cabs1( work( i ) )+safe1 ) /
333 $ ( rwork( i )+safe1 ) )
334 END IF
335 80 CONTINUE
336 berr( j ) = s
337*
338* Test stopping criterion. Continue iterating if
339* 1) The residual BERR(J) is larger than machine epsilon, and
340* 2) BERR(J) decreased by at least a factor of 2 during the
341* last iteration, and
342* 3) At most ITMAX iterations tried.
343*
344 IF( berr( j ).GT.eps .AND. two*berr( j ).LE.lstres .AND.
345 $ count.LE.itmax ) THEN
346*
347* Update solution and try again.
348*
349 CALL zpptrs( uplo, n, 1, afp, work, n, info )
350 CALL zaxpy( n, cone, work, 1, x( 1, j ), 1 )
351 lstres = berr( j )
352 count = count + 1
353 GO TO 20
354 END IF
355*
356* Bound error from formula
357*
358* norm(X - XTRUE) / norm(X) .le. FERR =
359* norm( abs(inv(A))*
360* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
361*
362* where
363* norm(Z) is the magnitude of the largest component of Z
364* inv(A) is the inverse of A
365* abs(Z) is the componentwise absolute value of the matrix or
366* vector Z
367* NZ is the maximum number of nonzeros in any row of A, plus 1
368* EPS is machine epsilon
369*
370* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
371* is incremented by SAFE1 if the i-th component of
372* abs(A)*abs(X) + abs(B) is less than SAFE2.
373*
374* Use ZLACN2 to estimate the infinity-norm of the matrix
375* inv(A) * diag(W),
376* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
377*
378 DO 90 i = 1, n
379 IF( rwork( i ).GT.safe2 ) THEN
380 rwork( i ) = cabs1( work( i ) ) + nz*eps*rwork( i )
381 ELSE
382 rwork( i ) = cabs1( work( i ) ) + nz*eps*rwork( i ) +
383 $ safe1
384 END IF
385 90 CONTINUE
386*
387 kase = 0
388 100 CONTINUE
389 CALL zlacn2( n, work( n+1 ), work, ferr( j ), kase, isave )
390 IF( kase.NE.0 ) THEN
391 IF( kase.EQ.1 ) THEN
392*
393* Multiply by diag(W)*inv(A**H).
394*
395 CALL zpptrs( uplo, n, 1, afp, work, n, info )
396 DO 110 i = 1, n
397 work( i ) = rwork( i )*work( i )
398 110 CONTINUE
399 ELSE IF( kase.EQ.2 ) THEN
400*
401* Multiply by inv(A)*diag(W).
402*
403 DO 120 i = 1, n
404 work( i ) = rwork( i )*work( i )
405 120 CONTINUE
406 CALL zpptrs( uplo, n, 1, afp, work, n, info )
407 END IF
408 GO TO 100
409 END IF
410*
411* Normalize error.
412*
413 lstres = zero
414 DO 130 i = 1, n
415 lstres = max( lstres, cabs1( x( i, j ) ) )
416 130 CONTINUE
417 IF( lstres.NE.zero )
418 $ ferr( j ) = ferr( j ) / lstres
419*
420 140 CONTINUE
421*
422 RETURN
423*
424* End of ZPPRFS
425*
426 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine zaxpy(n, za, zx, incx, zy, incy)
ZAXPY
Definition zaxpy.f:88
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
Definition zcopy.f:81
subroutine zhpmv(uplo, n, alpha, ap, x, incx, beta, y, incy)
ZHPMV
Definition zhpmv.f:149
subroutine zlacn2(n, v, x, est, kase, isave)
ZLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition zlacn2.f:131
subroutine zpprfs(uplo, n, nrhs, ap, afp, b, ldb, x, ldx, ferr, berr, work, rwork, info)
ZPPRFS
Definition zpprfs.f:170
subroutine zpptrs(uplo, n, nrhs, ap, b, ldb, info)
ZPPTRS
Definition zpptrs.f:106