00001 /* Ergo, version 3.7, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 00004 * and Anastasia Kruchinina. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * Primary academic reference: 00020 * Ergo: An open-source program for linear-scaling electronic structure 00021 * calculations, 00022 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 00023 * Kruchinina, 00024 * SoftwareX 7, 107 (2018), 00025 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 00026 * 00027 * For further information about Ergo, see <http://www.ergoscf.org>. 00028 */ 00029 00030 /* This file belongs to the template_lapack part of the Ergo source 00031 * code. The source files in the template_lapack directory are modified 00032 * versions of files originally distributed as CLAPACK, see the 00033 * Copyright/license notice in the file template_lapack/COPYING. 00034 */ 00035 00036 00037 #ifndef TEMPLATE_LAPACK_POTF2_HEADER 00038 #define TEMPLATE_LAPACK_POTF2_HEADER 00039 00040 00041 template<class Treal> 00042 int template_lapack_potf2(const char *uplo, const integer *n, Treal *a, const integer * 00043 lda, integer *info) 00044 { 00045 /* -- LAPACK routine (version 3.0) -- 00046 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00047 Courant Institute, Argonne National Lab, and Rice University 00048 February 29, 1992 00049 00050 00051 Purpose 00052 ======= 00053 00054 DPOTF2 computes the Cholesky factorization of a real symmetric 00055 positive definite matrix A. 00056 00057 The factorization has the form 00058 A = U' * U , if UPLO = 'U', or 00059 A = L * L', if UPLO = 'L', 00060 where U is an upper triangular matrix and L is lower triangular. 00061 00062 This is the unblocked version of the algorithm, calling Level 2 BLAS. 00063 00064 Arguments 00065 ========= 00066 00067 UPLO (input) CHARACTER*1 00068 Specifies whether the upper or lower triangular part of the 00069 symmetric matrix A is stored. 00070 = 'U': Upper triangular 00071 = 'L': Lower triangular 00072 00073 N (input) INTEGER 00074 The order of the matrix A. N >= 0. 00075 00076 A (input/output) DOUBLE PRECISION array, dimension (LDA,N) 00077 On entry, the symmetric matrix A. If UPLO = 'U', the leading 00078 n by n upper triangular part of A contains the upper 00079 triangular part of the matrix A, and the strictly lower 00080 triangular part of A is not referenced. If UPLO = 'L', the 00081 leading n by n lower triangular part of A contains the lower 00082 triangular part of the matrix A, and the strictly upper 00083 triangular part of A is not referenced. 00084 00085 On exit, if INFO = 0, the factor U or L from the Cholesky 00086 factorization A = U'*U or A = L*L'. 00087 00088 LDA (input) INTEGER 00089 The leading dimension of the array A. LDA >= max(1,N). 00090 00091 INFO (output) INTEGER 00092 = 0: successful exit 00093 < 0: if INFO = -k, the k-th argument had an illegal value 00094 > 0: if INFO = k, the leading minor of order k is not 00095 positive definite, and the factorization could not be 00096 completed. 00097 00098 ===================================================================== 00099 00100 00101 Test the input parameters. 00102 00103 Parameter adjustments */ 00104 /* Table of constant values */ 00105 integer c__1 = 1; 00106 Treal c_b10 = -1.; 00107 Treal c_b12 = 1.; 00108 00109 /* System generated locals */ 00110 integer a_dim1, a_offset, i__1, i__2, i__3; 00111 Treal d__1; 00112 /* Local variables */ 00113 integer j; 00114 logical upper; 00115 Treal ajj; 00116 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1] 00117 00118 00119 a_dim1 = *lda; 00120 a_offset = 1 + a_dim1 * 1; 00121 a -= a_offset; 00122 00123 /* Function Body */ 00124 *info = 0; 00125 upper = template_blas_lsame(uplo, "U"); 00126 if (! upper && ! template_blas_lsame(uplo, "L")) { 00127 *info = -1; 00128 } else if (*n < 0) { 00129 *info = -2; 00130 } else if (*lda < maxMACRO(1,*n)) { 00131 *info = -4; 00132 } 00133 if (*info != 0) { 00134 i__1 = -(*info); 00135 template_blas_erbla("POTF2 ", &i__1); 00136 return 0; 00137 } 00138 00139 /* Quick return if possible */ 00140 00141 if (*n == 0) { 00142 return 0; 00143 } 00144 00145 if (upper) { 00146 00147 /* Compute the Cholesky factorization A = U'*U. */ 00148 00149 i__1 = *n; 00150 for (j = 1; j <= i__1; ++j) { 00151 00152 /* Compute U(J,J) and test for non-positive-definiteness. */ 00153 00154 i__2 = j - 1; 00155 ajj = a_ref(j, j) - template_blas_dot(&i__2, &a_ref(1, j), &c__1, &a_ref(1, j) 00156 , &c__1); 00157 if (ajj <= 0.) { 00158 a_ref(j, j) = ajj; 00159 goto L30; 00160 } 00161 ajj = template_blas_sqrt(ajj); 00162 a_ref(j, j) = ajj; 00163 00164 /* Compute elements J+1:N of row J. */ 00165 00166 if (j < *n) { 00167 i__2 = j - 1; 00168 i__3 = *n - j; 00169 template_blas_gemv("Transpose", &i__2, &i__3, &c_b10, &a_ref(1, j + 1), 00170 lda, &a_ref(1, j), &c__1, &c_b12, &a_ref(j, j + 1), 00171 lda); 00172 i__2 = *n - j; 00173 d__1 = 1. / ajj; 00174 template_blas_scal(&i__2, &d__1, &a_ref(j, j + 1), lda); 00175 } 00176 /* L10: */ 00177 } 00178 } else { 00179 00180 /* Compute the Cholesky factorization A = L*L'. */ 00181 00182 i__1 = *n; 00183 for (j = 1; j <= i__1; ++j) { 00184 00185 /* Compute L(J,J) and test for non-positive-definiteness. */ 00186 00187 i__2 = j - 1; 00188 ajj = a_ref(j, j) - template_blas_dot(&i__2, &a_ref(j, 1), lda, &a_ref(j, 1), 00189 lda); 00190 if (ajj <= 0.) { 00191 a_ref(j, j) = ajj; 00192 goto L30; 00193 } 00194 ajj = template_blas_sqrt(ajj); 00195 a_ref(j, j) = ajj; 00196 00197 /* Compute elements J+1:N of column J. */ 00198 00199 if (j < *n) { 00200 i__2 = *n - j; 00201 i__3 = j - 1; 00202 template_blas_gemv("No transpose", &i__2, &i__3, &c_b10, &a_ref(j + 1, 1), 00203 lda, &a_ref(j, 1), lda, &c_b12, &a_ref(j + 1, j), & 00204 c__1); 00205 i__2 = *n - j; 00206 d__1 = 1. / ajj; 00207 template_blas_scal(&i__2, &d__1, &a_ref(j + 1, j), &c__1); 00208 } 00209 /* L20: */ 00210 } 00211 } 00212 goto L40; 00213 00214 L30: 00215 *info = j; 00216 00217 L40: 00218 return 0; 00219 00220 /* End of DPOTF2 */ 00221 00222 } /* dpotf2_ */ 00223 00224 #undef a_ref 00225 00226 00227 #endif