1DLAQR5(1) LAPACK auxiliary routine (version 3.2) DLAQR5(1)
2
3
4
7 SUBROUTINE DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS, SR, SI,
8 H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U, LDU, NV, WV,
9 LDWV, NH, WH, LDWH )
10
11 INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV, LDWH,
12 LDWV, LDZ, N, NH, NSHFTS, NV
13
14 LOGICAL WANTT, WANTZ
15
16 DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), U( LDU, *
17 ), V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ), Z(
18 LDZ, * )
19
20 DOUBLE PRECISION ZERO, ONE
21
22 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
23
24 DOUBLE PRECISION ALPHA, BETA, H11, H12, H21, H22, REFSUM,
25 SAFMAX, SAFMIN, SCL, SMLNUM, SWAP, TST1, TST2, ULP
26
27 INTEGER I, I2, I4, INCOL, J, J2, J4, JBOT, JCOL, JLEN, JROW,
28 JTOP, K, K1, KDU, KMS, KNZ, KRCOL, KZS, M, M22,
29 MBOT, MEND, MSTART, MTOP, NBMPS, NDCOL, NS, NU
30
31 LOGICAL ACCUM, BLK22, BMP22
32
33 DOUBLE PRECISION DLAMCH
34
35 EXTERNAL DLAMCH
36
37 INTRINSIC ABS, DBLE, MAX, MIN, MOD
38
39 DOUBLE PRECISION VT( 3 )
40
41 EXTERNAL DGEMM, DLABAD, DLACPY, DLAQR1, DLARFG, DLASET, DTRMM
42
43 IF( NSHFTS.LT.2 ) RETURN
44
45 IF( KTOP.GE.KBOT ) RETURN
46
47 DO 10 I = 1, NSHFTS - 2, 2
48
49 IF( SI( I ).NE.-SI( I+1 ) ) THEN
50
51 SWAP = SR( I )
52
53 SR( I ) = SR( I+1 )
54
55 SR( I+1 ) = SR( I+2 )
56
57 SR( I+2 ) = SWAP
58
59 SWAP = SI( I )
60
61 SI( I ) = SI( I+1 )
62
63 SI( I+1 ) = SI( I+2 )
64
65 SI( I+2 ) = SWAP
66
67 END IF
68
69 10 CONTINUE
70
71 NS = NSHFTS - MOD( NSHFTS, 2 )
72
73 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
74
75 SAFMAX = ONE / SAFMIN
76
77 CALL DLABAD( SAFMIN, SAFMAX )
78
79 ULP = DLAMCH( 'PRECISION' )
80
81 SMLNUM = SAFMIN*( DBLE( N ) / ULP )
82
83 ACCUM = ( KACC22.EQ.1 ) .OR. ( KACC22.EQ.2 )
84
85 BLK22 = ( NS.GT.2 ) .AND. ( KACC22.EQ.2 )
86
87 IF( KTOP+2.LE.KBOT ) H( KTOP+2, KTOP ) = ZERO
88
89 NBMPS = NS / 2
90
91 KDU = 6*NBMPS - 3
92
93 DO 220 INCOL = 3*( 1-NBMPS ) + KTOP - 1, KBOT - 2,
94 3*NBMPS - 2
95
96 NDCOL = INCOL + KDU
97
98 IF( ACCUM ) CALL DLASET( 'ALL', KDU, KDU, ZERO, ONE, U,
99 LDU )
100
101 DO 150 KRCOL = INCOL, MIN( INCOL+3*NBMPS-3, KBOT-2 )
102
103 MTOP = MAX( 1, ( ( KTOP-1 )-KRCOL+2 ) / 3+1 )
104
105 MBOT = MIN( NBMPS, ( KBOT-KRCOL ) / 3 )
106
107 M22 = MBOT + 1
108
109 BMP22 = ( MBOT.LT.NBMPS ) .AND. ( KRCOL+3*( M22-1 ) ).EQ.
110 ( KBOT-2 )
111
112 DO 20 M = MTOP, MBOT
113
114 K = KRCOL + 3*( M-1 )
115
116 IF( K.EQ.KTOP-1 ) THEN
117
118 CALL DLAQR1( 3, H( KTOP, KTOP ), LDH, SR( 2*M-1 ), SI(
119 2*M-1 ), SR( 2*M ), SI( 2*M ), V( 1, M ) )
120
121 ALPHA = V( 1, M )
122
123 CALL DLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
124
125 ELSE
126
127 BETA = H( K+1, K )
128
129 V( 2, M ) = H( K+2, K )
130
131 V( 3, M ) = H( K+3, K )
132
133 CALL DLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
134
135 IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE. ZERO
136 .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
137
138 H( K+1, K ) = BETA
139
140 H( K+2, K ) = ZERO
141
142 H( K+3, K ) = ZERO
143
144 ELSE
145
146 CALL DLAQR1( 3, H( K+1, K+1 ), LDH, SR( 2*M-1 ), SI(
147 2*M-1 ), SR( 2*M ), SI( 2*M ), VT )
148
149 ALPHA = VT( 1 )
150
151 CALL DLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
152
153 REFSUM = VT( 1 )*( H( K+1, K )+VT( 2 )* H( K+2, K ) )
154
155 IF( ABS( H( K+2, K )-REFSUM*VT( 2 ) )+ ABS( REFSUM*VT( 3
156 ) ).GT.ULP* ( ABS( H( K, K ) )+ABS( H( K+1, K+1 )
157 )+ABS( H( K+2, K+2 ) ) ) ) THEN
158
159 H( K+1, K ) = BETA
160
161 H( K+2, K ) = ZERO
162
163 H( K+3, K ) = ZERO
164
165 ELSE
166
167 H( K+1, K ) = H( K+1, K ) - REFSUM
168
169 H( K+2, K ) = ZERO
170
171 H( K+3, K ) = ZERO
172
173 V( 1, M ) = VT( 1 )
174
175 V( 2, M ) = VT( 2 )
176
177 V( 3, M ) = VT( 3 )
178
179 END IF
180
181 END IF
182
183 END IF
184
185 20 CONTINUE
186
187 K = KRCOL + 3*( M22-1 )
188
189 IF( BMP22 ) THEN
190
191 IF( K.EQ.KTOP-1 ) THEN
192
193 CALL DLAQR1( 2, H( K+1, K+1 ), LDH, SR( 2*M22-1 ), SI(
194 2*M22-1 ), SR( 2*M22 ), SI( 2*M22 ), V( 1, M22 ) )
195
196 BETA = V( 1, M22 )
197
198 CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
199
200 ELSE
201
202 BETA = H( K+1, K )
203
204 V( 2, M22 ) = H( K+2, K )
205
206 CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
207
208 H( K+1, K ) = BETA
209
210 H( K+2, K ) = ZERO
211
212 END IF
213
214 END IF
215
216 IF( ACCUM ) THEN
217
218 JBOT = MIN( NDCOL, KBOT )
219
220 ELSE IF( WANTT ) THEN
221
222 JBOT = N
223
224 ELSE
225
226 JBOT = KBOT
227
228 END IF
229
230 DO 40 J = MAX( KTOP, KRCOL ), JBOT
231
232 MEND = MIN( MBOT, ( J-KRCOL+2 ) / 3 )
233
234 DO 30 M = MTOP, MEND
235
236 K = KRCOL + 3*( M-1 )
237
238 REFSUM = V( 1, M )*( H( K+1, J )+V( 2, M )* H( K+2, J )+V(
239 3, M )*H( K+3, J ) )
240
241 H( K+1, J ) = H( K+1, J ) - REFSUM
242
243 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M )
244
245 H( K+3, J ) = H( K+3, J ) - REFSUM*V( 3, M )
246
247 30 CONTINUE
248
249 40 CONTINUE
250
251 IF( BMP22 ) THEN
252
253 K = KRCOL + 3*( M22-1 )
254
255 DO 50 J = MAX( K+1, KTOP ), JBOT
256
257 REFSUM = V( 1, M22 )*( H( K+1, J )+V( 2, M22 )* H( K+2, J )
258 )
259
260 H( K+1, J ) = H( K+1, J ) - REFSUM
261
262 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M22 )
263
264 50 CONTINUE
265
266 END IF
267
268 IF( ACCUM ) THEN
269
270 JTOP = MAX( KTOP, INCOL )
271
272 ELSE IF( WANTT ) THEN
273
274 JTOP = 1
275
276 ELSE
277
278 JTOP = KTOP
279
280 END IF
281
282 DO 90 M = MTOP, MBOT
283
284 IF( V( 1, M ).NE.ZERO ) THEN
285
286 K = KRCOL + 3*( M-1 )
287
288 DO 60 J = JTOP, MIN( KBOT, K+3 )
289
290 REFSUM = V( 1, M )*( H( J, K+1 )+V( 2, M )* H( J, K+2 )+V(
291 3, M )*H( J, K+3 ) )
292
293 H( J, K+1 ) = H( J, K+1 ) - REFSUM
294
295 H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M )
296
297 H( J, K+3 ) = H( J, K+3 ) - REFSUM*V( 3, M )
298
299 60 CONTINUE
300
301 IF( ACCUM ) THEN
302
303 KMS = K - INCOL
304
305 DO 70 J = MAX( 1, KTOP-INCOL ), KDU
306
307 REFSUM = V( 1, M )*( U( J, KMS+1 )+V( 2, M )* U( J, KMS+2
308 )+V( 3, M )*U( J, KMS+3 ) )
309
310 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
311
312 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M )
313
314 U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*V( 3, M )
315
316 70 CONTINUE
317
318 ELSE IF( WANTZ ) THEN
319
320 DO 80 J = ILOZ, IHIZ
321
322 REFSUM = V( 1, M )*( Z( J, K+1 )+V( 2, M )* Z( J, K+2 )+V(
323 3, M )*Z( J, K+3 ) )
324
325 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
326
327 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M )
328
329 Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*V( 3, M )
330
331 80 CONTINUE
332
333 END IF
334
335 END IF
336
337 90 CONTINUE
338
339 K = KRCOL + 3*( M22-1 )
340
341 IF( BMP22 .AND. ( V( 1, M22 ).NE.ZERO ) ) THEN
342
343 DO 100 J = JTOP, MIN( KBOT, K+3 )
344
345 REFSUM = V( 1, M22 )*( H( J, K+1 )+V( 2, M22 )* H( J, K+2 )
346 )
347
348 H( J, K+1 ) = H( J, K+1 ) - REFSUM
349
350 H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M22 )
351
352 100 CONTINUE
353
354 IF( ACCUM ) THEN
355
356 KMS = K - INCOL
357
358 DO 110 J = MAX( 1, KTOP-INCOL ), KDU
359
360 REFSUM = V( 1, M22 )*( U( J, KMS+1 )+V( 2, M22 )* U( J,
361 KMS+2 ) )
362
363 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
364
365 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M22 )
366
367 110 CONTINUE
368
369 ELSE IF( WANTZ ) THEN
370
371 DO 120 J = ILOZ, IHIZ
372
373 REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )* Z( J, K+2 )
374 )
375
376 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
377
378 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M22 )
379
380 120 CONTINUE
381
382 END IF
383
384 END IF
385
386 MSTART = MTOP
387
388 IF( KRCOL+3*( MSTART-1 ).LT.KTOP ) MSTART = MSTART + 1
389
390 MEND = MBOT
391
392 IF( BMP22 ) MEND = MEND + 1
393
394 IF( KRCOL.EQ.KBOT-2 ) MEND = MEND + 1
395
396 DO 130 M = MSTART, MEND
397
398 K = MIN( KBOT-1, KRCOL+3*( M-1 ) )
399
400 IF( H( K+1, K ).NE.ZERO ) THEN
401
402 TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
403
404 IF( TST1.EQ.ZERO ) THEN
405
406 IF( K.GE.KTOP+1 ) TST1 = TST1 + ABS( H( K, K-1 ) )
407
408 IF( K.GE.KTOP+2 ) TST1 = TST1 + ABS( H( K, K-2 ) )
409
410 IF( K.GE.KTOP+3 ) TST1 = TST1 + ABS( H( K, K-3 ) )
411
412 IF( K.LE.KBOT-2 ) TST1 = TST1 + ABS( H( K+2, K+1 ) )
413
414 IF( K.LE.KBOT-3 ) TST1 = TST1 + ABS( H( K+3, K+1 ) )
415
416 IF( K.LE.KBOT-4 ) TST1 = TST1 + ABS( H( K+4, K+1 ) )
417
418 END IF
419
420 IF( ABS( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) ) THEN
421
422 H12 = MAX( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
423
424 H21 = MIN( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
425
426 H11 = MAX( ABS( H( K+1, K+1 ) ), ABS( H( K, K )-H( K+1,
427 K+1 ) ) )
428
429 H22 = MIN( ABS( H( K+1, K+1 ) ), ABS( H( K, K )-H( K+1,
430 K+1 ) ) )
431
432 SCL = H11 + H12
433
434 TST2 = H22*( H11 / SCL )
435
436 IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE. MAX( SML‐
437 NUM, ULP*TST2 ) )H( K+1, K ) = ZERO
438
439 END IF
440
441 END IF
442
443 130 CONTINUE
444
445 MEND = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 3 )
446
447 DO 140 M = MTOP, MEND
448
449 K = KRCOL + 3*( M-1 )
450
451 REFSUM = V( 1, M )*V( 3, M )*H( K+4, K+3 )
452
453 H( K+4, K+1 ) = -REFSUM
454
455 H( K+4, K+2 ) = -REFSUM*V( 2, M )
456
457 H( K+4, K+3 ) = H( K+4, K+3 ) - REFSUM*V( 3, M )
458
459 140 CONTINUE
460
461 150 CONTINUE
462
463 IF( ACCUM ) THEN
464
465 IF( WANTT ) THEN
466
467 JTOP = 1
468
469 JBOT = N
470
471 ELSE
472
473 JTOP = KTOP
474
475 JBOT = KBOT
476
477 END IF
478
479 IF( ( .NOT.BLK22 ) .OR. ( INCOL.LT.KTOP ) .OR. (
480 NDCOL.GT.KBOT ) .OR. ( NS.LE.2 ) ) THEN
481
482 K1 = MAX( 1, KTOP-INCOL )
483
484 NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
485
486 DO 160 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
487
488 JLEN = MIN( NH, JBOT-JCOL+1 )
489
490 CALL DGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
491 LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH, LDWH )
492
493 CALL DLACPY( 'ALL', NU, JLEN, WH, LDWH, H( INCOL+K1, JCOL
494 ), LDH )
495
496 160 CONTINUE
497
498 DO 170 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
499
500 JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
501
502 CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE, H( JROW,
503 INCOL+K1 ), LDH, U( K1, K1 ), LDU, ZERO, WV, LDWV )
504
505 CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV, H( JROW, INCOL+K1
506 ), LDH )
507
508 170 CONTINUE
509
510 IF( WANTZ ) THEN
511
512 DO 180 JROW = ILOZ, IHIZ, NV
513
514 JLEN = MIN( NV, IHIZ-JROW+1 )
515
516 CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE, Z( JROW,
517 INCOL+K1 ), LDZ, U( K1, K1 ), LDU, ZERO, WV, LDWV )
518
519 CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV, Z( JROW, INCOL+K1
520 ), LDZ )
521
522 180 CONTINUE
523
524 END IF
525
526 ELSE
527
528 I2 = ( KDU+1 ) / 2
529
530 I4 = KDU
531
532 J2 = I4 - I2
533
534 J4 = KDU
535
536 KZS = ( J4-J2 ) - ( NS+1 )
537
538 KNZ = NS + 1
539
540 DO 190 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
541
542 JLEN = MIN( NH, JBOT-JCOL+1 )
543
544 CALL DLACPY( 'ALL', KNZ, JLEN, H( INCOL+1+J2, JCOL ),
545 LDH, WH( KZS+1, 1 ), LDWH )
546
547 CALL DLASET( 'ALL', KZS, JLEN, ZERO, ZERO, WH, LDWH )
548
549 CALL DTRMM( 'L', 'U', 'C', 'N', KNZ, JLEN, ONE, U( J2+1,
550 1+KZS ), LDU, WH( KZS+1, 1 ), LDWH )
551
552 CALL DGEMM( 'C', 'N', I2, JLEN, J2, ONE, U, LDU, H(
553 INCOL+1, JCOL ), LDH, ONE, WH, LDWH )
554
555 CALL DLACPY( 'ALL', J2, JLEN, H( INCOL+1, JCOL ), LDH,
556 WH( I2+1, 1 ), LDWH )
557
558 CALL DTRMM( 'L', 'L', 'C', 'N', J2, JLEN, ONE, U( 1, I2+1
559 ), LDU, WH( I2+1, 1 ), LDWH )
560
561 CALL DGEMM( 'C', 'N', I4-I2, JLEN, J4-J2, ONE, U( J2+1,
562 I2+1 ), LDU, H( INCOL+1+J2, JCOL ), LDH, ONE, WH(
563 I2+1, 1 ), LDWH )
564
565 CALL DLACPY( 'ALL', KDU, JLEN, WH, LDWH, H( INCOL+1, JCOL
566 ), LDH )
567
568 190 CONTINUE
569
570 DO 200 JROW = JTOP, MAX( INCOL, KTOP ) - 1, NV
571
572 JLEN = MIN( NV, MAX( INCOL, KTOP )-JROW )
573
574 CALL DLACPY( 'ALL', JLEN, KNZ, H( JROW, INCOL+1+J2 ),
575 LDH, WV( 1, 1+KZS ), LDWV )
576
577 CALL DLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
578
579 CALL DTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
580 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
581
582 CALL DGEMM( 'N', 'N', JLEN, I2, J2, ONE, H( JROW, INCOL+1
583 ), LDH, U, LDU, ONE, WV, LDWV )
584
585 CALL DLACPY( 'ALL', JLEN, J2, H( JROW, INCOL+1 ), LDH,
586 WV( 1, 1+I2 ), LDWV )
587
588 CALL DTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
589 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
590
591 CALL DGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, H( JROW,
592 INCOL+1+J2 ), LDH, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
593 1+I2 ), LDWV )
594
595 CALL DLACPY( 'ALL', JLEN, KDU, WV, LDWV, H( JROW, INCOL+1
596 ), LDH )
597
598 200 CONTINUE
599
600 IF( WANTZ ) THEN
601
602 DO 210 JROW = ILOZ, IHIZ, NV
603
604 JLEN = MIN( NV, IHIZ-JROW+1 )
605
606 CALL DLACPY( 'ALL', JLEN, KNZ, Z( JROW, INCOL+1+J2 ),
607 LDZ, WV( 1, 1+KZS ), LDWV )
608
609 CALL DLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
610
611 CALL DTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
612 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
613
614 CALL DGEMM( 'N', 'N', JLEN, I2, J2, ONE, Z( JROW, INCOL+1
615 ), LDZ, U, LDU, ONE, WV, LDWV )
616
617 CALL DLACPY( 'ALL', JLEN, J2, Z( JROW, INCOL+1 ), LDZ,
618 WV( 1, 1+I2 ), LDWV )
619
620 CALL DTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
621 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
622
623 CALL DGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, Z( JROW,
624 INCOL+1+J2 ), LDZ, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
625 1+I2 ), LDWV )
626
627 CALL DLACPY( 'ALL', JLEN, KDU, WV, LDWV, Z( JROW, INCOL+1
628 ), LDZ )
629
630 210 CONTINUE
631
632 END IF
633
634 END IF
635
636 END IF
637
638 220 CONTINUE
639
640 END
641
643 LAPACK auxiliary routine (versionNo3v.e2m)ber 2008 DLAQR5(1)