cptt05.c
Go to the documentation of this file.
00001 /* cptt05.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 integer c__1 = 1;
00019 
00020 /* Subroutine */ int cptt05_(integer *n, integer *nrhs, real *d__, complex *e, 
00021          complex *b, integer *ldb, complex *x, integer *ldx, complex *xact, 
00022         integer *ldxact, real *ferr, real *berr, real *reslts)
00023 {
00024     /* System generated locals */
00025     integer b_dim1, b_offset, x_dim1, x_offset, xact_dim1, xact_offset, i__1, 
00026             i__2, i__3, i__4, i__5, i__6, i__7, i__8, i__9;
00027     real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8, r__9, r__10, r__11, 
00028             r__12;
00029     complex q__1, q__2;
00030 
00031     /* Builtin functions */
00032     double r_imag(complex *);
00033 
00034     /* Local variables */
00035     integer i__, j, k, nz;
00036     real eps, tmp, diff, axbi;
00037     integer imax;
00038     real unfl, ovfl, xnorm;
00039     extern integer icamax_(integer *, complex *, integer *);
00040     extern doublereal slamch_(char *);
00041     real errbnd;
00042 
00043 
00044 /*  -- LAPACK test routine (version 3.1) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  CPTT05 tests the error bounds from iterative refinement for the */
00057 /*  computed solution to a system of equations A*X = B, where A is a */
00058 /*  Hermitian tridiagonal matrix of order n. */
00059 
00060 /*  RESLTS(1) = test of the error bound */
00061 /*            = norm(X - XACT) / ( norm(X) * FERR ) */
00062 
00063 /*  A large value is returned if this ratio is not less than one. */
00064 
00065 /*  RESLTS(2) = residual from the iterative refinement routine */
00066 /*            = the maximum of BERR / ( NZ*EPS + (*) ), where */
00067 /*              (*) = NZ*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i ) */
00068 /*              and NZ = max. number of nonzeros in any row of A, plus 1 */
00069 
00070 /*  Arguments */
00071 /*  ========= */
00072 
00073 /*  N       (input) INTEGER */
00074 /*          The number of rows of the matrices X, B, and XACT, and the */
00075 /*          order of the matrix A.  N >= 0. */
00076 
00077 /*  NRHS    (input) INTEGER */
00078 /*          The number of columns of the matrices X, B, and XACT. */
00079 /*          NRHS >= 0. */
00080 
00081 /*  D       (input) REAL array, dimension (N) */
00082 /*          The n diagonal elements of the tridiagonal matrix A. */
00083 
00084 /*  E       (input) COMPLEX array, dimension (N-1) */
00085 /*          The (n-1) subdiagonal elements of the tridiagonal matrix A. */
00086 
00087 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00088 /*          The right hand side vectors for the system of linear */
00089 /*          equations. */
00090 
00091 /*  LDB     (input) INTEGER */
00092 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00093 
00094 /*  X       (input) COMPLEX array, dimension (LDX,NRHS) */
00095 /*          The computed solution vectors.  Each vector is stored as a */
00096 /*          column of the matrix X. */
00097 
00098 /*  LDX     (input) INTEGER */
00099 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00100 
00101 /*  XACT    (input) COMPLEX array, dimension (LDX,NRHS) */
00102 /*          The exact solution vectors.  Each vector is stored as a */
00103 /*          column of the matrix XACT. */
00104 
00105 /*  LDXACT  (input) INTEGER */
00106 /*          The leading dimension of the array XACT.  LDXACT >= max(1,N). */
00107 
00108 /*  FERR    (input) REAL array, dimension (NRHS) */
00109 /*          The estimated forward error bounds for each solution vector */
00110 /*          X.  If XTRUE is the true solution, FERR bounds the magnitude */
00111 /*          of the largest entry in (X - XTRUE) divided by the magnitude */
00112 /*          of the largest entry in X. */
00113 
00114 /*  BERR    (input) REAL array, dimension (NRHS) */
00115 /*          The componentwise relative backward error of each solution */
00116 /*          vector (i.e., the smallest relative change in any entry of A */
00117 /*          or B that makes X an exact solution). */
00118 
00119 /*  RESLTS  (output) REAL array, dimension (2) */
00120 /*          The maximum over the NRHS solution vectors of the ratios: */
00121 /*          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR ) */
00122 /*          RESLTS(2) = BERR / ( NZ*EPS + (*) ) */
00123 
00124 /*  ===================================================================== */
00125 
00126 /*     .. Parameters .. */
00127 /*     .. */
00128 /*     .. Local Scalars .. */
00129 /*     .. */
00130 /*     .. External Functions .. */
00131 /*     .. */
00132 /*     .. Intrinsic Functions .. */
00133 /*     .. */
00134 /*     .. Statement Functions .. */
00135 /*     .. */
00136 /*     .. Statement Function definitions .. */
00137 /*     .. */
00138 /*     .. Executable Statements .. */
00139 
00140 /*     Quick exit if N = 0 or NRHS = 0. */
00141 
00142     /* Parameter adjustments */
00143     --d__;
00144     --e;
00145     b_dim1 = *ldb;
00146     b_offset = 1 + b_dim1;
00147     b -= b_offset;
00148     x_dim1 = *ldx;
00149     x_offset = 1 + x_dim1;
00150     x -= x_offset;
00151     xact_dim1 = *ldxact;
00152     xact_offset = 1 + xact_dim1;
00153     xact -= xact_offset;
00154     --ferr;
00155     --berr;
00156     --reslts;
00157 
00158     /* Function Body */
00159     if (*n <= 0 || *nrhs <= 0) {
00160         reslts[1] = 0.f;
00161         reslts[2] = 0.f;
00162         return 0;
00163     }
00164 
00165     eps = slamch_("Epsilon");
00166     unfl = slamch_("Safe minimum");
00167     ovfl = 1.f / unfl;
00168     nz = 4;
00169 
00170 /*     Test 1:  Compute the maximum of */
00171 /*        norm(X - XACT) / ( norm(X) * FERR ) */
00172 /*     over all the vectors X and XACT using the infinity-norm. */
00173 
00174     errbnd = 0.f;
00175     i__1 = *nrhs;
00176     for (j = 1; j <= i__1; ++j) {
00177         imax = icamax_(n, &x[j * x_dim1 + 1], &c__1);
00178 /* Computing MAX */
00179         i__2 = imax + j * x_dim1;
00180         r__3 = (r__1 = x[i__2].r, dabs(r__1)) + (r__2 = r_imag(&x[imax + j * 
00181                 x_dim1]), dabs(r__2));
00182         xnorm = dmax(r__3,unfl);
00183         diff = 0.f;
00184         i__2 = *n;
00185         for (i__ = 1; i__ <= i__2; ++i__) {
00186             i__3 = i__ + j * x_dim1;
00187             i__4 = i__ + j * xact_dim1;
00188             q__2.r = x[i__3].r - xact[i__4].r, q__2.i = x[i__3].i - xact[i__4]
00189                     .i;
00190             q__1.r = q__2.r, q__1.i = q__2.i;
00191 /* Computing MAX */
00192             r__3 = diff, r__4 = (r__1 = q__1.r, dabs(r__1)) + (r__2 = r_imag(&
00193                     q__1), dabs(r__2));
00194             diff = dmax(r__3,r__4);
00195 /* L10: */
00196         }
00197 
00198         if (xnorm > 1.f) {
00199             goto L20;
00200         } else if (diff <= ovfl * xnorm) {
00201             goto L20;
00202         } else {
00203             errbnd = 1.f / eps;
00204             goto L30;
00205         }
00206 
00207 L20:
00208         if (diff / xnorm <= ferr[j]) {
00209 /* Computing MAX */
00210             r__1 = errbnd, r__2 = diff / xnorm / ferr[j];
00211             errbnd = dmax(r__1,r__2);
00212         } else {
00213             errbnd = 1.f / eps;
00214         }
00215 L30:
00216         ;
00217     }
00218     reslts[1] = errbnd;
00219 
00220 /*     Test 2:  Compute the maximum of BERR / ( NZ*EPS + (*) ), where */
00221 /*     (*) = NZ*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i ) */
00222 
00223     i__1 = *nrhs;
00224     for (k = 1; k <= i__1; ++k) {
00225         if (*n == 1) {
00226             i__2 = k * x_dim1 + 1;
00227             q__2.r = d__[1] * x[i__2].r, q__2.i = d__[1] * x[i__2].i;
00228             q__1.r = q__2.r, q__1.i = q__2.i;
00229             i__3 = k * b_dim1 + 1;
00230             axbi = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[k * 
00231                     b_dim1 + 1]), dabs(r__2)) + ((r__3 = q__1.r, dabs(r__3)) 
00232                     + (r__4 = r_imag(&q__1), dabs(r__4)));
00233         } else {
00234             i__2 = k * x_dim1 + 1;
00235             q__2.r = d__[1] * x[i__2].r, q__2.i = d__[1] * x[i__2].i;
00236             q__1.r = q__2.r, q__1.i = q__2.i;
00237             i__3 = k * b_dim1 + 1;
00238             i__4 = k * x_dim1 + 2;
00239             axbi = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[k * 
00240                     b_dim1 + 1]), dabs(r__2)) + ((r__3 = q__1.r, dabs(r__3)) 
00241                     + (r__4 = r_imag(&q__1), dabs(r__4))) + ((r__5 = e[1].r, 
00242                     dabs(r__5)) + (r__6 = r_imag(&e[1]), dabs(r__6))) * ((
00243                     r__7 = x[i__4].r, dabs(r__7)) + (r__8 = r_imag(&x[k * 
00244                     x_dim1 + 2]), dabs(r__8)));
00245             i__2 = *n - 1;
00246             for (i__ = 2; i__ <= i__2; ++i__) {
00247                 i__3 = i__;
00248                 i__4 = i__ + k * x_dim1;
00249                 q__2.r = d__[i__3] * x[i__4].r, q__2.i = d__[i__3] * x[i__4]
00250                         .i;
00251                 q__1.r = q__2.r, q__1.i = q__2.i;
00252                 i__5 = i__ + k * b_dim1;
00253                 i__6 = i__ - 1;
00254                 i__7 = i__ - 1 + k * x_dim1;
00255                 i__8 = i__;
00256                 i__9 = i__ + 1 + k * x_dim1;
00257                 tmp = (r__1 = b[i__5].r, dabs(r__1)) + (r__2 = r_imag(&b[i__ 
00258                         + k * b_dim1]), dabs(r__2)) + ((r__3 = e[i__6].r, 
00259                         dabs(r__3)) + (r__4 = r_imag(&e[i__ - 1]), dabs(r__4))
00260                         ) * ((r__5 = x[i__7].r, dabs(r__5)) + (r__6 = r_imag(&
00261                         x[i__ - 1 + k * x_dim1]), dabs(r__6))) + ((r__7 = 
00262                         q__1.r, dabs(r__7)) + (r__8 = r_imag(&q__1), dabs(
00263                         r__8))) + ((r__9 = e[i__8].r, dabs(r__9)) + (r__10 = 
00264                         r_imag(&e[i__]), dabs(r__10))) * ((r__11 = x[i__9].r, 
00265                         dabs(r__11)) + (r__12 = r_imag(&x[i__ + 1 + k * 
00266                         x_dim1]), dabs(r__12)));
00267                 axbi = dmin(axbi,tmp);
00268 /* L40: */
00269             }
00270             i__2 = *n;
00271             i__3 = *n + k * x_dim1;
00272             q__2.r = d__[i__2] * x[i__3].r, q__2.i = d__[i__2] * x[i__3].i;
00273             q__1.r = q__2.r, q__1.i = q__2.i;
00274             i__4 = *n + k * b_dim1;
00275             i__5 = *n - 1;
00276             i__6 = *n - 1 + k * x_dim1;
00277             tmp = (r__1 = b[i__4].r, dabs(r__1)) + (r__2 = r_imag(&b[*n + k * 
00278                     b_dim1]), dabs(r__2)) + ((r__3 = e[i__5].r, dabs(r__3)) + 
00279                     (r__4 = r_imag(&e[*n - 1]), dabs(r__4))) * ((r__5 = x[
00280                     i__6].r, dabs(r__5)) + (r__6 = r_imag(&x[*n - 1 + k * 
00281                     x_dim1]), dabs(r__6))) + ((r__7 = q__1.r, dabs(r__7)) + (
00282                     r__8 = r_imag(&q__1), dabs(r__8)));
00283             axbi = dmin(axbi,tmp);
00284         }
00285 /* Computing MAX */
00286         r__1 = axbi, r__2 = nz * unfl;
00287         tmp = berr[k] / (nz * eps + nz * unfl / dmax(r__1,r__2));
00288         if (k == 1) {
00289             reslts[2] = tmp;
00290         } else {
00291             reslts[2] = dmax(reslts[2],tmp);
00292         }
00293 /* L50: */
00294     }
00295 
00296     return 0;
00297 
00298 /*     End of CPTT05 */
00299 
00300 } /* cptt05_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:33