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.

zgetrf2.f 7.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. *> \brief \b ZGETRF2
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * RECURSIVE SUBROUTINE ZGETRF2( M, N, A, LDA, IPIV, INFO )
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER INFO, LDA, M, N
  15. * ..
  16. * .. Array Arguments ..
  17. * INTEGER IPIV( * )
  18. * COMPLEX*16 A( LDA, * )
  19. * ..
  20. *
  21. *
  22. *> \par Purpose:
  23. * =============
  24. *>
  25. *> \verbatim
  26. *>
  27. *> ZGETRF2 computes an LU factorization of a general M-by-N matrix A
  28. *> using partial pivoting with row interchanges.
  29. *>
  30. *> The factorization has the form
  31. *> A = P * L * U
  32. *> where P is a permutation matrix, L is lower triangular with unit
  33. *> diagonal elements (lower trapezoidal if m > n), and U is upper
  34. *> triangular (upper trapezoidal if m < n).
  35. *>
  36. *> This is the recursive version of the algorithm. It divides
  37. *> the matrix into four submatrices:
  38. *>
  39. *> [ A11 | A12 ] where A11 is n1 by n1 and A22 is n2 by n2
  40. *> A = [ -----|----- ] with n1 = min(m,n)/2
  41. *> [ A21 | A22 ] n2 = n-n1
  42. *>
  43. *> [ A11 ]
  44. *> The subroutine calls itself to factor [ --- ],
  45. *> [ A12 ]
  46. *> [ A12 ]
  47. *> do the swaps on [ --- ], solve A12, update A22,
  48. *> [ A22 ]
  49. *>
  50. *> then calls itself to factor A22 and do the swaps on A21.
  51. *>
  52. *> \endverbatim
  53. *
  54. * Arguments:
  55. * ==========
  56. *
  57. *> \param[in] M
  58. *> \verbatim
  59. *> M is INTEGER
  60. *> The number of rows of the matrix A. M >= 0.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] N
  64. *> \verbatim
  65. *> N is INTEGER
  66. *> The number of columns of the matrix A. N >= 0.
  67. *> \endverbatim
  68. *>
  69. *> \param[in,out] A
  70. *> \verbatim
  71. *> A is COMPLEX*16 array, dimension (LDA,N)
  72. *> On entry, the M-by-N matrix to be factored.
  73. *> On exit, the factors L and U from the factorization
  74. *> A = P*L*U; the unit diagonal elements of L are not stored.
  75. *> \endverbatim
  76. *>
  77. *> \param[in] LDA
  78. *> \verbatim
  79. *> LDA is INTEGER
  80. *> The leading dimension of the array A. LDA >= max(1,M).
  81. *> \endverbatim
  82. *>
  83. *> \param[out] IPIV
  84. *> \verbatim
  85. *> IPIV is INTEGER array, dimension (min(M,N))
  86. *> The pivot indices; for 1 <= i <= min(M,N), row i of the
  87. *> matrix was interchanged with row IPIV(i).
  88. *> \endverbatim
  89. *>
  90. *> \param[out] INFO
  91. *> \verbatim
  92. *> INFO is INTEGER
  93. *> = 0: successful exit
  94. *> < 0: if INFO = -i, the i-th argument had an illegal value
  95. *> > 0: if INFO = i, U(i,i) is exactly zero. The factorization
  96. *> has been completed, but the factor U is exactly
  97. *> singular, and division by zero will occur if it is used
  98. *> to solve a system of equations.
  99. *> \endverbatim
  100. *
  101. * Authors:
  102. * ========
  103. *
  104. *> \author Univ. of Tennessee
  105. *> \author Univ. of California Berkeley
  106. *> \author Univ. of Colorado Denver
  107. *> \author NAG Ltd.
  108. *
  109. *> \date June 2016
  110. *
  111. *> \ingroup complex16GEcomputational
  112. *
  113. * =====================================================================
  114. RECURSIVE SUBROUTINE ZGETRF2( M, N, A, LDA, IPIV, INFO )
  115. *
  116. * -- LAPACK computational routine (version 3.7.0) --
  117. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  118. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  119. * June 2016
  120. *
  121. * .. Scalar Arguments ..
  122. INTEGER INFO, LDA, M, N
  123. * ..
  124. * .. Array Arguments ..
  125. INTEGER IPIV( * )
  126. COMPLEX*16 A( LDA, * )
  127. * ..
  128. *
  129. * =====================================================================
  130. *
  131. * .. Parameters ..
  132. COMPLEX*16 ONE, ZERO
  133. PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ),
  134. $ ZERO = ( 0.0D+0, 0.0D+0 ) )
  135. * ..
  136. * .. Local Scalars ..
  137. DOUBLE PRECISION SFMIN
  138. COMPLEX*16 TEMP
  139. INTEGER I, IINFO, N1, N2
  140. * ..
  141. * .. External Functions ..
  142. DOUBLE PRECISION DLAMCH
  143. INTEGER IZAMAX
  144. EXTERNAL DLAMCH, IZAMAX
  145. * ..
  146. * .. External Subroutines ..
  147. EXTERNAL ZGEMM, ZSCAL, ZLASWP, ZTRSM, XERBLA
  148. * ..
  149. * .. Intrinsic Functions ..
  150. INTRINSIC MAX, MIN
  151. * ..
  152. * .. Executable Statements ..
  153. *
  154. * Test the input parameters
  155. *
  156. INFO = 0
  157. IF( M.LT.0 ) THEN
  158. INFO = -1
  159. ELSE IF( N.LT.0 ) THEN
  160. INFO = -2
  161. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  162. INFO = -4
  163. END IF
  164. IF( INFO.NE.0 ) THEN
  165. CALL XERBLA( 'ZGETRF2', -INFO )
  166. RETURN
  167. END IF
  168. *
  169. * Quick return if possible
  170. *
  171. IF( M.EQ.0 .OR. N.EQ.0 )
  172. $ RETURN
  173. IF ( M.EQ.1 ) THEN
  174. *
  175. * Use unblocked code for one row case
  176. * Just need to handle IPIV and INFO
  177. *
  178. IPIV( 1 ) = 1
  179. IF ( A(1,1).EQ.ZERO )
  180. $ INFO = 1
  181. *
  182. ELSE IF( N.EQ.1 ) THEN
  183. *
  184. * Use unblocked code for one column case
  185. *
  186. *
  187. * Compute machine safe minimum
  188. *
  189. SFMIN = DLAMCH('S')
  190. *
  191. * Find pivot and test for singularity
  192. *
  193. I = IZAMAX( M, A( 1, 1 ), 1 )
  194. IPIV( 1 ) = I
  195. IF( A( I, 1 ).NE.ZERO ) THEN
  196. *
  197. * Apply the interchange
  198. *
  199. IF( I.NE.1 ) THEN
  200. TEMP = A( 1, 1 )
  201. A( 1, 1 ) = A( I, 1 )
  202. A( I, 1 ) = TEMP
  203. END IF
  204. *
  205. * Compute elements 2:M of the column
  206. *
  207. IF( ABS(A( 1, 1 )) .GE. SFMIN ) THEN
  208. CALL ZSCAL( M-1, ONE / A( 1, 1 ), A( 2, 1 ), 1 )
  209. ELSE
  210. DO 10 I = 1, M-1
  211. A( 1+I, 1 ) = A( 1+I, 1 ) / A( 1, 1 )
  212. 10 CONTINUE
  213. END IF
  214. *
  215. ELSE
  216. INFO = 1
  217. END IF
  218. ELSE
  219. *
  220. * Use recursive code
  221. *
  222. N1 = MIN( M, N ) / 2
  223. N2 = N-N1
  224. *
  225. * [ A11 ]
  226. * Factor [ --- ]
  227. * [ A21 ]
  228. *
  229. CALL ZGETRF2( M, N1, A, LDA, IPIV, IINFO )
  230. IF ( INFO.EQ.0 .AND. IINFO.GT.0 )
  231. $ INFO = IINFO
  232. *
  233. * [ A12 ]
  234. * Apply interchanges to [ --- ]
  235. * [ A22 ]
  236. *
  237. CALL ZLASWP( N2, A( 1, N1+1 ), LDA, 1, N1, IPIV, 1 )
  238. *
  239. * Solve A12
  240. *
  241. CALL ZTRSM( 'L', 'L', 'N', 'U', N1, N2, ONE, A, LDA,
  242. $ A( 1, N1+1 ), LDA )
  243. *
  244. * Update A22
  245. *
  246. CALL ZGEMM( 'N', 'N', M-N1, N2, N1, -ONE, A( N1+1, 1 ), LDA,
  247. $ A( 1, N1+1 ), LDA, ONE, A( N1+1, N1+1 ), LDA )
  248. *
  249. * Factor A22
  250. *
  251. CALL ZGETRF2( M-N1, N2, A( N1+1, N1+1 ), LDA, IPIV( N1+1 ),
  252. $ IINFO )
  253. *
  254. * Adjust INFO and the pivot indices
  255. *
  256. IF ( INFO.EQ.0 .AND. IINFO.GT.0 )
  257. $ INFO = IINFO + N1
  258. DO 20 I = N1+1, MIN( M, N )
  259. IPIV( I ) = IPIV( I ) + N1
  260. 20 CONTINUE
  261. *
  262. * Apply interchanges to A21
  263. *
  264. CALL ZLASWP( N1, A( 1, 1 ), LDA, N1+1, MIN( M, N), IPIV, 1 )
  265. *
  266. END IF
  267. RETURN
  268. *
  269. * End of ZGETRF2
  270. *
  271. END