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.

sgeqp3.f 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. *> \brief \b SGEQP3
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGEQP3 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeqp3.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeqp3.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeqp3.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER INFO, LDA, LWORK, M, N
  25. * ..
  26. * .. Array Arguments ..
  27. * INTEGER JPVT( * )
  28. * REAL A( LDA, * ), TAU( * ), WORK( * )
  29. * ..
  30. *
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> SGEQP3 computes a QR factorization with column pivoting of a
  38. *> matrix A: A*P = Q*R using Level 3 BLAS.
  39. *> \endverbatim
  40. *
  41. * Arguments:
  42. * ==========
  43. *
  44. *> \param[in] M
  45. *> \verbatim
  46. *> M is INTEGER
  47. *> The number of rows of the matrix A. M >= 0.
  48. *> \endverbatim
  49. *>
  50. *> \param[in] N
  51. *> \verbatim
  52. *> N is INTEGER
  53. *> The number of columns of the matrix A. N >= 0.
  54. *> \endverbatim
  55. *>
  56. *> \param[in,out] A
  57. *> \verbatim
  58. *> A is REAL array, dimension (LDA,N)
  59. *> On entry, the M-by-N matrix A.
  60. *> On exit, the upper triangle of the array contains the
  61. *> min(M,N)-by-N upper trapezoidal matrix R; the elements below
  62. *> the diagonal, together with the array TAU, represent the
  63. *> orthogonal matrix Q as a product of min(M,N) elementary
  64. *> reflectors.
  65. *> \endverbatim
  66. *>
  67. *> \param[in] LDA
  68. *> \verbatim
  69. *> LDA is INTEGER
  70. *> The leading dimension of the array A. LDA >= max(1,M).
  71. *> \endverbatim
  72. *>
  73. *> \param[in,out] JPVT
  74. *> \verbatim
  75. *> JPVT is INTEGER array, dimension (N)
  76. *> On entry, if JPVT(J).ne.0, the J-th column of A is permuted
  77. *> to the front of A*P (a leading column); if JPVT(J)=0,
  78. *> the J-th column of A is a free column.
  79. *> On exit, if JPVT(J)=K, then the J-th column of A*P was the
  80. *> the K-th column of A.
  81. *> \endverbatim
  82. *>
  83. *> \param[out] TAU
  84. *> \verbatim
  85. *> TAU is REAL array, dimension (min(M,N))
  86. *> The scalar factors of the elementary reflectors.
  87. *> \endverbatim
  88. *>
  89. *> \param[out] WORK
  90. *> \verbatim
  91. *> WORK is REAL array, dimension (MAX(1,LWORK))
  92. *> On exit, if INFO=0, WORK(1) returns the optimal LWORK.
  93. *> \endverbatim
  94. *>
  95. *> \param[in] LWORK
  96. *> \verbatim
  97. *> LWORK is INTEGER
  98. *> The dimension of the array WORK. LWORK >= 3*N+1.
  99. *> For optimal performance LWORK >= 2*N+( N+1 )*NB, where NB
  100. *> is the optimal blocksize.
  101. *>
  102. *> If LWORK = -1, then a workspace query is assumed; the routine
  103. *> only calculates the optimal size of the WORK array, returns
  104. *> this value as the first entry of the WORK array, and no error
  105. *> message related to LWORK is issued by XERBLA.
  106. *> \endverbatim
  107. *>
  108. *> \param[out] INFO
  109. *> \verbatim
  110. *> INFO is INTEGER
  111. *> = 0: successful exit.
  112. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  113. *> \endverbatim
  114. *
  115. * Authors:
  116. * ========
  117. *
  118. *> \author Univ. of Tennessee
  119. *> \author Univ. of California Berkeley
  120. *> \author Univ. of Colorado Denver
  121. *> \author NAG Ltd.
  122. *
  123. *> \ingroup realGEcomputational
  124. *
  125. *> \par Further Details:
  126. * =====================
  127. *>
  128. *> \verbatim
  129. *>
  130. *> The matrix Q is represented as a product of elementary reflectors
  131. *>
  132. *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
  133. *>
  134. *> Each H(i) has the form
  135. *>
  136. *> H(i) = I - tau * v * v**T
  137. *>
  138. *> where tau is a real scalar, and v is a real/complex vector
  139. *> with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in
  140. *> A(i+1:m,i), and tau in TAU(i).
  141. *> \endverbatim
  142. *
  143. *> \par Contributors:
  144. * ==================
  145. *>
  146. *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
  147. *> X. Sun, Computer Science Dept., Duke University, USA
  148. *>
  149. * =====================================================================
  150. SUBROUTINE SGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO )
  151. *
  152. * -- LAPACK computational routine --
  153. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  154. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  155. *
  156. * .. Scalar Arguments ..
  157. INTEGER INFO, LDA, LWORK, M, N
  158. * ..
  159. * .. Array Arguments ..
  160. INTEGER JPVT( * )
  161. REAL A( LDA, * ), TAU( * ), WORK( * )
  162. * ..
  163. *
  164. * =====================================================================
  165. *
  166. * .. Parameters ..
  167. INTEGER INB, INBMIN, IXOVER
  168. PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
  169. * ..
  170. * .. Local Scalars ..
  171. LOGICAL LQUERY
  172. INTEGER FJB, IWS, J, JB, LWKOPT, MINMN, MINWS, NA, NB,
  173. $ NBMIN, NFXD, NX, SM, SMINMN, SN, TOPBMN
  174. * ..
  175. * .. External Subroutines ..
  176. EXTERNAL SGEQRF, SLAQP2, SLAQPS, SORMQR, SSWAP, XERBLA
  177. * ..
  178. * .. External Functions ..
  179. INTEGER ILAENV
  180. REAL SNRM2
  181. EXTERNAL ILAENV, SNRM2
  182. * ..
  183. * .. Intrinsic Functions ..
  184. INTRINSIC INT, MAX, MIN
  185. * Test input arguments
  186. * ====================
  187. *
  188. INFO = 0
  189. LQUERY = ( LWORK.EQ.-1 )
  190. IF( M.LT.0 ) THEN
  191. INFO = -1
  192. ELSE IF( N.LT.0 ) THEN
  193. INFO = -2
  194. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  195. INFO = -4
  196. END IF
  197. *
  198. IF( INFO.EQ.0 ) THEN
  199. MINMN = MIN( M, N )
  200. IF( MINMN.EQ.0 ) THEN
  201. IWS = 1
  202. LWKOPT = 1
  203. ELSE
  204. IWS = 3*N + 1
  205. NB = ILAENV( INB, 'SGEQRF', ' ', M, N, -1, -1 )
  206. LWKOPT = 2*N + ( N + 1 )*NB
  207. END IF
  208. WORK( 1 ) = LWKOPT
  209. *
  210. IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
  211. INFO = -8
  212. END IF
  213. END IF
  214. *
  215. IF( INFO.NE.0 ) THEN
  216. CALL XERBLA( 'SGEQP3', -INFO )
  217. RETURN
  218. ELSE IF( LQUERY ) THEN
  219. RETURN
  220. END IF
  221. *
  222. * Move initial columns up front.
  223. *
  224. NFXD = 1
  225. DO 10 J = 1, N
  226. IF( JPVT( J ).NE.0 ) THEN
  227. IF( J.NE.NFXD ) THEN
  228. CALL SSWAP( M, A( 1, J ), 1, A( 1, NFXD ), 1 )
  229. JPVT( J ) = JPVT( NFXD )
  230. JPVT( NFXD ) = J
  231. ELSE
  232. JPVT( J ) = J
  233. END IF
  234. NFXD = NFXD + 1
  235. ELSE
  236. JPVT( J ) = J
  237. END IF
  238. 10 CONTINUE
  239. NFXD = NFXD - 1
  240. *
  241. * Factorize fixed columns
  242. * =======================
  243. *
  244. * Compute the QR factorization of fixed columns and update
  245. * remaining columns.
  246. *
  247. IF( NFXD.GT.0 ) THEN
  248. NA = MIN( M, NFXD )
  249. *CC CALL SGEQR2( M, NA, A, LDA, TAU, WORK, INFO )
  250. CALL SGEQRF( M, NA, A, LDA, TAU, WORK, LWORK, INFO )
  251. IWS = MAX( IWS, INT( WORK( 1 ) ) )
  252. IF( NA.LT.N ) THEN
  253. *CC CALL SORM2R( 'Left', 'Transpose', M, N-NA, NA, A, LDA,
  254. *CC $ TAU, A( 1, NA+1 ), LDA, WORK, INFO )
  255. CALL SORMQR( 'Left', 'Transpose', M, N-NA, NA, A, LDA, TAU,
  256. $ A( 1, NA+1 ), LDA, WORK, LWORK, INFO )
  257. IWS = MAX( IWS, INT( WORK( 1 ) ) )
  258. END IF
  259. END IF
  260. *
  261. * Factorize free columns
  262. * ======================
  263. *
  264. IF( NFXD.LT.MINMN ) THEN
  265. *
  266. SM = M - NFXD
  267. SN = N - NFXD
  268. SMINMN = MINMN - NFXD
  269. *
  270. * Determine the block size.
  271. *
  272. NB = ILAENV( INB, 'SGEQRF', ' ', SM, SN, -1, -1 )
  273. NBMIN = 2
  274. NX = 0
  275. *
  276. IF( ( NB.GT.1 ) .AND. ( NB.LT.SMINMN ) ) THEN
  277. *
  278. * Determine when to cross over from blocked to unblocked code.
  279. *
  280. NX = MAX( 0, ILAENV( IXOVER, 'SGEQRF', ' ', SM, SN, -1,
  281. $ -1 ) )
  282. *
  283. *
  284. IF( NX.LT.SMINMN ) THEN
  285. *
  286. * Determine if workspace is large enough for blocked code.
  287. *
  288. MINWS = 2*SN + ( SN+1 )*NB
  289. IWS = MAX( IWS, MINWS )
  290. IF( LWORK.LT.MINWS ) THEN
  291. *
  292. * Not enough workspace to use optimal NB: Reduce NB and
  293. * determine the minimum value of NB.
  294. *
  295. NB = ( LWORK-2*SN ) / ( SN+1 )
  296. NBMIN = MAX( 2, ILAENV( INBMIN, 'SGEQRF', ' ', SM, SN,
  297. $ -1, -1 ) )
  298. *
  299. *
  300. END IF
  301. END IF
  302. END IF
  303. *
  304. * Initialize partial column norms. The first N elements of work
  305. * store the exact column norms.
  306. *
  307. DO 20 J = NFXD + 1, N
  308. WORK( J ) = SNRM2( SM, A( NFXD+1, J ), 1 )
  309. WORK( N+J ) = WORK( J )
  310. 20 CONTINUE
  311. *
  312. IF( ( NB.GE.NBMIN ) .AND. ( NB.LT.SMINMN ) .AND.
  313. $ ( NX.LT.SMINMN ) ) THEN
  314. *
  315. * Use blocked code initially.
  316. *
  317. J = NFXD + 1
  318. *
  319. * Compute factorization: while loop.
  320. *
  321. *
  322. TOPBMN = MINMN - NX
  323. 30 CONTINUE
  324. IF( J.LE.TOPBMN ) THEN
  325. JB = MIN( NB, TOPBMN-J+1 )
  326. *
  327. * Factorize JB columns among columns J:N.
  328. *
  329. CALL SLAQPS( M, N-J+1, J-1, JB, FJB, A( 1, J ), LDA,
  330. $ JPVT( J ), TAU( J ), WORK( J ), WORK( N+J ),
  331. $ WORK( 2*N+1 ), WORK( 2*N+JB+1 ), N-J+1 )
  332. *
  333. J = J + FJB
  334. GO TO 30
  335. END IF
  336. ELSE
  337. J = NFXD + 1
  338. END IF
  339. *
  340. * Use unblocked code to factor the last or only block.
  341. *
  342. *
  343. IF( J.LE.MINMN )
  344. $ CALL SLAQP2( M, N-J+1, J-1, A( 1, J ), LDA, JPVT( J ),
  345. $ TAU( J ), WORK( J ), WORK( N+J ),
  346. $ WORK( 2*N+1 ) )
  347. *
  348. END IF
  349. *
  350. WORK( 1 ) = IWS
  351. RETURN
  352. *
  353. * End of SGEQP3
  354. *
  355. END