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.

zgeqp3rk.f 39 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. *> \brief \b ZGEQP3RK computes a truncated Householder QR factorization with column pivoting of a complex m-by-n matrix A by using Level 3 BLAS and overwrites m-by-nrhs matrix B with Q**H * B.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZGEQP3RK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeqp3rk.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeqp3rk.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeqp3rk.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZGEQP3RK( M, N, NRHS, KMAX, ABSTOL, RELTOL, A, LDA,
  22. * $ K, MAXC2NRMK, RELMAXC2NRMK, JPIV, TAU,
  23. * $ WORK, LWORK, RWORK, IWORK, INFO )
  24. * IMPLICIT NONE
  25. *
  26. * .. Scalar Arguments ..
  27. * INTEGER INFO, K, KMAX, LDA, LWORK, M, N, NRHS
  28. * DOUBLE PRECISION ABSTOL, MAXC2NRMK, RELMAXC2NRMK, RELTOL
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IWORK( * ), JPIV( * )
  32. * DOUBLE PRECISION RWORK( * )
  33. * COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> ZGEQP3RK performs two tasks simultaneously:
  43. *>
  44. *> Task 1: The routine computes a truncated (rank K) or full rank
  45. *> Householder QR factorization with column pivoting of a complex
  46. *> M-by-N matrix A using Level 3 BLAS. K is the number of columns
  47. *> that were factorized, i.e. factorization rank of the
  48. *> factor R, K <= min(M,N).
  49. *>
  50. *> A * P(K) = Q(K) * R(K) =
  51. *>
  52. *> = Q(K) * ( R11(K) R12(K) ) = Q(K) * ( R(K)_approx )
  53. *> ( 0 R22(K) ) ( 0 R(K)_residual ),
  54. *>
  55. *> where:
  56. *>
  57. *> P(K) is an N-by-N permutation matrix;
  58. *> Q(K) is an M-by-M unitary matrix;
  59. *> R(K)_approx = ( R11(K), R12(K) ) is a rank K approximation of the
  60. *> full rank factor R with K-by-K upper-triangular
  61. *> R11(K) and K-by-N rectangular R12(K). The diagonal
  62. *> entries of R11(K) appear in non-increasing order
  63. *> of absolute value, and absolute values of all of
  64. *> them exceed the maximum column 2-norm of R22(K)
  65. *> up to roundoff error.
  66. *> R(K)_residual = R22(K) is the residual of a rank K approximation
  67. *> of the full rank factor R. It is a
  68. *> an (M-K)-by-(N-K) rectangular matrix;
  69. *> 0 is a an (M-K)-by-K zero matrix.
  70. *>
  71. *> Task 2: At the same time, the routine overwrites a complex M-by-NRHS
  72. *> matrix B with Q(K)**H * B using Level 3 BLAS.
  73. *>
  74. *> =====================================================================
  75. *>
  76. *> The matrices A and B are stored on input in the array A as
  77. *> the left and right blocks A(1:M,1:N) and A(1:M, N+1:N+NRHS)
  78. *> respectively.
  79. *>
  80. *> N NRHS
  81. *> array_A = M [ mat_A, mat_B ]
  82. *>
  83. *> The truncation criteria (i.e. when to stop the factorization)
  84. *> can be any of the following:
  85. *>
  86. *> 1) The input parameter KMAX, the maximum number of columns
  87. *> KMAX to factorize, i.e. the factorization rank is limited
  88. *> to KMAX. If KMAX >= min(M,N), the criterion is not used.
  89. *>
  90. *> 2) The input parameter ABSTOL, the absolute tolerance for
  91. *> the maximum column 2-norm of the residual matrix R22(K). This
  92. *> means that the factorization stops if this norm is less or
  93. *> equal to ABSTOL. If ABSTOL < 0.0, the criterion is not used.
  94. *>
  95. *> 3) The input parameter RELTOL, the tolerance for the maximum
  96. *> column 2-norm matrix of the residual matrix R22(K) divided
  97. *> by the maximum column 2-norm of the original matrix A, which
  98. *> is equal to abs(R(1,1)). This means that the factorization stops
  99. *> when the ratio of the maximum column 2-norm of R22(K) to
  100. *> the maximum column 2-norm of A is less than or equal to RELTOL.
  101. *> If RELTOL < 0.0, the criterion is not used.
  102. *>
  103. *> 4) In case both stopping criteria ABSTOL or RELTOL are not used,
  104. *> and when the residual matrix R22(K) is a zero matrix in some
  105. *> factorization step K. ( This stopping criterion is implicit. )
  106. *>
  107. *> The algorithm stops when any of these conditions is first
  108. *> satisfied, otherwise the whole matrix A is factorized.
  109. *>
  110. *> To factorize the whole matrix A, use the values
  111. *> KMAX >= min(M,N), ABSTOL < 0.0 and RELTOL < 0.0.
  112. *>
  113. *> The routine returns:
  114. *> a) Q(K), R(K)_approx = ( R11(K), R12(K) ),
  115. *> R(K)_residual = R22(K), P(K), i.e. the resulting matrices
  116. *> of the factorization; P(K) is represented by JPIV,
  117. *> ( if K = min(M,N), R(K)_approx is the full factor R,
  118. *> and there is no residual matrix R(K)_residual);
  119. *> b) K, the number of columns that were factorized,
  120. *> i.e. factorization rank;
  121. *> c) MAXC2NRMK, the maximum column 2-norm of the residual
  122. *> matrix R(K)_residual = R22(K),
  123. *> ( if K = min(M,N), MAXC2NRMK = 0.0 );
  124. *> d) RELMAXC2NRMK equals MAXC2NRMK divided by MAXC2NRM, the maximum
  125. *> column 2-norm of the original matrix A, which is equal
  126. *> to abs(R(1,1)), ( if K = min(M,N), RELMAXC2NRMK = 0.0 );
  127. *> e) Q(K)**H * B, the matrix B with the unitary
  128. *> transformation Q(K)**H applied on the left.
  129. *>
  130. *> The N-by-N permutation matrix P(K) is stored in a compact form in
  131. *> the integer array JPIV. For 1 <= j <= N, column j
  132. *> of the matrix A was interchanged with column JPIV(j).
  133. *>
  134. *> The M-by-M unitary matrix Q is represented as a product
  135. *> of elementary Householder reflectors
  136. *>
  137. *> Q(K) = H(1) * H(2) * . . . * H(K),
  138. *>
  139. *> where K is the number of columns that were factorized.
  140. *>
  141. *> Each H(j) has the form
  142. *>
  143. *> H(j) = I - tau * v * v**H,
  144. *>
  145. *> where 1 <= j <= K and
  146. *> I is an M-by-M identity matrix,
  147. *> tau is a complex scalar,
  148. *> v is a complex vector with v(1:j-1) = 0 and v(j) = 1.
  149. *>
  150. *> v(j+1:M) is stored on exit in A(j+1:M,j) and tau in TAU(j).
  151. *>
  152. *> See the Further Details section for more information.
  153. *> \endverbatim
  154. *
  155. * Arguments:
  156. * ==========
  157. *
  158. *> \param[in] M
  159. *> \verbatim
  160. *> M is INTEGER
  161. *> The number of rows of the matrix A. M >= 0.
  162. *> \endverbatim
  163. *>
  164. *> \param[in] N
  165. *> \verbatim
  166. *> N is INTEGER
  167. *> The number of columns of the matrix A. N >= 0.
  168. *> \endverbatim
  169. *>
  170. *> \param[in] NRHS
  171. *> \verbatim
  172. *> NRHS is INTEGER
  173. *> The number of right hand sides, i.e. the number of
  174. *> columns of the matrix B. NRHS >= 0.
  175. *> \endverbatim
  176. *>
  177. *> \param[in] KMAX
  178. *> \verbatim
  179. *> KMAX is INTEGER
  180. *>
  181. *> The first factorization stopping criterion. KMAX >= 0.
  182. *>
  183. *> The maximum number of columns of the matrix A to factorize,
  184. *> i.e. the maximum factorization rank.
  185. *>
  186. *> a) If KMAX >= min(M,N), then this stopping criterion
  187. *> is not used, the routine factorizes columns
  188. *> depending on ABSTOL and RELTOL.
  189. *>
  190. *> b) If KMAX = 0, then this stopping criterion is
  191. *> satisfied on input and the routine exits immediately.
  192. *> This means that the factorization is not performed,
  193. *> the matrices A and B are not modified, and
  194. *> the matrix A is itself the residual.
  195. *> \endverbatim
  196. *>
  197. *> \param[in] ABSTOL
  198. *> \verbatim
  199. *> ABSTOL is DOUBLE PRECISION
  200. *>
  201. *> The second factorization stopping criterion, cannot be NaN.
  202. *>
  203. *> The absolute tolerance (stopping threshold) for
  204. *> maximum column 2-norm of the residual matrix R22(K).
  205. *> The algorithm converges (stops the factorization) when
  206. *> the maximum column 2-norm of the residual matrix R22(K)
  207. *> is less than or equal to ABSTOL. Let SAFMIN = DLAMCH('S').
  208. *>
  209. *> a) If ABSTOL is NaN, then no computation is performed
  210. *> and an error message ( INFO = -5 ) is issued
  211. *> by XERBLA.
  212. *>
  213. *> b) If ABSTOL < 0.0, then this stopping criterion is not
  214. *> used, the routine factorizes columns depending
  215. *> on KMAX and RELTOL.
  216. *> This includes the case ABSTOL = -Inf.
  217. *>
  218. *> c) If 0.0 <= ABSTOL < 2*SAFMIN, then ABSTOL = 2*SAFMIN
  219. *> is used. This includes the case ABSTOL = -0.0.
  220. *>
  221. *> d) If 2*SAFMIN <= ABSTOL then the input value
  222. *> of ABSTOL is used.
  223. *>
  224. *> Let MAXC2NRM be the maximum column 2-norm of the
  225. *> whole original matrix A.
  226. *> If ABSTOL chosen above is >= MAXC2NRM, then this
  227. *> stopping criterion is satisfied on input and routine exits
  228. *> immediately after MAXC2NRM is computed. The routine
  229. *> returns MAXC2NRM in MAXC2NORMK,
  230. *> and 1.0 in RELMAXC2NORMK.
  231. *> This includes the case ABSTOL = +Inf. This means that the
  232. *> factorization is not performed, the matrices A and B are not
  233. *> modified, and the matrix A is itself the residual.
  234. *> \endverbatim
  235. *>
  236. *> \param[in] RELTOL
  237. *> \verbatim
  238. *> RELTOL is DOUBLE PRECISION
  239. *>
  240. *> The third factorization stopping criterion, cannot be NaN.
  241. *>
  242. *> The tolerance (stopping threshold) for the ratio
  243. *> abs(R(K+1,K+1))/abs(R(1,1)) of the maximum column 2-norm of
  244. *> the residual matrix R22(K) to the maximum column 2-norm of
  245. *> the original matrix A. The algorithm converges (stops the
  246. *> factorization), when abs(R(K+1,K+1))/abs(R(1,1)) A is less
  247. *> than or equal to RELTOL. Let EPS = DLAMCH('E').
  248. *>
  249. *> a) If RELTOL is NaN, then no computation is performed
  250. *> and an error message ( INFO = -6 ) is issued
  251. *> by XERBLA.
  252. *>
  253. *> b) If RELTOL < 0.0, then this stopping criterion is not
  254. *> used, the routine factorizes columns depending
  255. *> on KMAX and ABSTOL.
  256. *> This includes the case RELTOL = -Inf.
  257. *>
  258. *> c) If 0.0 <= RELTOL < EPS, then RELTOL = EPS is used.
  259. *> This includes the case RELTOL = -0.0.
  260. *>
  261. *> d) If EPS <= RELTOL then the input value of RELTOL
  262. *> is used.
  263. *>
  264. *> Let MAXC2NRM be the maximum column 2-norm of the
  265. *> whole original matrix A.
  266. *> If RELTOL chosen above is >= 1.0, then this stopping
  267. *> criterion is satisfied on input and routine exits
  268. *> immediately after MAXC2NRM is computed.
  269. *> The routine returns MAXC2NRM in MAXC2NORMK,
  270. *> and 1.0 in RELMAXC2NORMK.
  271. *> This includes the case RELTOL = +Inf. This means that the
  272. *> factorization is not performed, the matrices A and B are not
  273. *> modified, and the matrix A is itself the residual.
  274. *>
  275. *> NOTE: We recommend that RELTOL satisfy
  276. *> min( 10*max(M,N)*EPS, sqrt(EPS) ) <= RELTOL
  277. *> \endverbatim
  278. *>
  279. *> \param[in,out] A
  280. *> \verbatim
  281. *> A is COMPLEX*16 array, dimension (LDA,N+NRHS)
  282. *>
  283. *> On entry:
  284. *>
  285. *> a) The subarray A(1:M,1:N) contains the M-by-N matrix A.
  286. *> b) The subarray A(1:M,N+1:N+NRHS) contains the M-by-NRHS
  287. *> matrix B.
  288. *>
  289. *> N NRHS
  290. *> array_A = M [ mat_A, mat_B ]
  291. *>
  292. *> On exit:
  293. *>
  294. *> a) The subarray A(1:M,1:N) contains parts of the factors
  295. *> of the matrix A:
  296. *>
  297. *> 1) If K = 0, A(1:M,1:N) contains the original matrix A.
  298. *> 2) If K > 0, A(1:M,1:N) contains parts of the
  299. *> factors:
  300. *>
  301. *> 1. The elements below the diagonal of the subarray
  302. *> A(1:M,1:K) together with TAU(1:K) represent the
  303. *> unitary matrix Q(K) as a product of K Householder
  304. *> elementary reflectors.
  305. *>
  306. *> 2. The elements on and above the diagonal of
  307. *> the subarray A(1:K,1:N) contain K-by-N
  308. *> upper-trapezoidal matrix
  309. *> R(K)_approx = ( R11(K), R12(K) ).
  310. *> NOTE: If K=min(M,N), i.e. full rank factorization,
  311. *> then R_approx(K) is the full factor R which
  312. *> is upper-trapezoidal. If, in addition, M>=N,
  313. *> then R is upper-triangular.
  314. *>
  315. *> 3. The subarray A(K+1:M,K+1:N) contains (M-K)-by-(N-K)
  316. *> rectangular matrix R(K)_residual = R22(K).
  317. *>
  318. *> b) If NRHS > 0, the subarray A(1:M,N+1:N+NRHS) contains
  319. *> the M-by-NRHS product Q(K)**H * B.
  320. *> \endverbatim
  321. *>
  322. *> \param[in] LDA
  323. *> \verbatim
  324. *> LDA is INTEGER
  325. *> The leading dimension of the array A. LDA >= max(1,M).
  326. *> This is the leading dimension for both matrices, A and B.
  327. *> \endverbatim
  328. *>
  329. *> \param[out] K
  330. *> \verbatim
  331. *> K is INTEGER
  332. *> Factorization rank of the matrix A, i.e. the rank of
  333. *> the factor R, which is the same as the number of non-zero
  334. *> rows of the factor R. 0 <= K <= min(M,KMAX,N).
  335. *>
  336. *> K also represents the number of non-zero Householder
  337. *> vectors.
  338. *>
  339. *> NOTE: If K = 0, a) the arrays A and B are not modified;
  340. *> b) the array TAU(1:min(M,N)) is set to ZERO,
  341. *> if the matrix A does not contain NaN,
  342. *> otherwise the elements TAU(1:min(M,N))
  343. *> are undefined;
  344. *> c) the elements of the array JPIV are set
  345. *> as follows: for j = 1:N, JPIV(j) = j.
  346. *> \endverbatim
  347. *>
  348. *> \param[out] MAXC2NRMK
  349. *> \verbatim
  350. *> MAXC2NRMK is DOUBLE PRECISION
  351. *> The maximum column 2-norm of the residual matrix R22(K),
  352. *> when the factorization stopped at rank K. MAXC2NRMK >= 0.
  353. *>
  354. *> a) If K = 0, i.e. the factorization was not performed,
  355. *> the matrix A was not modified and is itself a residual
  356. *> matrix, then MAXC2NRMK equals the maximum column 2-norm
  357. *> of the original matrix A.
  358. *>
  359. *> b) If 0 < K < min(M,N), then MAXC2NRMK is returned.
  360. *>
  361. *> c) If K = min(M,N), i.e. the whole matrix A was
  362. *> factorized and there is no residual matrix,
  363. *> then MAXC2NRMK = 0.0.
  364. *>
  365. *> NOTE: MAXC2NRMK in the factorization step K would equal
  366. *> R(K+1,K+1) in the next factorization step K+1.
  367. *> \endverbatim
  368. *>
  369. *> \param[out] RELMAXC2NRMK
  370. *> \verbatim
  371. *> RELMAXC2NRMK is DOUBLE PRECISION
  372. *> The ratio MAXC2NRMK / MAXC2NRM of the maximum column
  373. *> 2-norm of the residual matrix R22(K) (when the factorization
  374. *> stopped at rank K) to the maximum column 2-norm of the
  375. *> whole original matrix A. RELMAXC2NRMK >= 0.
  376. *>
  377. *> a) If K = 0, i.e. the factorization was not performed,
  378. *> the matrix A was not modified and is itself a residual
  379. *> matrix, then RELMAXC2NRMK = 1.0.
  380. *>
  381. *> b) If 0 < K < min(M,N), then
  382. *> RELMAXC2NRMK = MAXC2NRMK / MAXC2NRM is returned.
  383. *>
  384. *> c) If K = min(M,N), i.e. the whole matrix A was
  385. *> factorized and there is no residual matrix,
  386. *> then RELMAXC2NRMK = 0.0.
  387. *>
  388. *> NOTE: RELMAXC2NRMK in the factorization step K would equal
  389. *> abs(R(K+1,K+1))/abs(R(1,1)) in the next factorization
  390. *> step K+1.
  391. *> \endverbatim
  392. *>
  393. *> \param[out] JPIV
  394. *> \verbatim
  395. *> JPIV is INTEGER array, dimension (N)
  396. *> Column pivot indices. For 1 <= j <= N, column j
  397. *> of the matrix A was interchanged with column JPIV(j).
  398. *>
  399. *> The elements of the array JPIV(1:N) are always set
  400. *> by the routine, for example, even when no columns
  401. *> were factorized, i.e. when K = 0, the elements are
  402. *> set as JPIV(j) = j for j = 1:N.
  403. *> \endverbatim
  404. *>
  405. *> \param[out] TAU
  406. *> \verbatim
  407. *> TAU is COMPLEX*16 array, dimension (min(M,N))
  408. *> The scalar factors of the elementary reflectors.
  409. *>
  410. *> If 0 < K <= min(M,N), only the elements TAU(1:K) of
  411. *> the array TAU are modified by the factorization.
  412. *> After the factorization computed, if no NaN was found
  413. *> during the factorization, the remaining elements
  414. *> TAU(K+1:min(M,N)) are set to zero, otherwise the
  415. *> elements TAU(K+1:min(M,N)) are not set and therefore
  416. *> undefined.
  417. *> ( If K = 0, all elements of TAU are set to zero, if
  418. *> the matrix A does not contain NaN. )
  419. *> \endverbatim
  420. *>
  421. *> \param[out] WORK
  422. *> \verbatim
  423. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  424. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  425. *> \endverbatim
  426. *>
  427. *> \param[in] LWORK
  428. *> \verbatim
  429. *> LWORK is INTEGER
  430. *> The dimension of the array WORK.
  431. *> LWORK >= 1, if MIN(M,N) = 0, and
  432. *> LWORK >= N+NRHS-1, otherwise.
  433. *> For optimal performance LWORK >= NB*( N+NRHS+1 ),
  434. *> where NB is the optimal block size for ZGEQP3RK returned
  435. *> by ILAENV. Minimal block size MINNB=2.
  436. *>
  437. *> NOTE: The decision, whether to use unblocked BLAS 2
  438. *> or blocked BLAS 3 code is based not only on the dimension
  439. *> LWORK of the availbale workspace WORK, but also also on the
  440. *> matrix A dimension N via crossover point NX returned
  441. *> by ILAENV. (For N less than NX, unblocked code should be
  442. *> used.)
  443. *>
  444. *> If LWORK = -1, then a workspace query is assumed;
  445. *> the routine only calculates the optimal size of the WORK
  446. *> array, returns this value as the first entry of the WORK
  447. *> array, and no error message related to LWORK is issued
  448. *> by XERBLA.
  449. *> \endverbatim
  450. *>
  451. *> \param[out] RWORK
  452. *> \verbatim
  453. *> RWORK is DOUBLE PRECISION array, dimension (2*N)
  454. *> \endverbatim
  455. *>
  456. *> \param[out] IWORK
  457. *> \verbatim
  458. *> IWORK is INTEGER array, dimension (N-1).
  459. *> Is a work array. ( IWORK is used to store indices
  460. *> of "bad" columns for norm downdating in the residual
  461. *> matrix in the blocked step auxiliary subroutine ZLAQP3RK ).
  462. *> \endverbatim
  463. *>
  464. *> \param[out] INFO
  465. *> \verbatim
  466. *> INFO is INTEGER
  467. *> 1) INFO = 0: successful exit.
  468. *> 2) INFO < 0: if INFO = -i, the i-th argument had an
  469. *> illegal value.
  470. *> 3) If INFO = j_1, where 1 <= j_1 <= N, then NaN was
  471. *> detected and the routine stops the computation.
  472. *> The j_1-th column of the matrix A or the j_1-th
  473. *> element of array TAU contains the first occurrence
  474. *> of NaN in the factorization step K+1 ( when K columns
  475. *> have been factorized ).
  476. *>
  477. *> On exit:
  478. *> K is set to the number of
  479. *> factorized columns without
  480. *> exception.
  481. *> MAXC2NRMK is set to NaN.
  482. *> RELMAXC2NRMK is set to NaN.
  483. *> TAU(K+1:min(M,N)) is not set and contains undefined
  484. *> elements. If j_1=K+1, TAU(K+1)
  485. *> may contain NaN.
  486. *> 4) If INFO = j_2, where N+1 <= j_2 <= 2*N, then no NaN
  487. *> was detected, but +Inf (or -Inf) was detected and
  488. *> the routine continues the computation until completion.
  489. *> The (j_2-N)-th column of the matrix A contains the first
  490. *> occurrence of +Inf (or -Inf) in the factorization
  491. *> step K+1 ( when K columns have been factorized ).
  492. *> \endverbatim
  493. *
  494. * Authors:
  495. * ========
  496. *
  497. *> \author Univ. of Tennessee
  498. *> \author Univ. of California Berkeley
  499. *> \author Univ. of Colorado Denver
  500. *> \author NAG Ltd.
  501. *
  502. *> \ingroup geqp3rk
  503. *
  504. *> \par Further Details:
  505. * =====================
  506. *
  507. *> \verbatim
  508. *> ZGEQP3RK is based on the same BLAS3 Householder QR factorization
  509. *> algorithm with column pivoting as in ZGEQP3 routine which uses
  510. *> ZLARFG routine to generate Householder reflectors
  511. *> for QR factorization.
  512. *>
  513. *> We can also write:
  514. *>
  515. *> A = A_approx(K) + A_residual(K)
  516. *>
  517. *> The low rank approximation matrix A(K)_approx from
  518. *> the truncated QR factorization of rank K of the matrix A is:
  519. *>
  520. *> A(K)_approx = Q(K) * ( R(K)_approx ) * P(K)**T
  521. *> ( 0 0 )
  522. *>
  523. *> = Q(K) * ( R11(K) R12(K) ) * P(K)**T
  524. *> ( 0 0 )
  525. *>
  526. *> The residual A_residual(K) of the matrix A is:
  527. *>
  528. *> A_residual(K) = Q(K) * ( 0 0 ) * P(K)**T =
  529. *> ( 0 R(K)_residual )
  530. *>
  531. *> = Q(K) * ( 0 0 ) * P(K)**T
  532. *> ( 0 R22(K) )
  533. *>
  534. *> The truncated (rank K) factorization guarantees that
  535. *> the maximum column 2-norm of A_residual(K) is less than
  536. *> or equal to MAXC2NRMK up to roundoff error.
  537. *>
  538. *> NOTE: An approximation of the null vectors
  539. *> of A can be easily computed from R11(K)
  540. *> and R12(K):
  541. *>
  542. *> Null( A(K) )_approx = P * ( inv(R11(K)) * R12(K) )
  543. *> ( -I )
  544. *>
  545. *> \endverbatim
  546. *
  547. *> \par References:
  548. * ================
  549. *> [1] A Level 3 BLAS QR factorization algorithm with column pivoting developed in 1996.
  550. *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain.
  551. *> X. Sun, Computer Science Dept., Duke University, USA.
  552. *> C. H. Bischof, Math. and Comp. Sci. Div., Argonne National Lab, USA.
  553. *> A BLAS-3 version of the QR factorization with column pivoting.
  554. *> LAPACK Working Note 114
  555. *> \htmlonly
  556. *> <a href="https://www.netlib.org/lapack/lawnspdf/lawn114.pdf">https://www.netlib.org/lapack/lawnspdf/lawn114.pdf</a>
  557. *> \endhtmlonly
  558. *> and in
  559. *> SIAM J. Sci. Comput., 19(5):1486-1494, Sept. 1998.
  560. *> \htmlonly
  561. *> <a href="https://doi.org/10.1137/S1064827595296732">https://doi.org/10.1137/S1064827595296732</a>
  562. *> \endhtmlonly
  563. *>
  564. *> [2] A partial column norm updating strategy developed in 2006.
  565. *> Z. Drmac and Z. Bujanovic, Dept. of Math., University of Zagreb, Croatia.
  566. *> On the failure of rank revealing QR factorization software – a case study.
  567. *> LAPACK Working Note 176.
  568. *> \htmlonly
  569. *> <a href="http://www.netlib.org/lapack/lawnspdf/lawn176.pdf">http://www.netlib.org/lapack/lawnspdf/lawn176.pdf</a>
  570. *> \endhtmlonly
  571. *> and in
  572. *> ACM Trans. Math. Softw. 35, 2, Article 12 (July 2008), 28 pages.
  573. *> \htmlonly
  574. *> <a href="https://doi.org/10.1145/1377612.1377616">https://doi.org/10.1145/1377612.1377616</a>
  575. *> \endhtmlonly
  576. *
  577. *> \par Contributors:
  578. * ==================
  579. *>
  580. *> \verbatim
  581. *>
  582. *> November 2023, Igor Kozachenko, James Demmel,
  583. *> EECS Department,
  584. *> University of California, Berkeley, USA.
  585. *>
  586. *> \endverbatim
  587. *
  588. * =====================================================================
  589. SUBROUTINE ZGEQP3RK( M, N, NRHS, KMAX, ABSTOL, RELTOL, A, LDA,
  590. $ K, MAXC2NRMK, RELMAXC2NRMK, JPIV, TAU,
  591. $ WORK, LWORK, RWORK, IWORK, INFO )
  592. IMPLICIT NONE
  593. *
  594. * -- LAPACK computational routine --
  595. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  596. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  597. *
  598. * .. Scalar Arguments ..
  599. INTEGER INFO, K, KF, KMAX, LDA, LWORK, M, N, NRHS
  600. DOUBLE PRECISION ABSTOL, MAXC2NRMK, RELMAXC2NRMK, RELTOL
  601. * ..
  602. * .. Array Arguments ..
  603. INTEGER IWORK( * ), JPIV( * )
  604. DOUBLE PRECISION RWORK( * )
  605. COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * )
  606. * ..
  607. *
  608. * =====================================================================
  609. *
  610. * .. Parameters ..
  611. INTEGER INB, INBMIN, IXOVER
  612. PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
  613. DOUBLE PRECISION ZERO, ONE, TWO
  614. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
  615. COMPLEX*16 CZERO
  616. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) )
  617. * ..
  618. * .. Local Scalars ..
  619. LOGICAL LQUERY, DONE
  620. INTEGER IINFO, IOFFSET, IWS, J, JB, JBF, JMAXB, JMAX,
  621. $ JMAXC2NRM, KP1, LWKOPT, MINMN, N_SUB, NB,
  622. $ NBMIN, NX
  623. DOUBLE PRECISION EPS, HUGEVAL, MAXC2NRM, SAFMIN
  624. * ..
  625. * .. External Subroutines ..
  626. EXTERNAL ZLAQP2RK, ZLAQP3RK, XERBLA
  627. * ..
  628. * .. External Functions ..
  629. LOGICAL DISNAN
  630. INTEGER IDAMAX, ILAENV
  631. DOUBLE PRECISION DLAMCH, DZNRM2
  632. EXTERNAL DISNAN, DLAMCH, DZNRM2, IDAMAX, ILAENV
  633. * ..
  634. * .. Intrinsic Functions ..
  635. INTRINSIC DCMPLX, MAX, MIN
  636. * ..
  637. * .. Executable Statements ..
  638. *
  639. * Test input arguments
  640. * ====================
  641. *
  642. INFO = 0
  643. LQUERY = ( LWORK.EQ.-1 )
  644. IF( M.LT.0 ) THEN
  645. INFO = -1
  646. ELSE IF( N.LT.0 ) THEN
  647. INFO = -2
  648. ELSE IF( NRHS.LT.0 ) THEN
  649. INFO = -3
  650. ELSE IF( KMAX.LT.0 ) THEN
  651. INFO = -4
  652. ELSE IF( DISNAN( ABSTOL ) ) THEN
  653. INFO = -5
  654. ELSE IF( DISNAN( RELTOL ) ) THEN
  655. INFO = -6
  656. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  657. INFO = -8
  658. END IF
  659. *
  660. * If the input parameters M, N, NRHS, KMAX, LDA are valid:
  661. * a) Test the input workspace size LWORK for the minimum
  662. * size requirement IWS.
  663. * b) Determine the optimal block size NB and optimal
  664. * workspace size LWKOPT to be returned in WORK(1)
  665. * in case of (1) LWORK < IWS, (2) LQUERY = .TRUE.,
  666. * (3) when routine exits.
  667. * Here, IWS is the miminum workspace required for unblocked
  668. * code.
  669. *
  670. IF( INFO.EQ.0 ) THEN
  671. MINMN = MIN( M, N )
  672. IF( MINMN.EQ.0 ) THEN
  673. IWS = 1
  674. LWKOPT = 1
  675. ELSE
  676. *
  677. * Minimal workspace size in case of using only unblocked
  678. * BLAS 2 code in ZLAQP2RK.
  679. * 1) ZLAQP2RK: N+NRHS-1 to use in WORK array that is used
  680. * in ZLARF subroutine inside ZLAQP2RK to apply an
  681. * elementary reflector from the left.
  682. * TOTAL_WORK_SIZE = 3*N + NRHS - 1
  683. *
  684. IWS = N + NRHS - 1
  685. *
  686. * Assign to NB optimal block size.
  687. *
  688. NB = ILAENV( INB, 'ZGEQP3RK', ' ', M, N, -1, -1 )
  689. *
  690. * A formula for the optimal workspace size in case of using
  691. * both unblocked BLAS 2 in ZLAQP2RK and blocked BLAS 3 code
  692. * in ZLAQP3RK.
  693. * 1) ZGEQP3RK, ZLAQP2RK, ZLAQP3RK: 2*N to store full and
  694. * partial column 2-norms.
  695. * 2) ZLAQP2RK: N+NRHS-1 to use in WORK array that is used
  696. * in ZLARF subroutine to apply an elementary reflector
  697. * from the left.
  698. * 3) ZLAQP3RK: NB*(N+NRHS) to use in the work array F that
  699. * is used to apply a block reflector from
  700. * the left.
  701. * 4) ZLAQP3RK: NB to use in the auxilixary array AUX.
  702. * Sizes (2) and ((3) + (4)) should intersect, therefore
  703. * TOTAL_WORK_SIZE = 2*N + NB*( N+NRHS+1 ), given NBMIN=2.
  704. *
  705. LWKOPT = 2*N + NB*( N+NRHS+1 )
  706. END IF
  707. WORK( 1 ) = DCMPLX( LWKOPT )
  708. *
  709. IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
  710. INFO = -15
  711. END IF
  712. END IF
  713. *
  714. * NOTE: The optimal workspace size is returned in WORK(1), if
  715. * the input parameters M, N, NRHS, KMAX, LDA are valid.
  716. *
  717. IF( INFO.NE.0 ) THEN
  718. CALL XERBLA( 'ZGEQP3RK', -INFO )
  719. RETURN
  720. ELSE IF( LQUERY ) THEN
  721. RETURN
  722. END IF
  723. *
  724. * Quick return if possible for M=0 or N=0.
  725. *
  726. IF( MINMN.EQ.0 ) THEN
  727. K = 0
  728. MAXC2NRMK = ZERO
  729. RELMAXC2NRMK = ZERO
  730. WORK( 1 ) = DCMPLX( LWKOPT )
  731. RETURN
  732. END IF
  733. *
  734. * ==================================================================
  735. *
  736. * Initialize column pivot array JPIV.
  737. *
  738. DO J = 1, N
  739. JPIV( J ) = J
  740. END DO
  741. *
  742. * ==================================================================
  743. *
  744. * Initialize storage for partial and exact column 2-norms.
  745. * a) The elements WORK(1:N) are used to store partial column
  746. * 2-norms of the matrix A, and may decrease in each computation
  747. * step; initialize to the values of complete columns 2-norms.
  748. * b) The elements WORK(N+1:2*N) are used to store complete column
  749. * 2-norms of the matrix A, they are not changed during the
  750. * computation; initialize the values of complete columns 2-norms.
  751. *
  752. DO J = 1, N
  753. RWORK( J ) = DZNRM2( M, A( 1, J ), 1 )
  754. RWORK( N+J ) = RWORK( J )
  755. END DO
  756. *
  757. * ==================================================================
  758. *
  759. * Compute the pivot column index and the maximum column 2-norm
  760. * for the whole original matrix stored in A(1:M,1:N).
  761. *
  762. KP1 = IDAMAX( N, RWORK( 1 ), 1 )
  763. *
  764. * ==================================================================.
  765. *
  766. IF( DISNAN( MAXC2NRM ) ) THEN
  767. *
  768. * Check if the matrix A contains NaN, set INFO parameter
  769. * to the column number where the first NaN is found and return
  770. * from the routine.
  771. *
  772. K = 0
  773. INFO = KP1
  774. *
  775. * Set MAXC2NRMK and RELMAXC2NRMK to NaN.
  776. *
  777. MAXC2NRMK = MAXC2NRM
  778. RELMAXC2NRMK = MAXC2NRM
  779. *
  780. * Array TAU is not set and contains undefined elements.
  781. *
  782. WORK( 1 ) = DCMPLX( LWKOPT )
  783. RETURN
  784. END IF
  785. *
  786. * ===================================================================
  787. *
  788. IF( MAXC2NRM.EQ.ZERO ) THEN
  789. *
  790. * Check is the matrix A is a zero matrix, set array TAU and
  791. * return from the routine.
  792. *
  793. K = 0
  794. MAXC2NRMK = ZERO
  795. RELMAXC2NRMK = ZERO
  796. *
  797. DO J = 1, MINMN
  798. TAU( J ) = CZERO
  799. END DO
  800. *
  801. WORK( 1 ) = DCMPLX( LWKOPT )
  802. RETURN
  803. *
  804. END IF
  805. *
  806. * ===================================================================
  807. *
  808. HUGEVAL = DLAMCH( 'Overflow' )
  809. *
  810. IF( MAXC2NRM.GT.HUGEVAL ) THEN
  811. *
  812. * Check if the matrix A contains +Inf or -Inf, set INFO parameter
  813. * to the column number, where the first +/-Inf is found plus N,
  814. * and continue the computation.
  815. *
  816. INFO = N + KP1
  817. *
  818. END IF
  819. *
  820. * ==================================================================
  821. *
  822. * Quick return if possible for the case when the first
  823. * stopping criterion is satisfied, i.e. KMAX = 0.
  824. *
  825. IF( KMAX.EQ.0 ) THEN
  826. K = 0
  827. MAXC2NRMK = MAXC2NRM
  828. RELMAXC2NRMK = ONE
  829. DO J = 1, MINMN
  830. TAU( J ) = CZERO
  831. END DO
  832. WORK( 1 ) = DCMPLX( LWKOPT )
  833. RETURN
  834. END IF
  835. *
  836. * ==================================================================
  837. *
  838. EPS = DLAMCH('Epsilon')
  839. *
  840. * Adjust ABSTOL
  841. *
  842. IF( ABSTOL.GE.ZERO ) THEN
  843. SAFMIN = DLAMCH('Safe minimum')
  844. ABSTOL = MAX( ABSTOL, TWO*SAFMIN )
  845. END IF
  846. *
  847. * Adjust RELTOL
  848. *
  849. IF( RELTOL.GE.ZERO ) THEN
  850. RELTOL = MAX( RELTOL, EPS )
  851. END IF
  852. *
  853. * ===================================================================
  854. *
  855. * JMAX is the maximum index of the column to be factorized,
  856. * which is also limited by the first stopping criterion KMAX.
  857. *
  858. JMAX = MIN( KMAX, MINMN )
  859. *
  860. * ===================================================================
  861. *
  862. * Quick return if possible for the case when the second or third
  863. * stopping criterion for the whole original matrix is satified,
  864. * i.e. MAXC2NRM <= ABSTOL or RELMAXC2NRM <= RELTOL
  865. * (which is ONE <= RELTOL).
  866. *
  867. IF( MAXC2NRM.LE.ABSTOL .OR. ONE.LE.RELTOL ) THEN
  868. *
  869. K = 0
  870. MAXC2NRMK = MAXC2NRM
  871. RELMAXC2NRMK = ONE
  872. *
  873. DO J = 1, MINMN
  874. TAU( J ) = CZERO
  875. END DO
  876. *
  877. WORK( 1 ) = DCMPLX( LWKOPT )
  878. RETURN
  879. END IF
  880. *
  881. * ==================================================================
  882. * Factorize columns
  883. * ==================================================================
  884. *
  885. * Determine the block size.
  886. *
  887. NBMIN = 2
  888. NX = 0
  889. *
  890. IF( ( NB.GT.1 ) .AND. ( NB.LT.MINMN ) ) THEN
  891. *
  892. * Determine when to cross over from blocked to unblocked code.
  893. * (for N less than NX, unblocked code should be used).
  894. *
  895. NX = MAX( 0, ILAENV( IXOVER, 'ZGEQP3RK', ' ', M, N, -1, -1 ) )
  896. *
  897. IF( NX.LT.MINMN ) THEN
  898. *
  899. * Determine if workspace is large enough for blocked code.
  900. *
  901. IF( LWORK.LT.LWKOPT ) THEN
  902. *
  903. * Not enough workspace to use optimal block size that
  904. * is currently stored in NB.
  905. * Reduce NB and determine the minimum value of NB.
  906. *
  907. NB = ( LWORK-2*N ) / ( N+1 )
  908. NBMIN = MAX( 2, ILAENV( INBMIN, 'ZGEQP3RK', ' ', M, N,
  909. $ -1, -1 ) )
  910. *
  911. END IF
  912. END IF
  913. END IF
  914. *
  915. * ==================================================================
  916. *
  917. * DONE is the boolean flag to rerpresent the case when the
  918. * factorization completed in the block factorization routine,
  919. * before the end of the block.
  920. *
  921. DONE = .FALSE.
  922. *
  923. * J is the column index.
  924. *
  925. J = 1
  926. *
  927. * (1) Use blocked code initially.
  928. *
  929. * JMAXB is the maximum column index of the block, when the
  930. * blocked code is used, is also limited by the first stopping
  931. * criterion KMAX.
  932. *
  933. JMAXB = MIN( KMAX, MINMN - NX )
  934. *
  935. IF( NB.GE.NBMIN .AND. NB.LT.JMAX .AND. JMAXB.GT.0 ) THEN
  936. *
  937. * Loop over the column blocks of the matrix A(1:M,1:JMAXB). Here:
  938. * J is the column index of a column block;
  939. * JB is the column block size to pass to block factorization
  940. * routine in a loop step;
  941. * JBF is the number of columns that were actually factorized
  942. * that was returned by the block factorization routine
  943. * in a loop step, JBF <= JB;
  944. * N_SUB is the number of columns in the submatrix;
  945. * IOFFSET is the number of rows that should not be factorized.
  946. *
  947. DO WHILE( J.LE.JMAXB )
  948. *
  949. JB = MIN( NB, JMAXB-J+1 )
  950. N_SUB = N-J+1
  951. IOFFSET = J-1
  952. *
  953. * Factorize JB columns among the columns A(J:N).
  954. *
  955. CALL ZLAQP3RK( M, N_SUB, NRHS, IOFFSET, JB, ABSTOL,
  956. $ RELTOL, KP1, MAXC2NRM, A( 1, J ), LDA,
  957. $ DONE, JBF, MAXC2NRMK, RELMAXC2NRMK,
  958. $ JPIV( J ), TAU( J ),
  959. $ RWORK( J ), RWORK( N+J ),
  960. $ WORK( 1 ), WORK( JB+1 ),
  961. $ N+NRHS-J+1, IWORK, IINFO )
  962. *
  963. * Set INFO on the first occurence of Inf.
  964. *
  965. IF( IINFO.GT.N_SUB .AND. INFO.EQ.0 ) THEN
  966. INFO = 2*IOFFSET + IINFO
  967. END IF
  968. *
  969. IF( DONE ) THEN
  970. *
  971. * Either the submatrix is zero before the end of the
  972. * column block, or ABSTOL or RELTOL criterion is
  973. * satisfied before the end of the column block, we can
  974. * return from the routine. Perform the following before
  975. * returning:
  976. * a) Set the number of factorized columns K,
  977. * K = IOFFSET + JBF from the last call of blocked
  978. * routine.
  979. * NOTE: 1) MAXC2NRMK and RELMAXC2NRMK are returned
  980. * by the block factorization routine;
  981. * 2) The remaining TAUs are set to ZERO by the
  982. * block factorization routine.
  983. *
  984. K = IOFFSET + JBF
  985. *
  986. * Set INFO on the first occurrence of NaN, NaN takes
  987. * prcedence over Inf.
  988. *
  989. IF( IINFO.LE.N_SUB .AND. IINFO.GT.0 ) THEN
  990. INFO = IOFFSET + IINFO
  991. END IF
  992. *
  993. * Return from the routine.
  994. *
  995. WORK( 1 ) = DCMPLX( LWKOPT )
  996. *
  997. RETURN
  998. *
  999. END IF
  1000. *
  1001. J = J + JBF
  1002. *
  1003. END DO
  1004. *
  1005. END IF
  1006. *
  1007. * Use unblocked code to factor the last or only block.
  1008. * J = JMAX+1 means we factorized the maximum possible number of
  1009. * columns, that is in ELSE clause we need to compute
  1010. * the MAXC2NORM and RELMAXC2NORM to return after we processed
  1011. * the blocks.
  1012. *
  1013. IF( J.LE.JMAX ) THEN
  1014. *
  1015. * N_SUB is the number of columns in the submatrix;
  1016. * IOFFSET is the number of rows that should not be factorized.
  1017. *
  1018. N_SUB = N-J+1
  1019. IOFFSET = J-1
  1020. *
  1021. CALL ZLAQP2RK( M, N_SUB, NRHS, IOFFSET, JMAX-J+1,
  1022. $ ABSTOL, RELTOL, KP1, MAXC2NRM, A( 1, J ), LDA,
  1023. $ KF, MAXC2NRMK, RELMAXC2NRMK, JPIV( J ),
  1024. $ TAU( J ), RWORK( J ), RWORK( N+J ),
  1025. $ WORK( 1 ), IINFO )
  1026. *
  1027. * ABSTOL or RELTOL criterion is satisfied when the number of
  1028. * the factorized columns KF is smaller then the number
  1029. * of columns JMAX-J+1 supplied to be factorized by the
  1030. * unblocked routine, we can return from
  1031. * the routine. Perform the following before returning:
  1032. * a) Set the number of factorized columns K,
  1033. * b) MAXC2NRMK and RELMAXC2NRMK are returned by the
  1034. * unblocked factorization routine above.
  1035. *
  1036. K = J - 1 + KF
  1037. *
  1038. * Set INFO on the first exception occurence.
  1039. *
  1040. * Set INFO on the first exception occurence of Inf or NaN,
  1041. * (NaN takes precedence over Inf).
  1042. *
  1043. IF( IINFO.GT.N_SUB .AND. INFO.EQ.0 ) THEN
  1044. INFO = 2*IOFFSET + IINFO
  1045. ELSE IF( IINFO.LE.N_SUB .AND. IINFO.GT.0 ) THEN
  1046. INFO = IOFFSET + IINFO
  1047. END IF
  1048. *
  1049. ELSE
  1050. *
  1051. * Compute the return values for blocked code.
  1052. *
  1053. * Set the number of factorized columns if the unblocked routine
  1054. * was not called.
  1055. *
  1056. K = JMAX
  1057. *
  1058. * If there exits a residual matrix after the blocked code:
  1059. * 1) compute the values of MAXC2NRMK, RELMAXC2NRMK of the
  1060. * residual matrix, otherwise set them to ZERO;
  1061. * 2) Set TAU(K+1:MINMN) to ZERO.
  1062. *
  1063. IF( K.LT.MINMN ) THEN
  1064. JMAXC2NRM = K + IDAMAX( N-K, RWORK( K+1 ), 1 )
  1065. MAXC2NRMK = RWORK( JMAXC2NRM )
  1066. IF( K.EQ.0 ) THEN
  1067. RELMAXC2NRMK = ONE
  1068. ELSE
  1069. RELMAXC2NRMK = MAXC2NRMK / MAXC2NRM
  1070. END IF
  1071. *
  1072. DO J = K + 1, MINMN
  1073. TAU( J ) = CZERO
  1074. END DO
  1075. *
  1076. ELSE
  1077. MAXC2NRMK = ZERO
  1078. RELMAXC2NRMK = ZERO
  1079. *
  1080. END IF
  1081. *
  1082. * END IF( J.LE.JMAX ) THEN
  1083. *
  1084. END IF
  1085. *
  1086. WORK( 1 ) = DCMPLX( LWKOPT )
  1087. *
  1088. RETURN
  1089. *
  1090. * End of ZGEQP3RK
  1091. *
  1092. END