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


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