dpbrfs.c
Go to the documentation of this file.
00001 /* dpbrfs.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static doublereal c_b12 = -1.;
00020 static doublereal c_b14 = 1.;
00021 
00022 /* Subroutine */ int dpbrfs_(char *uplo, integer *n, integer *kd, integer *
00023         nrhs, doublereal *ab, integer *ldab, doublereal *afb, integer *ldafb, 
00024         doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal *
00025         ferr, doublereal *berr, doublereal *work, integer *iwork, integer *
00026         info)
00027 {
00028     /* System generated locals */
00029     integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset, 
00030             x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
00031     doublereal d__1, d__2, d__3;
00032 
00033     /* Local variables */
00034     integer i__, j, k, l;
00035     doublereal s, xk;
00036     integer nz;
00037     doublereal eps;
00038     integer kase;
00039     doublereal safe1, safe2;
00040     extern logical lsame_(char *, char *);
00041     integer isave[3];
00042     extern /* Subroutine */ int dsbmv_(char *, integer *, integer *, 
00043             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00044             doublereal *, doublereal *, integer *), dcopy_(integer *, 
00045             doublereal *, integer *, doublereal *, integer *), daxpy_(integer 
00046             *, doublereal *, doublereal *, integer *, doublereal *, integer *)
00047             ;
00048     integer count;
00049     logical upper;
00050     extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *, 
00051              integer *, doublereal *, integer *, integer *);
00052     extern doublereal dlamch_(char *);
00053     doublereal safmin;
00054     extern /* Subroutine */ int xerbla_(char *, integer *), dpbtrs_(
00055             char *, integer *, integer *, integer *, doublereal *, integer *, 
00056             doublereal *, integer *, integer *);
00057     doublereal lstres;
00058 
00059 
00060 /*  -- LAPACK routine (version 3.2) -- */
00061 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00062 /*     November 2006 */
00063 
00064 /*     Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
00065 
00066 /*     .. Scalar Arguments .. */
00067 /*     .. */
00068 /*     .. Array Arguments .. */
00069 /*     .. */
00070 
00071 /*  Purpose */
00072 /*  ======= */
00073 
00074 /*  DPBRFS improves the computed solution to a system of linear */
00075 /*  equations when the coefficient matrix is symmetric positive definite */
00076 /*  and banded, and provides error bounds and backward error estimates */
00077 /*  for the solution. */
00078 
00079 /*  Arguments */
00080 /*  ========= */
00081 
00082 /*  UPLO    (input) CHARACTER*1 */
00083 /*          = 'U':  Upper triangle of A is stored; */
00084 /*          = 'L':  Lower triangle of A is stored. */
00085 
00086 /*  N       (input) INTEGER */
00087 /*          The order of the matrix A.  N >= 0. */
00088 
00089 /*  KD      (input) INTEGER */
00090 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00091 /*          or the number of subdiagonals if UPLO = 'L'.  KD >= 0. */
00092 
00093 /*  NRHS    (input) INTEGER */
00094 /*          The number of right hand sides, i.e., the number of columns */
00095 /*          of the matrices B and X.  NRHS >= 0. */
00096 
00097 /*  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N) */
00098 /*          The upper or lower triangle of the symmetric band matrix A, */
00099 /*          stored in the first KD+1 rows of the array.  The j-th column */
00100 /*          of A is stored in the j-th column of the array AB as follows: */
00101 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00102 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00103 
00104 /*  LDAB    (input) INTEGER */
00105 /*          The leading dimension of the array AB.  LDAB >= KD+1. */
00106 
00107 /*  AFB     (input) DOUBLE PRECISION array, dimension (LDAFB,N) */
00108 /*          The triangular factor U or L from the Cholesky factorization */
00109 /*          A = U**T*U or A = L*L**T of the band matrix A as computed by */
00110 /*          DPBTRF, in the same storage format as A (see AB). */
00111 
00112 /*  LDAFB   (input) INTEGER */
00113 /*          The leading dimension of the array AFB.  LDAFB >= KD+1. */
00114 
00115 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
00116 /*          The right hand side matrix B. */
00117 
00118 /*  LDB     (input) INTEGER */
00119 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00120 
00121 /*  X       (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00122 /*          On entry, the solution matrix X, as computed by DPBTRS. */
00123 /*          On exit, the improved solution matrix X. */
00124 
00125 /*  LDX     (input) INTEGER */
00126 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00127 
00128 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00129 /*          The estimated forward error bound for each solution vector */
00130 /*          X(j) (the j-th column of the solution matrix X). */
00131 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00132 /*          is an estimated upper bound for the magnitude of the largest */
00133 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00134 /*          largest element in X(j).  The estimate is as reliable as */
00135 /*          the estimate for RCOND, and is almost always a slight */
00136 /*          overestimate of the true error. */
00137 
00138 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00139 /*          The componentwise relative backward error of each solution */
00140 /*          vector X(j) (i.e., the smallest relative change in */
00141 /*          any element of A or B that makes X(j) an exact solution). */
00142 
00143 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
00144 
00145 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00146 
00147 /*  INFO    (output) INTEGER */
00148 /*          = 0:  successful exit */
00149 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00150 
00151 /*  Internal Parameters */
00152 /*  =================== */
00153 
00154 /*  ITMAX is the maximum number of steps of iterative refinement. */
00155 
00156 /*  ===================================================================== */
00157 
00158 /*     .. Parameters .. */
00159 /*     .. */
00160 /*     .. Local Scalars .. */
00161 /*     .. */
00162 /*     .. Local Arrays .. */
00163 /*     .. */
00164 /*     .. External Subroutines .. */
00165 /*     .. */
00166 /*     .. Intrinsic Functions .. */
00167 /*     .. */
00168 /*     .. External Functions .. */
00169 /*     .. */
00170 /*     .. Executable Statements .. */
00171 
00172 /*     Test the input parameters. */
00173 
00174     /* Parameter adjustments */
00175     ab_dim1 = *ldab;
00176     ab_offset = 1 + ab_dim1;
00177     ab -= ab_offset;
00178     afb_dim1 = *ldafb;
00179     afb_offset = 1 + afb_dim1;
00180     afb -= afb_offset;
00181     b_dim1 = *ldb;
00182     b_offset = 1 + b_dim1;
00183     b -= b_offset;
00184     x_dim1 = *ldx;
00185     x_offset = 1 + x_dim1;
00186     x -= x_offset;
00187     --ferr;
00188     --berr;
00189     --work;
00190     --iwork;
00191 
00192     /* Function Body */
00193     *info = 0;
00194     upper = lsame_(uplo, "U");
00195     if (! upper && ! lsame_(uplo, "L")) {
00196         *info = -1;
00197     } else if (*n < 0) {
00198         *info = -2;
00199     } else if (*kd < 0) {
00200         *info = -3;
00201     } else if (*nrhs < 0) {
00202         *info = -4;
00203     } else if (*ldab < *kd + 1) {
00204         *info = -6;
00205     } else if (*ldafb < *kd + 1) {
00206         *info = -8;
00207     } else if (*ldb < max(1,*n)) {
00208         *info = -10;
00209     } else if (*ldx < max(1,*n)) {
00210         *info = -12;
00211     }
00212     if (*info != 0) {
00213         i__1 = -(*info);
00214         xerbla_("DPBRFS", &i__1);
00215         return 0;
00216     }
00217 
00218 /*     Quick return if possible */
00219 
00220     if (*n == 0 || *nrhs == 0) {
00221         i__1 = *nrhs;
00222         for (j = 1; j <= i__1; ++j) {
00223             ferr[j] = 0.;
00224             berr[j] = 0.;
00225 /* L10: */
00226         }
00227         return 0;
00228     }
00229 
00230 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00231 
00232 /* Computing MIN */
00233     i__1 = *n + 1, i__2 = (*kd << 1) + 2;
00234     nz = min(i__1,i__2);
00235     eps = dlamch_("Epsilon");
00236     safmin = dlamch_("Safe minimum");
00237     safe1 = nz * safmin;
00238     safe2 = safe1 / eps;
00239 
00240 /*     Do for each right hand side */
00241 
00242     i__1 = *nrhs;
00243     for (j = 1; j <= i__1; ++j) {
00244 
00245         count = 1;
00246         lstres = 3.;
00247 L20:
00248 
00249 /*        Loop until stopping criterion is satisfied. */
00250 
00251 /*        Compute residual R = B - A * X */
00252 
00253         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00254         dsbmv_(uplo, n, kd, &c_b12, &ab[ab_offset], ldab, &x[j * x_dim1 + 1], 
00255                 &c__1, &c_b14, &work[*n + 1], &c__1);
00256 
00257 /*        Compute componentwise relative backward error from formula */
00258 
00259 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00260 
00261 /*        where abs(Z) is the componentwise absolute value of the matrix */
00262 /*        or vector Z.  If the i-th component of the denominator is less */
00263 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00264 /*        numerator and denominator before dividing. */
00265 
00266         i__2 = *n;
00267         for (i__ = 1; i__ <= i__2; ++i__) {
00268             work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00269 /* L30: */
00270         }
00271 
00272 /*        Compute abs(A)*abs(X) + abs(B). */
00273 
00274         if (upper) {
00275             i__2 = *n;
00276             for (k = 1; k <= i__2; ++k) {
00277                 s = 0.;
00278                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00279                 l = *kd + 1 - k;
00280 /* Computing MAX */
00281                 i__3 = 1, i__4 = k - *kd;
00282                 i__5 = k - 1;
00283                 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00284                     work[i__] += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1))
00285                              * xk;
00286                     s += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1)) * (
00287                             d__2 = x[i__ + j * x_dim1], abs(d__2));
00288 /* L40: */
00289                 }
00290                 work[k] = work[k] + (d__1 = ab[*kd + 1 + k * ab_dim1], abs(
00291                         d__1)) * xk + s;
00292 /* L50: */
00293             }
00294         } else {
00295             i__2 = *n;
00296             for (k = 1; k <= i__2; ++k) {
00297                 s = 0.;
00298                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00299                 work[k] += (d__1 = ab[k * ab_dim1 + 1], abs(d__1)) * xk;
00300                 l = 1 - k;
00301 /* Computing MIN */
00302                 i__3 = *n, i__4 = k + *kd;
00303                 i__5 = min(i__3,i__4);
00304                 for (i__ = k + 1; i__ <= i__5; ++i__) {
00305                     work[i__] += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1))
00306                              * xk;
00307                     s += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1)) * (
00308                             d__2 = x[i__ + j * x_dim1], abs(d__2));
00309 /* L60: */
00310                 }
00311                 work[k] += s;
00312 /* L70: */
00313             }
00314         }
00315         s = 0.;
00316         i__2 = *n;
00317         for (i__ = 1; i__ <= i__2; ++i__) {
00318             if (work[i__] > safe2) {
00319 /* Computing MAX */
00320                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00321                         i__];
00322                 s = max(d__2,d__3);
00323             } else {
00324 /* Computing MAX */
00325                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00326                         / (work[i__] + safe1);
00327                 s = max(d__2,d__3);
00328             }
00329 /* L80: */
00330         }
00331         berr[j] = s;
00332 
00333 /*        Test stopping criterion. Continue iterating if */
00334 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00335 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00336 /*              last iteration, and */
00337 /*           3) At most ITMAX iterations tried. */
00338 
00339         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00340 
00341 /*           Update solution and try again. */
00342 
00343             dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n + 1]
00344 , n, info);
00345             daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00346                     ;
00347             lstres = berr[j];
00348             ++count;
00349             goto L20;
00350         }
00351 
00352 /*        Bound error from formula */
00353 
00354 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00355 /*        norm( abs(inv(A))* */
00356 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00357 
00358 /*        where */
00359 /*          norm(Z) is the magnitude of the largest component of Z */
00360 /*          inv(A) is the inverse of A */
00361 /*          abs(Z) is the componentwise absolute value of the matrix or */
00362 /*             vector Z */
00363 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00364 /*          EPS is machine epsilon */
00365 
00366 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00367 /*        is incremented by SAFE1 if the i-th component of */
00368 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00369 
00370 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00371 /*           inv(A) * diag(W), */
00372 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00373 
00374         i__2 = *n;
00375         for (i__ = 1; i__ <= i__2; ++i__) {
00376             if (work[i__] > safe2) {
00377                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00378                         work[i__];
00379             } else {
00380                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00381                         work[i__] + safe1;
00382             }
00383 /* L90: */
00384         }
00385 
00386         kase = 0;
00387 L100:
00388         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00389                 kase, isave);
00390         if (kase != 0) {
00391             if (kase == 1) {
00392 
00393 /*              Multiply by diag(W)*inv(A'). */
00394 
00395                 dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n 
00396                         + 1], n, info);
00397                 i__2 = *n;
00398                 for (i__ = 1; i__ <= i__2; ++i__) {
00399                     work[*n + i__] *= work[i__];
00400 /* L110: */
00401                 }
00402             } else if (kase == 2) {
00403 
00404 /*              Multiply by inv(A)*diag(W). */
00405 
00406                 i__2 = *n;
00407                 for (i__ = 1; i__ <= i__2; ++i__) {
00408                     work[*n + i__] *= work[i__];
00409 /* L120: */
00410                 }
00411                 dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n 
00412                         + 1], n, info);
00413             }
00414             goto L100;
00415         }
00416 
00417 /*        Normalize error. */
00418 
00419         lstres = 0.;
00420         i__2 = *n;
00421         for (i__ = 1; i__ <= i__2; ++i__) {
00422 /* Computing MAX */
00423             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00424             lstres = max(d__2,d__3);
00425 /* L130: */
00426         }
00427         if (lstres != 0.) {
00428             ferr[j] /= lstres;
00429         }
00430 
00431 /* L140: */
00432     }
00433 
00434     return 0;
00435 
00436 /*     End of DPBRFS */
00437 
00438 } /* dpbrfs_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:47