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