2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 #include "gmx_lapack.h"
37 #include "lapack_limits.h"
39 #include <types/simple.h>
42 F77_FUNC(sstebz,SSTEBZ)(const char *range,
62 float d__1, d__2, d__3, d__4, d__5;
68 int j, ib, jb, ie, je, nb;
78 int iend, ioff, iout, itmp1, jdisc;
84 float wkill, rtoli, tnorm;
92 const float safemn = GMX_FLOAT_MIN*(1.0+GMX_FLOAT_EPS);
104 if (*range=='A' || *range=='a') {
106 } else if (*range=='V' || *range=='v') {
108 } else if (*range=='I' || *range=='i') {
114 if (*order=='B' || *order=='b') {
116 } else if (*order=='E' || *order=='e') {
124 } else if (iorder <= 0) {
128 } else if (irange == 2) {
132 } else if (irange == 3 && (*il < 1 || *il > (*n))) {
134 } else if (irange == 3 && (*iu < ((*n<*il) ? *n : *il) || *iu > *n)) {
152 if (irange == 3 && *il == 1 && *iu == *n) {
156 ulp = 2*GMX_FLOAT_EPS;
158 nb = DSTEBZ_BLOCKSIZE;
166 if (irange == 2 && (*vl >= d__[1] || *vu < d__[1])) {
180 for (j = 2; j <= i__1; ++j) {
184 if (fabs(d__[j] * d__[j - 1]) * (d__2 * d__2) + safemn
186 isplit[*nsplit] = j - 1;
191 pivmin = (pivmin>tmp1) ? pivmin : tmp1;
194 isplit[*nsplit] = *n;
204 for (j = 1; j <= i__1; ++j) {
205 tmp2 = sqrt(work[j]);
206 d__1 = gu, d__2 = d__[j] + tmp1 + tmp2;
207 gu = (d__1>d__2) ? d__1 : d__2;
208 d__1 = gl, d__2 = d__[j] - tmp1 - tmp2;
209 gl = (d__1<d__2) ? d__1 : d__2;
213 d__1 = gu, d__2 = d__[*n] + tmp1;
214 gu = (d__1>d__2) ? d__1 : d__2;
215 d__1 = gl, d__2 = d__[*n] - tmp1;
216 gl = (d__1<d__2) ? d__1 : d__2;
219 tnorm = (d__1>d__2) ? d__1 : d__2;
220 gl = gl - tnorm * 2. * ulp * *n - pivmin * 4.;
221 gu = gu + tnorm * 2. * ulp * *n + pivmin * 2.;
223 itmax = (int) ((log(tnorm + pivmin) - log(pivmin)) / log(2.)) + 2;
243 F77_FUNC(slaebz,SLAEBZ)(&c__3, &itmax, n, &c__2, &c__2, &nb, &atoli, &rtoli, &pivmin,
244 &d__[1], &e[1], &work[1], &iwork[5], &work[*n + 1], &work[*n
245 + 5], &iout, &iwork[1], &w[1], &iblock[1], &iinfo);
247 if (iwork[6] == *iu) {
263 if (nwl < 0 || nwl >= *n || nwu < 1 || nwu > *n) {
270 /* avoid warnings for high gcc optimization */
273 d__3 = fabs(d__[1]) + fabs(e[1]);
274 d__4 = fabs(d__[*n]) + fabs(e[*n - 1]);
275 tnorm = (d__3>d__4) ? d__3 : d__4;
278 for (j = 2; j <= i__1; ++j) {
280 d__5 = fabs(d__[j]) + fabs(e[j - 1]) + fabs(e[j]);
281 tnorm = (d__4>d__5) ? d__4 : d__5;
306 for (jb = 1; jb <= i__1; ++jb) {
314 if (irange == 1 || wl >= d__[ibegin] - pivmin) {
317 if (irange == 1 || wu >= d__[ibegin] - pivmin) {
320 if (irange == 1 || ((wl < d__[ibegin] - pivmin) && (wu >= d__[ibegin] - pivmin))) {
332 for (j = ibegin; j <= i__2; ++j) {
334 d__1 = gu, d__2 = d__[j] + tmp1 + tmp2;
335 gu = (d__1>d__2) ? d__1 : d__2;
336 d__1 = gl, d__2 = d__[j] - tmp1 - tmp2;
337 gl = (d__1<d__2) ? d__1 : d__2;
341 d__1 = gu, d__2 = d__[iend] + tmp1;
342 gu = (d__1>d__2) ? d__1 : d__2;
343 d__1 = gl, d__2 = d__[iend] - tmp1;
344 gl = (d__1<d__2) ? d__1 : d__2;
347 bnorm = (d__1>d__2) ? d__1 : d__2;
348 gl = gl - bnorm * 2. * ulp * in - pivmin * 2.;
349 gu = gu + bnorm * 2. * ulp * in + pivmin * 2.;
354 atoli = ulp * ((d__1>d__2) ? d__1 : d__2);
364 gl = (gl>wl) ? gl : wl;
365 gu = (gu<wu) ? gu : wu;
372 work[*n + in + 1] = gu;
373 F77_FUNC(slaebz,SLAEBZ)(&c__1, &c__0, &in, &in, &c__1, &nb, &atoli, &rtoli, &
374 pivmin, &d__[ibegin], &e[ibegin], &work[ibegin], idumma, &
375 work[*n + 1], &work[*n + (in << 1) + 1], &im, &iwork[1], &
376 w[*m + 1], &iblock[*m + 1], &iinfo);
379 nwu += iwork[in + 1];
380 iwoff = *m - iwork[1];
382 itmax = (int) ((log(gu - gl + pivmin) - log(pivmin)) / log(2.)
384 F77_FUNC(slaebz,SLAEBZ)(&c__2, &itmax, &in, &in, &c__1, &nb, &atoli, &rtoli, &
385 pivmin, &d__[ibegin], &e[ibegin], &work[ibegin], idumma, &
386 work[*n + 1], &work[*n + (in << 1) + 1], &iout, &iwork[1],
387 &w[*m + 1], &iblock[*m + 1], &iinfo);
390 for (j = 1; j <= i__2; ++j) {
391 tmp1 = (work[j + *n] + work[j + in + *n]) * .5;
393 if (j > iout - iinfo) {
399 i__3 = iwork[j + in] + iwoff;
400 for (je = iwork[j] + 1 + iwoff; je <= i__3; ++je) {
412 idiscl = *il - 1 - nwl;
415 if (idiscl > 0 || idiscu > 0) {
417 for (je = 1; je <= i__1; ++je) {
418 if (w[je] <= wlu && idiscl > 0) {
420 } else if (w[je] >= wul && idiscu > 0) {
425 iblock[im] = iblock[je];
430 if (idiscl > 0 || idiscu > 0) {
435 for (jdisc = 1; jdisc <= i__1; ++jdisc) {
438 for (je = 1; je <= i__2; ++je) {
439 if (iblock[je] != 0 && (w[je] < wkill || iw == 0)) {
451 for (jdisc = 1; jdisc <= i__1; ++jdisc) {
454 for (je = 1; je <= i__2; ++je) {
455 if (iblock[je] != 0 && (w[je] > wkill || iw == 0)) {
465 for (je = 1; je <= i__1; ++je) {
466 if (iblock[je] != 0) {
469 iblock[im] = iblock[je];
474 if (idiscl < 0 || idiscu < 0) {
479 if (iorder == 1 && *nsplit > 1) {
481 for (je = 1; je <= i__1; ++je) {
485 for (j = je + 1; j <= i__2; ++j) {
495 iblock[ie] = iblock[je];