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