| 1 | SUBROUTINE PZGELQRV( M, N, A, IA, JA, DESCA, TAU, WORK ) |
| 2 | IMPLICIT NONE |
| 3 | * |
| 4 | * -- ScaLAPACK routine (version 1.7) -- |
| 5 | * University of Tennessee, Knoxville, Oak Ridge National Laboratory, |
| 6 | * and University of California, Berkeley. |
| 7 | * May 28, 2001 |
| 8 | * |
| 9 | * .. Scalar Arguments .. |
| 10 | INTEGER IA, JA, M, N |
| 11 | * .. |
| 12 | * .. Array Arguments .. |
| 13 | INTEGER DESCA( * ) |
| 14 | COMPLEX*16 A( * ), TAU( * ), WORK( * ) |
| 15 | * .. |
| 16 | * |
| 17 | * Purpose |
| 18 | * ======= |
| 19 | * |
| 20 | * PZGELQRV computes sub( A ) = A(IA:IA+M-1,JA:JA+N-1) from L, Q |
| 21 | * computed by PZGELQF. |
| 22 | * |
| 23 | * Notes |
| 24 | * ===== |
| 25 | * |
| 26 | * Each global data object is described by an associated description |
| 27 | * vector. This vector stores the information required to establish |
| 28 | * the mapping between an object element and its corresponding process |
| 29 | * and memory location. |
| 30 | * |
| 31 | * Let A be a generic term for any 2D block cyclicly distributed array. |
| 32 | * Such a global array has an associated description vector DESCA. |
| 33 | * In the following comments, the character _ should be read as |
| 34 | * "of the global array". |
| 35 | * |
| 36 | * NOTATION STORED IN EXPLANATION |
| 37 | * --------------- -------------- -------------------------------------- |
| 38 | * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case, |
| 39 | * DTYPE_A = 1. |
| 40 | * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating |
| 41 | * the BLACS process grid A is distribu- |
| 42 | * ted over. The context itself is glo- |
| 43 | * bal, but the handle (the integer |
| 44 | * value) may vary. |
| 45 | * M_A (global) DESCA( M_ ) The number of rows in the global |
| 46 | * array A. |
| 47 | * N_A (global) DESCA( N_ ) The number of columns in the global |
| 48 | * array A. |
| 49 | * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute |
| 50 | * the rows of the array. |
| 51 | * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute |
| 52 | * the columns of the array. |
| 53 | * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first |
| 54 | * row of the array A is distributed. |
| 55 | * CSRC_A (global) DESCA( CSRC_ ) The process column over which the |
| 56 | * first column of the array A is |
| 57 | * distributed. |
| 58 | * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local |
| 59 | * array. LLD_A >= MAX(1,LOCr(M_A)). |
| 60 | * |
| 61 | * Let K be the number of rows or columns of a distributed matrix, |
| 62 | * and assume that its process grid has dimension p x q. |
| 63 | * LOCr( K ) denotes the number of elements of K that a process |
| 64 | * would receive if K were distributed over the p processes of its |
| 65 | * process column. |
| 66 | * Similarly, LOCc( K ) denotes the number of elements of K that a |
| 67 | * process would receive if K were distributed over the q processes of |
| 68 | * its process row. |
| 69 | * The values of LOCr() and LOCc() may be determined via a call to the |
| 70 | * ScaLAPACK tool function, NUMROC: |
| 71 | * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ), |
| 72 | * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ). |
| 73 | * An upper bound for these quantities may be computed by: |
| 74 | * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A |
| 75 | * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A |
| 76 | * |
| 77 | * Arguments |
| 78 | * ========= |
| 79 | * |
| 80 | * M (global input) INTEGER |
| 81 | * The number of rows to be operated on, i.e. the number of rows |
| 82 | * of the distributed submatrix sub( A ). M >= 0. |
| 83 | * |
| 84 | * N (global input) INTEGER |
| 85 | * The number of columns to be operated on, i.e. the number of |
| 86 | * columns of the distributed submatrix sub( A ). N >= 0. |
| 87 | * |
| 88 | * A (local input/local output) COMPLEX*16 pointer into the |
| 89 | * local memory to an array of dimension (LLD_A, LOCc(JA+N-1)). |
| 90 | * On entry, sub( A ) contains the the factors L and Q computed |
| 91 | * by PZGELQF. On exit, the original matrix is restored. |
| 92 | * |
| 93 | * IA (global input) INTEGER |
| 94 | * The row index in the global array A indicating the first |
| 95 | * row of sub( A ). |
| 96 | * |
| 97 | * JA (global input) INTEGER |
| 98 | * The column index in the global array A indicating the |
| 99 | * first column of sub( A ). |
| 100 | * |
| 101 | * DESCA (global and local input) INTEGER array of dimension DLEN_. |
| 102 | * The array descriptor for the distributed matrix A. |
| 103 | * |
| 104 | * TAU (local input) COMPLEX*16, array, dimension |
| 105 | * LOCr(IA+MIN(M,N)-1). This array contains the scalar factors |
| 106 | * TAU of the elementary reflectors computed by PZGELQF. TAU |
| 107 | * is tied to the distributed matrix A. |
| 108 | * |
| 109 | * WORK (local workspace) COMPLEX*16 array, dimension |
| 110 | * LWORK = MB_A * ( Mp0 + 2*Nq0 + MB_A ), where |
| 111 | * Mp0 = NUMROC( M+IROFF, MB_A, MYROW, IAROW, NPROW ) * NB_A, |
| 112 | * Nq0 = NUMROC( N+ICOFF, NB_A, MYCOL, IACOL, NPCOL ) * MB_A, |
| 113 | * IROFF = MOD( IA-1, MB_A ), ICOFF = MOD( JA-1, NB_A ), |
| 114 | * IAROW = INDXG2P( IA, DESCA( MB_ ), MYROW, DESCA( RSRC_ ), |
| 115 | * NPROW ), |
| 116 | * IACOL = INDXG2P( JA, DESCA( NB_ ), MYCOL, DESCA( CSRC_ ), |
| 117 | * NPCOL ), |
| 118 | * and NUMROC, INDXG2P are ScaLAPACK tool functions. |
| 119 | * |
| 120 | * ===================================================================== |
| 121 | * |
| 122 | * .. Parameters .. |
| 123 | INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_, |
| 124 | $ LLD_, MB_, M_, NB_, N_, RSRC_ |
| 125 | PARAMETER ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1, |
| 126 | $ CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6, |
| 127 | $ RSRC_ = 7, CSRC_ = 8, LLD_ = 9 ) |
| 128 | COMPLEX*16 ONE, ZERO |
| 129 | PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ), |
| 130 | $ ZERO = ( 0.0D+0, 0.0D+0 ) ) |
| 131 | * .. |
| 132 | * .. Local Scalars .. |
| 133 | CHARACTER COLBTOP, ROWBTOP |
| 134 | INTEGER I, IACOL, IAROW, IB, ICOFF, ICTXT, IIA, IL, IN, |
| 135 | $ IPT, IPV, IPW, J, JJA, JV, K, MYCOL, MYROW, |
| 136 | $ NPCOL, NPROW, NQ |
| 137 | * .. |
| 138 | * .. Local Arrays .. |
| 139 | INTEGER DESCV( DLEN_ ) |
| 140 | * .. |
| 141 | * .. External Subroutines .. |
| 142 | EXTERNAL BLACS_GRIDINFO, DESCSET, INFOG2L, PZLACPY, |
| 143 | $ PZLARFB, PZLARFT, PZLASET |
| 144 | * .. |
| 145 | * .. External Functions .. |
| 146 | INTEGER ICEIL, NUMROC |
| 147 | EXTERNAL ICEIL, NUMROC |
| 148 | * .. |
| 149 | * .. Intrinsic Functions .. |
| 150 | INTRINSIC MAX, MIN, MOD |
| 151 | * .. |
| 152 | * .. Executable Statements .. |
| 153 | * |
| 154 | * Get grid parameters |
| 155 | * |
| 156 | ICTXT = DESCA( CTXT_ ) |
| 157 | CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL ) |
| 158 | * |
| 159 | K = MIN( M, N ) |
| 160 | IN = MIN( ICEIL( IA, DESCA( MB_ ) ) * DESCA( MB_ ), IA+K-1 ) |
| 161 | IL = MAX( ( (IA+K-2) / DESCA( MB_ ) ) * DESCA( MB_ ) + 1, IA ) |
| 162 | * |
| 163 | ICOFF = MOD( JA-1, DESCA( NB_ ) ) |
| 164 | CALL INFOG2L( IL, JA, DESCA, NPROW, NPCOL, MYROW, MYCOL, IIA, JJA, |
| 165 | $ IAROW, IACOL ) |
| 166 | NQ = NUMROC( N+ICOFF, DESCA( NB_ ), MYCOL, IACOL, NPCOL ) |
| 167 | IPV = 1 |
| 168 | IPT = IPV + NQ * DESCA( MB_ ) |
| 169 | IPW = IPT + DESCA( MB_ ) * DESCA( MB_ ) |
| 170 | CALL PB_TOPGET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP ) |
| 171 | CALL PB_TOPGET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP ) |
| 172 | CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', ' ' ) |
| 173 | CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', 'D-ring' ) |
| 174 | * |
| 175 | CALL DESCSET( DESCV, DESCA( MB_ ), N + ICOFF, DESCA( MB_ ), |
| 176 | $ DESCA( NB_ ), IAROW, IACOL, ICTXT, DESCA( MB_ ) ) |
| 177 | * |
| 178 | DO 10 I = IL, IN+1, -DESCA( MB_ ) |
| 179 | IB = MIN( IA+K-I, DESCA( MB_ ) ) |
| 180 | J = JA + I - IA |
| 181 | JV = 1 + I - IA + ICOFF |
| 182 | * |
| 183 | * Compute upper triangular matrix T |
| 184 | * |
| 185 | CALL PZLARFT( 'Forward', 'Rowwise', N-J+JA, IB, A, I, J, DESCA, |
| 186 | $ TAU, WORK( IPT ), WORK( IPW ) ) |
| 187 | * |
| 188 | * Copy Householder vectors into workspace |
| 189 | * |
| 190 | CALL PZLACPY( 'Upper', IB, N-J+JA, A, I, J, DESCA, WORK( IPV ), |
| 191 | $ 1, JV, DESCV ) |
| 192 | CALL PZLASET( 'Lower', IB, N-J+JA, ZERO, ONE, WORK( IPV ), 1, |
| 193 | $ JV, DESCV ) |
| 194 | * |
| 195 | * Zeroes the strict upper triangular part of sub( A ) to get |
| 196 | * block column of L |
| 197 | * |
| 198 | CALL PZLASET( 'Upper', IB, N-J+JA-1, ZERO, ZERO, A, I, J+1, |
| 199 | $ DESCA ) |
| 200 | * |
| 201 | * Apply block Householder transformation |
| 202 | * |
| 203 | CALL PZLARFB( 'Right', 'Conjugate transpose', 'Forward', |
| 204 | $ 'Rowwise', M-I+IA, N-J+JA, IB, WORK( IPV ), 1, |
| 205 | $ JV, DESCV, WORK( IPT ), A, I, J, DESCA, |
| 206 | $ WORK( IPW ) ) |
| 207 | * |
| 208 | DESCV( RSRC_ ) = MOD( DESCV( RSRC_ ) + NPROW - 1, NPROW ) |
| 209 | * |
| 210 | 10 CONTINUE |
| 211 | * |
| 212 | * Handle first block separately |
| 213 | * |
| 214 | IB = IN - IA + 1 |
| 215 | * |
| 216 | * Compute upper triangular matrix T |
| 217 | * |
| 218 | CALL PZLARFT( 'Forward', 'Rowwise', N, IB, A, IA, JA, DESCA, TAU, |
| 219 | $ WORK( IPT ), WORK( IPW ) ) |
| 220 | * |
| 221 | * Copy Householder vectors into workspace |
| 222 | * |
| 223 | CALL PZLACPY( 'Upper', IB, N, A, IA, JA, DESCA, WORK( IPV ), 1, |
| 224 | $ ICOFF+1, DESCV ) |
| 225 | CALL PZLASET( 'Lower', IB, N, ZERO, ONE, WORK, 1, ICOFF+1, DESCV ) |
| 226 | * |
| 227 | * Zeroes the strict upper triangular part of sub( A ) to get |
| 228 | * block column of L |
| 229 | * |
| 230 | CALL PZLASET( 'Upper', IB, N-1, ZERO, ZERO, A, IA, JA+1, DESCA ) |
| 231 | * |
| 232 | * Apply block Householder transformation |
| 233 | * |
| 234 | CALL PZLARFB( 'Right', 'Conjugate transpose', 'Forward', |
| 235 | $ 'Rowwise', M, N, IB, WORK( IPV ), 1, ICOFF+1, DESCV, |
| 236 | $ WORK( IPT ), A, IA, JA, DESCA, WORK( IPW ) ) |
| 237 | * |
| 238 | CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP ) |
| 239 | CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP ) |
| 240 | * |
| 241 | RETURN |
| 242 | * |
| 243 | * End of PZGELQRV |
| 244 | * |
| 245 | END |