134
135
136
137
138
139
140 CHARACTER UPLO
141 INTEGER INFO, LDA, LDB, N, NRHS
142
143
144 INTEGER IPIV( * )
145 REAL A( LDA, * ), B( LDB, * )
146
147
148
149
150
151 REAL ONE
152 parameter( one = 1.0e+0 )
153
154
155 LOGICAL UPPER
156 INTEGER J, K, KP
157 REAL AK, AKM1, AKM1K, BK, BKM1, DENOM
158
159
160 LOGICAL LSAME
162
163
165
166
167 INTRINSIC max
168
169
170
171 info = 0
172 upper =
lsame( uplo,
'U' )
173 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
174 info = -1
175 ELSE IF( n.LT.0 ) THEN
176 info = -2
177 ELSE IF( nrhs.LT.0 ) THEN
178 info = -3
179 ELSE IF( lda.LT.max( 1, n ) ) THEN
180 info = -5
181 ELSE IF( ldb.LT.max( 1, n ) ) THEN
182 info = -8
183 END IF
184 IF( info.NE.0 ) THEN
185 CALL xerbla(
'SSYTRS_ROOK', -info )
186 RETURN
187 END IF
188
189
190
191 IF( n.EQ.0 .OR. nrhs.EQ.0 )
192 $ RETURN
193
194 IF( upper ) THEN
195
196
197
198
199
200
201
202
203 k = n
204 10 CONTINUE
205
206
207
208 IF( k.LT.1 )
209 $ GO TO 30
210
211 IF( ipiv( k ).GT.0 ) THEN
212
213
214
215
216
217 kp = ipiv( k )
218 IF( kp.NE.k )
219 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
220
221
222
223
224 CALL sger( k-1, nrhs, -one, a( 1, k ), 1, b( k, 1 ), ldb,
225 $ b( 1, 1 ), ldb )
226
227
228
229 CALL sscal( nrhs, one / a( k, k ), b( k, 1 ), ldb )
230 k = k - 1
231 ELSE
232
233
234
235
236
237 kp = -ipiv( k )
238 IF( kp.NE.k )
239 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
240
241 kp = -ipiv( k-1 )
242 IF( kp.NE.k-1 )
243 $
CALL sswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
244
245
246
247
248 IF( k.GT.2 ) THEN
249 CALL sger( k-2, nrhs, -one, a( 1, k ), 1, b( k, 1 ),
250 $ ldb, b( 1, 1 ), ldb )
251 CALL sger( k-2, nrhs, -one, a( 1, k-1 ), 1, b( k-1,
252 $ 1 ),
253 $ ldb, b( 1, 1 ), ldb )
254 END IF
255
256
257
258 akm1k = a( k-1, k )
259 akm1 = a( k-1, k-1 ) / akm1k
260 ak = a( k, k ) / akm1k
261 denom = akm1*ak - one
262 DO 20 j = 1, nrhs
263 bkm1 = b( k-1, j ) / akm1k
264 bk = b( k, j ) / akm1k
265 b( k-1, j ) = ( ak*bkm1-bk ) / denom
266 b( k, j ) = ( akm1*bk-bkm1 ) / denom
267 20 CONTINUE
268 k = k - 2
269 END IF
270
271 GO TO 10
272 30 CONTINUE
273
274
275
276
277
278
279 k = 1
280 40 CONTINUE
281
282
283
284 IF( k.GT.n )
285 $ GO TO 50
286
287 IF( ipiv( k ).GT.0 ) THEN
288
289
290
291
292
293
294 IF( k.GT.1 )
295 $
CALL sgemv(
'Transpose', k-1, nrhs, -one, b,
296 $ ldb, a( 1, k ), 1, one, b( k, 1 ), ldb )
297
298
299
300 kp = ipiv( k )
301 IF( kp.NE.k )
302 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
303 k = k + 1
304 ELSE
305
306
307
308
309
310
311 IF( k.GT.1 ) THEN
312 CALL sgemv(
'Transpose', k-1, nrhs, -one, b,
313 $ ldb, a( 1, k ), 1, one, b( k, 1 ), ldb )
314 CALL sgemv(
'Transpose', k-1, nrhs, -one, b,
315 $ ldb, a( 1, k+1 ), 1, one, b( k+1, 1 ), ldb )
316 END IF
317
318
319
320 kp = -ipiv( k )
321 IF( kp.NE.k )
322 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
323
324 kp = -ipiv( k+1 )
325 IF( kp.NE.k+1 )
326 $
CALL sswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
327
328 k = k + 2
329 END IF
330
331 GO TO 40
332 50 CONTINUE
333
334 ELSE
335
336
337
338
339
340
341
342
343 k = 1
344 60 CONTINUE
345
346
347
348 IF( k.GT.n )
349 $ GO TO 80
350
351 IF( ipiv( k ).GT.0 ) THEN
352
353
354
355
356
357 kp = ipiv( k )
358 IF( kp.NE.k )
359 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
360
361
362
363
364 IF( k.LT.n )
365 $
CALL sger( n-k, nrhs, -one, a( k+1, k ), 1, b( k, 1 ),
366 $ ldb, b( k+1, 1 ), ldb )
367
368
369
370 CALL sscal( nrhs, one / a( k, k ), b( k, 1 ), ldb )
371 k = k + 1
372 ELSE
373
374
375
376
377
378 kp = -ipiv( k )
379 IF( kp.NE.k )
380 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
381
382 kp = -ipiv( k+1 )
383 IF( kp.NE.k+1 )
384 $
CALL sswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
385
386
387
388
389 IF( k.LT.n-1 ) THEN
390 CALL sger( n-k-1, nrhs, -one, a( k+2, k ), 1, b( k,
391 $ 1 ),
392 $ ldb, b( k+2, 1 ), ldb )
393 CALL sger( n-k-1, nrhs, -one, a( k+2, k+1 ), 1,
394 $ b( k+1, 1 ), ldb, b( k+2, 1 ), ldb )
395 END IF
396
397
398
399 akm1k = a( k+1, k )
400 akm1 = a( k, k ) / akm1k
401 ak = a( k+1, k+1 ) / akm1k
402 denom = akm1*ak - one
403 DO 70 j = 1, nrhs
404 bkm1 = b( k, j ) / akm1k
405 bk = b( k+1, j ) / akm1k
406 b( k, j ) = ( ak*bkm1-bk ) / denom
407 b( k+1, j ) = ( akm1*bk-bkm1 ) / denom
408 70 CONTINUE
409 k = k + 2
410 END IF
411
412 GO TO 60
413 80 CONTINUE
414
415
416
417
418
419
420 k = n
421 90 CONTINUE
422
423
424
425 IF( k.LT.1 )
426 $ GO TO 100
427
428 IF( ipiv( k ).GT.0 ) THEN
429
430
431
432
433
434
435 IF( k.LT.n )
436 $
CALL sgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
437 $ ldb, a( k+1, k ), 1, one, b( k, 1 ), ldb )
438
439
440
441 kp = ipiv( k )
442 IF( kp.NE.k )
443 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
444 k = k - 1
445 ELSE
446
447
448
449
450
451
452 IF( k.LT.n ) THEN
453 CALL sgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
454 $ ldb, a( k+1, k ), 1, one, b( k, 1 ), ldb )
455 CALL sgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
456 $ ldb, a( k+1, k-1 ), 1, one, b( k-1, 1 ),
457 $ ldb )
458 END IF
459
460
461
462 kp = -ipiv( k )
463 IF( kp.NE.k )
464 $
CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
465
466 kp = -ipiv( k-1 )
467 IF( kp.NE.k-1 )
468 $
CALL sswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
469
470 k = k - 2
471 END IF
472
473 GO TO 90
474 100 CONTINUE
475 END IF
476
477 RETURN
478
479
480
subroutine xerbla(srname, info)
subroutine sgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
SGEMV
subroutine sger(m, n, alpha, x, incx, y, incy, a, lda)
SGER
logical function lsame(ca, cb)
LSAME
subroutine sscal(n, sa, sx, incx)
SSCAL
subroutine sswap(n, sx, incx, sy, incy)
SSWAP