001:       SUBROUTINE DLARRJ( N, D, E2, IFIRST, ILAST,
002:      $                   RTOL, OFFSET, W, WERR, WORK, IWORK,
003:      $                   PIVMIN, SPDIAM, INFO )
004: *
005: *  -- LAPACK auxiliary routine (version 3.2) --
006: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       INTEGER            IFIRST, ILAST, INFO, N, OFFSET
011:       DOUBLE PRECISION   PIVMIN, RTOL, SPDIAM
012: *     ..
013: *     .. Array Arguments ..
014:       INTEGER            IWORK( * )
015:       DOUBLE PRECISION   D( * ), E2( * ), W( * ),
016:      $                   WERR( * ), WORK( * )
017: *     ..
018: *
019: *  Purpose
020: *  =======
021: *
022: *  Given the initial eigenvalue approximations of T, DLARRJ
023: *  does  bisection to refine the eigenvalues of T,
024: *  W( IFIRST-OFFSET ) through W( ILAST-OFFSET ), to more accuracy. Initial
025: *  guesses for these eigenvalues are input in W, the corresponding estimate
026: *  of the error in these guesses in WERR. During bisection, intervals
027: *  [left, right] are maintained by storing their mid-points and
028: *  semi-widths in the arrays W and WERR respectively.
029: *
030: *  Arguments
031: *  =========
032: *
033: *  N       (input) INTEGER
034: *          The order of the matrix.
035: *
036: *  D       (input) DOUBLE PRECISION array, dimension (N)
037: *          The N diagonal elements of T.
038: *
039: *  E2      (input) DOUBLE PRECISION array, dimension (N-1)
040: *          The Squares of the (N-1) subdiagonal elements of T.
041: *
042: *  IFIRST  (input) INTEGER
043: *          The index of the first eigenvalue to be computed.
044: *
045: *  ILAST   (input) INTEGER
046: *          The index of the last eigenvalue to be computed.
047: *
048: *  RTOL   (input) DOUBLE PRECISION
049: *          Tolerance for the convergence of the bisection intervals.
050: *          An interval [LEFT,RIGHT] has converged if
051: *          RIGHT-LEFT.LT.RTOL*MAX(|LEFT|,|RIGHT|).
052: *
053: *  OFFSET  (input) INTEGER
054: *          Offset for the arrays W and WERR, i.e., the IFIRST-OFFSET
055: *          through ILAST-OFFSET elements of these arrays are to be used.
056: *
057: *  W       (input/output) DOUBLE PRECISION array, dimension (N)
058: *          On input, W( IFIRST-OFFSET ) through W( ILAST-OFFSET ) are
059: *          estimates of the eigenvalues of L D L^T indexed IFIRST through
060: *          ILAST.
061: *          On output, these estimates are refined.
062: *
063: *  WERR    (input/output) DOUBLE PRECISION array, dimension (N)
064: *          On input, WERR( IFIRST-OFFSET ) through WERR( ILAST-OFFSET ) are
065: *          the errors in the estimates of the corresponding elements in W.
066: *          On output, these errors are refined.
067: *
068: *  WORK    (workspace) DOUBLE PRECISION array, dimension (2*N)
069: *          Workspace.
070: *
071: *  IWORK   (workspace) INTEGER array, dimension (2*N)
072: *          Workspace.
073: *
074: *  PIVMIN  (input) DOUBLE PRECISION
075: *          The minimum pivot in the Sturm sequence for T.
076: *
077: *  SPDIAM  (input) DOUBLE PRECISION
078: *          The spectral diameter of T.
079: *
080: *  INFO    (output) INTEGER
081: *          Error flag.
082: *
083: *  Further Details
084: *  ===============
085: *
086: *  Based on contributions by
087: *     Beresford Parlett, University of California, Berkeley, USA
088: *     Jim Demmel, University of California, Berkeley, USA
089: *     Inderjit Dhillon, University of Texas, Austin, USA
090: *     Osni Marques, LBNL/NERSC, USA
091: *     Christof Voemel, University of California, Berkeley, USA
092: *
093: *  =====================================================================
094: *
095: *     .. Parameters ..
096:       DOUBLE PRECISION   ZERO, ONE, TWO, HALF
097:       PARAMETER        ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
098:      $                   HALF = 0.5D0 )
099:       INTEGER   MAXITR
100: *     ..
101: *     .. Local Scalars ..
102:       INTEGER            CNT, I, I1, I2, II, ITER, J, K, NEXT, NINT,
103:      $                   OLNINT, P, PREV, SAVI1
104:       DOUBLE PRECISION   DPLUS, FAC, LEFT, MID, RIGHT, S, TMP, WIDTH
105: *
106: *     ..
107: *     .. Intrinsic Functions ..
108:       INTRINSIC          ABS, MAX
109: *     ..
110: *     .. Executable Statements ..
111: *
112:       INFO = 0
113: *
114:       MAXITR = INT( ( LOG( SPDIAM+PIVMIN )-LOG( PIVMIN ) ) /
115:      $           LOG( TWO ) ) + 2
116: *
117: *     Initialize unconverged intervals in [ WORK(2*I-1), WORK(2*I) ].
118: *     The Sturm Count, Count( WORK(2*I-1) ) is arranged to be I-1, while
119: *     Count( WORK(2*I) ) is stored in IWORK( 2*I ). The integer IWORK( 2*I-1 )
120: *     for an unconverged interval is set to the index of the next unconverged
121: *     interval, and is -1 or 0 for a converged interval. Thus a linked
122: *     list of unconverged intervals is set up.
123: *
124: 
125:       I1 = IFIRST
126:       I2 = ILAST
127: *     The number of unconverged intervals
128:       NINT = 0
129: *     The last unconverged interval found
130:       PREV = 0
131:       DO 75 I = I1, I2
132:          K = 2*I
133:          II = I - OFFSET
134:          LEFT = W( II ) - WERR( II )
135:          MID = W(II)
136:          RIGHT = W( II ) + WERR( II )
137:          WIDTH = RIGHT - MID
138:          TMP = MAX( ABS( LEFT ), ABS( RIGHT ) )
139: 
140: *        The following test prevents the test of converged intervals
141:          IF( WIDTH.LT.RTOL*TMP ) THEN
142: *           This interval has already converged and does not need refinement.
143: *           (Note that the gaps might change through refining the
144: *            eigenvalues, however, they can only get bigger.)
145: *           Remove it from the list.
146:             IWORK( K-1 ) = -1
147: *           Make sure that I1 always points to the first unconverged interval
148:             IF((I.EQ.I1).AND.(I.LT.I2)) I1 = I + 1
149:             IF((PREV.GE.I1).AND.(I.LE.I2)) IWORK( 2*PREV-1 ) = I + 1
150:          ELSE
151: *           unconverged interval found
152:             PREV = I
153: *           Make sure that [LEFT,RIGHT] contains the desired eigenvalue
154: *
155: *           Do while( CNT(LEFT).GT.I-1 )
156: *
157:             FAC = ONE
158:  20         CONTINUE
159:             CNT = 0
160:             S = LEFT
161:             DPLUS = D( 1 ) - S
162:             IF( DPLUS.LT.ZERO ) CNT = CNT + 1
163:             DO 30 J = 2, N
164:                DPLUS = D( J ) - S - E2( J-1 )/DPLUS
165:                IF( DPLUS.LT.ZERO ) CNT = CNT + 1
166:  30         CONTINUE
167:             IF( CNT.GT.I-1 ) THEN
168:                LEFT = LEFT - WERR( II )*FAC
169:                FAC = TWO*FAC
170:                GO TO 20
171:             END IF
172: *
173: *           Do while( CNT(RIGHT).LT.I )
174: *
175:             FAC = ONE
176:  50         CONTINUE
177:             CNT = 0
178:             S = RIGHT
179:             DPLUS = D( 1 ) - S
180:             IF( DPLUS.LT.ZERO ) CNT = CNT + 1
181:             DO 60 J = 2, N
182:                DPLUS = D( J ) - S - E2( J-1 )/DPLUS
183:                IF( DPLUS.LT.ZERO ) CNT = CNT + 1
184:  60         CONTINUE
185:             IF( CNT.LT.I ) THEN
186:                RIGHT = RIGHT + WERR( II )*FAC
187:                FAC = TWO*FAC
188:                GO TO 50
189:             END IF
190:             NINT = NINT + 1
191:             IWORK( K-1 ) = I + 1
192:             IWORK( K ) = CNT
193:          END IF
194:          WORK( K-1 ) = LEFT
195:          WORK( K ) = RIGHT
196:  75   CONTINUE
197: 
198: 
199:       SAVI1 = I1
200: *
201: *     Do while( NINT.GT.0 ), i.e. there are still unconverged intervals
202: *     and while (ITER.LT.MAXITR)
203: *
204:       ITER = 0
205:  80   CONTINUE
206:       PREV = I1 - 1
207:       I = I1
208:       OLNINT = NINT
209: 
210:       DO 100 P = 1, OLNINT
211:          K = 2*I
212:          II = I - OFFSET
213:          NEXT = IWORK( K-1 )
214:          LEFT = WORK( K-1 )
215:          RIGHT = WORK( K )
216:          MID = HALF*( LEFT + RIGHT )
217: 
218: *        semiwidth of interval
219:          WIDTH = RIGHT - MID
220:          TMP = MAX( ABS( LEFT ), ABS( RIGHT ) )
221: 
222:          IF( ( WIDTH.LT.RTOL*TMP ) .OR.
223:      $      (ITER.EQ.MAXITR) )THEN
224: *           reduce number of unconverged intervals
225:             NINT = NINT - 1
226: *           Mark interval as converged.
227:             IWORK( K-1 ) = 0
228:             IF( I1.EQ.I ) THEN
229:                I1 = NEXT
230:             ELSE
231: *              Prev holds the last unconverged interval previously examined
232:                IF(PREV.GE.I1) IWORK( 2*PREV-1 ) = NEXT
233:             END IF
234:             I = NEXT
235:             GO TO 100
236:          END IF
237:          PREV = I
238: *
239: *        Perform one bisection step
240: *
241:          CNT = 0
242:          S = MID
243:          DPLUS = D( 1 ) - S
244:          IF( DPLUS.LT.ZERO ) CNT = CNT + 1
245:          DO 90 J = 2, N
246:             DPLUS = D( J ) - S - E2( J-1 )/DPLUS
247:             IF( DPLUS.LT.ZERO ) CNT = CNT + 1
248:  90      CONTINUE
249:          IF( CNT.LE.I-1 ) THEN
250:             WORK( K-1 ) = MID
251:          ELSE
252:             WORK( K ) = MID
253:          END IF
254:          I = NEXT
255: 
256:  100  CONTINUE
257:       ITER = ITER + 1
258: *     do another loop if there are still unconverged intervals
259: *     However, in the last iteration, all intervals are accepted
260: *     since this is the best we can do.
261:       IF( ( NINT.GT.0 ).AND.(ITER.LE.MAXITR) ) GO TO 80
262: *
263: *
264: *     At this point, all the intervals have converged
265:       DO 110 I = SAVI1, ILAST
266:          K = 2*I
267:          II = I - OFFSET
268: *        All intervals marked by '0' have been refined.
269:          IF( IWORK( K-1 ).EQ.0 ) THEN
270:             W( II ) = HALF*( WORK( K-1 )+WORK( K ) )
271:             WERR( II ) = WORK( K ) - W( II )
272:          END IF
273:  110  CONTINUE
274: *
275: 
276:       RETURN
277: *
278: *     End of DLARRJ
279: *
280:       END
281: