ergo
template_lapack_lascl.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_LASCL_HEADER
36 #define TEMPLATE_LAPACK_LASCL_HEADER
37 
38 
39 template<class Treal>
40 int template_lapack_lascl(const char *type__, const integer *kl, const integer *ku,
41  const Treal *cfrom, const Treal *cto, const integer *m, const integer *n,
42  Treal *a, const integer *lda, integer *info)
43 {
44 /* -- LAPACK auxiliary routine (version 3.0) --
45  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
46  Courant Institute, Argonne National Lab, and Rice University
47  February 29, 1992
48 
49 
50  Purpose
51  =======
52 
53  DLASCL multiplies the M by N real matrix A by the real scalar
54  CTO/CFROM. This is done without over/underflow as long as the final
55  result CTO*A(I,J)/CFROM does not over/underflow. TYPE specifies that
56  A may be full, upper triangular, lower triangular, upper Hessenberg,
57  or banded.
58 
59  Arguments
60  =========
61 
62  TYPE (input) CHARACTER*1
63  TYPE indices the storage type of the input matrix.
64  = 'G': A is a full matrix.
65  = 'L': A is a lower triangular matrix.
66  = 'U': A is an upper triangular matrix.
67  = 'H': A is an upper Hessenberg matrix.
68  = 'B': A is a symmetric band matrix with lower bandwidth KL
69  and upper bandwidth KU and with the only the lower
70  half stored.
71  = 'Q': A is a symmetric band matrix with lower bandwidth KL
72  and upper bandwidth KU and with the only the upper
73  half stored.
74  = 'Z': A is a band matrix with lower bandwidth KL and upper
75  bandwidth KU.
76 
77  KL (input) INTEGER
78  The lower bandwidth of A. Referenced only if TYPE = 'B',
79  'Q' or 'Z'.
80 
81  KU (input) INTEGER
82  The upper bandwidth of A. Referenced only if TYPE = 'B',
83  'Q' or 'Z'.
84 
85  CFROM (input) DOUBLE PRECISION
86  CTO (input) DOUBLE PRECISION
87  The matrix A is multiplied by CTO/CFROM. A(I,J) is computed
88  without over/underflow if the final result CTO*A(I,J)/CFROM
89  can be represented without over/underflow. CFROM must be
90  nonzero.
91 
92  M (input) INTEGER
93  The number of rows of the matrix A. M >= 0.
94 
95  N (input) INTEGER
96  The number of columns of the matrix A. N >= 0.
97 
98  A (input/output) DOUBLE PRECISION array, dimension (LDA,M)
99  The matrix to be multiplied by CTO/CFROM. See TYPE for the
100  storage type.
101 
102  LDA (input) INTEGER
103  The leading dimension of the array A. LDA >= max(1,M).
104 
105  INFO (output) INTEGER
106  0 - successful exit
107  <0 - if INFO = -i, the i-th argument had an illegal value.
108 
109  =====================================================================
110 
111 
112  Test the input arguments
113 
114  Parameter adjustments */
115  /* System generated locals */
116  integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
117  /* Local variables */
118  logical done;
119  Treal ctoc;
120  integer i__, j;
121  integer itype, k1, k2, k3, k4;
122  Treal cfrom1;
123  Treal cfromc;
124  Treal bignum, smlnum, mul, cto1;
125 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
126 
127  a_dim1 = *lda;
128  a_offset = 1 + a_dim1 * 1;
129  a -= a_offset;
130 
131  /* Function Body */
132  *info = 0;
133 
134  if (template_blas_lsame(type__, "G")) {
135  itype = 0;
136  } else if (template_blas_lsame(type__, "L")) {
137  itype = 1;
138  } else if (template_blas_lsame(type__, "U")) {
139  itype = 2;
140  } else if (template_blas_lsame(type__, "H")) {
141  itype = 3;
142  } else if (template_blas_lsame(type__, "B")) {
143  itype = 4;
144  } else if (template_blas_lsame(type__, "Q")) {
145  itype = 5;
146  } else if (template_blas_lsame(type__, "Z")) {
147  itype = 6;
148  } else {
149  itype = -1;
150  }
151 
152  if (itype == -1) {
153  *info = -1;
154  } else if (*cfrom == 0.) {
155  *info = -4;
156  } else if (*m < 0) {
157  *info = -6;
158  } else if (*n < 0 || ( itype == 4 && *n != *m ) || ( itype == 5 && *n != *m ) ) {
159  *info = -7;
160  } else if (itype <= 3 && *lda < maxMACRO(1,*m)) {
161  *info = -9;
162  } else if (itype >= 4) {
163 /* Computing MAX */
164  i__1 = *m - 1;
165  if (*kl < 0 || *kl > maxMACRO(i__1,0)) {
166  *info = -2;
167  } else /* if(complicated condition) */ {
168 /* Computing MAX */
169  i__1 = *n - 1;
170  if (*ku < 0 || *ku > maxMACRO(i__1,0) || ( (itype == 4 || itype == 5) &&
171  *kl != *ku ) ) {
172  *info = -3;
173  } else if ( ( itype == 4 && *lda < *kl + 1 ) || ( itype == 5 && *lda < *
174  ku + 1 ) || ( itype == 6 && *lda < (*kl << 1) + *ku + 1 ) ) {
175  *info = -9;
176  }
177  }
178  }
179 
180  if (*info != 0) {
181  i__1 = -(*info);
182  template_blas_erbla("LASCL ", &i__1);
183  return 0;
184  }
185 
186 /* Quick return if possible */
187 
188  if (*n == 0 || *m == 0) {
189  return 0;
190  }
191 
192 /* Get machine parameters */
193 
194  smlnum = template_lapack_lamch("S", (Treal)0);
195  bignum = 1. / smlnum;
196 
197  cfromc = *cfrom;
198  ctoc = *cto;
199 
200 L10:
201  cfrom1 = cfromc * smlnum;
202  cto1 = ctoc / bignum;
203  if (absMACRO(cfrom1) > absMACRO(ctoc) && ctoc != 0.) {
204  mul = smlnum;
205  done = FALSE_;
206  cfromc = cfrom1;
207  } else if (absMACRO(cto1) > absMACRO(cfromc)) {
208  mul = bignum;
209  done = FALSE_;
210  ctoc = cto1;
211  } else {
212  mul = ctoc / cfromc;
213  done = TRUE_;
214  }
215 
216  if (itype == 0) {
217 
218 /* Full matrix */
219 
220  i__1 = *n;
221  for (j = 1; j <= i__1; ++j) {
222  i__2 = *m;
223  for (i__ = 1; i__ <= i__2; ++i__) {
224  a_ref(i__, j) = a_ref(i__, j) * mul;
225 /* L20: */
226  }
227 /* L30: */
228  }
229 
230  } else if (itype == 1) {
231 
232 /* Lower triangular matrix */
233 
234  i__1 = *n;
235  for (j = 1; j <= i__1; ++j) {
236  i__2 = *m;
237  for (i__ = j; i__ <= i__2; ++i__) {
238  a_ref(i__, j) = a_ref(i__, j) * mul;
239 /* L40: */
240  }
241 /* L50: */
242  }
243 
244  } else if (itype == 2) {
245 
246 /* Upper triangular matrix */
247 
248  i__1 = *n;
249  for (j = 1; j <= i__1; ++j) {
250  i__2 = minMACRO(j,*m);
251  for (i__ = 1; i__ <= i__2; ++i__) {
252  a_ref(i__, j) = a_ref(i__, j) * mul;
253 /* L60: */
254  }
255 /* L70: */
256  }
257 
258  } else if (itype == 3) {
259 
260 /* Upper Hessenberg matrix */
261 
262  i__1 = *n;
263  for (j = 1; j <= i__1; ++j) {
264 /* Computing MIN */
265  i__3 = j + 1;
266  i__2 = minMACRO(i__3,*m);
267  for (i__ = 1; i__ <= i__2; ++i__) {
268  a_ref(i__, j) = a_ref(i__, j) * mul;
269 /* L80: */
270  }
271 /* L90: */
272  }
273 
274  } else if (itype == 4) {
275 
276 /* Lower half of a symmetric band matrix */
277 
278  k3 = *kl + 1;
279  k4 = *n + 1;
280  i__1 = *n;
281  for (j = 1; j <= i__1; ++j) {
282 /* Computing MIN */
283  i__3 = k3, i__4 = k4 - j;
284  i__2 = minMACRO(i__3,i__4);
285  for (i__ = 1; i__ <= i__2; ++i__) {
286  a_ref(i__, j) = a_ref(i__, j) * mul;
287 /* L100: */
288  }
289 /* L110: */
290  }
291 
292  } else if (itype == 5) {
293 
294 /* Upper half of a symmetric band matrix */
295 
296  k1 = *ku + 2;
297  k3 = *ku + 1;
298  i__1 = *n;
299  for (j = 1; j <= i__1; ++j) {
300 /* Computing MAX */
301  i__2 = k1 - j;
302  i__3 = k3;
303  for (i__ = maxMACRO(i__2,1); i__ <= i__3; ++i__) {
304  a_ref(i__, j) = a_ref(i__, j) * mul;
305 /* L120: */
306  }
307 /* L130: */
308  }
309 
310  } else if (itype == 6) {
311 
312 /* Band matrix */
313 
314  k1 = *kl + *ku + 2;
315  k2 = *kl + 1;
316  k3 = (*kl << 1) + *ku + 1;
317  k4 = *kl + *ku + 1 + *m;
318  i__1 = *n;
319  for (j = 1; j <= i__1; ++j) {
320 /* Computing MAX */
321  i__3 = k1 - j;
322 /* Computing MIN */
323  i__4 = k3, i__5 = k4 - j;
324  i__2 = minMACRO(i__4,i__5);
325  for (i__ = maxMACRO(i__3,k2); i__ <= i__2; ++i__) {
326  a_ref(i__, j) = a_ref(i__, j) * mul;
327 /* L140: */
328  }
329 /* L150: */
330  }
331 
332  }
333 
334  if (! done) {
335  goto L10;
336  }
337 
338  return 0;
339 
340 /* End of DLASCL */
341 
342 } /* dlascl_ */
343 
344 #undef a_ref
345 
346 
347 #endif
#define absMACRO(x)
Definition: template_blas_common.h:45
int template_lapack_lascl(const char *type__, const integer *kl, const integer *ku, const Treal *cfrom, const Treal *cto, const integer *m, const integer *n, Treal *a, const integer *lda, integer *info)
Definition: template_lapack_lascl.h:40
int integer
Definition: template_blas_common.h:38
#define maxMACRO(a, b)
Definition: template_blas_common.h:43
#define minMACRO(a, b)
Definition: template_blas_common.h:44
int template_blas_erbla(const char *srname, integer *info)
Definition: template_blas_common.cc:144
#define a_ref(a_1, a_2)
Treal template_lapack_lamch(const char *cmach, Treal dummyReal)
Definition: template_lapack_lamch.h:199
bool logical
Definition: template_blas_common.h:39
#define TRUE_
Definition: template_lapack_common.h:40
#define FALSE_
Definition: template_lapack_common.h:41
logical template_blas_lsame(const char *ca, const char *cb)
Definition: template_blas_common.cc:44