dsytrf.c
Go to the documentation of this file.
00001 /* dsytrf.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 integer c_n1 = -1;
00020 static integer c__2 = 2;
00021 
00022 /* Subroutine */ int dsytrf_(char *uplo, integer *n, doublereal *a, integer *
00023         lda, integer *ipiv, doublereal *work, integer *lwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, i__1, i__2;
00027 
00028     /* Local variables */
00029     integer j, k, kb, nb, iws;
00030     extern logical lsame_(char *, char *);
00031     integer nbmin, iinfo;
00032     logical upper;
00033     extern /* Subroutine */ int dsytf2_(char *, integer *, doublereal *, 
00034             integer *, integer *, integer *), xerbla_(char *, integer 
00035             *);
00036     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00037             integer *, integer *);
00038     extern /* Subroutine */ int dlasyf_(char *, integer *, integer *, integer 
00039             *, doublereal *, integer *, integer *, doublereal *, integer *, 
00040             integer *);
00041     integer ldwork, lwkopt;
00042     logical lquery;
00043 
00044 
00045 /*  -- LAPACK routine (version 3.2) -- */
00046 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00047 /*     November 2006 */
00048 
00049 /*     .. Scalar Arguments .. */
00050 /*     .. */
00051 /*     .. Array Arguments .. */
00052 /*     .. */
00053 
00054 /*  Purpose */
00055 /*  ======= */
00056 
00057 /*  DSYTRF computes the factorization of a real symmetric matrix A using */
00058 /*  the Bunch-Kaufman diagonal pivoting method.  The form of the */
00059 /*  factorization is */
00060 
00061 /*     A = U*D*U**T  or  A = L*D*L**T */
00062 
00063 /*  where U (or L) is a product of permutation and unit upper (lower) */
00064 /*  triangular matrices, and D is symmetric and block diagonal with */
00065 /*  1-by-1 and 2-by-2 diagonal blocks. */
00066 
00067 /*  This is the blocked version of the algorithm, calling Level 3 BLAS. */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  UPLO    (input) CHARACTER*1 */
00073 /*          = 'U':  Upper triangle of A is stored; */
00074 /*          = 'L':  Lower triangle of A is stored. */
00075 
00076 /*  N       (input) INTEGER */
00077 /*          The order of the matrix A.  N >= 0. */
00078 
00079 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00080 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
00081 /*          N-by-N upper triangular part of A contains the upper */
00082 /*          triangular part of the matrix A, and the strictly lower */
00083 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00084 /*          leading N-by-N lower triangular part of A contains the lower */
00085 /*          triangular part of the matrix A, and the strictly upper */
00086 /*          triangular part of A is not referenced. */
00087 
00088 /*          On exit, the block diagonal matrix D and the multipliers used */
00089 /*          to obtain the factor U or L (see below for further details). */
00090 
00091 /*  LDA     (input) INTEGER */
00092 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00093 
00094 /*  IPIV    (output) INTEGER array, dimension (N) */
00095 /*          Details of the interchanges and the block structure of D. */
00096 /*          If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
00097 /*          interchanged and D(k,k) is a 1-by-1 diagonal block. */
00098 /*          If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
00099 /*          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
00100 /*          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) = */
00101 /*          IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
00102 /*          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
00103 
00104 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00105 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00106 
00107 /*  LWORK   (input) INTEGER */
00108 /*          The length of WORK.  LWORK >=1.  For best performance */
00109 /*          LWORK >= N*NB, where NB is the block size returned by ILAENV. */
00110 
00111 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00112 /*          only calculates the optimal size of the WORK array, returns */
00113 /*          this value as the first entry of the WORK array, and no error */
00114 /*          message related to LWORK is issued by XERBLA. */
00115 
00116 /*  INFO    (output) INTEGER */
00117 /*          = 0:  successful exit */
00118 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00119 /*          > 0:  if INFO = i, D(i,i) is exactly zero.  The factorization */
00120 /*                has been completed, but the block diagonal matrix D is */
00121 /*                exactly singular, and division by zero will occur if it */
00122 /*                is used to solve a system of equations. */
00123 
00124 /*  Further Details */
00125 /*  =============== */
00126 
00127 /*  If UPLO = 'U', then A = U*D*U', where */
00128 /*     U = P(n)*U(n)* ... *P(k)U(k)* ..., */
00129 /*  i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
00130 /*  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
00131 /*  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
00132 /*  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
00133 /*  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
00134 
00135 /*             (   I    v    0   )   k-s */
00136 /*     U(k) =  (   0    I    0   )   s */
00137 /*             (   0    0    I   )   n-k */
00138 /*                k-s   s   n-k */
00139 
00140 /*  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
00141 /*  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
00142 /*  and A(k,k), and v overwrites A(1:k-2,k-1:k). */
00143 
00144 /*  If UPLO = 'L', then A = L*D*L', where */
00145 /*     L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
00146 /*  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
00147 /*  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
00148 /*  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
00149 /*  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
00150 /*  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
00151 
00152 /*             (   I    0     0   )  k-1 */
00153 /*     L(k) =  (   0    I     0   )  s */
00154 /*             (   0    v     I   )  n-k-s+1 */
00155 /*                k-1   s  n-k-s+1 */
00156 
00157 /*  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
00158 /*  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
00159 /*  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
00160 
00161 /*  ===================================================================== */
00162 
00163 /*     .. Local Scalars .. */
00164 /*     .. */
00165 /*     .. External Functions .. */
00166 /*     .. */
00167 /*     .. External Subroutines .. */
00168 /*     .. */
00169 /*     .. Intrinsic Functions .. */
00170 /*     .. */
00171 /*     .. Executable Statements .. */
00172 
00173 /*     Test the input parameters. */
00174 
00175     /* Parameter adjustments */
00176     a_dim1 = *lda;
00177     a_offset = 1 + a_dim1;
00178     a -= a_offset;
00179     --ipiv;
00180     --work;
00181 
00182     /* Function Body */
00183     *info = 0;
00184     upper = lsame_(uplo, "U");
00185     lquery = *lwork == -1;
00186     if (! upper && ! lsame_(uplo, "L")) {
00187         *info = -1;
00188     } else if (*n < 0) {
00189         *info = -2;
00190     } else if (*lda < max(1,*n)) {
00191         *info = -4;
00192     } else if (*lwork < 1 && ! lquery) {
00193         *info = -7;
00194     }
00195 
00196     if (*info == 0) {
00197 
00198 /*        Determine the block size */
00199 
00200         nb = ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1);
00201         lwkopt = *n * nb;
00202         work[1] = (doublereal) lwkopt;
00203     }
00204 
00205     if (*info != 0) {
00206         i__1 = -(*info);
00207         xerbla_("DSYTRF", &i__1);
00208         return 0;
00209     } else if (lquery) {
00210         return 0;
00211     }
00212 
00213     nbmin = 2;
00214     ldwork = *n;
00215     if (nb > 1 && nb < *n) {
00216         iws = ldwork * nb;
00217         if (*lwork < iws) {
00218 /* Computing MAX */
00219             i__1 = *lwork / ldwork;
00220             nb = max(i__1,1);
00221 /* Computing MAX */
00222             i__1 = 2, i__2 = ilaenv_(&c__2, "DSYTRF", uplo, n, &c_n1, &c_n1, &
00223                     c_n1);
00224             nbmin = max(i__1,i__2);
00225         }
00226     } else {
00227         iws = 1;
00228     }
00229     if (nb < nbmin) {
00230         nb = *n;
00231     }
00232 
00233     if (upper) {
00234 
00235 /*        Factorize A as U*D*U' using the upper triangle of A */
00236 
00237 /*        K is the main loop index, decreasing from N to 1 in steps of */
00238 /*        KB, where KB is the number of columns factorized by DLASYF; */
00239 /*        KB is either NB or NB-1, or K for the last block */
00240 
00241         k = *n;
00242 L10:
00243 
00244 /*        If K < 1, exit from loop */
00245 
00246         if (k < 1) {
00247             goto L40;
00248         }
00249 
00250         if (k > nb) {
00251 
00252 /*           Factorize columns k-kb+1:k of A and use blocked code to */
00253 /*           update columns 1:k-kb */
00254 
00255             dlasyf_(uplo, &k, &nb, &kb, &a[a_offset], lda, &ipiv[1], &work[1], 
00256                      &ldwork, &iinfo);
00257         } else {
00258 
00259 /*           Use unblocked code to factorize columns 1:k of A */
00260 
00261             dsytf2_(uplo, &k, &a[a_offset], lda, &ipiv[1], &iinfo);
00262             kb = k;
00263         }
00264 
00265 /*        Set INFO on the first occurrence of a zero pivot */
00266 
00267         if (*info == 0 && iinfo > 0) {
00268             *info = iinfo;
00269         }
00270 
00271 /*        Decrease K and return to the start of the main loop */
00272 
00273         k -= kb;
00274         goto L10;
00275 
00276     } else {
00277 
00278 /*        Factorize A as L*D*L' using the lower triangle of A */
00279 
00280 /*        K is the main loop index, increasing from 1 to N in steps of */
00281 /*        KB, where KB is the number of columns factorized by DLASYF; */
00282 /*        KB is either NB or NB-1, or N-K+1 for the last block */
00283 
00284         k = 1;
00285 L20:
00286 
00287 /*        If K > N, exit from loop */
00288 
00289         if (k > *n) {
00290             goto L40;
00291         }
00292 
00293         if (k <= *n - nb) {
00294 
00295 /*           Factorize columns k:k+kb-1 of A and use blocked code to */
00296 /*           update columns k+kb:n */
00297 
00298             i__1 = *n - k + 1;
00299             dlasyf_(uplo, &i__1, &nb, &kb, &a[k + k * a_dim1], lda, &ipiv[k], 
00300                     &work[1], &ldwork, &iinfo);
00301         } else {
00302 
00303 /*           Use unblocked code to factorize columns k:n of A */
00304 
00305             i__1 = *n - k + 1;
00306             dsytf2_(uplo, &i__1, &a[k + k * a_dim1], lda, &ipiv[k], &iinfo);
00307             kb = *n - k + 1;
00308         }
00309 
00310 /*        Set INFO on the first occurrence of a zero pivot */
00311 
00312         if (*info == 0 && iinfo > 0) {
00313             *info = iinfo + k - 1;
00314         }
00315 
00316 /*        Adjust IPIV */
00317 
00318         i__1 = k + kb - 1;
00319         for (j = k; j <= i__1; ++j) {
00320             if (ipiv[j] > 0) {
00321                 ipiv[j] = ipiv[j] + k - 1;
00322             } else {
00323                 ipiv[j] = ipiv[j] - k + 1;
00324             }
00325 /* L30: */
00326         }
00327 
00328 /*        Increase K and return to the start of the main loop */
00329 
00330         k += kb;
00331         goto L20;
00332 
00333     }
00334 
00335 L40:
00336     work[1] = (doublereal) lwkopt;
00337     return 0;
00338 
00339 /*     End of DSYTRF */
00340 
00341 } /* dsytrf_ */


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