3 /* Subroutine */ int dlaebz_(integer *ijob, integer *nitmax, integer *n,
4 integer *mmax, integer *minp, integer *nbmin, doublereal *abstol,
5 doublereal *reltol, doublereal *pivmin, doublereal *d__, doublereal *
6 e, doublereal *e2, integer *nval, doublereal *ab, doublereal *c__,
7 integer *mout, integer *nab, doublereal *work, integer *iwork,
10 /* System generated locals */
11 integer nab_dim1, nab_offset, ab_dim1, ab_offset, i__1, i__2, i__3, i__4,
13 doublereal d__1, d__2, d__3, d__4;
16 integer j, kf, ji, kl, jp, jit;
17 doublereal tmp1, tmp2;
18 integer itmp1, itmp2, kfnew, klnew;
21 /* -- LAPACK auxiliary routine (version 3.1) -- */
22 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
25 /* .. Scalar Arguments .. */
27 /* .. Array Arguments .. */
33 /* DLAEBZ contains the iteration loops which compute and use the */
34 /* function N(w), which is the count of eigenvalues of a symmetric */
35 /* tridiagonal matrix T less than or equal to its argument w. It */
36 /* performs a choice of two types of loops: */
38 /* IJOB=1, followed by */
39 /* IJOB=2: It takes as input a list of intervals and returns a list of */
40 /* sufficiently small intervals whose union contains the same */
41 /* eigenvalues as the union of the original intervals. */
42 /* The input intervals are (AB(j,1),AB(j,2)], j=1,...,MINP. */
43 /* The output interval (AB(j,1),AB(j,2)] will contain */
44 /* eigenvalues NAB(j,1)+1,...,NAB(j,2), where 1 <= j <= MOUT. */
46 /* IJOB=3: It performs a binary search in each input interval */
47 /* (AB(j,1),AB(j,2)] for a point w(j) such that */
48 /* N(w(j))=NVAL(j), and uses C(j) as the starting point of */
49 /* the search. If such a w(j) is found, then on output */
50 /* AB(j,1)=AB(j,2)=w. If no such w(j) is found, then on output */
51 /* (AB(j,1),AB(j,2)] will be a small interval containing the */
52 /* point where N(w) jumps through NVAL(j), unless that point */
53 /* lies outside the initial interval. */
55 /* Note that the intervals are in all cases half-open intervals, */
56 /* i.e., of the form (a,b] , which includes b but not a . */
58 /* To avoid underflow, the matrix should be scaled so that its largest */
59 /* element is no greater than overflow**(1/2) * underflow**(1/4) */
60 /* in absolute value. To assure the most accurate computation */
61 /* of small eigenvalues, the matrix should be scaled to be */
62 /* not much smaller than that, either. */
64 /* See W. Kahan "Accurate Eigenvalues of a Symmetric Tridiagonal */
65 /* Matrix", Report CS41, Computer Science Dept., Stanford */
66 /* University, July 21, 1966 */
68 /* Note: the arguments are, in general, *not* checked for unreasonable */
74 /* IJOB (input) INTEGER */
75 /* Specifies what is to be done: */
76 /* = 1: Compute NAB for the initial intervals. */
77 /* = 2: Perform bisection iteration to find eigenvalues of T. */
78 /* = 3: Perform bisection iteration to invert N(w), i.e., */
79 /* to find a point which has a specified number of */
80 /* eigenvalues of T to its left. */
81 /* Other values will cause DLAEBZ to return with INFO=-1. */
83 /* NITMAX (input) INTEGER */
84 /* The maximum number of "levels" of bisection to be */
85 /* performed, i.e., an interval of width W will not be made */
86 /* smaller than 2^(-NITMAX) * W. If not all intervals */
87 /* have converged after NITMAX iterations, then INFO is set */
88 /* to the number of non-converged intervals. */
90 /* N (input) INTEGER */
91 /* The dimension n of the tridiagonal matrix T. It must be at */
94 /* MMAX (input) INTEGER */
95 /* The maximum number of intervals. If more than MMAX intervals */
96 /* are generated, then DLAEBZ will quit with INFO=MMAX+1. */
98 /* MINP (input) INTEGER */
99 /* The initial number of intervals. It may not be greater than */
102 /* NBMIN (input) INTEGER */
103 /* The smallest number of intervals that should be processed */
104 /* using a vector loop. If zero, then only the scalar loop */
107 /* ABSTOL (input) DOUBLE PRECISION */
108 /* The minimum (absolute) width of an interval. When an */
109 /* interval is narrower than ABSTOL, or than RELTOL times the */
110 /* larger (in magnitude) endpoint, then it is considered to be */
111 /* sufficiently small, i.e., converged. This must be at least */
114 /* RELTOL (input) DOUBLE PRECISION */
115 /* The minimum relative width of an interval. When an interval */
116 /* is narrower than ABSTOL, or than RELTOL times the larger (in */
117 /* magnitude) endpoint, then it is considered to be */
118 /* sufficiently small, i.e., converged. Note: this should */
119 /* always be at least radix*machine epsilon. */
121 /* PIVMIN (input) DOUBLE PRECISION */
122 /* The minimum absolute value of a "pivot" in the Sturm */
123 /* sequence loop. This *must* be at least max |e(j)**2| * */
124 /* safe_min and at least safe_min, where safe_min is at least */
125 /* the smallest number that can divide one without overflow. */
127 /* D (input) DOUBLE PRECISION array, dimension (N) */
128 /* The diagonal elements of the tridiagonal matrix T. */
130 /* E (input) DOUBLE PRECISION array, dimension (N) */
131 /* The offdiagonal elements of the tridiagonal matrix T in */
132 /* positions 1 through N-1. E(N) is arbitrary. */
134 /* E2 (input) DOUBLE PRECISION array, dimension (N) */
135 /* The squares of the offdiagonal elements of the tridiagonal */
136 /* matrix T. E2(N) is ignored. */
138 /* NVAL (input/output) INTEGER array, dimension (MINP) */
139 /* If IJOB=1 or 2, not referenced. */
140 /* If IJOB=3, the desired values of N(w). The elements of NVAL */
141 /* will be reordered to correspond with the intervals in AB. */
142 /* Thus, NVAL(j) on output will not, in general be the same as */
143 /* NVAL(j) on input, but it will correspond with the interval */
144 /* (AB(j,1),AB(j,2)] on output. */
146 /* AB (input/output) DOUBLE PRECISION array, dimension (MMAX,2) */
147 /* The endpoints of the intervals. AB(j,1) is a(j), the left */
148 /* endpoint of the j-th interval, and AB(j,2) is b(j), the */
149 /* right endpoint of the j-th interval. The input intervals */
150 /* will, in general, be modified, split, and reordered by the */
153 /* C (input/output) DOUBLE PRECISION array, dimension (MMAX) */
154 /* If IJOB=1, ignored. */
155 /* If IJOB=2, workspace. */
156 /* If IJOB=3, then on input C(j) should be initialized to the */
157 /* first search point in the binary search. */
159 /* MOUT (output) INTEGER */
160 /* If IJOB=1, the number of eigenvalues in the intervals. */
161 /* If IJOB=2 or 3, the number of intervals output. */
162 /* If IJOB=3, MOUT will equal MINP. */
164 /* NAB (input/output) INTEGER array, dimension (MMAX,2) */
165 /* If IJOB=1, then on output NAB(i,j) will be set to N(AB(i,j)). */
166 /* If IJOB=2, then on input, NAB(i,j) should be set. It must */
167 /* satisfy the condition: */
168 /* N(AB(i,1)) <= NAB(i,1) <= NAB(i,2) <= N(AB(i,2)), */
169 /* which means that in interval i only eigenvalues */
170 /* NAB(i,1)+1,...,NAB(i,2) will be considered. Usually, */
171 /* NAB(i,j)=N(AB(i,j)), from a previous call to DLAEBZ with */
173 /* On output, NAB(i,j) will contain */
174 /* max(na(k),min(nb(k),N(AB(i,j)))), where k is the index of */
175 /* the input interval that the output interval */
176 /* (AB(j,1),AB(j,2)] came from, and na(k) and nb(k) are the */
177 /* the input values of NAB(k,1) and NAB(k,2). */
178 /* If IJOB=3, then on output, NAB(i,j) contains N(AB(i,j)), */
179 /* unless N(w) > NVAL(i) for all search points w , in which */
180 /* case NAB(i,1) will not be modified, i.e., the output */
181 /* value will be the same as the input value (modulo */
182 /* reorderings -- see NVAL and AB), or unless N(w) < NVAL(i) */
183 /* for all search points w , in which case NAB(i,2) will */
184 /* not be modified. Normally, NAB should be set to some */
185 /* distinctive value(s) before DLAEBZ is called. */
187 /* WORK (workspace) DOUBLE PRECISION array, dimension (MMAX) */
190 /* IWORK (workspace) INTEGER array, dimension (MMAX) */
193 /* INFO (output) INTEGER */
194 /* = 0: All intervals converged. */
195 /* = 1--MMAX: The last INFO intervals did not converge. */
196 /* = MMAX+1: More than MMAX intervals were generated. */
198 /* Further Details */
199 /* =============== */
201 /* This routine is intended to be called only by other LAPACK */
202 /* routines, thus the interface is less user-friendly. It is intended */
203 /* for two purposes: */
205 /* (a) finding eigenvalues. In this case, DLAEBZ should have one or */
206 /* more initial intervals set up in AB, and DLAEBZ should be called */
207 /* with IJOB=1. This sets up NAB, and also counts the eigenvalues. */
208 /* Intervals with no eigenvalues would usually be thrown out at */
209 /* this point. Also, if not all the eigenvalues in an interval i */
210 /* are desired, NAB(i,1) can be increased or NAB(i,2) decreased. */
211 /* For example, set NAB(i,1)=NAB(i,2)-1 to get the largest */
212 /* eigenvalue. DLAEBZ is then called with IJOB=2 and MMAX */
213 /* no smaller than the value of MOUT returned by the call with */
214 /* IJOB=1. After this (IJOB=2) call, eigenvalues NAB(i,1)+1 */
215 /* through NAB(i,2) are approximately AB(i,1) (or AB(i,2)) to the */
216 /* tolerance specified by ABSTOL and RELTOL. */
218 /* (b) finding an interval (a',b'] containing eigenvalues w(f),...,w(l). */
219 /* In this case, start with a Gershgorin interval (a,b). Set up */
220 /* AB to contain 2 search intervals, both initially (a,b). One */
221 /* NVAL element should contain f-1 and the other should contain l */
222 /* , while C should contain a and b, resp. NAB(i,1) should be -1 */
223 /* and NAB(i,2) should be N+1, to flag an error if the desired */
224 /* interval does not lie in (a,b). DLAEBZ is then called with */
225 /* IJOB=3. On exit, if w(f-1) < w(f), then one of the intervals -- */
226 /* j -- will have AB(j,1)=AB(j,2) and NAB(j,1)=NAB(j,2)=f-1, while */
227 /* if, to the specified tolerance, w(f-k)=...=w(f+r), k > 0 and r */
228 /* >= 0, then the interval will have N(AB(j,1))=NAB(j,1)=f-k and */
229 /* N(AB(j,2))=NAB(j,2)=f+r. The cases w(l) < w(l+1) and */
230 /* w(l-r)=...=w(l+k) are handled similarly. */
232 /* ===================================================================== */
234 /* .. Parameters .. */
236 /* .. Local Scalars .. */
238 /* .. Intrinsic Functions .. */
240 /* .. Executable Statements .. */
242 /* Check for Errors */
244 /* Parameter adjustments */
246 nab_offset = 1 + nab_dim1;
249 ab_offset = 1 + ab_dim1;
261 if (*ijob < 1 || *ijob > 3) {
270 /* Compute the number of eigenvalues in the initial intervals. */
275 for (ji = 1; ji <= i__1; ++ji) {
276 for (jp = 1; jp <= 2; ++jp) {
277 tmp1 = d__[1] - ab[ji + jp * ab_dim1];
278 if (abs(tmp1) < *pivmin) {
281 nab[ji + jp * nab_dim1] = 0;
283 nab[ji + jp * nab_dim1] = 1;
287 for (j = 2; j <= i__2; ++j) {
288 tmp1 = d__[j] - e2[j - 1] / tmp1 - ab[ji + jp * ab_dim1];
289 if (abs(tmp1) < *pivmin) {
293 ++nab[ji + jp * nab_dim1];
299 *mout = *mout + nab[ji + (nab_dim1 << 1)] - nab[ji + nab_dim1];
305 /* Initialize for loop */
307 /* KF and KL have the following meaning: */
308 /* Intervals 1,...,KF-1 have converged. */
309 /* Intervals KF,...,KL still need to be refined. */
314 /* If IJOB=2, initialize C. */
315 /* If IJOB=3, use the user-supplied starting point. */
319 for (ji = 1; ji <= i__1; ++ji) {
320 c__[ji] = (ab[ji + ab_dim1] + ab[ji + (ab_dim1 << 1)]) * .5;
328 for (jit = 1; jit <= i__1; ++jit) {
330 /* Loop over intervals */
332 if (kl - kf + 1 >= *nbmin && *nbmin > 0) {
334 /* Begin of Parallel Version of the loop */
337 for (ji = kf; ji <= i__2; ++ji) {
339 /* Compute N(c), the number of eigenvalues less than c */
341 work[ji] = d__[1] - c__[ji];
343 if (work[ji] <= *pivmin) {
346 d__1 = work[ji], d__2 = -(*pivmin);
347 work[ji] = min(d__1,d__2);
351 for (j = 2; j <= i__3; ++j) {
352 work[ji] = d__[j] - e2[j - 1] / work[ji] - c__[ji];
353 if (work[ji] <= *pivmin) {
356 d__1 = work[ji], d__2 = -(*pivmin);
357 work[ji] = min(d__1,d__2);
366 /* IJOB=2: Choose all intervals containing eigenvalues. */
370 for (ji = kf; ji <= i__2; ++ji) {
372 /* Insure that N(w) is monotone */
376 i__5 = nab[ji + nab_dim1], i__6 = iwork[ji];
377 i__3 = nab[ji + (nab_dim1 << 1)], i__4 = max(i__5,i__6);
378 iwork[ji] = min(i__3,i__4);
380 /* Update the Queue -- add intervals if both halves */
381 /* contain eigenvalues. */
383 if (iwork[ji] == nab[ji + (nab_dim1 << 1)]) {
385 /* No eigenvalue in the upper interval: */
386 /* just use the lower interval. */
388 ab[ji + (ab_dim1 << 1)] = c__[ji];
390 } else if (iwork[ji] == nab[ji + nab_dim1]) {
392 /* No eigenvalue in the lower interval: */
393 /* just use the upper interval. */
395 ab[ji + ab_dim1] = c__[ji];
398 if (klnew <= *mmax) {
400 /* Eigenvalue in both intervals -- add upper to */
403 ab[klnew + (ab_dim1 << 1)] = ab[ji + (ab_dim1 <<
405 nab[klnew + (nab_dim1 << 1)] = nab[ji + (nab_dim1
407 ab[klnew + ab_dim1] = c__[ji];
408 nab[klnew + nab_dim1] = iwork[ji];
409 ab[ji + (ab_dim1 << 1)] = c__[ji];
410 nab[ji + (nab_dim1 << 1)] = iwork[ji];
423 /* IJOB=3: Binary search. Keep only the interval containing */
424 /* w s.t. N(w) = NVAL */
427 for (ji = kf; ji <= i__2; ++ji) {
428 if (iwork[ji] <= nval[ji]) {
429 ab[ji + ab_dim1] = c__[ji];
430 nab[ji + nab_dim1] = iwork[ji];
432 if (iwork[ji] >= nval[ji]) {
433 ab[ji + (ab_dim1 << 1)] = c__[ji];
434 nab[ji + (nab_dim1 << 1)] = iwork[ji];
442 /* End of Parallel Version of the loop */
444 /* Begin of Serial Version of the loop */
448 for (ji = kf; ji <= i__2; ++ji) {
450 /* Compute N(w), the number of eigenvalues less than w */
453 tmp2 = d__[1] - tmp1;
455 if (tmp2 <= *pivmin) {
458 d__1 = tmp2, d__2 = -(*pivmin);
459 tmp2 = min(d__1,d__2);
462 /* A series of compiler directives to defeat vectorization */
463 /* for the next loop */
465 /* $PL$ CMCHAR=' ' */
466 /* DIR$ NEXTSCALAR */
468 /* DIR$ NEXT SCALAR */
473 /* VOCL LOOP,SCALAR */
474 /* IBM PREFER SCALAR */
475 /* $PL$ CMCHAR='*' */
478 for (j = 2; j <= i__3; ++j) {
479 tmp2 = d__[j] - e2[j - 1] / tmp2 - tmp1;
480 if (tmp2 <= *pivmin) {
483 d__1 = tmp2, d__2 = -(*pivmin);
484 tmp2 = min(d__1,d__2);
491 /* IJOB=2: Choose all intervals containing eigenvalues. */
493 /* Insure that N(w) is monotone */
497 i__5 = nab[ji + nab_dim1];
498 i__3 = nab[ji + (nab_dim1 << 1)], i__4 = max(i__5,itmp1);
499 itmp1 = min(i__3,i__4);
501 /* Update the Queue -- add intervals if both halves */
502 /* contain eigenvalues. */
504 if (itmp1 == nab[ji + (nab_dim1 << 1)]) {
506 /* No eigenvalue in the upper interval: */
507 /* just use the lower interval. */
509 ab[ji + (ab_dim1 << 1)] = tmp1;
511 } else if (itmp1 == nab[ji + nab_dim1]) {
513 /* No eigenvalue in the lower interval: */
514 /* just use the upper interval. */
516 ab[ji + ab_dim1] = tmp1;
517 } else if (klnew < *mmax) {
519 /* Eigenvalue in both intervals -- add upper to queue. */
522 ab[klnew + (ab_dim1 << 1)] = ab[ji + (ab_dim1 << 1)];
523 nab[klnew + (nab_dim1 << 1)] = nab[ji + (nab_dim1 <<
525 ab[klnew + ab_dim1] = tmp1;
526 nab[klnew + nab_dim1] = itmp1;
527 ab[ji + (ab_dim1 << 1)] = tmp1;
528 nab[ji + (nab_dim1 << 1)] = itmp1;
535 /* IJOB=3: Binary search. Keep only the interval */
536 /* containing w s.t. N(w) = NVAL */
538 if (itmp1 <= nval[ji]) {
539 ab[ji + ab_dim1] = tmp1;
540 nab[ji + nab_dim1] = itmp1;
542 if (itmp1 >= nval[ji]) {
543 ab[ji + (ab_dim1 << 1)] = tmp1;
544 nab[ji + (nab_dim1 << 1)] = itmp1;
551 /* End of Serial Version of the loop */
555 /* Check for convergence */
559 for (ji = kf; ji <= i__2; ++ji) {
560 tmp1 = (d__1 = ab[ji + (ab_dim1 << 1)] - ab[ji + ab_dim1], abs(
563 d__3 = (d__1 = ab[ji + (ab_dim1 << 1)], abs(d__1)), d__4 = (d__2 =
564 ab[ji + ab_dim1], abs(d__2));
565 tmp2 = max(d__3,d__4);
567 d__1 = max(*abstol,*pivmin), d__2 = *reltol * tmp2;
568 if (tmp1 < max(d__1,d__2) || nab[ji + nab_dim1] >= nab[ji + (
571 /* Converged -- Swap with position KFNEW, */
572 /* then increment KFNEW */
575 tmp1 = ab[ji + ab_dim1];
576 tmp2 = ab[ji + (ab_dim1 << 1)];
577 itmp1 = nab[ji + nab_dim1];
578 itmp2 = nab[ji + (nab_dim1 << 1)];
579 ab[ji + ab_dim1] = ab[kfnew + ab_dim1];
580 ab[ji + (ab_dim1 << 1)] = ab[kfnew + (ab_dim1 << 1)];
581 nab[ji + nab_dim1] = nab[kfnew + nab_dim1];
582 nab[ji + (nab_dim1 << 1)] = nab[kfnew + (nab_dim1 << 1)];
583 ab[kfnew + ab_dim1] = tmp1;
584 ab[kfnew + (ab_dim1 << 1)] = tmp2;
585 nab[kfnew + nab_dim1] = itmp1;
586 nab[kfnew + (nab_dim1 << 1)] = itmp2;
589 nval[ji] = nval[kfnew];
599 /* Choose Midpoints */
602 for (ji = kf; ji <= i__2; ++ji) {
603 c__[ji] = (ab[ji + ab_dim1] + ab[ji + (ab_dim1 << 1)]) * .5;
607 /* If no more intervals to refine, quit. */