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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:12