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


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