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