ergo
template_lapack_lansy.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28  /* This file belongs to the template_lapack part of the Ergo source
29  * code. The source files in the template_lapack directory are modified
30  * versions of files originally distributed as CLAPACK, see the
31  * Copyright/license notice in the file template_lapack/COPYING.
32  */
33 
34 
35 #ifndef TEMPLATE_LAPACK_LANSY_HEADER
36 #define TEMPLATE_LAPACK_LANSY_HEADER
37 
38 
39 template<class Treal>
40 Treal template_lapack_lansy(const char *norm, const char *uplo, const integer *n, const Treal *a, const integer
41  *lda, Treal *work)
42 {
43 /* -- LAPACK auxiliary routine (version 3.0) --
44  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
45  Courant Institute, Argonne National Lab, and Rice University
46  October 31, 1992
47 
48 
49  Purpose
50  =======
51 
52  DLANSY returns the value of the one norm, or the Frobenius norm, or
53  the infinity norm, or the element of largest absolute value of a
54  real symmetric matrix A.
55 
56  Description
57  ===========
58 
59  DLANSY returns the value
60 
61  DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'
62  (
63  ( norm1(A), NORM = '1', 'O' or 'o'
64  (
65  ( normI(A), NORM = 'I' or 'i'
66  (
67  ( normF(A), NORM = 'F', 'f', 'E' or 'e'
68 
69  where norm1 denotes the one norm of a matrix (maximum column sum),
70  normI denotes the infinity norm of a matrix (maximum row sum) and
71  normF denotes the Frobenius norm of a matrix (square root of sum of
72  squares). Note that max(abs(A(i,j))) is not a matrix norm.
73 
74  Arguments
75  =========
76 
77  NORM (input) CHARACTER*1
78  Specifies the value to be returned in DLANSY as described
79  above.
80 
81  UPLO (input) CHARACTER*1
82  Specifies whether the upper or lower triangular part of the
83  symmetric matrix A is to be referenced.
84  = 'U': Upper triangular part of A is referenced
85  = 'L': Lower triangular part of A is referenced
86 
87  N (input) INTEGER
88  The order of the matrix A. N >= 0. When N = 0, DLANSY is
89  set to zero.
90 
91  A (input) DOUBLE PRECISION array, dimension (LDA,N)
92  The symmetric matrix A. If UPLO = 'U', the leading n by n
93  upper triangular part of A contains the upper triangular part
94  of the matrix A, and the strictly lower triangular part of A
95  is not referenced. If UPLO = 'L', the leading n by n lower
96  triangular part of A contains the lower triangular part of
97  the matrix A, and the strictly upper triangular part of A is
98  not referenced.
99 
100  LDA (input) INTEGER
101  The leading dimension of the array A. LDA >= max(N,1).
102 
103  WORK (workspace) DOUBLE PRECISION array, dimension (LWORK),
104  where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
105  WORK is not referenced.
106 
107  =====================================================================
108 
109 
110  Parameter adjustments */
111  /* Table of constant values */
112  integer c__1 = 1;
113 
114  /* System generated locals */
115  integer a_dim1, a_offset, i__1, i__2;
116  Treal ret_val, d__1, d__2, d__3;
117  /* Local variables */
118  Treal absa;
119  integer i__, j;
120  Treal scale;
121  Treal value;
122  Treal sum;
123 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
124 
125 
126  a_dim1 = *lda;
127  a_offset = 1 + a_dim1 * 1;
128  a -= a_offset;
129  --work;
130 
131  /* Initialization added by Elias to get rid of compiler warnings. */
132  value = 0;
133  /* Function Body */
134  if (*n == 0) {
135  value = 0.;
136  } else if (template_blas_lsame(norm, "M")) {
137 
138 /* Find max(abs(A(i,j))). */
139 
140  value = 0.;
141  if (template_blas_lsame(uplo, "U")) {
142  i__1 = *n;
143  for (j = 1; j <= i__1; ++j) {
144  i__2 = j;
145  for (i__ = 1; i__ <= i__2; ++i__) {
146 /* Computing MAX */
147  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
148  value = maxMACRO(d__2,d__3);
149 /* L10: */
150  }
151 /* L20: */
152  }
153  } else {
154  i__1 = *n;
155  for (j = 1; j <= i__1; ++j) {
156  i__2 = *n;
157  for (i__ = j; i__ <= i__2; ++i__) {
158 /* Computing MAX */
159  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
160  value = maxMACRO(d__2,d__3);
161 /* L30: */
162  }
163 /* L40: */
164  }
165  }
166  } else if (template_blas_lsame(norm, "I") || template_blas_lsame(norm, "O") || *(unsigned char *)norm == '1') {
167 
168 /* Find normI(A) ( = norm1(A), since A is symmetric). */
169 
170  value = 0.;
171  if (template_blas_lsame(uplo, "U")) {
172  i__1 = *n;
173  for (j = 1; j <= i__1; ++j) {
174  sum = 0.;
175  i__2 = j - 1;
176  for (i__ = 1; i__ <= i__2; ++i__) {
177  absa = (d__1 = a_ref(i__, j), absMACRO(d__1));
178  sum += absa;
179  work[i__] += absa;
180 /* L50: */
181  }
182  work[j] = sum + (d__1 = a_ref(j, j), absMACRO(d__1));
183 /* L60: */
184  }
185  i__1 = *n;
186  for (i__ = 1; i__ <= i__1; ++i__) {
187 /* Computing MAX */
188  d__1 = value, d__2 = work[i__];
189  value = maxMACRO(d__1,d__2);
190 /* L70: */
191  }
192  } else {
193  i__1 = *n;
194  for (i__ = 1; i__ <= i__1; ++i__) {
195  work[i__] = 0.;
196 /* L80: */
197  }
198  i__1 = *n;
199  for (j = 1; j <= i__1; ++j) {
200  sum = work[j] + (d__1 = a_ref(j, j), absMACRO(d__1));
201  i__2 = *n;
202  for (i__ = j + 1; i__ <= i__2; ++i__) {
203  absa = (d__1 = a_ref(i__, j), absMACRO(d__1));
204  sum += absa;
205  work[i__] += absa;
206 /* L90: */
207  }
208  value = maxMACRO(value,sum);
209 /* L100: */
210  }
211  }
212  } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) {
213 
214 /* Find normF(A). */
215 
216  scale = 0.;
217  sum = 1.;
218  if (template_blas_lsame(uplo, "U")) {
219  i__1 = *n;
220  for (j = 2; j <= i__1; ++j) {
221  i__2 = j - 1;
222  template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum);
223 /* L110: */
224  }
225  } else {
226  i__1 = *n - 1;
227  for (j = 1; j <= i__1; ++j) {
228  i__2 = *n - j;
229  template_lapack_lassq(&i__2, &a_ref(j + 1, j), &c__1, &scale, &sum);
230 /* L120: */
231  }
232  }
233  sum *= 2;
234  i__1 = *lda + 1;
235  template_lapack_lassq(n, &a[a_offset], &i__1, &scale, &sum);
236  value = scale * template_blas_sqrt(sum);
237  }
238 
239  ret_val = value;
240  return ret_val;
241 
242 /* End of DLANSY */
243 
244 } /* dlansy_ */
245 
246 #undef a_ref
247 
248 
249 #endif
#define absMACRO(x)
Definition: template_blas_common.h:45
int integer
Definition: template_blas_common.h:38
#define a_ref(a_1, a_2)
#define maxMACRO(a, b)
Definition: template_blas_common.h:43
Treal template_lapack_lansy(const char *norm, const char *uplo, const integer *n, const Treal *a, const integer *lda, Treal *work)
Definition: template_lapack_lansy.h:40
int template_lapack_lassq(const integer *n, const Treal *x, const integer *incx, Treal *scale, Treal *sumsq)
Definition: template_lapack_lamch.h:70
Treal template_blas_sqrt(Treal x)
logical template_blas_lsame(const char *ca, const char *cb)
Definition: template_blas_common.cc:44