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