LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ spbrfs()

subroutine spbrfs ( character uplo,
integer n,
integer kd,
integer nrhs,
real, dimension( ldab, * ) ab,
integer ldab,
real, dimension( ldafb, * ) afb,
integer ldafb,
real, dimension( ldb, * ) b,
integer ldb,
real, dimension( ldx, * ) x,
integer ldx,
real, dimension( * ) ferr,
real, dimension( * ) berr,
real, dimension( * ) work,
integer, dimension( * ) iwork,
integer info )

SPBRFS

Download SPBRFS + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> SPBRFS improves the computed solution to a system of linear
!> equations when the coefficient matrix is symmetric positive definite
!> and banded, and provides error bounds and backward error estimates
!> for the solution.
!> 
Parameters
[in]UPLO
!>          UPLO is CHARACTER*1
!>          = 'U':  Upper triangle of A is stored;
!>          = 'L':  Lower triangle of A is stored.
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in]KD
!>          KD is INTEGER
!>          The number of superdiagonals of the matrix A if UPLO = 'U',
!>          or the number of subdiagonals if UPLO = 'L'.  KD >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of right hand sides, i.e., the number of columns
!>          of the matrices B and X.  NRHS >= 0.
!> 
[in]AB
!>          AB is REAL array, dimension (LDAB,N)
!>          The upper or lower triangle of the symmetric band matrix A,
!>          stored in the first KD+1 rows of the array.  The j-th column
!>          of A is stored in the j-th column of the array AB as follows:
!>          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
!>          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
!> 
[in]LDAB
!>          LDAB is INTEGER
!>          The leading dimension of the array AB.  LDAB >= KD+1.
!> 
[in]AFB
!>          AFB is REAL array, dimension (LDAFB,N)
!>          The triangular factor U or L from the Cholesky factorization
!>          A = U**T*U or A = L*L**T of the band matrix A as computed by
!>          SPBTRF, in the same storage format as A (see AB).
!> 
[in]LDAFB
!>          LDAFB is INTEGER
!>          The leading dimension of the array AFB.  LDAFB >= KD+1.
!> 
[in]B
!>          B is REAL array, dimension (LDB,NRHS)
!>          The right hand side matrix B.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B.  LDB >= max(1,N).
!> 
[in,out]X
!>          X is REAL array, dimension (LDX,NRHS)
!>          On entry, the solution matrix X, as computed by SPBTRS.
!>          On exit, the improved solution matrix X.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= max(1,N).
!> 
[out]FERR
!>          FERR is REAL array, dimension (NRHS)
!>          The estimated forward error bound for each solution vector
!>          X(j) (the j-th column of the solution matrix X).
!>          If XTRUE is the true solution corresponding to X(j), FERR(j)
!>          is an estimated upper bound for the magnitude of the largest
!>          element in (X(j) - XTRUE) divided by the magnitude of the
!>          largest element in X(j).  The estimate is as reliable as
!>          the estimate for RCOND, and is almost always a slight
!>          overestimate of the true error.
!> 
[out]BERR
!>          BERR is REAL array, dimension (NRHS)
!>          The componentwise relative backward error of each solution
!>          vector X(j) (i.e., the smallest relative change in
!>          any element of A or B that makes X(j) an exact solution).
!> 
[out]WORK
!>          WORK is REAL array, dimension (3*N)
!> 
[out]IWORK
!>          IWORK is INTEGER array, dimension (N)
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value
!> 
Internal Parameters:
!>  ITMAX is the maximum number of steps of iterative refinement.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 185 of file spbrfs.f.

