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