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


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