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.

chetrd_he2hb.f 18 kB

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