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

◆ dporfs()

subroutine dporfs ( character uplo,
integer n,
integer nrhs,
double precision, dimension( lda, * ) a,
integer lda,
double precision, dimension( ldaf, * ) af,
integer ldaf,
double precision, dimension( ldb, * ) b,
integer ldb,
double precision, dimension( ldx, * ) x,
integer ldx,
double precision, dimension( * ) ferr,
double precision, dimension( * ) berr,
double precision, dimension( * ) work,
integer, dimension( * ) iwork,
integer info )

DPORFS

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

Purpose:
!>
!> DPORFS improves the computed solution to a system of linear
!> equations when the coefficient matrix is symmetric positive definite,
!> 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]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]A
!>          A is DOUBLE PRECISION array, dimension (LDA,N)
!>          The symmetric matrix A.  If UPLO = 'U', the leading N-by-N
!>          upper triangular part of A contains the upper triangular part
!>          of the matrix A, and the strictly lower triangular part of A
!>          is not referenced.  If UPLO = 'L', the leading N-by-N lower
!>          triangular part of A contains the lower triangular part of
!>          the matrix A, and the strictly upper triangular part of A is
!>          not referenced.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= max(1,N).
!> 
[in]AF
!>          AF is DOUBLE PRECISION array, dimension (LDAF,N)
!>          The triangular factor U or L from the Cholesky factorization
!>          A = U**T*U or A = L*L**T, as computed by DPOTRF.
!> 
[in]LDAF
!>          LDAF is INTEGER
!>          The leading dimension of the array AF.  LDAF >= max(1,N).
!> 
[in]B
!>          B is DOUBLE PRECISION 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 DOUBLE PRECISION array, dimension (LDX,NRHS)
!>          On entry, the solution matrix X, as computed by DPOTRS.
!>          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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 179 of file dporfs.f.

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 INTEGER IWORK( * )
192 DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
193 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
194* ..
195*
196* =====================================================================
197*
198* .. Parameters ..
199 INTEGER ITMAX
200 parameter( itmax = 5 )
201 DOUBLE PRECISION ZERO
202 parameter( zero = 0.0d+0 )
203 DOUBLE PRECISION ONE
204 parameter( one = 1.0d+0 )
205 DOUBLE PRECISION TWO
206 parameter( two = 2.0d+0 )
207 DOUBLE PRECISION THREE
208 parameter( three = 3.0d+0 )
209* ..
210* .. Local Scalars ..
211 LOGICAL UPPER
212 INTEGER COUNT, I, J, K, KASE, NZ
213 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
214* ..
215* .. Local Arrays ..
216 INTEGER ISAVE( 3 )
217* ..
218* .. External Subroutines ..
219 EXTERNAL daxpy, dcopy, dlacn2, dpotrs, dsymv,
220 $ xerbla
221* ..
222* .. Intrinsic Functions ..
223 INTRINSIC abs, max
224* ..
225* .. External Functions ..
226 LOGICAL LSAME
227 DOUBLE PRECISION DLAMCH
228 EXTERNAL lsame, dlamch
229* ..
230* .. Executable Statements ..
231*
232* Test the input parameters.
233*
234 info = 0
235 upper = lsame( uplo, 'U' )
236 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
237 info = -1
238 ELSE IF( n.LT.0 ) THEN
239 info = -2
240 ELSE IF( nrhs.LT.0 ) THEN
241 info = -3
242 ELSE IF( lda.LT.max( 1, n ) ) THEN
243 info = -5
244 ELSE IF( ldaf.LT.max( 1, n ) ) THEN
245 info = -7
246 ELSE IF( ldb.LT.max( 1, n ) ) THEN
247 info = -9
248 ELSE IF( ldx.LT.max( 1, n ) ) THEN
249 info = -11
250 END IF
251 IF( info.NE.0 ) THEN
252 CALL xerbla( 'DPORFS', -info )
253 RETURN
254 END IF
255*
256* Quick return if possible
257*
258 IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
259 DO 10 j = 1, nrhs
260 ferr( j ) = zero
261 berr( j ) = zero
262 10 CONTINUE
263 RETURN
264 END IF
265*
266* NZ = maximum number of nonzero elements in each row of A, plus 1
267*
268 nz = n + 1
269 eps = dlamch( 'Epsilon' )
270 safmin = dlamch( 'Safe minimum' )
271 safe1 = nz*safmin
272 safe2 = safe1 / eps
273*
274* Do for each right hand side
275*
276 DO 140 j = 1, nrhs
277*
278 count = 1
279 lstres = three
280 20 CONTINUE
281*
282* Loop until stopping criterion is satisfied.
283*
284* Compute residual R = B - A * X
285*
286 CALL dcopy( n, b( 1, j ), 1, work( n+1 ), 1 )
287 CALL dsymv( uplo, n, -one, a, lda, x( 1, j ), 1, one,
288 $ work( n+1 ), 1 )
289*
290* Compute componentwise relative backward error from formula
291*
292* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
293*
294* where abs(Z) is the componentwise absolute value of the matrix
295* or vector Z. If the i-th component of the denominator is less
296* than SAFE2, then SAFE1 is added to the i-th components of the
297* numerator and denominator before dividing.
298*
299 DO 30 i = 1, n
300 work( i ) = abs( b( i, j ) )
301 30 CONTINUE
302*
303* Compute abs(A)*abs(X) + abs(B).
304*
305 IF( upper ) THEN
306 DO 50 k = 1, n
307 s = zero
308 xk = abs( x( k, j ) )
309 DO 40 i = 1, k - 1
310 work( i ) = work( i ) + abs( a( i, k ) )*xk
311 s = s + abs( a( i, k ) )*abs( x( i, j ) )
312 40 CONTINUE
313 work( k ) = work( k ) + abs( a( k, k ) )*xk + s
314 50 CONTINUE
315 ELSE
316 DO 70 k = 1, n
317 s = zero
318 xk = abs( x( k, j ) )
319 work( k ) = work( k ) + abs( a( k, k ) )*xk
320 DO 60 i = k + 1, n
321 work( i ) = work( i ) + abs( a( i, k ) )*xk
322 s = s + abs( a( i, k ) )*abs( x( i, j ) )
323 60 CONTINUE
324 work( k ) = work( k ) + s
325 70 CONTINUE
326 END IF
327 s = zero
328 DO 80 i = 1, n
329 IF( work( i ).GT.safe2 ) THEN
330 s = max( s, abs( work( n+i ) ) / work( i ) )
331 ELSE
332 s = max( s, ( abs( work( n+i ) )+safe1 ) /
333 $ ( work( 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 dpotrs( uplo, n, 1, af, ldaf, work( n+1 ), n, info )
350 CALL daxpy( n, one, work( n+1 ), 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 DLACN2 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( work( i ).GT.safe2 ) THEN
380 work( i ) = abs( work( n+i ) ) + nz*eps*work( i )
381 ELSE
382 work( i ) = abs( work( n+i ) ) + nz*eps*work( i ) + safe1
383 END IF
384 90 CONTINUE
385*
386 kase = 0
387 100 CONTINUE
388 CALL dlacn2( n, work( 2*n+1 ), work( n+1 ), iwork,
389 $ ferr( j ),
390 $ kase, isave )
391 IF( kase.NE.0 ) THEN
392 IF( kase.EQ.1 ) THEN
393*
394* Multiply by diag(W)*inv(A**T).
395*
396 CALL dpotrs( uplo, n, 1, af, ldaf, work( n+1 ), n,
397 $ info )
398 DO 110 i = 1, n
399 work( n+i ) = work( i )*work( n+i )
400 110 CONTINUE
401 ELSE IF( kase.EQ.2 ) THEN
402*
403* Multiply by inv(A)*diag(W).
404*
405 DO 120 i = 1, n
406 work( n+i ) = work( i )*work( n+i )
407 120 CONTINUE
408 CALL dpotrs( uplo, n, 1, af, ldaf, work( n+1 ), n,
409 $ info )
410 END IF
411 GO TO 100
412 END IF
413*
414* Normalize error.
415*
416 lstres = zero
417 DO 130 i = 1, n
418 lstres = max( lstres, abs( x( i, j ) ) )
419 130 CONTINUE
420 IF( lstres.NE.zero )
421 $ ferr( j ) = ferr( j ) / lstres
422*
423 140 CONTINUE
424*
425 RETURN
426*
427* End of DPORFS
428*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine daxpy(n, da, dx, incx, dy, incy)
DAXPY
Definition daxpy.f:89
subroutine dcopy(n, dx, incx, dy, incy)
DCOPY
Definition dcopy.f:82
subroutine dsymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
DSYMV
Definition dsymv.f:152
subroutine dlacn2(n, v, x, isgn, est, kase, isave)
DLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition dlacn2.f:134
double precision function dlamch(cmach)
DLAMCH
Definition dlamch.f:69
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine dpotrs(uplo, n, nrhs, a, lda, b, ldb, info)
DPOTRS
Definition dpotrs.f:108
Here is the call graph for this function:
Here is the caller graph for this function: