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


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