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


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