zcposv.c
Go to the documentation of this file.
00001 /* zcposv.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 doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021 
00022 /* Subroutine */ int zcposv_(char *uplo, integer *n, integer *nrhs, 
00023         doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, 
00024         doublecomplex *x, integer *ldx, doublecomplex *work, complex *swork, 
00025         doublereal *rwork, integer *iter, integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, b_dim1, b_offset, work_dim1, work_offset, 
00029             x_dim1, x_offset, i__1, i__2;
00030     doublereal d__1, d__2;
00031 
00032     /* Builtin functions */
00033     double sqrt(doublereal), d_imag(doublecomplex *);
00034 
00035     /* Local variables */
00036     integer i__;
00037     doublereal cte, eps, anrm;
00038     integer ptsa;
00039     doublereal rnrm, xnrm;
00040     integer ptsx;
00041     extern logical lsame_(char *, char *);
00042     integer iiter;
00043     extern /* Subroutine */ int zhemm_(char *, char *, integer *, integer *, 
00044             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00045             integer *, doublecomplex *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *, 
00046             integer *, doublecomplex *, integer *), zlag2c_(integer *, 
00047             integer *, doublecomplex *, integer *, complex *, integer *, 
00048             integer *), clag2z_(integer *, integer *, complex *, integer *, 
00049             doublecomplex *, integer *, integer *), zlat2c_(char *, integer *, 
00050              doublecomplex *, integer *, complex *, integer *, integer *);
00051     extern doublereal dlamch_(char *);
00052     extern /* Subroutine */ int xerbla_(char *, integer *);
00053     extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *, 
00054             integer *, doublereal *);
00055     extern integer izamax_(integer *, doublecomplex *, integer *);
00056     extern /* Subroutine */ int cpotrf_(char *, integer *, complex *, integer 
00057             *, integer *), zlacpy_(char *, integer *, integer *, 
00058             doublecomplex *, integer *, doublecomplex *, integer *), 
00059             cpotrs_(char *, integer *, integer *, complex *, integer *, 
00060             complex *, integer *, integer *), zpotrf_(char *, integer 
00061             *, doublecomplex *, integer *, integer *), zpotrs_(char *, 
00062              integer *, integer *, doublecomplex *, integer *, doublecomplex *
00063 , integer *, integer *);
00064 
00065 
00066 /*  -- LAPACK PROTOTYPE driver routine (version 3.2.1)                 -- */
00067 
00068 /*  -- April 2009                                                      -- */
00069 
00070 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00071 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00072 /*     .. */
00073 /*     .. Scalar Arguments .. */
00074 /*     .. */
00075 /*     .. Array Arguments .. */
00076 /*     .. */
00077 
00078 /*  Purpose */
00079 /*  ======= */
00080 
00081 /*  ZCPOSV computes the solution to a complex system of linear equations */
00082 /*     A * X = B, */
00083 /*  where A is an N-by-N Hermitian positive definite matrix and X and B */
00084 /*  are N-by-NRHS matrices. */
00085 
00086 /*  ZCPOSV first attempts to factorize the matrix in COMPLEX and use this */
00087 /*  factorization within an iterative refinement procedure to produce a */
00088 /*  solution with COMPLEX*16 normwise backward error quality (see below). */
00089 /*  If the approach fails the method switches to a COMPLEX*16 */
00090 /*  factorization and solve. */
00091 
00092 /*  The iterative refinement is not going to be a winning strategy if */
00093 /*  the ratio COMPLEX performance over COMPLEX*16 performance is too */
00094 /*  small. A reasonable strategy should take the number of right-hand */
00095 /*  sides and the size of the matrix into account. This might be done */
00096 /*  with a call to ILAENV in the future. Up to now, we always try */
00097 /*  iterative refinement. */
00098 
00099 /*  The iterative refinement process is stopped if */
00100 /*      ITER > ITERMAX */
00101 /*  or for all the RHS we have: */
00102 /*      RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX */
00103 /*  where */
00104 /*      o ITER is the number of the current iteration in the iterative */
00105 /*        refinement process */
00106 /*      o RNRM is the infinity-norm of the residual */
00107 /*      o XNRM is the infinity-norm of the solution */
00108 /*      o ANRM is the infinity-operator-norm of the matrix A */
00109 /*      o EPS is the machine epsilon returned by DLAMCH('Epsilon') */
00110 /*  The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00 */
00111 /*  respectively. */
00112 
00113 /*  Arguments */
00114 /*  ========= */
00115 
00116 /*  UPLO    (input) CHARACTER */
00117 /*          = 'U':  Upper triangle of A is stored; */
00118 /*          = 'L':  Lower triangle of A is stored. */
00119 
00120 /*  N       (input) INTEGER */
00121 /*          The number of linear equations, i.e., the order of the */
00122 /*          matrix A.  N >= 0. */
00123 
00124 /*  NRHS    (input) INTEGER */
00125 /*          The number of right hand sides, i.e., the number of columns */
00126 /*          of the matrix B.  NRHS >= 0. */
00127 
00128 /*  A       (input or input/ouptut) COMPLEX*16 array, */
00129 /*          dimension (LDA,N) */
00130 /*          On entry, the Hermitian matrix A. If UPLO = 'U', the leading */
00131 /*          N-by-N upper triangular part of A contains the upper */
00132 /*          triangular part of the matrix A, and the strictly lower */
00133 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00134 /*          leading N-by-N lower triangular part of A contains the lower */
00135 /*          triangular part of the matrix A, and the strictly upper */
00136 /*          triangular part of A is not referenced. */
00137 
00138 /*          Note that the imaginary parts of the diagonal */
00139 /*          elements need not be set and are assumed to be zero. */
00140 
00141 /*          On exit, if iterative refinement has been successfully used */
00142 /*          (INFO.EQ.0 and ITER.GE.0, see description below), then A is */
00143 /*          unchanged, if double precision factorization has been used */
00144 /*          (INFO.EQ.0 and ITER.LT.0, see description below), then the */
00145 /*          array A contains the factor U or L from the Cholesky */
00146 /*          factorization A = U**H*U or A = L*L**H. */
00147 
00148 /*  LDA     (input) INTEGER */
00149 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00150 
00151 /*  B       (input) COMPLEX*16 array, dimension (LDB,NRHS) */
00152 /*          The N-by-NRHS right hand side matrix B. */
00153 
00154 /*  LDB     (input) INTEGER */
00155 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00156 
00157 /*  X       (output) COMPLEX*16 array, dimension (LDX,NRHS) */
00158 /*          If INFO = 0, the N-by-NRHS solution matrix X. */
00159 
00160 /*  LDX     (input) INTEGER */
00161 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00162 
00163 /*  WORK    (workspace) COMPLEX*16 array, dimension (N*NRHS) */
00164 /*          This array is used to hold the residual vectors. */
00165 
00166 /*  SWORK   (workspace) COMPLEX array, dimension (N*(N+NRHS)) */
00167 /*          This array is used to use the single precision matrix and the */
00168 /*          right-hand sides or solutions in single precision. */
00169 
00170 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (N) */
00171 
00172 /*  ITER    (output) INTEGER */
00173 /*          < 0: iterative refinement has failed, COMPLEX*16 */
00174 /*               factorization has been performed */
00175 /*               -1 : the routine fell back to full precision for */
00176 /*                    implementation- or machine-specific reasons */
00177 /*               -2 : narrowing the precision induced an overflow, */
00178 /*                    the routine fell back to full precision */
00179 /*               -3 : failure of CPOTRF */
00180 /*               -31: stop the iterative refinement after the 30th */
00181 /*                    iterations */
00182 /*          > 0: iterative refinement has been sucessfully used. */
00183 /*               Returns the number of iterations */
00184 
00185 /*  INFO    (output) INTEGER */
00186 /*          = 0:  successful exit */
00187 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00188 /*          > 0:  if INFO = i, the leading minor of order i of */
00189 /*                (COMPLEX*16) A is not positive definite, so the */
00190 /*                factorization could not be completed, and the solution */
00191 /*                has not been computed. */
00192 
00193 /*  ========= */
00194 
00195 /*     .. Parameters .. */
00196 
00197 
00198 
00199 
00200 /*     .. Local Scalars .. */
00201 
00202 /*     .. External Subroutines .. */
00203 /*     .. */
00204 /*     .. External Functions .. */
00205 /*     .. */
00206 /*     .. Intrinsic Functions .. */
00207 /*     .. Statement Functions .. */
00208 /*     .. */
00209 /*     .. Statement Function definitions .. */
00210 /*     .. */
00211 /*     .. Executable Statements .. */
00212 
00213     /* Parameter adjustments */
00214     work_dim1 = *n;
00215     work_offset = 1 + work_dim1;
00216     work -= work_offset;
00217     a_dim1 = *lda;
00218     a_offset = 1 + a_dim1;
00219     a -= a_offset;
00220     b_dim1 = *ldb;
00221     b_offset = 1 + b_dim1;
00222     b -= b_offset;
00223     x_dim1 = *ldx;
00224     x_offset = 1 + x_dim1;
00225     x -= x_offset;
00226     --swork;
00227     --rwork;
00228 
00229     /* Function Body */
00230     *info = 0;
00231     *iter = 0;
00232 
00233 /*     Test the input parameters. */
00234 
00235     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00236         *info = -1;
00237     } else if (*n < 0) {
00238         *info = -2;
00239     } else if (*nrhs < 0) {
00240         *info = -3;
00241     } else if (*lda < max(1,*n)) {
00242         *info = -5;
00243     } else if (*ldb < max(1,*n)) {
00244         *info = -7;
00245     } else if (*ldx < max(1,*n)) {
00246         *info = -9;
00247     }
00248     if (*info != 0) {
00249         i__1 = -(*info);
00250         xerbla_("ZCPOSV", &i__1);
00251         return 0;
00252     }
00253 
00254 /*     Quick return if (N.EQ.0). */
00255 
00256     if (*n == 0) {
00257         return 0;
00258     }
00259 
00260 /*     Skip single precision iterative refinement if a priori slower */
00261 /*     than double precision factorization. */
00262 
00263     if (FALSE_) {
00264         *iter = -1;
00265         goto L40;
00266     }
00267 
00268 /*     Compute some constants. */
00269 
00270     anrm = zlanhe_("I", uplo, n, &a[a_offset], lda, &rwork[1]);
00271     eps = dlamch_("Epsilon");
00272     cte = anrm * eps * sqrt((doublereal) (*n)) * 1.;
00273 
00274 /*     Set the indices PTSA, PTSX for referencing SA and SX in SWORK. */
00275 
00276     ptsa = 1;
00277     ptsx = ptsa + *n * *n;
00278 
00279 /*     Convert B from double precision to single precision and store the */
00280 /*     result in SX. */
00281 
00282     zlag2c_(n, nrhs, &b[b_offset], ldb, &swork[ptsx], n, info);
00283 
00284     if (*info != 0) {
00285         *iter = -2;
00286         goto L40;
00287     }
00288 
00289 /*     Convert A from double precision to single precision and store the */
00290 /*     result in SA. */
00291 
00292     zlat2c_(uplo, n, &a[a_offset], lda, &swork[ptsa], n, info);
00293 
00294     if (*info != 0) {
00295         *iter = -2;
00296         goto L40;
00297     }
00298 
00299 /*     Compute the Cholesky factorization of SA. */
00300 
00301     cpotrf_(uplo, n, &swork[ptsa], n, info);
00302 
00303     if (*info != 0) {
00304         *iter = -3;
00305         goto L40;
00306     }
00307 
00308 /*     Solve the system SA*SX = SB. */
00309 
00310     cpotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
00311 
00312 /*     Convert SX back to COMPLEX*16 */
00313 
00314     clag2z_(n, nrhs, &swork[ptsx], n, &x[x_offset], ldx, info);
00315 
00316 /*     Compute R = B - AX (R is WORK). */
00317 
00318     zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00319 
00320     zhemm_("Left", uplo, n, nrhs, &c_b1, &a[a_offset], lda, &x[x_offset], ldx, 
00321              &c_b2, &work[work_offset], n);
00322 
00323 /*     Check whether the NRHS normwise backward errors satisfy the */
00324 /*     stopping criterion. If yes, set ITER=0 and return. */
00325 
00326     i__1 = *nrhs;
00327     for (i__ = 1; i__ <= i__1; ++i__) {
00328         i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00329         xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(n, &
00330                 x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(d__2));
00331         i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ * 
00332                 work_dim1;
00333         rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00334                 izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ * 
00335                 work_dim1]), abs(d__2));
00336         if (rnrm > xnrm * cte) {
00337             goto L10;
00338         }
00339     }
00340 
00341 /*     If we are here, the NRHS normwise backward errors satisfy the */
00342 /*     stopping criterion. We are good to exit. */
00343 
00344     *iter = 0;
00345     return 0;
00346 
00347 L10:
00348 
00349     for (iiter = 1; iiter <= 30; ++iiter) {
00350 
00351 /*        Convert R (in WORK) from double precision to single precision */
00352 /*        and store the result in SX. */
00353 
00354         zlag2c_(n, nrhs, &work[work_offset], n, &swork[ptsx], n, info);
00355 
00356         if (*info != 0) {
00357             *iter = -2;
00358             goto L40;
00359         }
00360 
00361 /*        Solve the system SA*SX = SR. */
00362 
00363         cpotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
00364 
00365 /*        Convert SX back to double precision and update the current */
00366 /*        iterate. */
00367 
00368         clag2z_(n, nrhs, &swork[ptsx], n, &work[work_offset], n, info);
00369 
00370         i__1 = *nrhs;
00371         for (i__ = 1; i__ <= i__1; ++i__) {
00372             zaxpy_(n, &c_b2, &work[i__ * work_dim1 + 1], &c__1, &x[i__ * 
00373                     x_dim1 + 1], &c__1);
00374         }
00375 
00376 /*        Compute R = B - AX (R is WORK). */
00377 
00378         zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00379 
00380         zhemm_("L", uplo, n, nrhs, &c_b1, &a[a_offset], lda, &x[x_offset], 
00381                 ldx, &c_b2, &work[work_offset], n);
00382 
00383 /*        Check whether the NRHS normwise backward errors satisfy the */
00384 /*        stopping criterion. If yes, set ITER=IITER>0 and return. */
00385 
00386         i__1 = *nrhs;
00387         for (i__ = 1; i__ <= i__1; ++i__) {
00388             i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00389             xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(
00390                     n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(
00391                     d__2));
00392             i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ * 
00393                     work_dim1;
00394             rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00395                     izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ * 
00396                     work_dim1]), abs(d__2));
00397             if (rnrm > xnrm * cte) {
00398                 goto L20;
00399             }
00400         }
00401 
00402 /*        If we are here, the NRHS normwise backward errors satisfy the */
00403 /*        stopping criterion, we are good to exit. */
00404 
00405         *iter = iiter;
00406 
00407         return 0;
00408 
00409 L20:
00410 
00411 /* L30: */
00412         ;
00413     }
00414 
00415 /*     If we are at this place of the code, this is because we have */
00416 /*     performed ITER=ITERMAX iterations and never satisified the */
00417 /*     stopping criterion, set up the ITER flag accordingly and follow */
00418 /*     up on double precision routine. */
00419 
00420     *iter = -31;
00421 
00422 L40:
00423 
00424 /*     Single-precision iterative refinement failed to converge to a */
00425 /*     satisfactory solution, so we resort to double precision. */
00426 
00427     zpotrf_(uplo, n, &a[a_offset], lda, info);
00428 
00429     if (*info != 0) {
00430         return 0;
00431     }
00432 
00433     zlacpy_("All", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
00434     zpotrs_(uplo, n, nrhs, &a[a_offset], lda, &x[x_offset], ldx, info);
00435 
00436     return 0;
00437 
00438 /*     End of ZCPOSV. */
00439 
00440 } /* zcposv_ */


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