00001 SUBROUTINE DTGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D,
00002 $ LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
00003 $ IWORK, INFO )
00004
00005
00006
00007
00008
00009
00010
00011 CHARACTER TRANS
00012 INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
00013 $ LWORK, M, N
00014 DOUBLE PRECISION DIF, SCALE
00015
00016
00017 INTEGER IWORK( * )
00018 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),
00019 $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
00020 $ WORK( * )
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 DOUBLE PRECISION ZERO, ONE
00201 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00202
00203
00204 LOGICAL LQUERY, NOTRAN
00205 INTEGER I, IE, IFUNC, IROUND, IS, ISOLVE, J, JE, JS, K,
00206 $ LINFO, LWMIN, MB, NB, P, PPQQ, PQ, Q
00207 DOUBLE PRECISION DSCALE, DSUM, SCALE2, SCALOC
00208
00209
00210 LOGICAL LSAME
00211 INTEGER ILAENV
00212 EXTERNAL LSAME, ILAENV
00213
00214
00215 EXTERNAL DGEMM, DLACPY, DLASET, DSCAL, DTGSY2, XERBLA
00216
00217
00218 INTRINSIC DBLE, MAX, SQRT
00219
00220
00221
00222
00223
00224 INFO = 0
00225 NOTRAN = LSAME( TRANS, 'N' )
00226 LQUERY = ( LWORK.EQ.-1 )
00227
00228 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
00229 INFO = -1
00230 ELSE IF( NOTRAN ) THEN
00231 IF( ( IJOB.LT.0 ) .OR. ( IJOB.GT.4 ) ) THEN
00232 INFO = -2
00233 END IF
00234 END IF
00235 IF( INFO.EQ.0 ) THEN
00236 IF( M.LE.0 ) THEN
00237 INFO = -3
00238 ELSE IF( N.LE.0 ) THEN
00239 INFO = -4
00240 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00241 INFO = -6
00242 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00243 INFO = -8
00244 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
00245 INFO = -10
00246 ELSE IF( LDD.LT.MAX( 1, M ) ) THEN
00247 INFO = -12
00248 ELSE IF( LDE.LT.MAX( 1, N ) ) THEN
00249 INFO = -14
00250 ELSE IF( LDF.LT.MAX( 1, M ) ) THEN
00251 INFO = -16
00252 END IF
00253 END IF
00254
00255 IF( INFO.EQ.0 ) THEN
00256 IF( NOTRAN ) THEN
00257 IF( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN
00258 LWMIN = MAX( 1, 2*M*N )
00259 ELSE
00260 LWMIN = 1
00261 END IF
00262 ELSE
00263 LWMIN = 1
00264 END IF
00265 WORK( 1 ) = LWMIN
00266
00267 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
00268 INFO = -20
00269 END IF
00270 END IF
00271
00272 IF( INFO.NE.0 ) THEN
00273 CALL XERBLA( 'DTGSYL', -INFO )
00274 RETURN
00275 ELSE IF( LQUERY ) THEN
00276 RETURN
00277 END IF
00278
00279
00280
00281 IF( M.EQ.0 .OR. N.EQ.0 ) THEN
00282 SCALE = 1
00283 IF( NOTRAN ) THEN
00284 IF( IJOB.NE.0 ) THEN
00285 DIF = 0
00286 END IF
00287 END IF
00288 RETURN
00289 END IF
00290
00291
00292
00293 MB = ILAENV( 2, 'DTGSYL', TRANS, M, N, -1, -1 )
00294 NB = ILAENV( 5, 'DTGSYL', TRANS, M, N, -1, -1 )
00295
00296 ISOLVE = 1
00297 IFUNC = 0
00298 IF( NOTRAN ) THEN
00299 IF( IJOB.GE.3 ) THEN
00300 IFUNC = IJOB - 2
00301 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
00302 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
00303 ELSE IF( IJOB.GE.1 ) THEN
00304 ISOLVE = 2
00305 END IF
00306 END IF
00307
00308 IF( ( MB.LE.1 .AND. NB.LE.1 ) .OR. ( MB.GE.M .AND. NB.GE.N ) )
00309 $ THEN
00310
00311 DO 30 IROUND = 1, ISOLVE
00312
00313
00314
00315 DSCALE = ZERO
00316 DSUM = ONE
00317 PQ = 0
00318 CALL DTGSY2( TRANS, IFUNC, M, N, A, LDA, B, LDB, C, LDC, D,
00319 $ LDD, E, LDE, F, LDF, SCALE, DSUM, DSCALE,
00320 $ IWORK, PQ, INFO )
00321 IF( DSCALE.NE.ZERO ) THEN
00322 IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
00323 DIF = SQRT( DBLE( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
00324 ELSE
00325 DIF = SQRT( DBLE( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
00326 END IF
00327 END IF
00328
00329 IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
00330 IF( NOTRAN ) THEN
00331 IFUNC = IJOB
00332 END IF
00333 SCALE2 = SCALE
00334 CALL DLACPY( 'F', M, N, C, LDC, WORK, M )
00335 CALL DLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
00336 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
00337 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
00338 ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
00339 CALL DLACPY( 'F', M, N, WORK, M, C, LDC )
00340 CALL DLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
00341 SCALE = SCALE2
00342 END IF
00343 30 CONTINUE
00344
00345 RETURN
00346 END IF
00347
00348
00349
00350 P = 0
00351 I = 1
00352 40 CONTINUE
00353 IF( I.GT.M )
00354 $ GO TO 50
00355 P = P + 1
00356 IWORK( P ) = I
00357 I = I + MB
00358 IF( I.GE.M )
00359 $ GO TO 50
00360 IF( A( I, I-1 ).NE.ZERO )
00361 $ I = I + 1
00362 GO TO 40
00363 50 CONTINUE
00364
00365 IWORK( P+1 ) = M + 1
00366 IF( IWORK( P ).EQ.IWORK( P+1 ) )
00367 $ P = P - 1
00368
00369
00370
00371 Q = P + 1
00372 J = 1
00373 60 CONTINUE
00374 IF( J.GT.N )
00375 $ GO TO 70
00376 Q = Q + 1
00377 IWORK( Q ) = J
00378 J = J + NB
00379 IF( J.GE.N )
00380 $ GO TO 70
00381 IF( B( J, J-1 ).NE.ZERO )
00382 $ J = J + 1
00383 GO TO 60
00384 70 CONTINUE
00385
00386 IWORK( Q+1 ) = N + 1
00387 IF( IWORK( Q ).EQ.IWORK( Q+1 ) )
00388 $ Q = Q - 1
00389
00390 IF( NOTRAN ) THEN
00391
00392 DO 150 IROUND = 1, ISOLVE
00393
00394
00395
00396
00397
00398
00399 DSCALE = ZERO
00400 DSUM = ONE
00401 PQ = 0
00402 SCALE = ONE
00403 DO 130 J = P + 2, Q
00404 JS = IWORK( J )
00405 JE = IWORK( J+1 ) - 1
00406 NB = JE - JS + 1
00407 DO 120 I = P, 1, -1
00408 IS = IWORK( I )
00409 IE = IWORK( I+1 ) - 1
00410 MB = IE - IS + 1
00411 PPQQ = 0
00412 CALL DTGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
00413 $ B( JS, JS ), LDB, C( IS, JS ), LDC,
00414 $ D( IS, IS ), LDD, E( JS, JS ), LDE,
00415 $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
00416 $ IWORK( Q+2 ), PPQQ, LINFO )
00417 IF( LINFO.GT.0 )
00418 $ INFO = LINFO
00419
00420 PQ = PQ + PPQQ
00421 IF( SCALOC.NE.ONE ) THEN
00422 DO 80 K = 1, JS - 1
00423 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
00424 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
00425 80 CONTINUE
00426 DO 90 K = JS, JE
00427 CALL DSCAL( IS-1, SCALOC, C( 1, K ), 1 )
00428 CALL DSCAL( IS-1, SCALOC, F( 1, K ), 1 )
00429 90 CONTINUE
00430 DO 100 K = JS, JE
00431 CALL DSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
00432 CALL DSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
00433 100 CONTINUE
00434 DO 110 K = JE + 1, N
00435 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
00436 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
00437 110 CONTINUE
00438 SCALE = SCALE*SCALOC
00439 END IF
00440
00441
00442
00443
00444 IF( I.GT.1 ) THEN
00445 CALL DGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
00446 $ A( 1, IS ), LDA, C( IS, JS ), LDC, ONE,
00447 $ C( 1, JS ), LDC )
00448 CALL DGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
00449 $ D( 1, IS ), LDD, C( IS, JS ), LDC, ONE,
00450 $ F( 1, JS ), LDF )
00451 END IF
00452 IF( J.LT.Q ) THEN
00453 CALL DGEMM( 'N', 'N', MB, N-JE, NB, ONE,
00454 $ F( IS, JS ), LDF, B( JS, JE+1 ), LDB,
00455 $ ONE, C( IS, JE+1 ), LDC )
00456 CALL DGEMM( 'N', 'N', MB, N-JE, NB, ONE,
00457 $ F( IS, JS ), LDF, E( JS, JE+1 ), LDE,
00458 $ ONE, F( IS, JE+1 ), LDF )
00459 END IF
00460 120 CONTINUE
00461 130 CONTINUE
00462 IF( DSCALE.NE.ZERO ) THEN
00463 IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
00464 DIF = SQRT( DBLE( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
00465 ELSE
00466 DIF = SQRT( DBLE( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
00467 END IF
00468 END IF
00469 IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
00470 IF( NOTRAN ) THEN
00471 IFUNC = IJOB
00472 END IF
00473 SCALE2 = SCALE
00474 CALL DLACPY( 'F', M, N, C, LDC, WORK, M )
00475 CALL DLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
00476 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
00477 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
00478 ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
00479 CALL DLACPY( 'F', M, N, WORK, M, C, LDC )
00480 CALL DLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
00481 SCALE = SCALE2
00482 END IF
00483 150 CONTINUE
00484
00485 ELSE
00486
00487
00488
00489
00490
00491
00492 SCALE = ONE
00493 DO 210 I = 1, P
00494 IS = IWORK( I )
00495 IE = IWORK( I+1 ) - 1
00496 MB = IE - IS + 1
00497 DO 200 J = Q, P + 2, -1
00498 JS = IWORK( J )
00499 JE = IWORK( J+1 ) - 1
00500 NB = JE - JS + 1
00501 CALL DTGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
00502 $ B( JS, JS ), LDB, C( IS, JS ), LDC,
00503 $ D( IS, IS ), LDD, E( JS, JS ), LDE,
00504 $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
00505 $ IWORK( Q+2 ), PPQQ, LINFO )
00506 IF( LINFO.GT.0 )
00507 $ INFO = LINFO
00508 IF( SCALOC.NE.ONE ) THEN
00509 DO 160 K = 1, JS - 1
00510 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
00511 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
00512 160 CONTINUE
00513 DO 170 K = JS, JE
00514 CALL DSCAL( IS-1, SCALOC, C( 1, K ), 1 )
00515 CALL DSCAL( IS-1, SCALOC, F( 1, K ), 1 )
00516 170 CONTINUE
00517 DO 180 K = JS, JE
00518 CALL DSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
00519 CALL DSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
00520 180 CONTINUE
00521 DO 190 K = JE + 1, N
00522 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
00523 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
00524 190 CONTINUE
00525 SCALE = SCALE*SCALOC
00526 END IF
00527
00528
00529
00530 IF( J.GT.P+2 ) THEN
00531 CALL DGEMM( 'N', 'T', MB, JS-1, NB, ONE, C( IS, JS ),
00532 $ LDC, B( 1, JS ), LDB, ONE, F( IS, 1 ),
00533 $ LDF )
00534 CALL DGEMM( 'N', 'T', MB, JS-1, NB, ONE, F( IS, JS ),
00535 $ LDF, E( 1, JS ), LDE, ONE, F( IS, 1 ),
00536 $ LDF )
00537 END IF
00538 IF( I.LT.P ) THEN
00539 CALL DGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
00540 $ A( IS, IE+1 ), LDA, C( IS, JS ), LDC, ONE,
00541 $ C( IE+1, JS ), LDC )
00542 CALL DGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
00543 $ D( IS, IE+1 ), LDD, F( IS, JS ), LDF, ONE,
00544 $ C( IE+1, JS ), LDC )
00545 END IF
00546 200 CONTINUE
00547 210 CONTINUE
00548
00549 END IF
00550
00551 WORK( 1 ) = LWMIN
00552
00553 RETURN
00554
00555
00556
00557 END