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