ergo
template_lapack_lasq6.h
Go to the documentation of this file.
1 /* Ergo, version 3.2, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2012 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_LASQ6_HEADER
36 #define TEMPLATE_LAPACK_LASQ6_HEADER
37 
38 template<class Treal>
39 int template_lapack_lasq6(integer *i0, integer *n0, Treal *z__,
40  integer *pp, Treal *dmin__, Treal *dmin1, Treal *dmin2,
41  Treal *dn, Treal *dnm1, Treal *dnm2)
42 {
43  /* System generated locals */
44  integer i__1;
45  Treal d__1, d__2;
46 
47  /* Local variables */
48  Treal d__;
49  integer j4, j4p2;
50  Treal emin, temp;
51  Treal safmin;
52 
53 
54 /* -- LAPACK routine (version 3.2) -- */
55 
56 /* -- Contributed by Osni Marques of the Lawrence Berkeley National -- */
57 /* -- Laboratory and Beresford Parlett of the Univ. of California at -- */
58 /* -- Berkeley -- */
59 /* -- November 2008 -- */
60 
61 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
62 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
63 
64 /* .. Scalar Arguments .. */
65 /* .. */
66 /* .. Array Arguments .. */
67 /* .. */
68 
69 /* Purpose */
70 /* ======= */
71 
72 /* DLASQ6 computes one dqd (shift equal to zero) transform in */
73 /* ping-pong form, with protection against underflow and overflow. */
74 
75 /* Arguments */
76 /* ========= */
77 
78 /* I0 (input) INTEGER */
79 /* First index. */
80 
81 /* N0 (input) INTEGER */
82 /* Last index. */
83 
84 /* Z (input) DOUBLE PRECISION array, dimension ( 4*N ) */
85 /* Z holds the qd array. EMIN is stored in Z(4*N0) to avoid */
86 /* an extra argument. */
87 
88 /* PP (input) INTEGER */
89 /* PP=0 for ping, PP=1 for pong. */
90 
91 /* DMIN (output) DOUBLE PRECISION */
92 /* Minimum value of d. */
93 
94 /* DMIN1 (output) DOUBLE PRECISION */
95 /* Minimum value of d, excluding D( N0 ). */
96 
97 /* DMIN2 (output) DOUBLE PRECISION */
98 /* Minimum value of d, excluding D( N0 ) and D( N0-1 ). */
99 
100 /* DN (output) DOUBLE PRECISION */
101 /* d(N0), the last value of d. */
102 
103 /* DNM1 (output) DOUBLE PRECISION */
104 /* d(N0-1). */
105 
106 /* DNM2 (output) DOUBLE PRECISION */
107 /* d(N0-2). */
108 
109 /* ===================================================================== */
110 
111 /* .. Parameter .. */
112 /* .. */
113 /* .. Local Scalars .. */
114 /* .. */
115 /* .. External Function .. */
116 /* .. */
117 /* .. Intrinsic Functions .. */
118 /* .. */
119 /* .. Executable Statements .. */
120 
121  /* Parameter adjustments */
122  --z__;
123 
124  /* Function Body */
125  if (*n0 - *i0 - 1 <= 0) {
126  return 0;
127  }
128 
129  safmin = template_lapack_lamch("Safe minimum", (Treal)0);
130  j4 = (*i0 << 2) + *pp - 3;
131  emin = z__[j4 + 4];
132  d__ = z__[j4];
133  *dmin__ = d__;
134 
135  if (*pp == 0) {
136  i__1 = (*n0 - 3) << 2;
137  for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
138  z__[j4 - 2] = d__ + z__[j4 - 1];
139  if (z__[j4 - 2] == 0.) {
140  z__[j4] = 0.;
141  d__ = z__[j4 + 1];
142  *dmin__ = d__;
143  emin = 0.;
144  } else if (safmin * z__[j4 + 1] < z__[j4 - 2] && safmin * z__[j4
145  - 2] < z__[j4 + 1]) {
146  temp = z__[j4 + 1] / z__[j4 - 2];
147  z__[j4] = z__[j4 - 1] * temp;
148  d__ *= temp;
149  } else {
150  z__[j4] = z__[j4 + 1] * (z__[j4 - 1] / z__[j4 - 2]);
151  d__ = z__[j4 + 1] * (d__ / z__[j4 - 2]);
152  }
153  *dmin__ = minMACRO(*dmin__,d__);
154 /* Computing MIN */
155  d__1 = emin, d__2 = z__[j4];
156  emin = minMACRO(d__1,d__2);
157 /* L10: */
158  }
159  } else {
160  i__1 = ( *n0 - 3 ) << 2;
161  for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
162  z__[j4 - 3] = d__ + z__[j4];
163  if (z__[j4 - 3] == 0.) {
164  z__[j4 - 1] = 0.;
165  d__ = z__[j4 + 2];
166  *dmin__ = d__;
167  emin = 0.;
168  } else if (safmin * z__[j4 + 2] < z__[j4 - 3] && safmin * z__[j4
169  - 3] < z__[j4 + 2]) {
170  temp = z__[j4 + 2] / z__[j4 - 3];
171  z__[j4 - 1] = z__[j4] * temp;
172  d__ *= temp;
173  } else {
174  z__[j4 - 1] = z__[j4 + 2] * (z__[j4] / z__[j4 - 3]);
175  d__ = z__[j4 + 2] * (d__ / z__[j4 - 3]);
176  }
177  *dmin__ = minMACRO(*dmin__,d__);
178 /* Computing MIN */
179  d__1 = emin, d__2 = z__[j4 - 1];
180  emin = minMACRO(d__1,d__2);
181 /* L20: */
182  }
183  }
184 
185 /* Unroll last two steps. */
186 
187  *dnm2 = d__;
188  *dmin2 = *dmin__;
189  j4 = ( ( *n0 - 2 ) << 2) - *pp;
190  j4p2 = j4 + (*pp << 1) - 1;
191  z__[j4 - 2] = *dnm2 + z__[j4p2];
192  if (z__[j4 - 2] == 0.) {
193  z__[j4] = 0.;
194  *dnm1 = z__[j4p2 + 2];
195  *dmin__ = *dnm1;
196  emin = 0.;
197  } else if (safmin * z__[j4p2 + 2] < z__[j4 - 2] && safmin * z__[j4 - 2] <
198  z__[j4p2 + 2]) {
199  temp = z__[j4p2 + 2] / z__[j4 - 2];
200  z__[j4] = z__[j4p2] * temp;
201  *dnm1 = *dnm2 * temp;
202  } else {
203  z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
204  *dnm1 = z__[j4p2 + 2] * (*dnm2 / z__[j4 - 2]);
205  }
206  *dmin__ = minMACRO(*dmin__,*dnm1);
207 
208  *dmin1 = *dmin__;
209  j4 += 4;
210  j4p2 = j4 + (*pp << 1) - 1;
211  z__[j4 - 2] = *dnm1 + z__[j4p2];
212  if (z__[j4 - 2] == 0.) {
213  z__[j4] = 0.;
214  *dn = z__[j4p2 + 2];
215  *dmin__ = *dn;
216  emin = 0.;
217  } else if (safmin * z__[j4p2 + 2] < z__[j4 - 2] && safmin * z__[j4 - 2] <
218  z__[j4p2 + 2]) {
219  temp = z__[j4p2 + 2] / z__[j4 - 2];
220  z__[j4] = z__[j4p2] * temp;
221  *dn = *dnm1 * temp;
222  } else {
223  z__[j4] = z__[j4p2 + 2] * (z__[j4p2] / z__[j4 - 2]);
224  *dn = z__[j4p2 + 2] * (*dnm1 / z__[j4 - 2]);
225  }
226  *dmin__ = minMACRO(*dmin__,*dn);
227 
228  z__[j4 + 2] = *dn;
229  z__[(*n0 << 2) - *pp] = emin;
230  return 0;
231 
232 /* End of DLASQ6 */
233 
234 } /* dlasq6_ */
235 
236 #endif