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.

csysv_rk.f 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. *> \brief <b> CSYSV_RK computes the solution to system of linear equations A * X = B for SY matrices</b>
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CSYSV_RK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csysv_rk.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csysv_rk.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csysv_rk.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB,
  22. * WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER UPLO
  26. * INTEGER INFO, LDA, LDB, LWORK, N, NRHS
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IPIV( * )
  30. * COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *> CSYSV_RK computes the solution to a complex system of linear
  39. *> equations A * X = B, where A is an N-by-N symmetric matrix
  40. *> and X and B are N-by-NRHS matrices.
  41. *>
  42. *> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used
  43. *> to factor A as
  44. *> A = P*U*D*(U**T)*(P**T), if UPLO = 'U', or
  45. *> A = P*L*D*(L**T)*(P**T), if UPLO = 'L',
  46. *> where U (or L) is unit upper (or lower) triangular matrix,
  47. *> U**T (or L**T) is the transpose of U (or L), P is a permutation
  48. *> matrix, P**T is the transpose of P, and D is symmetric and block
  49. *> diagonal with 1-by-1 and 2-by-2 diagonal blocks.
  50. *>
  51. *> CSYTRF_RK is called to compute the factorization of a complex
  52. *> symmetric matrix. The factored form of A is then used to solve
  53. *> the system of equations A * X = B by calling BLAS3 routine CSYTRS_3.
  54. *> \endverbatim
  55. *
  56. * Arguments:
  57. * ==========
  58. *
  59. *> \param[in] UPLO
  60. *> \verbatim
  61. *> UPLO is CHARACTER*1
  62. *> Specifies whether the upper or lower triangular part of the
  63. *> symmetric matrix A is stored:
  64. *> = 'U': Upper triangle of A is stored;
  65. *> = 'L': Lower triangle of A is stored.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] N
  69. *> \verbatim
  70. *> N is INTEGER
  71. *> The number of linear equations, i.e., the order of the
  72. *> matrix A. N >= 0.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] NRHS
  76. *> \verbatim
  77. *> NRHS is INTEGER
  78. *> The number of right hand sides, i.e., the number of columns
  79. *> of the matrix B. NRHS >= 0.
  80. *> \endverbatim
  81. *>
  82. *> \param[in,out] A
  83. *> \verbatim
  84. *> A is COMPLEX array, dimension (LDA,N)
  85. *> On entry, the symmetric matrix A.
  86. *> If UPLO = 'U': the leading N-by-N upper triangular part
  87. *> of A contains the upper triangular part of the matrix A,
  88. *> and the strictly lower triangular part of A is not
  89. *> referenced.
  90. *>
  91. *> If UPLO = 'L': the leading N-by-N lower triangular part
  92. *> of A contains the lower triangular part of the matrix A,
  93. *> and the strictly upper triangular part of A is not
  94. *> referenced.
  95. *>
  96. *> On exit, if INFO = 0, diagonal of the block diagonal
  97. *> matrix D and factors U or L as computed by CSYTRF_RK:
  98. *> a) ONLY diagonal elements of the symmetric block diagonal
  99. *> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k);
  100. *> (superdiagonal (or subdiagonal) elements of D
  101. *> are stored on exit in array E), and
  102. *> b) If UPLO = 'U': factor U in the superdiagonal part of A.
  103. *> If UPLO = 'L': factor L in the subdiagonal part of A.
  104. *>
  105. *> For more info see the description of CSYTRF_RK routine.
  106. *> \endverbatim
  107. *>
  108. *> \param[in] LDA
  109. *> \verbatim
  110. *> LDA is INTEGER
  111. *> The leading dimension of the array A. LDA >= max(1,N).
  112. *> \endverbatim
  113. *>
  114. *> \param[out] E
  115. *> \verbatim
  116. *> E is COMPLEX array, dimension (N)
  117. *> On exit, contains the output computed by the factorization
  118. *> routine CSYTRF_RK, i.e. the superdiagonal (or subdiagonal)
  119. *> elements of the symmetric block diagonal matrix D
  120. *> with 1-by-1 or 2-by-2 diagonal blocks, where
  121. *> If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0;
  122. *> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0.
  123. *>
  124. *> NOTE: For 1-by-1 diagonal block D(k), where
  125. *> 1 <= k <= N, the element E(k) is set to 0 in both
  126. *> UPLO = 'U' or UPLO = 'L' cases.
  127. *>
  128. *> For more info see the description of CSYTRF_RK routine.
  129. *> \endverbatim
  130. *>
  131. *> \param[out] IPIV
  132. *> \verbatim
  133. *> IPIV is INTEGER array, dimension (N)
  134. *> Details of the interchanges and the block structure of D,
  135. *> as determined by CSYTRF_RK.
  136. *>
  137. *> For more info see the description of CSYTRF_RK routine.
  138. *> \endverbatim
  139. *>
  140. *> \param[in,out] B
  141. *> \verbatim
  142. *> B is COMPLEX array, dimension (LDB,NRHS)
  143. *> On entry, the N-by-NRHS right hand side matrix B.
  144. *> On exit, if INFO = 0, the N-by-NRHS solution matrix X.
  145. *> \endverbatim
  146. *>
  147. *> \param[in] LDB
  148. *> \verbatim
  149. *> LDB is INTEGER
  150. *> The leading dimension of the array B. LDB >= max(1,N).
  151. *> \endverbatim
  152. *>
  153. *> \param[out] WORK
  154. *> \verbatim
  155. *> WORK is COMPLEX array, dimension ( MAX(1,LWORK) ).
  156. *> Work array used in the factorization stage.
  157. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  158. *> \endverbatim
  159. *>
  160. *> \param[in] LWORK
  161. *> \verbatim
  162. *> LWORK is INTEGER
  163. *> The length of WORK. LWORK >= 1. For best performance
  164. *> of factorization stage LWORK >= max(1,N*NB), where NB is
  165. *> the optimal blocksize for CSYTRF_RK.
  166. *>
  167. *> If LWORK = -1, then a workspace query is assumed;
  168. *> the routine only calculates the optimal size of the WORK
  169. *> array for factorization stage, returns this value as
  170. *> the first entry of the WORK array, and no error message
  171. *> related to LWORK is issued by XERBLA.
  172. *> \endverbatim
  173. *>
  174. *> \param[out] INFO
  175. *> \verbatim
  176. *> INFO is INTEGER
  177. *> = 0: successful exit
  178. *>
  179. *> < 0: If INFO = -k, the k-th argument had an illegal value
  180. *>
  181. *> > 0: If INFO = k, the matrix A is singular, because:
  182. *> If UPLO = 'U': column k in the upper
  183. *> triangular part of A contains all zeros.
  184. *> If UPLO = 'L': column k in the lower
  185. *> triangular part of A contains all zeros.
  186. *>
  187. *> Therefore D(k,k) is exactly zero, and superdiagonal
  188. *> elements of column k of U (or subdiagonal elements of
  189. *> column k of L ) are all zeros. The factorization has
  190. *> been completed, but the block diagonal matrix D is
  191. *> exactly singular, and division by zero will occur if
  192. *> it is used to solve a system of equations.
  193. *>
  194. *> NOTE: INFO only stores the first occurrence of
  195. *> a singularity, any subsequent occurrence of singularity
  196. *> is not stored in INFO even though the factorization
  197. *> always completes.
  198. *> \endverbatim
  199. *
  200. * Authors:
  201. * ========
  202. *
  203. *> \author Univ. of Tennessee
  204. *> \author Univ. of California Berkeley
  205. *> \author Univ. of Colorado Denver
  206. *> \author NAG Ltd.
  207. *
  208. *> \ingroup hesv_rk
  209. *
  210. *> \par Contributors:
  211. * ==================
  212. *>
  213. *> \verbatim
  214. *>
  215. *> December 2016, Igor Kozachenko,
  216. *> Computer Science Division,
  217. *> University of California, Berkeley
  218. *>
  219. *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
  220. *> School of Mathematics,
  221. *> University of Manchester
  222. *>
  223. *> \endverbatim
  224. *
  225. * =====================================================================
  226. SUBROUTINE CSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, WORK,
  227. $ LWORK, INFO )
  228. *
  229. * -- LAPACK driver routine --
  230. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  231. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  232. *
  233. * .. Scalar Arguments ..
  234. CHARACTER UPLO
  235. INTEGER INFO, LDA, LDB, LWORK, N, NRHS
  236. * ..
  237. * .. Array Arguments ..
  238. INTEGER IPIV( * )
  239. COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * )
  240. * ..
  241. *
  242. * =====================================================================
  243. *
  244. * .. Local Scalars ..
  245. LOGICAL LQUERY
  246. INTEGER LWKOPT
  247. * ..
  248. * .. External Functions ..
  249. LOGICAL LSAME
  250. REAL SROUNDUP_LWORK
  251. EXTERNAL LSAME, SROUNDUP_LWORK
  252. * ..
  253. * .. External Subroutines ..
  254. EXTERNAL XERBLA, CSYTRF_RK, CSYTRS_3
  255. * ..
  256. * .. Intrinsic Functions ..
  257. INTRINSIC MAX
  258. * ..
  259. * .. Executable Statements ..
  260. *
  261. * Test the input parameters.
  262. *
  263. INFO = 0
  264. LQUERY = ( LWORK.EQ.-1 )
  265. IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  266. INFO = -1
  267. ELSE IF( N.LT.0 ) THEN
  268. INFO = -2
  269. ELSE IF( NRHS.LT.0 ) THEN
  270. INFO = -3
  271. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  272. INFO = -5
  273. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  274. INFO = -9
  275. ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
  276. INFO = -11
  277. END IF
  278. *
  279. IF( INFO.EQ.0 ) THEN
  280. IF( N.EQ.0 ) THEN
  281. LWKOPT = 1
  282. ELSE
  283. CALL CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO )
  284. LWKOPT = INT( WORK( 1 ) )
  285. END IF
  286. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  287. END IF
  288. *
  289. IF( INFO.NE.0 ) THEN
  290. CALL XERBLA( 'CSYSV_RK ', -INFO )
  291. RETURN
  292. ELSE IF( LQUERY ) THEN
  293. RETURN
  294. END IF
  295. *
  296. * Compute the factorization A = U*D*U**T or A = L*D*L**T.
  297. *
  298. CALL CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO )
  299. *
  300. IF( INFO.EQ.0 ) THEN
  301. *
  302. * Solve the system A*X = B with BLAS3 solver, overwriting B with X.
  303. *
  304. CALL CSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO )
  305. *
  306. END IF
  307. *
  308. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  309. *
  310. RETURN
  311. *
  312. * End of CSYSV_RK
  313. *
  314. END