ergo
|
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * Primary academic reference: 00019 * KohnâSham Density Functional Theory Electronic Structure Calculations 00020 * with Linearly Scaling Computational Time and Memory Usage, 00021 * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek, 00022 * J. Chem. Theory Comput. 7, 340 (2011), 00023 * <http://dx.doi.org/10.1021/ct100611z> 00024 * 00025 * For further information about Ergo, see <http://www.ergoscf.org>. 00026 */ 00027 00028 /* This file belongs to the template_lapack part of the Ergo source 00029 * code. The source files in the template_lapack directory are modified 00030 * versions of files originally distributed as CLAPACK, see the 00031 * Copyright/license notice in the file template_lapack/COPYING. 00032 */ 00033 00034 00035 #ifndef TEMPLATE_LAPACK_LANHS_HEADER 00036 #define TEMPLATE_LAPACK_LANHS_HEADER 00037 00038 00039 template<class Treal> 00040 Treal dlanhs_(const char *norm, const integer *n, const Treal *a, const integer *lda, 00041 Treal *work) 00042 { 00043 /* -- LAPACK auxiliary routine (version 3.0) -- 00044 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00045 Courant Institute, Argonne National Lab, and Rice University 00046 October 31, 1992 00047 00048 00049 Purpose 00050 ======= 00051 00052 DLANHS returns the value of the one norm, or the Frobenius norm, or 00053 the infinity norm, or the element of largest absolute value of a 00054 Hessenberg matrix A. 00055 00056 Description 00057 =========== 00058 00059 DLANHS returns the value 00060 00061 DLANHS = ( max(abs(A(i,j))), NORM = 'M' or 'm' 00062 ( 00063 ( norm1(A), NORM = '1', 'O' or 'o' 00064 ( 00065 ( normI(A), NORM = 'I' or 'i' 00066 ( 00067 ( normF(A), NORM = 'F', 'f', 'E' or 'e' 00068 00069 where norm1 denotes the one norm of a matrix (maximum column sum), 00070 normI denotes the infinity norm of a matrix (maximum row sum) and 00071 normF denotes the Frobenius norm of a matrix (square root of sum of 00072 squares). Note that max(abs(A(i,j))) is not a matrix norm. 00073 00074 Arguments 00075 ========= 00076 00077 NORM (input) CHARACTER*1 00078 Specifies the value to be returned in DLANHS as described 00079 above. 00080 00081 N (input) INTEGER 00082 The order of the matrix A. N >= 0. When N = 0, DLANHS is 00083 set to zero. 00084 00085 A (input) DOUBLE PRECISION array, dimension (LDA,N) 00086 The n by n upper Hessenberg matrix A; the part of A below the 00087 first sub-diagonal is not referenced. 00088 00089 LDA (input) INTEGER 00090 The leading dimension of the array A. LDA >= max(N,1). 00091 00092 WORK (workspace) DOUBLE PRECISION array, dimension (LWORK), 00093 where LWORK >= N when NORM = 'I'; otherwise, WORK is not 00094 referenced. 00095 00096 ===================================================================== 00097 00098 00099 Parameter adjustments */ 00100 /* Table of constant values */ 00101 integer c__1 = 1; 00102 00103 /* System generated locals */ 00104 integer a_dim1, a_offset, i__1, i__2, i__3, i__4; 00105 Treal ret_val, d__1, d__2, d__3; 00106 /* Local variables */ 00107 integer i__, j; 00108 Treal scale; 00109 Treal value; 00110 Treal sum; 00111 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1] 00112 00113 00114 a_dim1 = *lda; 00115 a_offset = 1 + a_dim1 * 1; 00116 a -= a_offset; 00117 --work; 00118 00119 /* Initialization added by Elias to get rid of compiler warnings. */ 00120 value = 0; 00121 /* Function Body */ 00122 if (*n == 0) { 00123 value = 0.; 00124 } else if (template_blas_lsame(norm, "M")) { 00125 00126 /* Find max(abs(A(i,j))). */ 00127 00128 value = 0.; 00129 i__1 = *n; 00130 for (j = 1; j <= i__1; ++j) { 00131 /* Computing MIN */ 00132 i__3 = *n, i__4 = j + 1; 00133 i__2 = minMACRO(i__3,i__4); 00134 for (i__ = 1; i__ <= i__2; ++i__) { 00135 /* Computing MAX */ 00136 d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00137 value = maxMACRO(d__2,d__3); 00138 /* L10: */ 00139 } 00140 /* L20: */ 00141 } 00142 } else if (template_blas_lsame(norm, "O") || *(unsigned char *) 00143 norm == '1') { 00144 00145 /* Find norm1(A). */ 00146 00147 value = 0.; 00148 i__1 = *n; 00149 for (j = 1; j <= i__1; ++j) { 00150 sum = 0.; 00151 /* Computing MIN */ 00152 i__3 = *n, i__4 = j + 1; 00153 i__2 = minMACRO(i__3,i__4); 00154 for (i__ = 1; i__ <= i__2; ++i__) { 00155 sum += (d__1 = a_ref(i__, j), absMACRO(d__1)); 00156 /* L30: */ 00157 } 00158 value = maxMACRO(value,sum); 00159 /* L40: */ 00160 } 00161 } else if (template_blas_lsame(norm, "I")) { 00162 00163 /* Find normI(A). */ 00164 00165 i__1 = *n; 00166 for (i__ = 1; i__ <= i__1; ++i__) { 00167 work[i__] = 0.; 00168 /* L50: */ 00169 } 00170 i__1 = *n; 00171 for (j = 1; j <= i__1; ++j) { 00172 /* Computing MIN */ 00173 i__3 = *n, i__4 = j + 1; 00174 i__2 = minMACRO(i__3,i__4); 00175 for (i__ = 1; i__ <= i__2; ++i__) { 00176 work[i__] += (d__1 = a_ref(i__, j), absMACRO(d__1)); 00177 /* L60: */ 00178 } 00179 /* L70: */ 00180 } 00181 value = 0.; 00182 i__1 = *n; 00183 for (i__ = 1; i__ <= i__1; ++i__) { 00184 /* Computing MAX */ 00185 d__1 = value, d__2 = work[i__]; 00186 value = maxMACRO(d__1,d__2); 00187 /* L80: */ 00188 } 00189 } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) { 00190 00191 /* Find normF(A). */ 00192 00193 scale = 0.; 00194 sum = 1.; 00195 i__1 = *n; 00196 for (j = 1; j <= i__1; ++j) { 00197 /* Computing MIN */ 00198 i__3 = *n, i__4 = j + 1; 00199 i__2 = minMACRO(i__3,i__4); 00200 template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum); 00201 /* L90: */ 00202 } 00203 value = scale * template_blas_sqrt(sum); 00204 } 00205 00206 ret_val = value; 00207 return ret_val; 00208 00209 /* End of DLANHS */ 00210 00211 } /* dlanhs_ */ 00212 00213 #undef a_ref 00214 00215 00216 #endif