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.

ssygvd.f 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. *> \brief \b SSYGVD
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SSYGVD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssygvd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssygvd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssygvd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SSYGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,
  22. * LWORK, IWORK, LIWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER JOBZ, UPLO
  26. * INTEGER INFO, ITYPE, LDA, LDB, LIWORK, LWORK, N
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IWORK( * )
  30. * REAL A( LDA, * ), B( LDB, * ), W( * ), WORK( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> SSYGVD computes all the eigenvalues, and optionally, the eigenvectors
  40. *> of a real generalized symmetric-definite eigenproblem, of the form
  41. *> A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and
  42. *> B are assumed to be symmetric and B is also positive definite.
  43. *> If eigenvectors are desired, it uses a divide and conquer algorithm.
  44. *>
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] ITYPE
  51. *> \verbatim
  52. *> ITYPE is INTEGER
  53. *> Specifies the problem type to be solved:
  54. *> = 1: A*x = (lambda)*B*x
  55. *> = 2: A*B*x = (lambda)*x
  56. *> = 3: B*A*x = (lambda)*x
  57. *> \endverbatim
  58. *>
  59. *> \param[in] JOBZ
  60. *> \verbatim
  61. *> JOBZ is CHARACTER*1
  62. *> = 'N': Compute eigenvalues only;
  63. *> = 'V': Compute eigenvalues and eigenvectors.
  64. *> \endverbatim
  65. *>
  66. *> \param[in] UPLO
  67. *> \verbatim
  68. *> UPLO is CHARACTER*1
  69. *> = 'U': Upper triangles of A and B are stored;
  70. *> = 'L': Lower triangles of A and B are stored.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] N
  74. *> \verbatim
  75. *> N is INTEGER
  76. *> The order of the matrices A and B. N >= 0.
  77. *> \endverbatim
  78. *>
  79. *> \param[in,out] A
  80. *> \verbatim
  81. *> A is REAL array, dimension (LDA, N)
  82. *> On entry, the symmetric matrix A. If UPLO = 'U', the
  83. *> leading N-by-N upper triangular part of A contains the
  84. *> upper triangular part of the matrix A. If UPLO = 'L',
  85. *> the leading N-by-N lower triangular part of A contains
  86. *> the lower triangular part of the matrix A.
  87. *>
  88. *> On exit, if JOBZ = 'V', then if INFO = 0, A contains the
  89. *> matrix Z of eigenvectors. The eigenvectors are normalized
  90. *> as follows:
  91. *> if ITYPE = 1 or 2, Z**T*B*Z = I;
  92. *> if ITYPE = 3, Z**T*inv(B)*Z = I.
  93. *> If JOBZ = 'N', then on exit the upper triangle (if UPLO='U')
  94. *> or the lower triangle (if UPLO='L') of A, including the
  95. *> diagonal, is destroyed.
  96. *> \endverbatim
  97. *>
  98. *> \param[in] LDA
  99. *> \verbatim
  100. *> LDA is INTEGER
  101. *> The leading dimension of the array A. LDA >= max(1,N).
  102. *> \endverbatim
  103. *>
  104. *> \param[in,out] B
  105. *> \verbatim
  106. *> B is REAL array, dimension (LDB, N)
  107. *> On entry, the symmetric matrix B. If UPLO = 'U', the
  108. *> leading N-by-N upper triangular part of B contains the
  109. *> upper triangular part of the matrix B. If UPLO = 'L',
  110. *> the leading N-by-N lower triangular part of B contains
  111. *> the lower triangular part of the matrix B.
  112. *>
  113. *> On exit, if INFO <= N, the part of B containing the matrix is
  114. *> overwritten by the triangular factor U or L from the Cholesky
  115. *> factorization B = U**T*U or B = L*L**T.
  116. *> \endverbatim
  117. *>
  118. *> \param[in] LDB
  119. *> \verbatim
  120. *> LDB is INTEGER
  121. *> The leading dimension of the array B. LDB >= max(1,N).
  122. *> \endverbatim
  123. *>
  124. *> \param[out] W
  125. *> \verbatim
  126. *> W is REAL array, dimension (N)
  127. *> If INFO = 0, the eigenvalues in ascending order.
  128. *> \endverbatim
  129. *>
  130. *> \param[out] WORK
  131. *> \verbatim
  132. *> WORK is REAL array, dimension (MAX(1,LWORK))
  133. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  134. *> \endverbatim
  135. *>
  136. *> \param[in] LWORK
  137. *> \verbatim
  138. *> LWORK is INTEGER
  139. *> The dimension of the array WORK.
  140. *> If N <= 1, LWORK >= 1.
  141. *> If JOBZ = 'N' and N > 1, LWORK >= 2*N+1.
  142. *> If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2.
  143. *>
  144. *> If LWORK = -1, then a workspace query is assumed; the routine
  145. *> only calculates the optimal sizes of the WORK and IWORK
  146. *> arrays, returns these values as the first entries of the WORK
  147. *> and IWORK arrays, and no error message related to LWORK or
  148. *> LIWORK is issued by XERBLA.
  149. *> \endverbatim
  150. *>
  151. *> \param[out] IWORK
  152. *> \verbatim
  153. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  154. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] LIWORK
  158. *> \verbatim
  159. *> LIWORK is INTEGER
  160. *> The dimension of the array IWORK.
  161. *> If N <= 1, LIWORK >= 1.
  162. *> If JOBZ = 'N' and N > 1, LIWORK >= 1.
  163. *> If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N.
  164. *>
  165. *> If LIWORK = -1, then a workspace query is assumed; the
  166. *> routine only calculates the optimal sizes of the WORK and
  167. *> IWORK arrays, returns these values as the first entries of
  168. *> the WORK and IWORK arrays, and no error message related to
  169. *> LWORK or LIWORK is issued by XERBLA.
  170. *> \endverbatim
  171. *>
  172. *> \param[out] INFO
  173. *> \verbatim
  174. *> INFO is INTEGER
  175. *> = 0: successful exit
  176. *> < 0: if INFO = -i, the i-th argument had an illegal value
  177. *> > 0: SPOTRF or SSYEVD returned an error code:
  178. *> <= N: if INFO = i and JOBZ = 'N', then the algorithm
  179. *> failed to converge; i off-diagonal elements of an
  180. *> intermediate tridiagonal form did not converge to
  181. *> zero;
  182. *> if INFO = i and JOBZ = 'V', then the algorithm
  183. *> failed to compute an eigenvalue while working on
  184. *> the submatrix lying in rows and columns INFO/(N+1)
  185. *> through mod(INFO,N+1);
  186. *> > N: if INFO = N + i, for 1 <= i <= N, then the leading
  187. *> principal minor of order i of B is not positive.
  188. *> The factorization of B could not be completed and
  189. *> no eigenvalues or eigenvectors were computed.
  190. *> \endverbatim
  191. *
  192. * Authors:
  193. * ========
  194. *
  195. *> \author Univ. of Tennessee
  196. *> \author Univ. of California Berkeley
  197. *> \author Univ. of Colorado Denver
  198. *> \author NAG Ltd.
  199. *
  200. *> \ingroup hegvd
  201. *
  202. *> \par Further Details:
  203. * =====================
  204. *>
  205. *> \verbatim
  206. *>
  207. *> Modified so that no backsubstitution is performed if SSYEVD fails to
  208. *> converge (NEIG in old code could be greater than N causing out of
  209. *> bounds reference to A - reported by Ralf Meyer). Also corrected the
  210. *> description of INFO and the test on ITYPE. Sven, 16 Feb 05.
  211. *> \endverbatim
  212. *
  213. *> \par Contributors:
  214. * ==================
  215. *>
  216. *> Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
  217. *>
  218. * =====================================================================
  219. SUBROUTINE SSYGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,
  220. $ LWORK, IWORK, LIWORK, INFO )
  221. *
  222. * -- LAPACK driver routine --
  223. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  224. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  225. *
  226. * .. Scalar Arguments ..
  227. CHARACTER JOBZ, UPLO
  228. INTEGER INFO, ITYPE, LDA, LDB, LIWORK, LWORK, N
  229. * ..
  230. * .. Array Arguments ..
  231. INTEGER IWORK( * )
  232. REAL A( LDA, * ), B( LDB, * ), W( * ), WORK( * )
  233. * ..
  234. *
  235. * =====================================================================
  236. *
  237. * .. Parameters ..
  238. REAL ONE
  239. PARAMETER ( ONE = 1.0E+0 )
  240. * ..
  241. * .. Local Scalars ..
  242. LOGICAL LQUERY, UPPER, WANTZ
  243. CHARACTER TRANS
  244. INTEGER LIOPT, LIWMIN, LOPT, LWMIN
  245. * ..
  246. * .. External Functions ..
  247. LOGICAL LSAME
  248. REAL SROUNDUP_LWORK
  249. EXTERNAL LSAME, SROUNDUP_LWORK
  250. * ..
  251. * .. External Subroutines ..
  252. EXTERNAL SPOTRF, SSYEVD, SSYGST, STRMM, STRSM, XERBLA
  253. * ..
  254. * .. Intrinsic Functions ..
  255. INTRINSIC MAX, REAL
  256. * ..
  257. * .. Executable Statements ..
  258. *
  259. * Test the input parameters.
  260. *
  261. WANTZ = LSAME( JOBZ, 'V' )
  262. UPPER = LSAME( UPLO, 'U' )
  263. LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
  264. *
  265. INFO = 0
  266. IF( N.LE.1 ) THEN
  267. LIWMIN = 1
  268. LWMIN = 1
  269. ELSE IF( WANTZ ) THEN
  270. LIWMIN = 3 + 5*N
  271. LWMIN = 1 + 6*N + 2*N**2
  272. ELSE
  273. LIWMIN = 1
  274. LWMIN = 2*N + 1
  275. END IF
  276. LOPT = LWMIN
  277. LIOPT = LIWMIN
  278. IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
  279. INFO = -1
  280. ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  281. INFO = -2
  282. ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
  283. INFO = -3
  284. ELSE IF( N.LT.0 ) THEN
  285. INFO = -4
  286. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  287. INFO = -6
  288. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  289. INFO = -8
  290. END IF
  291. *
  292. IF( INFO.EQ.0 ) THEN
  293. WORK( 1 ) = SROUNDUP_LWORK(LOPT)
  294. IWORK( 1 ) = LIOPT
  295. *
  296. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  297. INFO = -11
  298. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  299. INFO = -13
  300. END IF
  301. END IF
  302. *
  303. IF( INFO.NE.0 ) THEN
  304. CALL XERBLA( 'SSYGVD', -INFO )
  305. RETURN
  306. ELSE IF( LQUERY ) THEN
  307. RETURN
  308. END IF
  309. *
  310. * Quick return if possible
  311. *
  312. IF( N.EQ.0 )
  313. $ RETURN
  314. *
  315. * Form a Cholesky factorization of B.
  316. *
  317. CALL SPOTRF( UPLO, N, B, LDB, INFO )
  318. IF( INFO.NE.0 ) THEN
  319. INFO = N + INFO
  320. RETURN
  321. END IF
  322. *
  323. * Transform problem to standard eigenvalue problem and solve.
  324. *
  325. CALL SSYGST( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
  326. CALL SSYEVD( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, IWORK, LIWORK,
  327. $ INFO )
  328. LOPT = INT( MAX( REAL( LOPT ), REAL( WORK( 1 ) ) ) )
  329. LIOPT = INT( MAX( REAL( LIOPT ), REAL( IWORK( 1 ) ) ) )
  330. *
  331. IF( WANTZ .AND. INFO.EQ.0 ) THEN
  332. *
  333. * Backtransform eigenvectors to the original problem.
  334. *
  335. IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
  336. *
  337. * For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
  338. * backtransform eigenvectors: x = inv(L)**T*y or inv(U)*y
  339. *
  340. IF( UPPER ) THEN
  341. TRANS = 'N'
  342. ELSE
  343. TRANS = 'T'
  344. END IF
  345. *
  346. CALL STRSM( 'Left', UPLO, TRANS, 'Non-unit', N, N, ONE,
  347. $ B, LDB, A, LDA )
  348. *
  349. ELSE IF( ITYPE.EQ.3 ) THEN
  350. *
  351. * For B*A*x=(lambda)*x;
  352. * backtransform eigenvectors: x = L*y or U**T*y
  353. *
  354. IF( UPPER ) THEN
  355. TRANS = 'T'
  356. ELSE
  357. TRANS = 'N'
  358. END IF
  359. *
  360. CALL STRMM( 'Left', UPLO, TRANS, 'Non-unit', N, N, ONE,
  361. $ B, LDB, A, LDA )
  362. END IF
  363. END IF
  364. *
  365. WORK( 1 ) = SROUNDUP_LWORK(LOPT)
  366. IWORK( 1 ) = LIOPT
  367. *
  368. RETURN
  369. *
  370. * End of SSYGVD
  371. *
  372. END