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