You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zhetrd_he2hb.f 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. *> \brief \b ZHETRD_HE2HB
  2. *
  3. * @precisions fortran z -> s d c
  4. *
  5. * =========== DOCUMENTATION ===========
  6. *
  7. * Online html documentation available at
  8. * http://www.netlib.org/lapack/explore-html/
  9. *
  10. *> \htmlonly
  11. *> Download ZHETRD_HE2HB + dependencies
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrd_he2hb.f">
  13. *> [TGZ]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrd_he2hb.f">
  15. *> [ZIP]</a>
  16. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrd_he2hb.f">
  17. *> [TXT]</a>
  18. *> \endhtmlonly
  19. *
  20. * Definition:
  21. * ===========
  22. *
  23. * SUBROUTINE ZHETRD_HE2HB( UPLO, N, KD, A, LDA, AB, LDAB, TAU,
  24. * WORK, LWORK, INFO )
  25. *
  26. * IMPLICIT NONE
  27. *
  28. * .. Scalar Arguments ..
  29. * CHARACTER UPLO
  30. * INTEGER INFO, LDA, LDAB, LWORK, N, KD
  31. * ..
  32. * .. Array Arguments ..
  33. * COMPLEX*16 A( LDA, * ), AB( LDAB, * ),
  34. * TAU( * ), WORK( * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> ZHETRD_HE2HB reduces a complex Hermitian matrix A to complex Hermitian
  44. *> band-diagonal form AB by a unitary similarity transformation:
  45. *> Q**H * A * Q = AB.
  46. *> \endverbatim
  47. *
  48. * Arguments:
  49. * ==========
  50. *
  51. *> \param[in] UPLO
  52. *> \verbatim
  53. *> UPLO is CHARACTER*1
  54. *> = 'U': Upper triangle of A is stored;
  55. *> = 'L': Lower triangle of A is stored.
  56. *> \endverbatim
  57. *>
  58. *> \param[in] N
  59. *> \verbatim
  60. *> N is INTEGER
  61. *> The order of the matrix A. N >= 0.
  62. *> \endverbatim
  63. *>
  64. *> \param[in] KD
  65. *> \verbatim
  66. *> KD is INTEGER
  67. *> The number of superdiagonals of the reduced matrix if UPLO = 'U',
  68. *> or the number of subdiagonals if UPLO = 'L'. KD >= 0.
  69. *> The reduced matrix is stored in the array AB.
  70. *> \endverbatim
  71. *>
  72. *> \param[in,out] A
  73. *> \verbatim
  74. *> A is COMPLEX*16 array, dimension (LDA,N)
  75. *> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
  76. *> N-by-N upper triangular part of A contains the upper
  77. *> triangular part of the matrix A, and the strictly lower
  78. *> triangular part of A is not referenced. If UPLO = 'L', the
  79. *> leading N-by-N lower triangular part of A contains the lower
  80. *> triangular part of the matrix A, and the strictly upper
  81. *> triangular part of A is not referenced.
  82. *> On exit, if UPLO = 'U', the diagonal and first superdiagonal
  83. *> of A are overwritten by the corresponding elements of the
  84. *> tridiagonal matrix T, and the elements above the first
  85. *> superdiagonal, with the array TAU, represent the unitary
  86. *> matrix Q as a product of elementary reflectors; if UPLO
  87. *> = 'L', the diagonal and first subdiagonal of A are over-
  88. *> written by the corresponding elements of the tridiagonal
  89. *> matrix T, and the elements below the first subdiagonal, with
  90. *> the array TAU, represent the unitary matrix Q as a product
  91. *> of elementary reflectors. See Further Details.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] LDA
  95. *> \verbatim
  96. *> LDA is INTEGER
  97. *> The leading dimension of the array A. LDA >= max(1,N).
  98. *> \endverbatim
  99. *>
  100. *> \param[out] AB
  101. *> \verbatim
  102. *> AB is COMPLEX*16 array, dimension (LDAB,N)
  103. *> On exit, the upper or lower triangle of the Hermitian band
  104. *> matrix A, stored in the first KD+1 rows of the array. The
  105. *> j-th column of A is stored in the j-th column of the array AB
  106. *> as follows:
  107. *> if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
  108. *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
  109. *> \endverbatim
  110. *>
  111. *> \param[in] LDAB
  112. *> \verbatim
  113. *> LDAB is INTEGER
  114. *> The leading dimension of the array AB. LDAB >= KD+1.
  115. *> \endverbatim
  116. *>
  117. *> \param[out] TAU
  118. *> \verbatim
  119. *> TAU is COMPLEX*16 array, dimension (N-KD)
  120. *> The scalar factors of the elementary reflectors (see Further
  121. *> Details).
  122. *> \endverbatim
  123. *>
  124. *> \param[out] WORK
  125. *> \verbatim
  126. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  127. *> On exit, if INFO = 0, or if LWORK = -1,
  128. *> WORK(1) returns the size of LWORK.
  129. *> \endverbatim
  130. *>
  131. *> \param[in] LWORK
  132. *> \verbatim
  133. *> LWORK is INTEGER
  134. *> The dimension of the array WORK which should be calculated
  135. *> by a workspace query.
  136. *> If N <= KD+1, LWORK >= 1, else LWORK = MAX(1, LWORK_QUERY).
  137. *>
  138. *> If LWORK = -1, then a workspace query is assumed; the routine
  139. *> only calculates the optimal size of the WORK array, returns
  140. *> this value as the first entry of the WORK array, and no error
  141. *> message related to LWORK is issued by XERBLA.
  142. *> LWORK_QUERY = N*KD + N*max(KD,FACTOPTNB) + 2*KD*KD
  143. *> where FACTOPTNB is the blocking used by the QR or LQ
  144. *> algorithm, usually FACTOPTNB=128 is a good choice otherwise
  145. *> putting LWORK=-1 will provide the size of WORK.
  146. *> \endverbatim
  147. *>
  148. *> \param[out] INFO
  149. *> \verbatim
  150. *> INFO is INTEGER
  151. *> = 0: successful exit
  152. *> < 0: if INFO = -i, the i-th argument had an illegal value
  153. *> \endverbatim
  154. *
  155. * Authors:
  156. * ========
  157. *
  158. *> \author Univ. of Tennessee
  159. *> \author Univ. of California Berkeley
  160. *> \author Univ. of Colorado Denver
  161. *> \author NAG Ltd.
  162. *
  163. *> \ingroup hetrd_he2hb
  164. *
  165. *> \par Further Details:
  166. * =====================
  167. *>
  168. *> \verbatim
  169. *>
  170. *> Implemented by Azzam Haidar.
  171. *>
  172. *> All details are available on technical report, SC11, SC13 papers.
  173. *>
  174. *> Azzam Haidar, Hatem Ltaief, and Jack Dongarra.
  175. *> Parallel reduction to condensed forms for symmetric eigenvalue problems
  176. *> using aggregated fine-grained and memory-aware kernels. In Proceedings
  177. *> of 2011 International Conference for High Performance Computing,
  178. *> Networking, Storage and Analysis (SC '11), New York, NY, USA,
  179. *> Article 8 , 11 pages.
  180. *> http://doi.acm.org/10.1145/2063384.2063394
  181. *>
  182. *> A. Haidar, J. Kurzak, P. Luszczek, 2013.
  183. *> An improved parallel singular value algorithm and its implementation
  184. *> for multicore hardware, In Proceedings of 2013 International Conference
  185. *> for High Performance Computing, Networking, Storage and Analysis (SC '13).
  186. *> Denver, Colorado, USA, 2013.
  187. *> Article 90, 12 pages.
  188. *> http://doi.acm.org/10.1145/2503210.2503292
  189. *>
  190. *> A. Haidar, R. Solca, S. Tomov, T. Schulthess and J. Dongarra.
  191. *> A novel hybrid CPU-GPU generalized eigensolver for electronic structure
  192. *> calculations based on fine-grained memory aware tasks.
  193. *> International Journal of High Performance Computing Applications.
  194. *> Volume 28 Issue 2, Pages 196-209, May 2014.
  195. *> http://hpc.sagepub.com/content/28/2/196
  196. *>
  197. *> \endverbatim
  198. *>
  199. *> \verbatim
  200. *>
  201. *> If UPLO = 'U', the matrix Q is represented as a product of elementary
  202. *> reflectors
  203. *>
  204. *> Q = H(k)**H . . . H(2)**H H(1)**H, where k = n-kd.
  205. *>
  206. *> Each H(i) has the form
  207. *>
  208. *> H(i) = I - tau * v * v**H
  209. *>
  210. *> where tau is a complex scalar, and v is a complex vector with
  211. *> v(1:i+kd-1) = 0 and v(i+kd) = 1; conjg(v(i+kd+1:n)) is stored on exit in
  212. *> A(i,i+kd+1:n), and tau in TAU(i).
  213. *>
  214. *> If UPLO = 'L', the matrix Q is represented as a product of elementary
  215. *> reflectors
  216. *>
  217. *> Q = H(1) H(2) . . . H(k), where k = n-kd.
  218. *>
  219. *> Each H(i) has the form
  220. *>
  221. *> H(i) = I - tau * v * v**H
  222. *>
  223. *> where tau is a complex scalar, and v is a complex vector with
  224. *> v(kd+1:i) = 0 and v(i+kd+1) = 1; v(i+kd+2:n) is stored on exit in
  225. *> A(i+kd+2:n,i), and tau in TAU(i).
  226. *>
  227. *> The contents of A on exit are illustrated by the following examples
  228. *> with n = 5:
  229. *>
  230. *> if UPLO = 'U': if UPLO = 'L':
  231. *>
  232. *> ( ab ab/v1 v1 v1 v1 ) ( ab )
  233. *> ( ab ab/v2 v2 v2 ) ( ab/v1 ab )
  234. *> ( ab ab/v3 v3 ) ( v1 ab/v2 ab )
  235. *> ( ab ab/v4 ) ( v1 v2 ab/v3 ab )
  236. *> ( ab ) ( v1 v2 v3 ab/v4 ab )
  237. *>
  238. *> where d and e denote diagonal and off-diagonal elements of T, and vi
  239. *> denotes an element of the vector defining H(i).
  240. *> \endverbatim
  241. *>
  242. * =====================================================================
  243. SUBROUTINE ZHETRD_HE2HB( UPLO, N, KD, A, LDA, AB, LDAB, TAU,
  244. $ WORK, LWORK, INFO )
  245. *
  246. IMPLICIT NONE
  247. *
  248. * -- LAPACK computational routine --
  249. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  250. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  251. *
  252. * .. Scalar Arguments ..
  253. CHARACTER UPLO
  254. INTEGER INFO, LDA, LDAB, LWORK, N, KD
  255. * ..
  256. * .. Array Arguments ..
  257. COMPLEX*16 A( LDA, * ), AB( LDAB, * ),
  258. $ TAU( * ), WORK( * )
  259. * ..
  260. *
  261. * =====================================================================
  262. *
  263. * .. Parameters ..
  264. DOUBLE PRECISION RONE
  265. COMPLEX*16 ZERO, ONE, HALF
  266. PARAMETER ( RONE = 1.0D+0,
  267. $ ZERO = ( 0.0D+0, 0.0D+0 ),
  268. $ ONE = ( 1.0D+0, 0.0D+0 ),
  269. $ HALF = ( 0.5D+0, 0.0D+0 ) )
  270. * ..
  271. * .. Local Scalars ..
  272. LOGICAL LQUERY, UPPER
  273. INTEGER I, J, IINFO, LWMIN, PN, PK, LK,
  274. $ LDT, LDW, LDS2, LDS1,
  275. $ LS2, LS1, LW, LT,
  276. $ TPOS, WPOS, S2POS, S1POS
  277. * ..
  278. * .. External Subroutines ..
  279. EXTERNAL XERBLA, ZHER2K, ZHEMM, ZGEMM, ZCOPY,
  280. $ ZLARFT, ZGELQF, ZGEQRF, ZLASET
  281. * ..
  282. * .. Intrinsic Functions ..
  283. INTRINSIC MIN, MAX
  284. * ..
  285. * .. External Functions ..
  286. LOGICAL LSAME
  287. INTEGER ILAENV2STAGE
  288. EXTERNAL LSAME, ILAENV2STAGE
  289. * ..
  290. * .. Executable Statements ..
  291. *
  292. * Determine the minimal workspace size required
  293. * and test the input parameters
  294. *
  295. INFO = 0
  296. UPPER = LSAME( UPLO, 'U' )
  297. LQUERY = ( LWORK.EQ.-1 )
  298. IF( N.LE.KD+1 ) THEN
  299. LWMIN = 1
  300. ELSE
  301. LWMIN = ILAENV2STAGE( 4, 'ZHETRD_HE2HB', '', N, KD, -1, -1 )
  302. END IF
  303. *
  304. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  305. INFO = -1
  306. ELSE IF( N.LT.0 ) THEN
  307. INFO = -2
  308. ELSE IF( KD.LT.0 ) THEN
  309. INFO = -3
  310. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  311. INFO = -5
  312. ELSE IF( LDAB.LT.MAX( 1, KD+1 ) ) THEN
  313. INFO = -7
  314. ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  315. INFO = -10
  316. END IF
  317. *
  318. IF( INFO.NE.0 ) THEN
  319. CALL XERBLA( 'ZHETRD_HE2HB', -INFO )
  320. RETURN
  321. ELSE IF( LQUERY ) THEN
  322. WORK( 1 ) = LWMIN
  323. RETURN
  324. END IF
  325. *
  326. * Quick return if possible
  327. * Copy the upper/lower portion of A into AB
  328. *
  329. IF( N.LE.KD+1 ) THEN
  330. IF( UPPER ) THEN
  331. DO 100 I = 1, N
  332. LK = MIN( KD+1, I )
  333. CALL ZCOPY( LK, A( I-LK+1, I ), 1,
  334. $ AB( KD+1-LK+1, I ), 1 )
  335. 100 CONTINUE
  336. ELSE
  337. DO 110 I = 1, N
  338. LK = MIN( KD+1, N-I+1 )
  339. CALL ZCOPY( LK, A( I, I ), 1, AB( 1, I ), 1 )
  340. 110 CONTINUE
  341. ENDIF
  342. WORK( 1 ) = 1
  343. RETURN
  344. END IF
  345. *
  346. * Determine the pointer position for the workspace
  347. *
  348. LDT = KD
  349. LDS1 = KD
  350. LT = LDT*KD
  351. LW = N*KD
  352. LS1 = LDS1*KD
  353. LS2 = LWMIN - LT - LW - LS1
  354. * LS2 = N*MAX(KD,FACTOPTNB)
  355. TPOS = 1
  356. WPOS = TPOS + LT
  357. S1POS = WPOS + LW
  358. S2POS = S1POS + LS1
  359. IF( UPPER ) THEN
  360. LDW = KD
  361. LDS2 = KD
  362. ELSE
  363. LDW = N
  364. LDS2 = N
  365. ENDIF
  366. *
  367. *
  368. * Set the workspace of the triangular matrix T to zero once such a
  369. * way every time T is generated the upper/lower portion will be always zero
  370. *
  371. CALL ZLASET( "A", LDT, KD, ZERO, ZERO, WORK( TPOS ), LDT )
  372. *
  373. IF( UPPER ) THEN
  374. DO 10 I = 1, N - KD, KD
  375. PN = N-I-KD+1
  376. PK = MIN( N-I-KD+1, KD )
  377. *
  378. * Compute the LQ factorization of the current block
  379. *
  380. CALL ZGELQF( KD, PN, A( I, I+KD ), LDA,
  381. $ TAU( I ), WORK( S2POS ), LS2, IINFO )
  382. *
  383. * Copy the upper portion of A into AB
  384. *
  385. DO 20 J = I, I+PK-1
  386. LK = MIN( KD, N-J ) + 1
  387. CALL ZCOPY( LK, A( J, J ), LDA, AB( KD+1, J ), LDAB-1 )
  388. 20 CONTINUE
  389. *
  390. CALL ZLASET( 'Lower', PK, PK, ZERO, ONE,
  391. $ A( I, I+KD ), LDA )
  392. *
  393. * Form the matrix T
  394. *
  395. CALL ZLARFT( 'Forward', 'Rowwise', PN, PK,
  396. $ A( I, I+KD ), LDA, TAU( I ),
  397. $ WORK( TPOS ), LDT )
  398. *
  399. * Compute W:
  400. *
  401. CALL ZGEMM( 'Conjugate', 'No transpose', PK, PN, PK,
  402. $ ONE, WORK( TPOS ), LDT,
  403. $ A( I, I+KD ), LDA,
  404. $ ZERO, WORK( S2POS ), LDS2 )
  405. *
  406. CALL ZHEMM( 'Right', UPLO, PK, PN,
  407. $ ONE, A( I+KD, I+KD ), LDA,
  408. $ WORK( S2POS ), LDS2,
  409. $ ZERO, WORK( WPOS ), LDW )
  410. *
  411. CALL ZGEMM( 'No transpose', 'Conjugate', PK, PK, PN,
  412. $ ONE, WORK( WPOS ), LDW,
  413. $ WORK( S2POS ), LDS2,
  414. $ ZERO, WORK( S1POS ), LDS1 )
  415. *
  416. CALL ZGEMM( 'No transpose', 'No transpose', PK, PN, PK,
  417. $ -HALF, WORK( S1POS ), LDS1,
  418. $ A( I, I+KD ), LDA,
  419. $ ONE, WORK( WPOS ), LDW )
  420. *
  421. *
  422. * Update the unreduced submatrix A(i+kd:n,i+kd:n), using
  423. * an update of the form: A := A - V'*W - W'*V
  424. *
  425. CALL ZHER2K( UPLO, 'Conjugate', PN, PK,
  426. $ -ONE, A( I, I+KD ), LDA,
  427. $ WORK( WPOS ), LDW,
  428. $ RONE, A( I+KD, I+KD ), LDA )
  429. 10 CONTINUE
  430. *
  431. * Copy the upper band to AB which is the band storage matrix
  432. *
  433. DO 30 J = N-KD+1, N
  434. LK = MIN(KD, N-J) + 1
  435. CALL ZCOPY( LK, A( J, J ), LDA, AB( KD+1, J ), LDAB-1 )
  436. 30 CONTINUE
  437. *
  438. ELSE
  439. *
  440. * Reduce the lower triangle of A to lower band matrix
  441. *
  442. DO 40 I = 1, N - KD, KD
  443. PN = N-I-KD+1
  444. PK = MIN( N-I-KD+1, KD )
  445. *
  446. * Compute the QR factorization of the current block
  447. *
  448. CALL ZGEQRF( PN, KD, A( I+KD, I ), LDA,
  449. $ TAU( I ), WORK( S2POS ), LS2, IINFO )
  450. *
  451. * Copy the upper portion of A into AB
  452. *
  453. DO 50 J = I, I+PK-1
  454. LK = MIN( KD, N-J ) + 1
  455. CALL ZCOPY( LK, A( J, J ), 1, AB( 1, J ), 1 )
  456. 50 CONTINUE
  457. *
  458. CALL ZLASET( 'Upper', PK, PK, ZERO, ONE,
  459. $ A( I+KD, I ), LDA )
  460. *
  461. * Form the matrix T
  462. *
  463. CALL ZLARFT( 'Forward', 'Columnwise', PN, PK,
  464. $ A( I+KD, I ), LDA, TAU( I ),
  465. $ WORK( TPOS ), LDT )
  466. *
  467. * Compute W:
  468. *
  469. CALL ZGEMM( 'No transpose', 'No transpose', PN, PK, PK,
  470. $ ONE, A( I+KD, I ), LDA,
  471. $ WORK( TPOS ), LDT,
  472. $ ZERO, WORK( S2POS ), LDS2 )
  473. *
  474. CALL ZHEMM( 'Left', UPLO, PN, PK,
  475. $ ONE, A( I+KD, I+KD ), LDA,
  476. $ WORK( S2POS ), LDS2,
  477. $ ZERO, WORK( WPOS ), LDW )
  478. *
  479. CALL ZGEMM( 'Conjugate', 'No transpose', PK, PK, PN,
  480. $ ONE, WORK( S2POS ), LDS2,
  481. $ WORK( WPOS ), LDW,
  482. $ ZERO, WORK( S1POS ), LDS1 )
  483. *
  484. CALL ZGEMM( 'No transpose', 'No transpose', PN, PK, PK,
  485. $ -HALF, A( I+KD, I ), LDA,
  486. $ WORK( S1POS ), LDS1,
  487. $ ONE, WORK( WPOS ), LDW )
  488. *
  489. *
  490. * Update the unreduced submatrix A(i+kd:n,i+kd:n), using
  491. * an update of the form: A := A - V*W' - W*V'
  492. *
  493. CALL ZHER2K( UPLO, 'No transpose', PN, PK,
  494. $ -ONE, A( I+KD, I ), LDA,
  495. $ WORK( WPOS ), LDW,
  496. $ RONE, A( I+KD, I+KD ), LDA )
  497. * ==================================================================
  498. * RESTORE A FOR COMPARISON AND CHECKING TO BE REMOVED
  499. * DO 45 J = I, I+PK-1
  500. * LK = MIN( KD, N-J ) + 1
  501. * CALL ZCOPY( LK, AB( 1, J ), 1, A( J, J ), 1 )
  502. * 45 CONTINUE
  503. * ==================================================================
  504. 40 CONTINUE
  505. *
  506. * Copy the lower band to AB which is the band storage matrix
  507. *
  508. DO 60 J = N-KD+1, N
  509. LK = MIN(KD, N-J) + 1
  510. CALL ZCOPY( LK, A( J, J ), 1, AB( 1, J ), 1 )
  511. 60 CONTINUE
  512. END IF
  513. *
  514. WORK( 1 ) = LWMIN
  515. RETURN
  516. *
  517. * End of ZHETRD_HE2HB
  518. *
  519. END