zsyrfs.c
Go to the documentation of this file.
00001 /* zsyrfs.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 zsyrfs_(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     logical upper;
00046     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00047             doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, 
00048             doublecomplex *, integer *, doublecomplex *, integer *), zsymv_(
00049             char *, integer *, doublecomplex *, doublecomplex *, integer *, 
00050             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00051             integer *), zlacn2_(integer *, doublecomplex *, 
00052             doublecomplex *, doublereal *, integer *, integer *);
00053     extern doublereal dlamch_(char *);
00054     doublereal safmin;
00055     extern /* Subroutine */ int xerbla_(char *, integer *);
00056     doublereal lstres;
00057     extern /* Subroutine */ int zsytrs_(char *, integer *, integer *, 
00058             doublecomplex *, integer *, integer *, doublecomplex *, integer *, 
00059              integer *);
00060 
00061 
00062 /*  -- LAPACK routine (version 3.2) -- */
00063 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00064 /*     November 2006 */
00065 
00066 /*     Modified to call ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */
00067 
00068 /*     .. Scalar Arguments .. */
00069 /*     .. */
00070 /*     .. Array Arguments .. */
00071 /*     .. */
00072 
00073 /*  Purpose */
00074 /*  ======= */
00075 
00076 /*  ZSYRFS improves the computed solution to a system of linear */
00077 /*  equations when the coefficient matrix is symmetric indefinite, and */
00078 /*  provides error bounds and backward error estimates for the solution. */
00079 
00080 /*  Arguments */
00081 /*  ========= */
00082 
00083 /*  UPLO    (input) CHARACTER*1 */
00084 /*          = 'U':  Upper triangle of A is stored; */
00085 /*          = 'L':  Lower triangle of A is stored. */
00086 
00087 /*  N       (input) INTEGER */
00088 /*          The order of the matrix A.  N >= 0. */
00089 
00090 /*  NRHS    (input) INTEGER */
00091 /*          The number of right hand sides, i.e., the number of columns */
00092 /*          of the matrices B and X.  NRHS >= 0. */
00093 
00094 /*  A       (input) COMPLEX*16 array, dimension (LDA,N) */
00095 /*          The symmetric matrix A.  If UPLO = 'U', the leading N-by-N */
00096 /*          upper triangular part of A contains the upper triangular part */
00097 /*          of the matrix A, and the strictly lower triangular part of A */
00098 /*          is not referenced.  If UPLO = 'L', the leading N-by-N lower */
00099 /*          triangular part of A contains the lower triangular part of */
00100 /*          the matrix A, and the strictly upper triangular part of A is */
00101 /*          not referenced. */
00102 
00103 /*  LDA     (input) INTEGER */
00104 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00105 
00106 /*  AF      (input) COMPLEX*16 array, dimension (LDAF,N) */
00107 /*          The factored form of the matrix A.  AF contains the block */
00108 /*          diagonal matrix D and the multipliers used to obtain the */
00109 /*          factor U or L from the factorization A = U*D*U**T or */
00110 /*          A = L*D*L**T as computed by ZSYTRF. */
00111 
00112 /*  LDAF    (input) INTEGER */
00113 /*          The leading dimension of the array AF.  LDAF >= max(1,N). */
00114 
00115 /*  IPIV    (input) INTEGER array, dimension (N) */
00116 /*          Details of the interchanges and the block structure of D */
00117 /*          as determined by ZSYTRF. */
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 ZSYTRS. */
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     a_dim1 = *lda;
00184     a_offset = 1 + a_dim1;
00185     a -= a_offset;
00186     af_dim1 = *ldaf;
00187     af_offset = 1 + af_dim1;
00188     af -= af_offset;
00189     --ipiv;
00190     b_dim1 = *ldb;
00191     b_offset = 1 + b_dim1;
00192     b -= b_offset;
00193     x_dim1 = *ldx;
00194     x_offset = 1 + x_dim1;
00195     x -= x_offset;
00196     --ferr;
00197     --berr;
00198     --work;
00199     --rwork;
00200 
00201     /* Function Body */
00202     *info = 0;
00203     upper = lsame_(uplo, "U");
00204     if (! upper && ! lsame_(uplo, "L")) {
00205         *info = -1;
00206     } else if (*n < 0) {
00207         *info = -2;
00208     } else if (*nrhs < 0) {
00209         *info = -3;
00210     } else if (*lda < max(1,*n)) {
00211         *info = -5;
00212     } else if (*ldaf < max(1,*n)) {
00213         *info = -7;
00214     } else if (*ldb < max(1,*n)) {
00215         *info = -10;
00216     } else if (*ldx < max(1,*n)) {
00217         *info = -12;
00218     }
00219     if (*info != 0) {
00220         i__1 = -(*info);
00221         xerbla_("ZSYRFS", &i__1);
00222         return 0;
00223     }
00224 
00225 /*     Quick return if possible */
00226 
00227     if (*n == 0 || *nrhs == 0) {
00228         i__1 = *nrhs;
00229         for (j = 1; j <= i__1; ++j) {
00230             ferr[j] = 0.;
00231             berr[j] = 0.;
00232 /* L10: */
00233         }
00234         return 0;
00235     }
00236 
00237 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00238 
00239     nz = *n + 1;
00240     eps = dlamch_("Epsilon");
00241     safmin = dlamch_("Safe minimum");
00242     safe1 = nz * safmin;
00243     safe2 = safe1 / eps;
00244 
00245 /*     Do for each right hand side */
00246 
00247     i__1 = *nrhs;
00248     for (j = 1; j <= i__1; ++j) {
00249 
00250         count = 1;
00251         lstres = 3.;
00252 L20:
00253 
00254 /*        Loop until stopping criterion is satisfied. */
00255 
00256 /*        Compute residual R = B - A * X */
00257 
00258         zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00259         z__1.r = -1., z__1.i = -0.;
00260         zsymv_(uplo, n, &z__1, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, &
00261                 c_b1, &work[1], &c__1);
00262 
00263 /*        Compute componentwise relative backward error from formula */
00264 
00265 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00266 
00267 /*        where abs(Z) is the componentwise absolute value of the matrix */
00268 /*        or vector Z.  If the i-th component of the denominator is less */
00269 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00270 /*        numerator and denominator before dividing. */
00271 
00272         i__2 = *n;
00273         for (i__ = 1; i__ <= i__2; ++i__) {
00274             i__3 = i__ + j * b_dim1;
00275             rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[
00276                     i__ + j * b_dim1]), abs(d__2));
00277 /* L30: */
00278         }
00279 
00280 /*        Compute abs(A)*abs(X) + abs(B). */
00281 
00282         if (upper) {
00283             i__2 = *n;
00284             for (k = 1; k <= i__2; ++k) {
00285                 s = 0.;
00286                 i__3 = k + j * x_dim1;
00287                 xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j *
00288                          x_dim1]), abs(d__2));
00289                 i__3 = k - 1;
00290                 for (i__ = 1; i__ <= i__3; ++i__) {
00291                     i__4 = i__ + k * a_dim1;
00292                     rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = 
00293                             d_imag(&a[i__ + k * a_dim1]), abs(d__2))) * xk;
00294                     i__4 = i__ + k * a_dim1;
00295                     i__5 = i__ + j * x_dim1;
00296                     s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[
00297                             i__ + k * a_dim1]), abs(d__2))) * ((d__3 = x[i__5]
00298                             .r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * 
00299                             x_dim1]), abs(d__4)));
00300 /* L40: */
00301                 }
00302                 i__3 = k + k * a_dim1;
00303                 rwork[k] = rwork[k] + ((d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00304                          d_imag(&a[k + k * a_dim1]), abs(d__2))) * 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)) + (d__2 = d_imag(&
00316                         a[k + k * a_dim1]), abs(d__2))) * xk;
00317                 i__3 = *n;
00318                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00319                     i__4 = i__ + k * a_dim1;
00320                     rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = 
00321                             d_imag(&a[i__ + k * a_dim1]), abs(d__2))) * xk;
00322                     i__4 = i__ + k * a_dim1;
00323                     i__5 = i__ + j * x_dim1;
00324                     s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[
00325                             i__ + k * a_dim1]), abs(d__2))) * ((d__3 = x[i__5]
00326                             .r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * 
00327                             x_dim1]), abs(d__4)));
00328 /* L60: */
00329                 }
00330                 rwork[k] += s;
00331 /* L70: */
00332             }
00333         }
00334         s = 0.;
00335         i__2 = *n;
00336         for (i__ = 1; i__ <= i__2; ++i__) {
00337             if (rwork[i__] > safe2) {
00338 /* Computing MAX */
00339                 i__3 = i__;
00340                 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00341                         d_imag(&work[i__]), abs(d__2))) / rwork[i__];
00342                 s = max(d__3,d__4);
00343             } else {
00344 /* Computing MAX */
00345                 i__3 = i__;
00346                 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00347                         d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__] 
00348                         + safe1);
00349                 s = max(d__3,d__4);
00350             }
00351 /* L80: */
00352         }
00353         berr[j] = s;
00354 
00355 /*        Test stopping criterion. Continue iterating if */
00356 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00357 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00358 /*              last iteration, and */
00359 /*           3) At most ITMAX iterations tried. */
00360 
00361         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00362 
00363 /*           Update solution and try again. */
00364 
00365             zsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[1], 
00366                     n, info);
00367             zaxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00368             lstres = berr[j];
00369             ++count;
00370             goto L20;
00371         }
00372 
00373 /*        Bound error from formula */
00374 
00375 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00376 /*        norm( abs(inv(A))* */
00377 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00378 
00379 /*        where */
00380 /*          norm(Z) is the magnitude of the largest component of Z */
00381 /*          inv(A) is the inverse of A */
00382 /*          abs(Z) is the componentwise absolute value of the matrix or */
00383 /*             vector Z */
00384 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00385 /*          EPS is machine epsilon */
00386 
00387 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00388 /*        is incremented by SAFE1 if the i-th component of */
00389 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00390 
00391 /*        Use ZLACN2 to estimate the infinity-norm of the matrix */
00392 /*           inv(A) * diag(W), */
00393 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00394 
00395         i__2 = *n;
00396         for (i__ = 1; i__ <= i__2; ++i__) {
00397             if (rwork[i__] > safe2) {
00398                 i__3 = i__;
00399                 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00400                         d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00401                         ;
00402             } else {
00403                 i__3 = i__;
00404                 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00405                         d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00406                          + safe1;
00407             }
00408 /* L90: */
00409         }
00410 
00411         kase = 0;
00412 L100:
00413         zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00414         if (kase != 0) {
00415             if (kase == 1) {
00416 
00417 /*              Multiply by diag(W)*inv(A'). */
00418 
00419                 zsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00420                         1], n, info);
00421                 i__2 = *n;
00422                 for (i__ = 1; i__ <= i__2; ++i__) {
00423                     i__3 = i__;
00424                     i__4 = i__;
00425                     i__5 = i__;
00426                     z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] 
00427                             * work[i__5].i;
00428                     work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00429 /* L110: */
00430                 }
00431             } else if (kase == 2) {
00432 
00433 /*              Multiply by inv(A)*diag(W). */
00434 
00435                 i__2 = *n;
00436                 for (i__ = 1; i__ <= i__2; ++i__) {
00437                     i__3 = i__;
00438                     i__4 = i__;
00439                     i__5 = i__;
00440                     z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] 
00441                             * work[i__5].i;
00442                     work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00443 /* L120: */
00444                 }
00445                 zsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00446                         1], n, info);
00447             }
00448             goto L100;
00449         }
00450 
00451 /*        Normalize error. */
00452 
00453         lstres = 0.;
00454         i__2 = *n;
00455         for (i__ = 1; i__ <= i__2; ++i__) {
00456 /* Computing MAX */
00457             i__3 = i__ + j * x_dim1;
00458             d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = 
00459                     d_imag(&x[i__ + j * x_dim1]), abs(d__2));
00460             lstres = max(d__3,d__4);
00461 /* L130: */
00462         }
00463         if (lstres != 0.) {
00464             ferr[j] /= lstres;
00465         }
00466 
00467 /* L140: */
00468     }
00469 
00470     return 0;
00471 
00472 /*     End of ZSYRFS */
00473 
00474 } /* zsyrfs_ */


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