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


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