187*
188* -- LAPACK computational routine --
189* -- LAPACK is a software package provided by Univ. of Tennessee, --
190* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
191*
192* .. Scalar Arguments ..
193 CHARACTER UPLO
194 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
195* ..
196* .. Array Arguments ..
197 INTEGER IWORK( * )
198 REAL AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
199 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
200* ..
201*
202* =====================================================================
203*
204* .. Parameters ..
205 INTEGER ITMAX
206 parameter( itmax = 5 )
207 REAL ZERO
208 parameter( zero = 0.0e+0 )
209 REAL ONE
210 parameter( one = 1.0e+0 )
211 REAL TWO
212 parameter( two = 2.0e+0 )
213 REAL THREE
214 parameter( three = 3.0e+0 )
215* ..
216* .. Local Scalars ..
217 LOGICAL UPPER
218 INTEGER COUNT, I, J, K, KASE, L, NZ
219 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
220* ..
221* .. Local Arrays ..
222 INTEGER ISAVE( 3 )
223* ..
224* .. External Subroutines ..
225 EXTERNAL saxpy, scopy, slacn2, spbtrs, ssbmv,
226 $ xerbla
227* ..
228* .. Intrinsic Functions ..
229 INTRINSIC abs, max, min
230* ..
231* .. External Functions ..
232 LOGICAL LSAME
233 REAL SLAMCH
234 EXTERNAL lsame, slamch
235* ..
236* .. Executable Statements ..
237*
238* Test the input parameters.
239*
240 info = 0
241 upper = lsame( uplo, 'U' )
242 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
243 info = -1
244 ELSE IF( n.LT.0 ) THEN
245 info = -2
246 ELSE IF( kd.LT.0 ) THEN
247 info = -3
248 ELSE IF( nrhs.LT.0 ) THEN
249 info = -4
250 ELSE IF( ldab.LT.kd+1 ) THEN
251 info = -6
252 ELSE IF( ldafb.LT.kd+1 ) THEN
253 info = -8
254 ELSE IF( ldb.LT.max( 1, n ) ) THEN
255 info = -10
256 ELSE IF( ldx.LT.max( 1, n ) ) THEN
257 info = -12
258 END IF
259 IF( info.NE.0 ) THEN
260 CALL xerbla( 'SPBRFS', -info )
261 RETURN
262 END IF
263*
264* Quick return if possible
265*
266 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
267 DO 10 j = 1, nrhs
268 ferr( j ) = zero
269 berr( j ) = zero
270 10 CONTINUE
271 RETURN
272 END IF
273*
274* NZ = maximum number of nonzero elements in each row of A, plus 1
275*
276 nz = min( n+1, 2*kd+2 )
277 eps = slamch( 'Epsilon' )
278 safmin = slamch( 'Safe minimum' )
279 safe1 = real( nz )*safmin
280 safe2 = safe1 / eps
281*
282* Do for each right hand side
283*
284 DO 140 j = 1, nrhs
285*
286 count = 1
287 lstres = three
288 20 CONTINUE
289*
290* Loop until stopping criterion is satisfied.
291*
292* Compute residual R = B - A * X
293*
294 CALL scopy( n, b( 1, j ), 1, work( n+1 ), 1 )
295 CALL ssbmv( uplo, n, kd, -one, ab, ldab, x( 1, j ), 1, one,
296 $ work( n+1 ), 1 )
297*
298* Compute componentwise relative backward error from formula
299*
300* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
301*
302* where abs(Z) is the componentwise absolute value of the matrix
303* or vector Z. If the i-th component of the denominator is less
304* than SAFE2, then SAFE1 is added to the i-th components of the
305* numerator and denominator before dividing.
306*
307 DO 30 i = 1, n
308 work( i ) = abs( b( i, j ) )
309 30 CONTINUE
310*
311* Compute abs(A)*abs(X) + abs(B).
312*
313 IF( upper ) THEN
314 DO 50 k = 1, n
315 s = zero
316 xk = abs( x( k, j ) )
317 l = kd + 1 - k
318 DO 40 i = max( 1, k-kd ), k - 1
319 work( i ) = work( i ) + abs( ab( l+i, k ) )*xk
320 s = s + abs( ab( l+i, k ) )*abs( x( i, j ) )
321 40 CONTINUE
322 work( k ) = work( k ) + abs( ab( kd+1, 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( ab( 1, k ) )*xk
329 l = 1 - k
330 DO 60 i = k + 1, min( n, k+kd )
331 work( i ) = work( i ) + abs( ab( l+i, k ) )*xk
332 s = s + abs( ab( l+i, k ) )*abs( x( i, j ) )
333 60 CONTINUE
334 work( k ) = work( k ) + s
335 70 CONTINUE
336 END IF
337 s = zero
338 DO 80 i = 1, n
339 IF( work( i ).GT.safe2 ) THEN
340 s = max( s, abs( work( n+i ) ) / work( i ) )
341 ELSE
342 s = max( s, ( abs( work( n+i ) )+safe1 ) /
343 $ ( work( i )+safe1 ) )
344 END IF
345 80 CONTINUE
346 berr( j ) = s
347*
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.
353*
354 IF( berr( j ).GT.eps .AND. two*berr( j ).LE.lstres .AND.
355 $ count.LE.itmax ) THEN
356*
357* Update solution and try again.
358*
359 CALL spbtrs( uplo, n, kd, 1, afb, ldafb, work( n+1 ), n,
360 $ info )
361 CALL saxpy( n, one, work( n+1 ), 1, x( 1, j ), 1 )
362 lstres = berr( j )
363 count = count + 1
364 GO TO 20
365 END IF
366*
367* Bound error from formula
368*
369* norm(X - XTRUE) / norm(X) .le. FERR =
370* norm( abs(inv(A))*
371* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
372*
373* where
374* norm(Z) is the magnitude of the largest component of Z
375* inv(A) is the inverse of A
376* abs(Z) is the componentwise absolute value of the matrix or
377* vector Z
378* NZ is the maximum number of nonzeros in any row of A, plus 1
379* EPS is machine epsilon
380*
381* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
382* is incremented by SAFE1 if the i-th component of
383* abs(A)*abs(X) + abs(B) is less than SAFE2.
384*
385* Use SLACN2 to estimate the infinity-norm of the matrix
386* inv(A) * diag(W),
387* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
388*
389 DO 90 i = 1, n
390 IF( work( i ).GT.safe2 ) THEN
391 work( i ) = abs( work( n+i ) ) + real( nz )*eps*work( i )
392 ELSE
393 work( i ) = abs( work( n+i ) ) + real( nz )*eps*work( i )
394 $ + safe1
395 END IF
396 90 CONTINUE
397*
398 kase = 0
399 100 CONTINUE
400 CALL slacn2( n, work( 2*n+1 ), work( n+1 ), iwork,
401 $ ferr( j ),
402 $ kase, isave )
403 IF( kase.NE.0 ) THEN
404 IF( kase.EQ.1 ) THEN
405*
406* Multiply by diag(W)*inv(A**T).
407*
408 CALL spbtrs( uplo, n, kd, 1, afb, ldafb, work( n+1 ),
409 $ n,
410 $ info )
411 DO 110 i = 1, n
412 work( n+i ) = work( n+i )*work( i )
413 110 CONTINUE
414 ELSE IF( kase.EQ.2 ) THEN
415*
416* Multiply by inv(A)*diag(W).
417*
418 DO 120 i = 1, n
419 work( n+i ) = work( n+i )*work( i )
420 120 CONTINUE
421 CALL spbtrs( uplo, n, kd, 1, afb, ldafb, work( n+1 ),
422 $ n,
423 $ info )
424 END IF
425 GO TO 100
426 END IF
427*
428* Normalize error.
429*
430 lstres = zero
431 DO 130 i = 1, n
432 lstres = max( lstres, abs( x( i, j ) ) )
433 130 CONTINUE
434 IF( lstres.NE.zero )
435 $ ferr( j ) = ferr( j ) / lstres
436*
437 140 CONTINUE
438*
439 RETURN
440*
441* End of SPBRFS
442*
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 ssbmv(uplo, n, k, alpha, a, lda, x, incx, beta, y, incy)
SSBMV
Definition ssbmv.f:184
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
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine spbtrs(uplo, n, kd, nrhs, ab, ldab, b, ldb, info)
SPBTRS
Definition spbtrs.f:119
Here is the call graph for this function:
Here is the caller graph for this function: