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.

chetrs.f 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. *> \brief \b CHETRS
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHETRS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHETRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, LDA, LDB, N, NRHS
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IPIV( * )
  29. * COMPLEX A( LDA, * ), B( LDB, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> CHETRS solves a system of linear equations A*X = B with a complex
  39. *> Hermitian matrix A using the factorization A = U*D*U**H or
  40. *> A = L*D*L**H computed by CHETRF.
  41. *> \endverbatim
  42. *
  43. * Arguments:
  44. * ==========
  45. *
  46. *> \param[in] UPLO
  47. *> \verbatim
  48. *> UPLO is CHARACTER*1
  49. *> Specifies whether the details of the factorization are stored
  50. *> as an upper or lower triangular matrix.
  51. *> = 'U': Upper triangular, form is A = U*D*U**H;
  52. *> = 'L': Lower triangular, form is A = L*D*L**H.
  53. *> \endverbatim
  54. *>
  55. *> \param[in] N
  56. *> \verbatim
  57. *> N is INTEGER
  58. *> The order of the matrix A. N >= 0.
  59. *> \endverbatim
  60. *>
  61. *> \param[in] NRHS
  62. *> \verbatim
  63. *> NRHS is INTEGER
  64. *> The number of right hand sides, i.e., the number of columns
  65. *> of the matrix B. NRHS >= 0.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] A
  69. *> \verbatim
  70. *> A is COMPLEX array, dimension (LDA,N)
  71. *> The block diagonal matrix D and the multipliers used to
  72. *> obtain the factor U or L as computed by CHETRF.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] LDA
  76. *> \verbatim
  77. *> LDA is INTEGER
  78. *> The leading dimension of the array A. LDA >= max(1,N).
  79. *> \endverbatim
  80. *>
  81. *> \param[in] IPIV
  82. *> \verbatim
  83. *> IPIV is INTEGER array, dimension (N)
  84. *> Details of the interchanges and the block structure of D
  85. *> as determined by CHETRF.
  86. *> \endverbatim
  87. *>
  88. *> \param[in,out] B
  89. *> \verbatim
  90. *> B is COMPLEX array, dimension (LDB,NRHS)
  91. *> On entry, the right hand side matrix B.
  92. *> On exit, the solution matrix X.
  93. *> \endverbatim
  94. *>
  95. *> \param[in] LDB
  96. *> \verbatim
  97. *> LDB is INTEGER
  98. *> The leading dimension of the array B. LDB >= max(1,N).
  99. *> \endverbatim
  100. *>
  101. *> \param[out] INFO
  102. *> \verbatim
  103. *> INFO is INTEGER
  104. *> = 0: successful exit
  105. *> < 0: if INFO = -i, the i-th argument had an illegal value
  106. *> \endverbatim
  107. *
  108. * Authors:
  109. * ========
  110. *
  111. *> \author Univ. of Tennessee
  112. *> \author Univ. of California Berkeley
  113. *> \author Univ. of Colorado Denver
  114. *> \author NAG Ltd.
  115. *
  116. *> \date December 2016
  117. *
  118. *> \ingroup complexHEcomputational
  119. *
  120. * =====================================================================
  121. SUBROUTINE CHETRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
  122. *
  123. * -- LAPACK computational routine (version 3.7.0) --
  124. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  125. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  126. * December 2016
  127. *
  128. * .. Scalar Arguments ..
  129. CHARACTER UPLO
  130. INTEGER INFO, LDA, LDB, N, NRHS
  131. * ..
  132. * .. Array Arguments ..
  133. INTEGER IPIV( * )
  134. COMPLEX A( LDA, * ), B( LDB, * )
  135. * ..
  136. *
  137. * =====================================================================
  138. *
  139. * .. Parameters ..
  140. COMPLEX ONE
  141. PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
  142. * ..
  143. * .. Local Scalars ..
  144. LOGICAL UPPER
  145. INTEGER J, K, KP
  146. REAL S
  147. COMPLEX AK, AKM1, AKM1K, BK, BKM1, DENOM
  148. * ..
  149. * .. External Functions ..
  150. LOGICAL LSAME
  151. EXTERNAL LSAME
  152. * ..
  153. * .. External Subroutines ..
  154. EXTERNAL CGEMV, CGERU, CLACGV, CSSCAL, CSWAP, XERBLA
  155. * ..
  156. * .. Intrinsic Functions ..
  157. INTRINSIC CONJG, MAX, REAL
  158. * ..
  159. * .. Executable Statements ..
  160. *
  161. INFO = 0
  162. UPPER = LSAME( UPLO, 'U' )
  163. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  164. INFO = -1
  165. ELSE IF( N.LT.0 ) THEN
  166. INFO = -2
  167. ELSE IF( NRHS.LT.0 ) THEN
  168. INFO = -3
  169. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  170. INFO = -5
  171. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  172. INFO = -8
  173. END IF
  174. IF( INFO.NE.0 ) THEN
  175. CALL XERBLA( 'CHETRS', -INFO )
  176. RETURN
  177. END IF
  178. *
  179. * Quick return if possible
  180. *
  181. IF( N.EQ.0 .OR. NRHS.EQ.0 )
  182. $ RETURN
  183. *
  184. IF( UPPER ) THEN
  185. *
  186. * Solve A*X = B, where A = U*D*U**H.
  187. *
  188. * First solve U*D*X = B, overwriting B with X.
  189. *
  190. * K is the main loop index, decreasing from N to 1 in steps of
  191. * 1 or 2, depending on the size of the diagonal blocks.
  192. *
  193. K = N
  194. 10 CONTINUE
  195. *
  196. * If K < 1, exit from loop.
  197. *
  198. IF( K.LT.1 )
  199. $ GO TO 30
  200. *
  201. IF( IPIV( K ).GT.0 ) THEN
  202. *
  203. * 1 x 1 diagonal block
  204. *
  205. * Interchange rows K and IPIV(K).
  206. *
  207. KP = IPIV( K )
  208. IF( KP.NE.K )
  209. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  210. *
  211. * Multiply by inv(U(K)), where U(K) is the transformation
  212. * stored in column K of A.
  213. *
  214. CALL CGERU( K-1, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
  215. $ B( 1, 1 ), LDB )
  216. *
  217. * Multiply by the inverse of the diagonal block.
  218. *
  219. S = REAL( ONE ) / REAL( A( K, K ) )
  220. CALL CSSCAL( NRHS, S, B( K, 1 ), LDB )
  221. K = K - 1
  222. ELSE
  223. *
  224. * 2 x 2 diagonal block
  225. *
  226. * Interchange rows K-1 and -IPIV(K).
  227. *
  228. KP = -IPIV( K )
  229. IF( KP.NE.K-1 )
  230. $ CALL CSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
  231. *
  232. * Multiply by inv(U(K)), where U(K) is the transformation
  233. * stored in columns K-1 and K of A.
  234. *
  235. CALL CGERU( K-2, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
  236. $ B( 1, 1 ), LDB )
  237. CALL CGERU( K-2, NRHS, -ONE, A( 1, K-1 ), 1, B( K-1, 1 ),
  238. $ LDB, B( 1, 1 ), LDB )
  239. *
  240. * Multiply by the inverse of the diagonal block.
  241. *
  242. AKM1K = A( K-1, K )
  243. AKM1 = A( K-1, K-1 ) / AKM1K
  244. AK = A( K, K ) / CONJG( AKM1K )
  245. DENOM = AKM1*AK - ONE
  246. DO 20 J = 1, NRHS
  247. BKM1 = B( K-1, J ) / AKM1K
  248. BK = B( K, J ) / CONJG( AKM1K )
  249. B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
  250. B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
  251. 20 CONTINUE
  252. K = K - 2
  253. END IF
  254. *
  255. GO TO 10
  256. 30 CONTINUE
  257. *
  258. * Next solve U**H *X = B, overwriting B with X.
  259. *
  260. * K is the main loop index, increasing from 1 to N in steps of
  261. * 1 or 2, depending on the size of the diagonal blocks.
  262. *
  263. K = 1
  264. 40 CONTINUE
  265. *
  266. * If K > N, exit from loop.
  267. *
  268. IF( K.GT.N )
  269. $ GO TO 50
  270. *
  271. IF( IPIV( K ).GT.0 ) THEN
  272. *
  273. * 1 x 1 diagonal block
  274. *
  275. * Multiply by inv(U**H(K)), where U(K) is the transformation
  276. * stored in column K of A.
  277. *
  278. IF( K.GT.1 ) THEN
  279. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  280. CALL CGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
  281. $ LDB, A( 1, K ), 1, ONE, B( K, 1 ), LDB )
  282. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  283. END IF
  284. *
  285. * Interchange rows K and IPIV(K).
  286. *
  287. KP = IPIV( K )
  288. IF( KP.NE.K )
  289. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  290. K = K + 1
  291. ELSE
  292. *
  293. * 2 x 2 diagonal block
  294. *
  295. * Multiply by inv(U**H(K+1)), where U(K+1) is the transformation
  296. * stored in columns K and K+1 of A.
  297. *
  298. IF( K.GT.1 ) THEN
  299. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  300. CALL CGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
  301. $ LDB, A( 1, K ), 1, ONE, B( K, 1 ), LDB )
  302. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  303. *
  304. CALL CLACGV( NRHS, B( K+1, 1 ), LDB )
  305. CALL CGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
  306. $ LDB, A( 1, K+1 ), 1, ONE, B( K+1, 1 ), LDB )
  307. CALL CLACGV( NRHS, B( K+1, 1 ), LDB )
  308. END IF
  309. *
  310. * Interchange rows K and -IPIV(K).
  311. *
  312. KP = -IPIV( K )
  313. IF( KP.NE.K )
  314. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  315. K = K + 2
  316. END IF
  317. *
  318. GO TO 40
  319. 50 CONTINUE
  320. *
  321. ELSE
  322. *
  323. * Solve A*X = B, where A = L*D*L**H.
  324. *
  325. * First solve L*D*X = B, overwriting B with X.
  326. *
  327. * K is the main loop index, increasing from 1 to N in steps of
  328. * 1 or 2, depending on the size of the diagonal blocks.
  329. *
  330. K = 1
  331. 60 CONTINUE
  332. *
  333. * If K > N, exit from loop.
  334. *
  335. IF( K.GT.N )
  336. $ GO TO 80
  337. *
  338. IF( IPIV( K ).GT.0 ) THEN
  339. *
  340. * 1 x 1 diagonal block
  341. *
  342. * Interchange rows K and IPIV(K).
  343. *
  344. KP = IPIV( K )
  345. IF( KP.NE.K )
  346. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  347. *
  348. * Multiply by inv(L(K)), where L(K) is the transformation
  349. * stored in column K of A.
  350. *
  351. IF( K.LT.N )
  352. $ CALL CGERU( N-K, NRHS, -ONE, A( K+1, K ), 1, B( K, 1 ),
  353. $ LDB, B( K+1, 1 ), LDB )
  354. *
  355. * Multiply by the inverse of the diagonal block.
  356. *
  357. S = REAL( ONE ) / REAL( A( K, K ) )
  358. CALL CSSCAL( NRHS, S, B( K, 1 ), LDB )
  359. K = K + 1
  360. ELSE
  361. *
  362. * 2 x 2 diagonal block
  363. *
  364. * Interchange rows K+1 and -IPIV(K).
  365. *
  366. KP = -IPIV( K )
  367. IF( KP.NE.K+1 )
  368. $ CALL CSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
  369. *
  370. * Multiply by inv(L(K)), where L(K) is the transformation
  371. * stored in columns K and K+1 of A.
  372. *
  373. IF( K.LT.N-1 ) THEN
  374. CALL CGERU( N-K-1, NRHS, -ONE, A( K+2, K ), 1, B( K, 1 ),
  375. $ LDB, B( K+2, 1 ), LDB )
  376. CALL CGERU( N-K-1, NRHS, -ONE, A( K+2, K+1 ), 1,
  377. $ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
  378. END IF
  379. *
  380. * Multiply by the inverse of the diagonal block.
  381. *
  382. AKM1K = A( K+1, K )
  383. AKM1 = A( K, K ) / CONJG( AKM1K )
  384. AK = A( K+1, K+1 ) / AKM1K
  385. DENOM = AKM1*AK - ONE
  386. DO 70 J = 1, NRHS
  387. BKM1 = B( K, J ) / CONJG( AKM1K )
  388. BK = B( K+1, J ) / AKM1K
  389. B( K, J ) = ( AK*BKM1-BK ) / DENOM
  390. B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
  391. 70 CONTINUE
  392. K = K + 2
  393. END IF
  394. *
  395. GO TO 60
  396. 80 CONTINUE
  397. *
  398. * Next solve L**H *X = B, overwriting B with X.
  399. *
  400. * K is the main loop index, decreasing from N to 1 in steps of
  401. * 1 or 2, depending on the size of the diagonal blocks.
  402. *
  403. K = N
  404. 90 CONTINUE
  405. *
  406. * If K < 1, exit from loop.
  407. *
  408. IF( K.LT.1 )
  409. $ GO TO 100
  410. *
  411. IF( IPIV( K ).GT.0 ) THEN
  412. *
  413. * 1 x 1 diagonal block
  414. *
  415. * Multiply by inv(L**H(K)), where L(K) is the transformation
  416. * stored in column K of A.
  417. *
  418. IF( K.LT.N ) THEN
  419. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  420. CALL CGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
  421. $ B( K+1, 1 ), LDB, A( K+1, K ), 1, ONE,
  422. $ B( K, 1 ), LDB )
  423. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  424. END IF
  425. *
  426. * Interchange rows K and IPIV(K).
  427. *
  428. KP = IPIV( K )
  429. IF( KP.NE.K )
  430. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  431. K = K - 1
  432. ELSE
  433. *
  434. * 2 x 2 diagonal block
  435. *
  436. * Multiply by inv(L**H(K-1)), where L(K-1) is the transformation
  437. * stored in columns K-1 and K of A.
  438. *
  439. IF( K.LT.N ) THEN
  440. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  441. CALL CGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
  442. $ B( K+1, 1 ), LDB, A( K+1, K ), 1, ONE,
  443. $ B( K, 1 ), LDB )
  444. CALL CLACGV( NRHS, B( K, 1 ), LDB )
  445. *
  446. CALL CLACGV( NRHS, B( K-1, 1 ), LDB )
  447. CALL CGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
  448. $ B( K+1, 1 ), LDB, A( K+1, K-1 ), 1, ONE,
  449. $ B( K-1, 1 ), LDB )
  450. CALL CLACGV( NRHS, B( K-1, 1 ), LDB )
  451. END IF
  452. *
  453. * Interchange rows K and -IPIV(K).
  454. *
  455. KP = -IPIV( K )
  456. IF( KP.NE.K )
  457. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  458. K = K - 2
  459. END IF
  460. *
  461. GO TO 90
  462. 100 CONTINUE
  463. END IF
  464. *
  465. RETURN
  466. *
  467. * End of CHETRS
  468. *
  469. END