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