1CLAQR5(1) LAPACK auxiliary routine (version 3.1) 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( V( 1, M ).NE.ZERO .AND. ( V( 3, M ).NE.ZERO .OR. (
121 H( K+3, K+1 ).EQ.ZERO .AND. H( K+3, K+2 ).EQ.ZERO )
122 ) ) THEN
123
124 H( K+1, K ) = BETA
125
126 H( K+2, K ) = ZERO
127
128 H( K+3, K ) = ZERO
129
130 ELSE
131
132 CALL CLAQR1( 3, H( K+1, K+1 ), LDH, S( 2*M-1 ), S( 2*M ),
133 VT )
134
135 SCL = CABS1( VT( 1 ) ) + CABS1( VT( 2 ) ) + CABS1( VT( 3
136 ) )
137
138 IF( SCL.NE.RZERO ) THEN
139
140 VT( 1 ) = VT( 1 ) / SCL
141
142 VT( 2 ) = VT( 2 ) / SCL
143
144 VT( 3 ) = VT( 3 ) / SCL
145
146 END IF
147
148 IF( CABS1( H( K+1, K ) )* ( CABS1( VT( 2 ) )+CABS1( VT(
149 3 ) ) ).GT.ULP* CABS1( VT( 1 ) )*( CABS1( H( K, K )
150 )+CABS1( H( K+1, K+1 ) )+CABS1( H( K+2, K+2 ) ) ) )
151 THEN
152
153 IF( V( 2, M ).EQ.ZERO .AND. V( 3, M ).EQ.ZERO ) THEN
154
155 V( 1, M ) = ZERO
156
157 ELSE
158
159 H( K+1, K ) = BETA
160
161 H( K+2, K ) = ZERO
162
163 H( K+3, K ) = ZERO
164
165 END IF
166
167 ELSE
168
169 ALPHA = VT( 1 )
170
171 CALL CLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
172
173 REFSUM = H( K+1, K ) + H( K+2, K )*CONJG( VT( 2 ) ) + H(
174 K+3, K )*CONJG( VT( 3 ) )
175
176 H( K+1, K ) = H( K+1, K ) - CONJG( VT( 1 ) )*REFSUM
177
178 H( K+2, K ) = ZERO
179
180 H( K+3, K ) = ZERO
181
182 V( 1, M ) = VT( 1 )
183
184 V( 2, M ) = VT( 2 )
185
186 V( 3, M ) = VT( 3 )
187
188 END IF
189
190 END IF
191
192 END IF
193
194 10 CONTINUE
195
196 K = KRCOL + 3*( M22-1 )
197
198 IF( BMP22 ) THEN
199
200 IF( K.EQ.KTOP-1 ) THEN
201
202 CALL CLAQR1( 2, H( K+1, K+1 ), LDH, S( 2*M22-1 ), S(
203 2*M22 ), V( 1, M22 ) )
204
205 BETA = V( 1, M22 )
206
207 CALL CLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
208
209 ELSE
210
211 BETA = H( K+1, K )
212
213 V( 2, M22 ) = H( K+2, K )
214
215 CALL CLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
216
217 H( K+1, K ) = BETA
218
219 H( K+2, K ) = ZERO
220
221 END IF
222
223 ELSE
224
225 V( 1, M22 ) = ZERO
226
227 END IF
228
229 IF( ACCUM ) THEN
230
231 JBOT = MIN( NDCOL, KBOT )
232
233 ELSE IF( WANTT ) THEN
234
235 JBOT = N
236
237 ELSE
238
239 JBOT = KBOT
240
241 END IF
242
243 DO 30 J = MAX( KTOP, KRCOL ), JBOT
244
245 MEND = MIN( MBOT, ( J-KRCOL+2 ) / 3 )
246
247 DO 20 M = MTOP, MEND
248
249 K = KRCOL + 3*( M-1 )
250
251 REFSUM = CONJG( V( 1, M ) )* ( H( K+1, J )+CONJG( V( 2, M )
252 )*H( K+2, J )+ CONJG( V( 3, M ) )*H( K+3, J ) )
253
254 H( K+1, J ) = H( K+1, J ) - REFSUM
255
256 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M )
257
258 H( K+3, J ) = H( K+3, J ) - REFSUM*V( 3, M )
259
260 20 CONTINUE
261
262 30 CONTINUE
263
264 IF( BMP22 ) THEN
265
266 K = KRCOL + 3*( M22-1 )
267
268 DO 40 J = MAX( K+1, KTOP ), JBOT
269
270 REFSUM = CONJG( V( 1, M22 ) )* ( H( K+1, J )+CONJG( V( 2,
271 M22 ) )* H( K+2, J ) )
272
273 H( K+1, J ) = H( K+1, J ) - REFSUM
274
275 H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M22 )
276
277 40 CONTINUE
278
279 END IF
280
281 IF( ACCUM ) THEN
282
283 JTOP = MAX( KTOP, INCOL )
284
285 ELSE IF( WANTT ) THEN
286
287 JTOP = 1
288
289 ELSE
290
291 JTOP = KTOP
292
293 END IF
294
295 DO 80 M = MTOP, MBOT
296
297 IF( V( 1, M ).NE.ZERO ) THEN
298
299 K = KRCOL + 3*( M-1 )
300
301 DO 50 J = JTOP, MIN( KBOT, K+3 )
302
303 REFSUM = V( 1, M )*( H( J, K+1 )+V( 2, M )* H( J, K+2 )+V(
304 3, M )*H( J, K+3 ) )
305
306 H( J, K+1 ) = H( J, K+1 ) - REFSUM
307
308 H( J, K+2 ) = H( J, K+2 ) - REFSUM*CONJG( V( 2, M ) )
309
310 H( J, K+3 ) = H( J, K+3 ) - REFSUM*CONJG( V( 3, M ) )
311
312 50 CONTINUE
313
314 IF( ACCUM ) THEN
315
316 KMS = K - INCOL
317
318 DO 60 J = MAX( 1, KTOP-INCOL ), KDU
319
320 REFSUM = V( 1, M )*( U( J, KMS+1 )+V( 2, M )* U( J, KMS+2
321 )+V( 3, M )*U( J, KMS+3 ) )
322
323 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
324
325 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*CONJG( V( 2, M )
326 )
327
328 U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*CONJG( V( 3, M )
329 )
330
331 60 CONTINUE
332
333 ELSE IF( WANTZ ) THEN
334
335 DO 70 J = ILOZ, IHIZ
336
337 REFSUM = V( 1, M )*( Z( J, K+1 )+V( 2, M )* Z( J, K+2 )+V(
338 3, M )*Z( J, K+3 ) )
339
340 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
341
342 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*CONJG( V( 2, M ) )
343
344 Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*CONJG( V( 3, M ) )
345
346 70 CONTINUE
347
348 END IF
349
350 END IF
351
352 80 CONTINUE
353
354 K = KRCOL + 3*( M22-1 )
355
356 IF( BMP22 .AND. ( V( 1, M22 ).NE.ZERO ) ) THEN
357
358 DO 90 J = JTOP, MIN( KBOT, K+3 )
359
360 REFSUM = V( 1, M22 )*( H( J, K+1 )+V( 2, M22 )* H( J, K+2 )
361 )
362
363 H( J, K+1 ) = H( J, K+1 ) - REFSUM
364
365 H( J, K+2 ) = H( J, K+2 ) - REFSUM*CONJG( V( 2, M22 ) )
366
367 90 CONTINUE
368
369 IF( ACCUM ) THEN
370
371 KMS = K - INCOL
372
373 DO 100 J = MAX( 1, KTOP-INCOL ), KDU
374
375 REFSUM = V( 1, M22 )*( U( J, KMS+1 )+V( 2, M22 )* U( J,
376 KMS+2 ) )
377
378 U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
379
380 U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*CONJG( V( 2, M22
381 ) )
382
383 100 CONTINUE
384
385 ELSE IF( WANTZ ) THEN
386
387 DO 110 J = ILOZ, IHIZ
388
389 REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )* Z( J, K+2 )
390 )
391
392 Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
393
394 Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*CONJG( V( 2, M22 ) )
395
396 110 CONTINUE
397
398 END IF
399
400 END IF
401
402 MSTART = MTOP
403
404 IF( KRCOL+3*( MSTART-1 ).LT.KTOP ) MSTART = MSTART + 1
405
406 MEND = MBOT
407
408 IF( BMP22 ) MEND = MEND + 1
409
410 IF( KRCOL.EQ.KBOT-2 ) MEND = MEND + 1
411
412 DO 120 M = MSTART, MEND
413
414 K = MIN( KBOT-1, KRCOL+3*( M-1 ) )
415
416 IF( H( K+1, K ).NE.ZERO ) THEN
417
418 TST1 = CABS1( H( K, K ) ) + CABS1( H( K+1, K+1 ) )
419
420 IF( TST1.EQ.RZERO ) THEN
421
422 IF( K.GE.KTOP+1 ) TST1 = TST1 + CABS1( H( K, K-1 ) )
423
424 IF( K.GE.KTOP+2 ) TST1 = TST1 + CABS1( H( K, K-2 ) )
425
426 IF( K.GE.KTOP+3 ) TST1 = TST1 + CABS1( H( K, K-3 ) )
427
428 IF( K.LE.KBOT-2 ) TST1 = TST1 + CABS1( H( K+2, K+1 ) )
429
430 IF( K.LE.KBOT-3 ) TST1 = TST1 + CABS1( H( K+3, K+1 ) )
431
432 IF( K.LE.KBOT-4 ) TST1 = TST1 + CABS1( H( K+4, K+1 ) )
433
434 END IF
435
436 IF( CABS1( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
437 THEN
438
439 H12 = MAX( CABS1( H( K+1, K ) ), CABS1( H( K, K+1 ) ) )
440
441 H21 = MIN( CABS1( H( K+1, K ) ), CABS1( H( K, K+1 ) ) )
442
443 H11 = MAX( CABS1( H( K+1, K+1 ) ), CABS1( H( K, K )-H(
444 K+1, K+1 ) ) )
445
446 H22 = MIN( CABS1( H( K+1, K+1 ) ), CABS1( H( K, K )-H(
447 K+1, K+1 ) ) )
448
449 SCL = H11 + H12
450
451 TST2 = H22*( H11 / SCL )
452
453 IF( TST2.EQ.RZERO .OR. H21*( H12 / SCL ).LE. MAX( SML‐
454 NUM, ULP*TST2 ) )H( K+1, K ) = ZERO
455
456 END IF
457
458 END IF
459
460 120 CONTINUE
461
462 MEND = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 3 )
463
464 DO 130 M = MTOP, MEND
465
466 K = KRCOL + 3*( M-1 )
467
468 REFSUM = V( 1, M )*V( 3, M )*H( K+4, K+3 )
469
470 H( K+4, K+1 ) = -REFSUM
471
472 H( K+4, K+2 ) = -REFSUM*CONJG( V( 2, M ) )
473
474 H( K+4, K+3 ) = H( K+4, K+3 ) - REFSUM*CONJG( V( 3, M )
475 )
476
477 130 CONTINUE
478
479 140 CONTINUE
480
481 IF( ACCUM ) THEN
482
483 IF( WANTT ) THEN
484
485 JTOP = 1
486
487 JBOT = N
488
489 ELSE
490
491 JTOP = KTOP
492
493 JBOT = KBOT
494
495 END IF
496
497 IF( ( .NOT.BLK22 ) .OR. ( INCOL.LT.KTOP ) .OR. (
498 NDCOL.GT.KBOT ) .OR. ( NS.LE.2 ) ) THEN
499
500 K1 = MAX( 1, KTOP-INCOL )
501
502 NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
503
504 DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
505
506 JLEN = MIN( NH, JBOT-JCOL+1 )
507
508 CALL CGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
509 LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH, LDWH )
510
511 CALL CLACPY( 'ALL', NU, JLEN, WH, LDWH, H( INCOL+K1, JCOL
512 ), LDH )
513
514 150 CONTINUE
515
516 DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
517
518 JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
519
520 CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE, H( JROW,
521 INCOL+K1 ), LDH, U( K1, K1 ), LDU, ZERO, WV, LDWV )
522
523 CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV, H( JROW, INCOL+K1
524 ), LDH )
525
526 160 CONTINUE
527
528 IF( WANTZ ) THEN
529
530 DO 170 JROW = ILOZ, IHIZ, NV
531
532 JLEN = MIN( NV, IHIZ-JROW+1 )
533
534 CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE, Z( JROW,
535 INCOL+K1 ), LDZ, U( K1, K1 ), LDU, ZERO, WV, LDWV )
536
537 CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV, Z( JROW, INCOL+K1
538 ), LDZ )
539
540 170 CONTINUE
541
542 END IF
543
544 ELSE
545
546 I2 = ( KDU+1 ) / 2
547
548 I4 = KDU
549
550 J2 = I4 - I2
551
552 J4 = KDU
553
554 KZS = ( J4-J2 ) - ( NS+1 )
555
556 KNZ = NS + 1
557
558 DO 180 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
559
560 JLEN = MIN( NH, JBOT-JCOL+1 )
561
562 CALL CLACPY( 'ALL', KNZ, JLEN, H( INCOL+1+J2, JCOL ),
563 LDH, WH( KZS+1, 1 ), LDWH )
564
565 CALL CLASET( 'ALL', KZS, JLEN, ZERO, ZERO, WH, LDWH )
566
567 CALL CTRMM( 'L', 'U', 'C', 'N', KNZ, JLEN, ONE, U( J2+1,
568 1+KZS ), LDU, WH( KZS+1, 1 ), LDWH )
569
570 CALL CGEMM( 'C', 'N', I2, JLEN, J2, ONE, U, LDU, H(
571 INCOL+1, JCOL ), LDH, ONE, WH, LDWH )
572
573 CALL CLACPY( 'ALL', J2, JLEN, H( INCOL+1, JCOL ), LDH,
574 WH( I2+1, 1 ), LDWH )
575
576 CALL CTRMM( 'L', 'L', 'C', 'N', J2, JLEN, ONE, U( 1, I2+1
577 ), LDU, WH( I2+1, 1 ), LDWH )
578
579 CALL CGEMM( 'C', 'N', I4-I2, JLEN, J4-J2, ONE, U( J2+1,
580 I2+1 ), LDU, H( INCOL+1+J2, JCOL ), LDH, ONE, WH(
581 I2+1, 1 ), LDWH )
582
583 CALL CLACPY( 'ALL', KDU, JLEN, WH, LDWH, H( INCOL+1, JCOL
584 ), LDH )
585
586 180 CONTINUE
587
588 DO 190 JROW = JTOP, MAX( INCOL, KTOP ) - 1, NV
589
590 JLEN = MIN( NV, MAX( INCOL, KTOP )-JROW )
591
592 CALL CLACPY( 'ALL', JLEN, KNZ, H( JROW, INCOL+1+J2 ),
593 LDH, WV( 1, 1+KZS ), LDWV )
594
595 CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
596
597 CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
598 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
599
600 CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE, H( JROW, INCOL+1
601 ), LDH, U, LDU, ONE, WV, LDWV )
602
603 CALL CLACPY( 'ALL', JLEN, J2, H( JROW, INCOL+1 ), LDH,
604 WV( 1, 1+I2 ), LDWV )
605
606 CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
607 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
608
609 CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, H( JROW,
610 INCOL+1+J2 ), LDH, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
611 1+I2 ), LDWV )
612
613 CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV, H( JROW, INCOL+1
614 ), LDH )
615
616 190 CONTINUE
617
618 IF( WANTZ ) THEN
619
620 DO 200 JROW = ILOZ, IHIZ, NV
621
622 JLEN = MIN( NV, IHIZ-JROW+1 )
623
624 CALL CLACPY( 'ALL', JLEN, KNZ, Z( JROW, INCOL+1+J2 ),
625 LDZ, WV( 1, 1+KZS ), LDWV )
626
627 CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
628
629 CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE, U( J2+1,
630 1+KZS ), LDU, WV( 1, 1+KZS ), LDWV )
631
632 CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE, Z( JROW, INCOL+1
633 ), LDZ, U, LDU, ONE, WV, LDWV )
634
635 CALL CLACPY( 'ALL', JLEN, J2, Z( JROW, INCOL+1 ), LDZ,
636 WV( 1, 1+I2 ), LDWV )
637
638 CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE, U( 1,
639 I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
640
641 CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE, Z( JROW,
642 INCOL+1+J2 ), LDZ, U( J2+1, I2+1 ), LDU, ONE, WV( 1,
643 1+I2 ), LDWV )
644
645 CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV, Z( JROW, INCOL+1
646 ), LDZ )
647
648 200 CONTINUE
649
650 END IF
651
652 END IF
653
654 END IF
655
656 210 CONTINUE
657
658 END
659
661 LAPACK auxiliary routine (versionNo3v.e1m)ber 2006 CLAQR5(1)