00001 /* zhetrf.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 zhetrf_(char *uplo, integer *n, doublecomplex *a, 00023 integer *lda, integer *ipiv, doublecomplex *work, integer *lwork, 00024 integer *info) 00025 { 00026 /* System generated locals */ 00027 integer a_dim1, a_offset, i__1, i__2; 00028 00029 /* Local variables */ 00030 integer j, k, kb, nb, iws; 00031 extern logical lsame_(char *, char *); 00032 integer nbmin, iinfo; 00033 logical upper; 00034 extern /* Subroutine */ int zhetf2_(char *, integer *, doublecomplex *, 00035 integer *, integer *, integer *), zlahef_(char *, integer 00036 *, integer *, integer *, doublecomplex *, integer *, integer *, 00037 doublecomplex *, integer *, integer *), xerbla_(char *, 00038 integer *); 00039 extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 00040 integer *, 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 /* ZHETRF computes the factorization of a complex Hermitian matrix A */ 00058 /* using the Bunch-Kaufman diagonal pivoting method. The form of the */ 00059 /* factorization is */ 00060 00061 /* A = U*D*U**H or A = L*D*L**H */ 00062 00063 /* where U (or L) is a product of permutation and unit upper (lower) */ 00064 /* triangular matrices, and D is Hermitian 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) COMPLEX*16 array, dimension (LDA,N) */ 00080 /* On entry, the Hermitian 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) COMPLEX*16 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 /* INFO (output) INTEGER */ 00112 /* = 0: successful exit */ 00113 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00114 /* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ 00115 /* has been completed, but the block diagonal matrix D is */ 00116 /* exactly singular, and division by zero will occur if it */ 00117 /* is used to solve a system of equations. */ 00118 00119 /* Further Details */ 00120 /* =============== */ 00121 00122 /* If UPLO = 'U', then A = U*D*U', where */ 00123 /* U = P(n)*U(n)* ... *P(k)U(k)* ..., */ 00124 /* i.e., U is a product of terms P(k)*U(k), where k decreases from n to */ 00125 /* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ 00126 /* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ 00127 /* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */ 00128 /* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ 00129 00130 /* ( I v 0 ) k-s */ 00131 /* U(k) = ( 0 I 0 ) s */ 00132 /* ( 0 0 I ) n-k */ 00133 /* k-s s n-k */ 00134 00135 /* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */ 00136 /* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */ 00137 /* and A(k,k), and v overwrites A(1:k-2,k-1:k). */ 00138 00139 /* If UPLO = 'L', then A = L*D*L', where */ 00140 /* L = P(1)*L(1)* ... *P(k)*L(k)* ..., */ 00141 /* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */ 00142 /* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ 00143 /* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ 00144 /* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */ 00145 /* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ 00146 00147 /* ( I 0 0 ) k-1 */ 00148 /* L(k) = ( 0 I 0 ) s */ 00149 /* ( 0 v I ) n-k-s+1 */ 00150 /* k-1 s n-k-s+1 */ 00151 00152 /* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */ 00153 /* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */ 00154 /* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */ 00155 00156 /* ===================================================================== */ 00157 00158 /* .. Local Scalars .. */ 00159 /* .. */ 00160 /* .. External Functions .. */ 00161 /* .. */ 00162 /* .. External Subroutines .. */ 00163 /* .. */ 00164 /* .. Intrinsic 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 --ipiv; 00175 --work; 00176 00177 /* Function Body */ 00178 *info = 0; 00179 upper = lsame_(uplo, "U"); 00180 lquery = *lwork == -1; 00181 if (! upper && ! lsame_(uplo, "L")) { 00182 *info = -1; 00183 } else if (*n < 0) { 00184 *info = -2; 00185 } else if (*lda < max(1,*n)) { 00186 *info = -4; 00187 } else if (*lwork < 1 && ! lquery) { 00188 *info = -7; 00189 } 00190 00191 if (*info == 0) { 00192 00193 /* Determine the block size */ 00194 00195 nb = ilaenv_(&c__1, "ZHETRF", uplo, n, &c_n1, &c_n1, &c_n1); 00196 lwkopt = *n * nb; 00197 work[1].r = (doublereal) lwkopt, work[1].i = 0.; 00198 } 00199 00200 if (*info != 0) { 00201 i__1 = -(*info); 00202 xerbla_("ZHETRF", &i__1); 00203 return 0; 00204 } else if (lquery) { 00205 return 0; 00206 } 00207 00208 nbmin = 2; 00209 ldwork = *n; 00210 if (nb > 1 && nb < *n) { 00211 iws = ldwork * nb; 00212 if (*lwork < iws) { 00213 /* Computing MAX */ 00214 i__1 = *lwork / ldwork; 00215 nb = max(i__1,1); 00216 /* Computing MAX */ 00217 i__1 = 2, i__2 = ilaenv_(&c__2, "ZHETRF", uplo, n, &c_n1, &c_n1, & 00218 c_n1); 00219 nbmin = max(i__1,i__2); 00220 } 00221 } else { 00222 iws = 1; 00223 } 00224 if (nb < nbmin) { 00225 nb = *n; 00226 } 00227 00228 if (upper) { 00229 00230 /* Factorize A as U*D*U' using the upper triangle of A */ 00231 00232 /* K is the main loop index, decreasing from N to 1 in steps of */ 00233 /* KB, where KB is the number of columns factorized by ZLAHEF; */ 00234 /* KB is either NB or NB-1, or K for the last block */ 00235 00236 k = *n; 00237 L10: 00238 00239 /* If K < 1, exit from loop */ 00240 00241 if (k < 1) { 00242 goto L40; 00243 } 00244 00245 if (k > nb) { 00246 00247 /* Factorize columns k-kb+1:k of A and use blocked code to */ 00248 /* update columns 1:k-kb */ 00249 00250 zlahef_(uplo, &k, &nb, &kb, &a[a_offset], lda, &ipiv[1], &work[1], 00251 n, &iinfo); 00252 } else { 00253 00254 /* Use unblocked code to factorize columns 1:k of A */ 00255 00256 zhetf2_(uplo, &k, &a[a_offset], lda, &ipiv[1], &iinfo); 00257 kb = k; 00258 } 00259 00260 /* Set INFO on the first occurrence of a zero pivot */ 00261 00262 if (*info == 0 && iinfo > 0) { 00263 *info = iinfo; 00264 } 00265 00266 /* Decrease K and return to the start of the main loop */ 00267 00268 k -= kb; 00269 goto L10; 00270 00271 } else { 00272 00273 /* Factorize A as L*D*L' using the lower triangle of A */ 00274 00275 /* K is the main loop index, increasing from 1 to N in steps of */ 00276 /* KB, where KB is the number of columns factorized by ZLAHEF; */ 00277 /* KB is either NB or NB-1, or N-K+1 for the last block */ 00278 00279 k = 1; 00280 L20: 00281 00282 /* If K > N, exit from loop */ 00283 00284 if (k > *n) { 00285 goto L40; 00286 } 00287 00288 if (k <= *n - nb) { 00289 00290 /* Factorize columns k:k+kb-1 of A and use blocked code to */ 00291 /* update columns k+kb:n */ 00292 00293 i__1 = *n - k + 1; 00294 zlahef_(uplo, &i__1, &nb, &kb, &a[k + k * a_dim1], lda, &ipiv[k], 00295 &work[1], n, &iinfo); 00296 } else { 00297 00298 /* Use unblocked code to factorize columns k:n of A */ 00299 00300 i__1 = *n - k + 1; 00301 zhetf2_(uplo, &i__1, &a[k + k * a_dim1], lda, &ipiv[k], &iinfo); 00302 kb = *n - k + 1; 00303 } 00304 00305 /* Set INFO on the first occurrence of a zero pivot */ 00306 00307 if (*info == 0 && iinfo > 0) { 00308 *info = iinfo + k - 1; 00309 } 00310 00311 /* Adjust IPIV */ 00312 00313 i__1 = k + kb - 1; 00314 for (j = k; j <= i__1; ++j) { 00315 if (ipiv[j] > 0) { 00316 ipiv[j] = ipiv[j] + k - 1; 00317 } else { 00318 ipiv[j] = ipiv[j] - k + 1; 00319 } 00320 /* L30: */ 00321 } 00322 00323 /* Increase K and return to the start of the main loop */ 00324 00325 k += kb; 00326 goto L20; 00327 00328 } 00329 00330 L40: 00331 work[1].r = (doublereal) lwkopt, work[1].i = 0.; 00332 return 0; 00333 00334 /* End of ZHETRF */ 00335 00336 } /* zhetrf_ */