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