132
133
134
135
136
137 IMPLICIT NONE
138
139
140 CHARACTER UPLO
141 INTEGER N, LDA, LWORK, INFO
142
143
144 INTEGER IPIV( * )
145 COMPLEX*16 A( LDA, * ), WORK( * )
146
147
148
149
150 COMPLEX*16 ZERO, ONE
151 parameter( zero = (0.0d+0, 0.0d+0), one = (1.0d+0, 0.0d+0) )
152
153
154 LOGICAL LQUERY, UPPER
155 INTEGER J, LWKOPT
156 INTEGER NB, MJ, NJ, K1, K2, J1, J2, J3, JB
157 COMPLEX*16 ALPHA
158
159
160 LOGICAL LSAME
161 INTEGER ILAENV
163
164
166
167
168 INTRINSIC dble, dconjg, max
169
170
171
172
173
174 nb =
ilaenv( 1,
'ZHETRF_AA', uplo, n, -1, -1, -1 )
175
176
177
178 info = 0
179 upper =
lsame( uplo,
'U' )
180 lquery = ( lwork.EQ.-1 )
181 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
182 info = -1
183 ELSE IF( n.LT.0 ) THEN
184 info = -2
185 ELSE IF( lda.LT.max( 1, n ) ) THEN
186 info = -4
187 ELSE IF( lwork.LT.max( 1, 2*n ) .AND. .NOT.lquery ) THEN
188 info = -7
189 END IF
190
191 IF( info.EQ.0 ) THEN
192 lwkopt = (nb+1)*n
193 work( 1 ) = lwkopt
194 END IF
195
196 IF( info.NE.0 ) THEN
197 CALL xerbla(
'ZHETRF_AA', -info )
198 RETURN
199 ELSE IF( lquery ) THEN
200 RETURN
201 END IF
202
203
204
205 IF ( n.EQ.0 ) THEN
206 RETURN
207 ENDIF
208 ipiv( 1 ) = 1
209 IF ( n.EQ.1 ) THEN
210 a( 1, 1 ) = dble( a( 1, 1 ) )
211 RETURN
212 END IF
213
214
215
216 IF( lwork.LT.((1+nb)*n) ) THEN
217 nb = ( lwork-n ) / n
218 END IF
219
220 IF( upper ) THEN
221
222
223
224
225
226
227
228 CALL zcopy( n, a( 1, 1 ), lda, work( 1 ), 1 )
229
230
231
232
233
234 j = 0
235 10 CONTINUE
236 IF( j.GE.n )
237 $ GO TO 20
238
239
240
241
242
243
244
245
246 j1 = j + 1
247 jb = min( n-j1+1, nb )
248 k1 = max(1, j)-j
249
250
251
253 $ a( max(1, j), j+1 ), lda,
254 $ ipiv( j+1 ), work, n, work( n*nb+1 ) )
255
256
257
258 DO j2 = j+2, min(n, j+jb+1)
259 ipiv( j2 ) = ipiv( j2 ) + j
260 IF( (j2.NE.ipiv(j2)) .AND. ((j1-k1).GT.2) ) THEN
261 CALL zswap( j1-k1-2, a( 1, j2 ), 1,
262 $ a( 1, ipiv(j2) ), 1 )
263 END IF
264 END DO
265 j = j + jb
266
267
268
269
270
271 IF( j.LT.n ) THEN
272
273
274
275 IF( j1.GT.1 .OR. jb.GT.1 ) THEN
276
277
278
279 alpha = dconjg( a( j, j+1 ) )
280 a( j, j+1 ) = one
281 CALL zcopy( n-j, a( j-1, j+1 ), lda,
282 $ work( (j+1-j1+1)+jb*n ), 1 )
283 CALL zscal( n-j, alpha, work( (j+1-j1+1)+jb*n ), 1 )
284
285
286
287
288
289 IF( j1.GT.1 ) THEN
290
291
292
293 k2 = 1
294 ELSE
295
296
297
298 k2 = 0
299
300
301
302 jb = jb - 1
303 END IF
304
305 DO j2 = j+1, n, nb
306 nj = min( nb, n-j2+1 )
307
308
309
310 j3 = j2
311 DO mj = nj-1, 1, -1
312 CALL zgemm(
'Conjugate transpose',
'Transpose',
313 $ 1, mj, jb+1,
314 $ -one, a( j1-k2, j3 ), lda,
315 $ work( (j3-j1+1)+k1*n ), n,
316 $ one, a( j3, j3 ), lda )
317 j3 = j3 + 1
318 END DO
319
320
321
322 CALL zgemm(
'Conjugate transpose',
'Transpose',
323 $ nj, n-j3+1, jb+1,
324 $ -one, a( j1-k2, j2 ), lda,
325 $ work( (j3-j1+1)+k1*n ), n,
326 $ one, a( j2, j3 ), lda )
327 END DO
328
329
330
331 a( j, j+1 ) = dconjg( alpha )
332 END IF
333
334
335
336 CALL zcopy( n-j, a( j+1, j+1 ), lda, work( 1 ), 1 )
337 END IF
338 GO TO 10
339 ELSE
340
341
342
343
344
345
346
347
348 CALL zcopy( n, a( 1, 1 ), 1, work( 1 ), 1 )
349
350
351
352
353
354 j = 0
355 11 CONTINUE
356 IF( j.GE.n )
357 $ GO TO 20
358
359
360
361
362
363
364
365
366 j1 = j+1
367 jb = min( n-j1+1, nb )
368 k1 = max(1, j)-j
369
370
371
373 $ a( j+1, max(1, j) ), lda,
374 $ ipiv( j+1 ), work, n, work( n*nb+1 ) )
375
376
377
378 DO j2 = j+2, min(n, j+jb+1)
379 ipiv( j2 ) = ipiv( j2 ) + j
380 IF( (j2.NE.ipiv(j2)) .AND. ((j1-k1).GT.2) ) THEN
381 CALL zswap( j1-k1-2, a( j2, 1 ), lda,
382 $ a( ipiv(j2), 1 ), lda )
383 END IF
384 END DO
385 j = j + jb
386
387
388
389
390
391 IF( j.LT.n ) THEN
392
393
394
395 IF( j1.GT.1 .OR. jb.GT.1 ) THEN
396
397
398
399 alpha = dconjg( a( j+1, j ) )
400 a( j+1, j ) = one
401 CALL zcopy( n-j, a( j+1, j-1 ), 1,
402 $ work( (j+1-j1+1)+jb*n ), 1 )
403 CALL zscal( n-j, alpha, work( (j+1-j1+1)+jb*n ), 1 )
404
405
406
407
408
409 IF( j1.GT.1 ) THEN
410
411
412
413 k2 = 1
414 ELSE
415
416
417
418 k2 = 0
419
420
421
422 jb = jb - 1
423 END IF
424
425 DO j2 = j+1, n, nb
426 nj = min( nb, n-j2+1 )
427
428
429
430 j3 = j2
431 DO mj = nj-1, 1, -1
432 CALL zgemm(
'No transpose',
'Conjugate transpose',
433 $ mj, 1, jb+1,
434 $ -one, work( (j3-j1+1)+k1*n ), n,
435 $ a( j3, j1-k2 ), lda,
436 $ one, a( j3, j3 ), lda )
437 j3 = j3 + 1
438 END DO
439
440
441
442 CALL zgemm(
'No transpose',
'Conjugate transpose',
443 $ n-j3+1, nj, jb+1,
444 $ -one, work( (j3-j1+1)+k1*n ), n,
445 $ a( j2, j1-k2 ), lda,
446 $ one, a( j3, j2 ), lda )
447 END DO
448
449
450
451 a( j+1, j ) = dconjg( alpha )
452 END IF
453
454
455
456 CALL zcopy( n-j, a( j+1, j+1 ), 1, work( 1 ), 1 )
457 END IF
458 GO TO 11
459 END IF
460
461 20 CONTINUE
462 work( 1 ) = lwkopt
463 RETURN
464
465
466
subroutine xerbla(srname, info)
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
subroutine zgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
ZGEMV
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
subroutine zlahef_aa(uplo, j1, m, nb, a, lda, ipiv, h, ldh, work)
ZLAHEF_AA
logical function lsame(ca, cb)
LSAME
subroutine zscal(n, za, zx, incx)
ZSCAL
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP