1CLAQR5(1) LAPACK auxiliary routine (version 3.2) CLAQR5(1)
2
3
4
7 SUBROUTINE CLAQR5( 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 H( LDH, * ), S( * ), U( LDU, * ), V( LDV, * ), WH(
17 LDWH, * ), WV( LDWV, * ), Z( LDZ, * )
18
19 COMPLEX ZERO, ONE
20
21 PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ), ONE = ( 1.0e0, 0.0e0 ) )
22
23 REAL RZERO, RONE
24
25 PARAMETER ( RZERO = 0.0e0, RONE = 1.0e0 )
26
27 COMPLEX ALPHA, BETA, CDUM, REFSUM
28
29 REAL H11, H12, H21, H22, SAFMAX, SAFMIN, SCL, SMLNUM,
30 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 REAL SLAMCH
39
40 EXTERNAL SLAMCH
41
42 INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, MOD, REAL
43
44 COMPLEX VT( 3 )
45
46 EXTERNAL CGEMM, CLACPY, CLAQR1, CLARFG, CLASET, CTRMM, SLABAD
47
48 REAL CABS1
49
50 CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( 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 = SLAMCH( 'SAFE MINIMUM' )
59
60 SAFMAX = RONE / SAFMIN
61
62 CALL SLABAD( SAFMIN, SAFMAX )
63
64 ULP = SLAMCH( 'PRECISION' )
65
66 SMLNUM = SAFMIN*( REAL( 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 CLASET( '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 CLAQR1( 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 CLARFG( 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 CLARFG( 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 CLAQR1( 3, H( K+1, K+1 ), LDH, S( 2*M-1 ), S( 2*M ),
132 VT )
133
134 ALPHA = VT( 1 )
135
136 CALL CLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
137
138 REFSUM = CONJG( VT( 1 ) )* ( H( K+1, K )+CONJG( 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 CLAQR1( 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 CLARFG( 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 CLARFG( 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 = CONJG( V( 1, M ) )* ( H( K+1, J )+CONJG( V( 2, M )
225 )*H( K+2, J )+ CONJG( 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 = CONJG( V( 1, M22 ) )* ( H( K+1, J )+CONJG( 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*CONJG( V( 2, M ) )
282
283 H( J, K+3 ) = H( J, K+3 ) - REFSUM*CONJG( 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*CONJG( V( 2, M )
299 )
300
301 U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*CONJG( 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*CONJG( V( 2, M ) )
316
317 Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*CONJG( 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*CONJG( V( 2, M22 ) )
339
340 90 CONTINUE
341
342 IF( ACCUM ) THEN
343
344 KMS = K - INCOL
345
346 DO 100 J = MAX( 1, KTOP-INCOL ), KDU
347
348 REFSUM = V( 1, M22 )*( U( J, KMS+1 )+V( 2, M22 )* U( J,
349 KMS+2 ) )
350
351 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
352
353 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*CONJG( V( 2, M22
354 ) )
355
356 100 CONTINUE
357
358 ELSE IF( WANTZ ) THEN
359
360 DO 110 J = ILOZ, IHIZ
361
362 REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )* Z( J, K+2 )
363 )
364
365 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
366
367 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*CONJG( V( 2, M22 ) )
368
369 110 CONTINUE
370
371 END IF
372
373 END IF
374
375 MSTART = MTOP
376
377 IF( KRCOL+3*( MSTART-1 ).LT.KTOP ) MSTART = MSTART + 1
378
379 MEND = MBOT
380
381 IF( BMP22 ) MEND = MEND + 1
382
383 IF( KRCOL.EQ.KBOT-2 ) MEND = MEND + 1
384
385 DO 120 M = MSTART, MEND
386
387 K = MIN( KBOT-1, KRCOL+3*( M-1 ) )
388
389 IF( H( K+1, K ).NE.ZERO ) THEN
390
391 TST1 = CABS1( H( K, K ) ) + CABS1( H( K+1, K+1 ) )
392
393 IF( TST1.EQ.RZERO ) THEN
394
395 IF( K.GE.KTOP+1 ) TST1 = TST1 + CABS1( H( K, K-1 ) )
396
397 IF( K.GE.KTOP+2 ) TST1 = TST1 + CABS1( H( K, K-2 ) )
398
399 IF( K.GE.KTOP+3 ) TST1 = TST1 + CABS1( H( K, K-3 ) )
400
401 IF( K.LE.KBOT-2 ) TST1 = TST1 + CABS1( H( K+2, K+1 ) )
402
403 IF( K.LE.KBOT-3 ) TST1 = TST1 + CABS1( H( K+3, K+1 ) )
404
405 IF( K.LE.KBOT-4 ) TST1 = TST1 + CABS1( H( K+4, K+1 ) )
406
407 END IF
408
409 IF( CABS1( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
410 THEN
411
412 H12 = MAX( CABS1( H( K+1, K ) ), CABS1( H( K, K+1 ) ) )
413
414 H21 = MIN( CABS1( H( K+1, K ) ), CABS1( H( K, K+1 ) ) )
415
416 H11 = MAX( CABS1( H( K+1, K+1 ) ), CABS1( H( K, K )-H(
417 K+1, K+1 ) ) )
418
419 H22 = MIN( CABS1( H( K+1, K+1 ) ), CABS1( H( K, K )-H(
420 K+1, K+1 ) ) )
421
422 SCL = H11 + H12
423
424 TST2 = H22*( H11 / SCL )
425
426 IF( TST2.EQ.RZERO .OR. H21*( H12 / SCL ).LE. MAX( SML‐
427 NUM, ULP*TST2 ) )H( K+1, K ) = ZERO
428
429 END IF
430
431 END IF
432
433 120 CONTINUE
434
435 MEND = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 3 )
436
437 DO 130 M = MTOP, MEND
438
439 K = KRCOL + 3*( M-1 )
440
441 REFSUM = V( 1, M )*V( 3, M )*H( K+4, K+3 )
442
443 H( K+4, K+1 ) = -REFSUM
444
445 H( K+4, K+2 ) = -REFSUM*CONJG( V( 2, M ) )
446
447 H( K+4, K+3 ) = H( K+4, K+3 ) - REFSUM*CONJG( V( 3, M )
448 )
449
450 130 CONTINUE
451
452 140 CONTINUE
453
454 IF( ACCUM ) THEN
455
456 IF( WANTT ) THEN
457
458 JTOP = 1
459
460 JBOT = N
461
462 ELSE
463
464 JTOP = KTOP
465
466 JBOT = KBOT
467
468 END IF
469
470 IF( ( .NOT.BLK22 ) .OR. ( INCOL.LT.KTOP ) .OR. (
471 NDCOL.GT.KBOT ) .OR. ( NS.LE.2 ) ) THEN
472
473 K1 = MAX( 1, KTOP-INCOL )
474
475 NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
476
477 DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
478
479 JLEN = MIN( NH, JBOT-JCOL+1 )
480
481 CALL CGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
482 LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH, LDWH )
483
484 CALL CLACPY( 'ALL', NU, JLEN, WH, LDWH, H( INCOL+K1, JCOL
485 ), LDH )
486
487 150 CONTINUE
488
489 DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
490
491 JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
492
493 CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE, H( JROW,
494 INCOL+K1 ), LDH, U( K1, K1 ), LDU, ZERO, WV, LDWV )
495
496 CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV, H( JROW, INCOL+K1
497 ), LDH )
498
499 160 CONTINUE
500
501 IF( WANTZ ) THEN
502
503 DO 170 JROW = ILOZ, IHIZ, NV
504
505 JLEN = MIN( NV, IHIZ-JROW+1 )
506
507 CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE, Z( JROW,
508 INCOL+K1 ), LDZ, U( K1, K1 ), LDU, ZERO, WV, LDWV )
509
510 CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV, Z( JROW, INCOL+K1
511 ), LDZ )
512
513 170 CONTINUE
514
515 END IF
516
517 ELSE
518
519 I2 = ( KDU+1 ) / 2
520
521 I4 = KDU
522
523 J2 = I4 - I2
524
525 J4 = KDU
526
527 KZS = ( J4-J2 ) - ( NS+1 )
528
529 KNZ = NS + 1
530
531 DO 180 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
532
533 JLEN = MIN( NH, JBOT-JCOL+1 )
534
535 CALL CLACPY( 'ALL', KNZ, JLEN, H( INCOL+1+J2, JCOL ),
536 LDH, WH( KZS+1, 1 ), LDWH )
537
538 CALL CLASET( 'ALL', KZS, JLEN, ZERO, ZERO, WH, LDWH )
539
540 CALL CTRMM( 'L', 'U', 'C', 'N', KNZ, JLEN, ONE, U( J2+1,
541 1+KZS ), LDU, WH( KZS+1, 1 ), LDWH )
542
543 CALL CGEMM( 'C', 'N', I2, JLEN, J2, ONE, U, LDU, H(
544 INCOL+1, JCOL ), LDH, ONE, WH, LDWH )
545
546 CALL CLACPY( 'ALL', J2, JLEN, H( INCOL+1, JCOL ), LDH,
547 WH( I2+1, 1 ), LDWH )
548
549 CALL CTRMM( 'L', 'L', 'C', 'N', J2, JLEN, ONE, U( 1, I2+1
550 ), LDU, WH( I2+1, 1 ), LDWH )
551
552 CALL CGEMM( 'C', 'N', I4-I2, JLEN, J4-J2, ONE, U( J2+1,
553 I2+1 ), LDU, H( INCOL+1+J2, JCOL ), LDH, ONE, WH(
554 I2+1, 1 ), LDWH )
555
556 CALL CLACPY( 'ALL', KDU, JLEN, WH, LDWH, H( INCOL+1, JCOL
557 ), LDH )
558
559 180 CONTINUE
560
561 DO 190 JROW = JTOP, MAX( INCOL, KTOP ) - 1, NV
562
563 JLEN = MIN( NV, MAX( INCOL, KTOP )-JROW )
564
565 CALL CLACPY( 'ALL', JLEN, KNZ, H( JROW, INCOL+1+J2 ),
566 LDH, WV( 1, 1+KZS ), LDWV )
567
568 CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
569
570 CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
571 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
572
573 CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE, H( JROW, INCOL+1
574 ), LDH, U, LDU, ONE, WV, LDWV )
575
576 CALL CLACPY( 'ALL', JLEN, J2, H( JROW, INCOL+1 ), LDH,
577 WV( 1, 1+I2 ), LDWV )
578
579 CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
580 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
581
582 CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, H( JROW,
583 INCOL+1+J2 ), LDH, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
584 1+I2 ), LDWV )
585
586 CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV, H( JROW, INCOL+1
587 ), LDH )
588
589 190 CONTINUE
590
591 IF( WANTZ ) THEN
592
593 DO 200 JROW = ILOZ, IHIZ, NV
594
595 JLEN = MIN( NV, IHIZ-JROW+1 )
596
597 CALL CLACPY( 'ALL', JLEN, KNZ, Z( JROW, INCOL+1+J2 ),
598 LDZ, WV( 1, 1+KZS ), LDWV )
599
600 CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
601
602 CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
603 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
604
605 CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE, Z( JROW, INCOL+1
606 ), LDZ, U, LDU, ONE, WV, LDWV )
607
608 CALL CLACPY( 'ALL', JLEN, J2, Z( JROW, INCOL+1 ), LDZ,
609 WV( 1, 1+I2 ), LDWV )
610
611 CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
612 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
613
614 CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, Z( JROW,
615 INCOL+1+J2 ), LDZ, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
616 1+I2 ), LDWV )
617
618 CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV, Z( JROW, INCOL+1
619 ), LDZ )
620
621 200 CONTINUE
622
623 END IF
624
625 END IF
626
627 END IF
628
629 210 CONTINUE
630
631 END
632
634 LAPACK auxiliary routine (versionNo3v.e2m)ber 2008 CLAQR5(1)