1*> \brief \b CLAQPS computes a step of QR factorization with column pivoting of a real m-by-n matrix A by using BLAS level 3. 2* 3* =========== DOCUMENTATION =========== 4* 5* Online html documentation available at 6* http://www.netlib.org/lapack/explore-html/ 7* 8*> \htmlonly 9*> Download CLAQPS + dependencies 10*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/claqps.f"> 11*> [TGZ]</a> 12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/claqps.f"> 13*> [ZIP]</a> 14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/claqps.f"> 15*> [TXT]</a> 16*> \endhtmlonly 17* 18* Definition: 19* =========== 20* 21* SUBROUTINE CLAQPS( M, N, OFFSET, NB, KB, A, LDA, JPVT, TAU, VN1, 22* VN2, AUXV, F, LDF ) 23* 24* .. Scalar Arguments .. 25* INTEGER KB, LDA, LDF, M, N, NB, OFFSET 26* .. 27* .. Array Arguments .. 28* INTEGER JPVT( * ) 29* REAL VN1( * ), VN2( * ) 30* COMPLEX A( LDA, * ), AUXV( * ), F( LDF, * ), TAU( * ) 31* .. 32* 33* 34*> \par Purpose: 35* ============= 36*> 37*> \verbatim 38*> 39*> CLAQPS computes a step of QR factorization with column pivoting 40*> of a complex M-by-N matrix A by using Blas-3. It tries to factorize 41*> NB columns from A starting from the row OFFSET+1, and updates all 42*> of the matrix with Blas-3 xGEMM. 43*> 44*> In some cases, due to catastrophic cancellations, it cannot 45*> factorize NB columns. Hence, the actual number of factorized 46*> columns is returned in KB. 47*> 48*> Block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized. 49*> \endverbatim 50* 51* Arguments: 52* ========== 53* 54*> \param[in] M 55*> \verbatim 56*> M is INTEGER 57*> The number of rows of the matrix A. M >= 0. 58*> \endverbatim 59*> 60*> \param[in] N 61*> \verbatim 62*> N is INTEGER 63*> The number of columns of the matrix A. N >= 0 64*> \endverbatim 65*> 66*> \param[in] OFFSET 67*> \verbatim 68*> OFFSET is INTEGER 69*> The number of rows of A that have been factorized in 70*> previous steps. 71*> \endverbatim 72*> 73*> \param[in] NB 74*> \verbatim 75*> NB is INTEGER 76*> The number of columns to factorize. 77*> \endverbatim 78*> 79*> \param[out] KB 80*> \verbatim 81*> KB is INTEGER 82*> The number of columns actually factorized. 83*> \endverbatim 84*> 85*> \param[in,out] A 86*> \verbatim 87*> A is COMPLEX array, dimension (LDA,N) 88*> On entry, the M-by-N matrix A. 89*> On exit, block A(OFFSET+1:M,1:KB) is the triangular 90*> factor obtained and block A(1:OFFSET,1:N) has been 91*> accordingly pivoted, but no factorized. 92*> The rest of the matrix, block A(OFFSET+1:M,KB+1:N) has 93*> been updated. 94*> \endverbatim 95*> 96*> \param[in] LDA 97*> \verbatim 98*> LDA is INTEGER 99*> The leading dimension of the array A. LDA >= max(1,M). 100*> \endverbatim 101*> 102*> \param[in,out] JPVT 103*> \verbatim 104*> JPVT is INTEGER array, dimension (N) 105*> JPVT(I) = K <==> Column K of the full matrix A has been 106*> permuted into position I in AP. 107*> \endverbatim 108*> 109*> \param[out] TAU 110*> \verbatim 111*> TAU is COMPLEX array, dimension (KB) 112*> The scalar factors of the elementary reflectors. 113*> \endverbatim 114*> 115*> \param[in,out] VN1 116*> \verbatim 117*> VN1 is REAL array, dimension (N) 118*> The vector with the partial column norms. 119*> \endverbatim 120*> 121*> \param[in,out] VN2 122*> \verbatim 123*> VN2 is REAL array, dimension (N) 124*> The vector with the exact column norms. 125*> \endverbatim 126*> 127*> \param[in,out] AUXV 128*> \verbatim 129*> AUXV is COMPLEX array, dimension (NB) 130*> Auxiliary vector. 131*> \endverbatim 132*> 133*> \param[in,out] F 134*> \verbatim 135*> F is COMPLEX array, dimension (LDF,NB) 136*> Matrix F**H = L * Y**H * A. 137*> \endverbatim 138*> 139*> \param[in] LDF 140*> \verbatim 141*> LDF is INTEGER 142*> The leading dimension of the array F. LDF >= max(1,N). 143*> \endverbatim 144* 145* Authors: 146* ======== 147* 148*> \author Univ. of Tennessee 149*> \author Univ. of California Berkeley 150*> \author Univ. of Colorado Denver 151*> \author NAG Ltd. 152* 153*> \ingroup complexOTHERauxiliary 154* 155*> \par Contributors: 156* ================== 157*> 158*> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain 159*> X. Sun, Computer Science Dept., Duke University, USA 160*> 161*> \n 162*> Partial column norm updating strategy modified on April 2011 163*> Z. Drmac and Z. Bujanovic, Dept. of Mathematics, 164*> University of Zagreb, Croatia. 165* 166*> \par References: 167* ================ 168*> 169*> LAPACK Working Note 176 170* 171*> \htmlonly 172*> <a href="http://www.netlib.org/lapack/lawnspdf/lawn176.pdf">[PDF]</a> 173*> \endhtmlonly 174* 175* ===================================================================== 176 SUBROUTINE CLAQPS( M, N, OFFSET, NB, KB, A, LDA, JPVT, TAU, VN1, 177 $ VN2, AUXV, F, LDF ) 178* 179* -- LAPACK auxiliary routine -- 180* -- LAPACK is a software package provided by Univ. of Tennessee, -- 181* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 182* 183* .. Scalar Arguments .. 184 INTEGER KB, LDA, LDF, M, N, NB, OFFSET 185* .. 186* .. Array Arguments .. 187 INTEGER JPVT( * ) 188 REAL VN1( * ), VN2( * ) 189 COMPLEX A( LDA, * ), AUXV( * ), F( LDF, * ), TAU( * ) 190* .. 191* 192* ===================================================================== 193* 194* .. Parameters .. 195 REAL ZERO, ONE 196 COMPLEX CZERO, CONE 197 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, 198 $ CZERO = ( 0.0E+0, 0.0E+0 ), 199 $ CONE = ( 1.0E+0, 0.0E+0 ) ) 200* .. 201* .. Local Scalars .. 202 INTEGER ITEMP, J, K, LASTRK, LSTICC, PVT, RK 203 REAL TEMP, TEMP2, TOL3Z 204 COMPLEX AKK 205* .. 206* .. External Subroutines .. 207 EXTERNAL CGEMM, CGEMV, CLARFG, CSWAP 208* .. 209* .. Intrinsic Functions .. 210 INTRINSIC ABS, CONJG, MAX, MIN, NINT, REAL, SQRT 211* .. 212* .. External Functions .. 213 INTEGER ISAMAX 214 REAL SCNRM2, SLAMCH 215 EXTERNAL ISAMAX, SCNRM2, SLAMCH 216* .. 217* .. Executable Statements .. 218* 219 LASTRK = MIN( M, N+OFFSET ) 220 LSTICC = 0 221 K = 0 222 TOL3Z = SQRT(SLAMCH('Epsilon')) 223* 224* Beginning of while loop. 225* 226 10 CONTINUE 227 IF( ( K.LT.NB ) .AND. ( LSTICC.EQ.0 ) ) THEN 228 K = K + 1 229 RK = OFFSET + K 230* 231* Determine ith pivot column and swap if necessary 232* 233 PVT = ( K-1 ) + ISAMAX( N-K+1, VN1( K ), 1 ) 234 IF( PVT.NE.K ) THEN 235 CALL CSWAP( M, A( 1, PVT ), 1, A( 1, K ), 1 ) 236 CALL CSWAP( K-1, F( PVT, 1 ), LDF, F( K, 1 ), LDF ) 237 ITEMP = JPVT( PVT ) 238 JPVT( PVT ) = JPVT( K ) 239 JPVT( K ) = ITEMP 240 VN1( PVT ) = VN1( K ) 241 VN2( PVT ) = VN2( K ) 242 END IF 243* 244* Apply previous Householder reflectors to column K: 245* A(RK:M,K) := A(RK:M,K) - A(RK:M,1:K-1)*F(K,1:K-1)**H. 246* 247 IF( K.GT.1 ) THEN 248 DO 20 J = 1, K - 1 249 F( K, J ) = CONJG( F( K, J ) ) 250 20 CONTINUE 251 CALL CGEMV( 'No transpose', M-RK+1, K-1, -CONE, A( RK, 1 ), 252 $ LDA, F( K, 1 ), LDF, CONE, A( RK, K ), 1 ) 253 DO 30 J = 1, K - 1 254 F( K, J ) = CONJG( F( K, J ) ) 255 30 CONTINUE 256 END IF 257* 258* Generate elementary reflector H(k). 259* 260 IF( RK.LT.M ) THEN 261 CALL CLARFG( M-RK+1, A( RK, K ), A( RK+1, K ), 1, TAU( K ) ) 262 ELSE 263 CALL CLARFG( 1, A( RK, K ), A( RK, K ), 1, TAU( K ) ) 264 END IF 265* 266 AKK = A( RK, K ) 267 A( RK, K ) = CONE 268* 269* Compute Kth column of F: 270* 271* Compute F(K+1:N,K) := tau(K)*A(RK:M,K+1:N)**H*A(RK:M,K). 272* 273 IF( K.LT.N ) THEN 274 CALL CGEMV( 'Conjugate transpose', M-RK+1, N-K, TAU( K ), 275 $ A( RK, K+1 ), LDA, A( RK, K ), 1, CZERO, 276 $ F( K+1, K ), 1 ) 277 END IF 278* 279* Padding F(1:K,K) with zeros. 280* 281 DO 40 J = 1, K 282 F( J, K ) = CZERO 283 40 CONTINUE 284* 285* Incremental updating of F: 286* F(1:N,K) := F(1:N,K) - tau(K)*F(1:N,1:K-1)*A(RK:M,1:K-1)**H 287* *A(RK:M,K). 288* 289 IF( K.GT.1 ) THEN 290 CALL CGEMV( 'Conjugate transpose', M-RK+1, K-1, -TAU( K ), 291 $ A( RK, 1 ), LDA, A( RK, K ), 1, CZERO, 292 $ AUXV( 1 ), 1 ) 293* 294 CALL CGEMV( 'No transpose', N, K-1, CONE, F( 1, 1 ), LDF, 295 $ AUXV( 1 ), 1, CONE, F( 1, K ), 1 ) 296 END IF 297* 298* Update the current row of A: 299* A(RK,K+1:N) := A(RK,K+1:N) - A(RK,1:K)*F(K+1:N,1:K)**H. 300* 301 IF( K.LT.N ) THEN 302 CALL CGEMM( 'No transpose', 'Conjugate transpose', 1, N-K, 303 $ K, -CONE, A( RK, 1 ), LDA, F( K+1, 1 ), LDF, 304 $ CONE, A( RK, K+1 ), LDA ) 305 END IF 306* 307* Update partial column norms. 308* 309 IF( RK.LT.LASTRK ) THEN 310 DO 50 J = K + 1, N 311 IF( VN1( J ).NE.ZERO ) THEN 312* 313* NOTE: The following 4 lines follow from the analysis in 314* Lapack Working Note 176. 315* 316 TEMP = ABS( A( RK, J ) ) / VN1( J ) 317 TEMP = MAX( ZERO, ( ONE+TEMP )*( ONE-TEMP ) ) 318 TEMP2 = TEMP*( VN1( J ) / VN2( J ) )**2 319 IF( TEMP2 .LE. TOL3Z ) THEN 320 VN2( J ) = REAL( LSTICC ) 321 LSTICC = J 322 ELSE 323 VN1( J ) = VN1( J )*SQRT( TEMP ) 324 END IF 325 END IF 326 50 CONTINUE 327 END IF 328* 329 A( RK, K ) = AKK 330* 331* End of while loop. 332* 333 GO TO 10 334 END IF 335 KB = K 336 RK = OFFSET + KB 337* 338* Apply the block reflector to the rest of the matrix: 339* A(OFFSET+KB+1:M,KB+1:N) := A(OFFSET+KB+1:M,KB+1:N) - 340* A(OFFSET+KB+1:M,1:KB)*F(KB+1:N,1:KB)**H. 341* 342 IF( KB.LT.MIN( N, M-OFFSET ) ) THEN 343 CALL CGEMM( 'No transpose', 'Conjugate transpose', M-RK, N-KB, 344 $ KB, -CONE, A( RK+1, 1 ), LDA, F( KB+1, 1 ), LDF, 345 $ CONE, A( RK+1, KB+1 ), LDA ) 346 END IF 347* 348* Recomputation of difficult columns. 349* 350 60 CONTINUE 351 IF( LSTICC.GT.0 ) THEN 352 ITEMP = NINT( VN2( LSTICC ) ) 353 VN1( LSTICC ) = SCNRM2( M-RK, A( RK+1, LSTICC ), 1 ) 354* 355* NOTE: The computation of VN1( LSTICC ) relies on the fact that 356* SNRM2 does not fail on vectors with norm below the value of 357* SQRT(DLAMCH('S')) 358* 359 VN2( LSTICC ) = VN1( LSTICC ) 360 LSTICC = ITEMP 361 GO TO 60 362 END IF 363* 364 RETURN 365* 366* End of CLAQPS 367* 368 END 369