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_PPTRF_HEADER 00038 #define TEMPLATE_LAPACK_PPTRF_HEADER 00039 00040 #include "template_lapack_common.h" 00041 00042 template<class Treal> 00043 int template_lapack_pptrf(const char *uplo, const integer *n, Treal *ap, integer * 00044 info) 00045 { 00046 /* -- LAPACK routine (version 3.0) -- 00047 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00048 Courant Institute, Argonne National Lab, and Rice University 00049 March 31, 1993 00050 00051 00052 Purpose 00053 ======= 00054 00055 DPPTRF computes the Cholesky factorization of a real symmetric 00056 positive definite matrix A stored in packed format. 00057 00058 The factorization has the form 00059 A = U**T * U, if UPLO = 'U', or 00060 A = L * L**T, if UPLO = 'L', 00061 where U is an upper triangular matrix and L is lower triangular. 00062 00063 Arguments 00064 ========= 00065 00066 UPLO (input) CHARACTER*1 00067 = 'U': Upper triangle of A is stored; 00068 = 'L': Lower triangle of A is stored. 00069 00070 N (input) INTEGER 00071 The order of the matrix A. N >= 0. 00072 00073 AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) 00074 On entry, the upper or lower triangle of the symmetric matrix 00075 A, packed columnwise in a linear array. The j-th column of A 00076 is stored in the array AP as follows: 00077 if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00078 if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. 00079 See below for further details. 00080 00081 On exit, if INFO = 0, the triangular factor U or L from the 00082 Cholesky factorization A = U**T*U or A = L*L**T, in the same 00083 storage format as A. 00084 00085 INFO (output) INTEGER 00086 = 0: successful exit 00087 < 0: if INFO = -i, the i-th argument had an illegal value 00088 > 0: if INFO = i, the leading minor of order i is not 00089 positive definite, and the factorization could not be 00090 completed. 00091 00092 Further Details 00093 ======= ======= 00094 00095 The packed storage scheme is illustrated by the following example 00096 when N = 4, UPLO = 'U': 00097 00098 Two-dimensional storage of the symmetric matrix A: 00099 00100 a11 a12 a13 a14 00101 a22 a23 a24 00102 a33 a34 (aij = aji) 00103 a44 00104 00105 Packed storage of the upper triangle of A: 00106 00107 AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] 00108 00109 ===================================================================== 00110 00111 00112 Test the input parameters. 00113 00114 Parameter adjustments */ 00115 /* Table of constant values */ 00116 integer c__1 = 1; 00117 Treal c_b16 = -1.; 00118 00119 /* System generated locals */ 00120 integer i__1, i__2; 00121 Treal d__1; 00122 /* Local variables */ 00123 integer j; 00124 logical upper; 00125 integer jc, jj; 00126 Treal ajj; 00127 00128 00129 --ap; 00130 00131 /* Function Body */ 00132 *info = 0; 00133 upper = template_blas_lsame(uplo, "U"); 00134 if (! upper && ! template_blas_lsame(uplo, "L")) { 00135 *info = -1; 00136 } else if (*n < 0) { 00137 *info = -2; 00138 } 00139 if (*info != 0) { 00140 i__1 = -(*info); 00141 template_blas_erbla("DPPTRF", &i__1); 00142 return 0; 00143 } 00144 00145 /* Quick return if possible */ 00146 00147 if (*n == 0) { 00148 return 0; 00149 } 00150 00151 if (upper) { 00152 00153 /* Compute the Cholesky factorization A = U'*U. */ 00154 00155 jj = 0; 00156 i__1 = *n; 00157 for (j = 1; j <= i__1; ++j) { 00158 jc = jj + 1; 00159 jj += j; 00160 00161 /* Compute elements 1:J-1 of column J. */ 00162 00163 if (j > 1) { 00164 i__2 = j - 1; 00165 template_blas_tpsv("Upper", "Transpose", "Non-unit", &i__2, &ap[1], &ap[ 00166 jc], &c__1); 00167 } 00168 00169 /* Compute U(J,J) and test for non-positive-definiteness. */ 00170 00171 i__2 = j - 1; 00172 ajj = ap[jj] - template_blas_dot(&i__2, &ap[jc], &c__1, &ap[jc], &c__1); 00173 if (ajj <= 0.) { 00174 ap[jj] = ajj; 00175 goto L30; 00176 } 00177 ap[jj] = template_blas_sqrt(ajj); 00178 /* L10: */ 00179 } 00180 } else { 00181 00182 /* Compute the Cholesky factorization A = L*L'. */ 00183 00184 jj = 1; 00185 i__1 = *n; 00186 for (j = 1; j <= i__1; ++j) { 00187 00188 /* Compute L(J,J) and test for non-positive-definiteness. */ 00189 00190 ajj = ap[jj]; 00191 if (ajj <= 0.) { 00192 ap[jj] = ajj; 00193 goto L30; 00194 } 00195 ajj = template_blas_sqrt(ajj); 00196 ap[jj] = ajj; 00197 00198 /* Compute elements J+1:N of column J and update the trailing 00199 submatrix. */ 00200 00201 if (j < *n) { 00202 i__2 = *n - j; 00203 d__1 = 1. / ajj; 00204 template_blas_scal(&i__2, &d__1, &ap[jj + 1], &c__1); 00205 i__2 = *n - j; 00206 template_blas_spr("Lower", &i__2, &c_b16, &ap[jj + 1], &c__1, &ap[jj + *n 00207 - j + 1]); 00208 jj = jj + *n - j + 1; 00209 } 00210 /* L20: */ 00211 } 00212 } 00213 goto L40; 00214 00215 L30: 00216 *info = j; 00217 00218 L40: 00219 return 0; 00220 00221 /* End of DPPTRF */ 00222 00223 } /* dpptrf_ */ 00224 00225 #endif