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