ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pdorgrq.f
Go to the documentation of this file.
1  SUBROUTINE pdorgrq( M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK,
2  $ INFO )
3 *
4 * -- ScaLAPACK routine (version 1.7) --
5 * University of Tennessee, Knoxville, Oak Ridge National Laboratory,
6 * and University of California, Berkeley.
7 * May 25, 2001
8 *
9 * .. Scalar Arguments ..
10  INTEGER IA, INFO, JA, K, LWORK, M, N
11 * ..
12 * .. Array Arguments ..
13  INTEGER DESCA( * )
14  DOUBLE PRECISION A( * ), TAU( * ), WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * PDORGRQ generates an M-by-N real distributed matrix Q denoting
21 * A(IA:IA+M-1,JA:JA+N-1) with orthonormal rows, which is defined as the
22 * last M rows of a product of K elementary reflectors of order N
23 *
24 * Q = H(1) H(2) . . . H(k)
25 *
26 * as returned by PDGERQF.
27 *
28 * Notes
29 * =====
30 *
31 * Each global data object is described by an associated description
32 * vector. This vector stores the information required to establish
33 * the mapping between an object element and its corresponding process
34 * and memory location.
35 *
36 * Let A be a generic term for any 2D block cyclicly distributed array.
37 * Such a global array has an associated description vector DESCA.
38 * In the following comments, the character _ should be read as
39 * "of the global array".
40 *
41 * NOTATION STORED IN EXPLANATION
42 * --------------- -------------- --------------------------------------
43 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
44 * DTYPE_A = 1.
45 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
46 * the BLACS process grid A is distribu-
47 * ted over. The context itself is glo-
48 * bal, but the handle (the integer
49 * value) may vary.
50 * M_A (global) DESCA( M_ ) The number of rows in the global
51 * array A.
52 * N_A (global) DESCA( N_ ) The number of columns in the global
53 * array A.
54 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
55 * the rows of the array.
56 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
57 * the columns of the array.
58 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
59 * row of the array A is distributed.
60 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
61 * first column of the array A is
62 * distributed.
63 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
64 * array. LLD_A >= MAX(1,LOCr(M_A)).
65 *
66 * Let K be the number of rows or columns of a distributed matrix,
67 * and assume that its process grid has dimension p x q.
68 * LOCr( K ) denotes the number of elements of K that a process
69 * would receive if K were distributed over the p processes of its
70 * process column.
71 * Similarly, LOCc( K ) denotes the number of elements of K that a
72 * process would receive if K were distributed over the q processes of
73 * its process row.
74 * The values of LOCr() and LOCc() may be determined via a call to the
75 * ScaLAPACK tool function, NUMROC:
76 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
77 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
78 * An upper bound for these quantities may be computed by:
79 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
80 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
81 *
82 * Arguments
83 * =========
84 *
85 * M (global input) INTEGER
86 * The number of rows to be operated on i.e the number of rows
87 * of the distributed submatrix Q. M >= 0.
88 *
89 * N (global input) INTEGER
90 * The number of columns to be operated on i.e the number of
91 * columns of the distributed submatrix Q.
92 * N >= M >= 0.
93 *
94 * K (global input) INTEGER
95 * The number of elementary reflectors whose product defines the
96 * matrix Q. M >= K >= 0.
97 *
98 * A (local input/local output) DOUBLE PRECISION pointer into the
99 * local memory to an array of dimension (LLD_A,LOCc(JA+N-1)).
100 * On entry, the i-th row must contain the vector which defines
101 * the elementary reflector H(i), IA+M-K <= i <= IA+M-1, as
102 * returned by PDGERQF in the K rows of its distributed
103 * matrix argument A(IA+M-K:IA+M-1,JA:*). On exit, this array
104 * contains the local pieces of the M-by-N distributed matrix Q.
105 *
106 * IA (global input) INTEGER
107 * The row index in the global array A indicating the first
108 * row of sub( A ).
109 *
110 * JA (global input) INTEGER
111 * The column index in the global array A indicating the
112 * first column of sub( A ).
113 *
114 * DESCA (global and local input) INTEGER array of dimension DLEN_.
115 * The array descriptor for the distributed matrix A.
116 *
117 * TAU (local input) DOUBLE PRECISION array, dimension LOCr(IA+M-1)
118 * This array contains the scalar factors TAU(i) of the
119 * elementary reflectors H(i) as returned by PDGERQF.
120 * TAU is tied to the distributed matrix A.
121 *
122 * WORK (local workspace/local output) DOUBLE PRECISION array,
123 * dimension (LWORK)
124 * On exit, WORK(1) returns the minimal and optimal LWORK.
125 *
126 * LWORK (local or global input) INTEGER
127 * The dimension of the array WORK.
128 * LWORK is local input and must be at least
129 * LWORK >= MB_A * ( MpA0 + NqA0 + MB_A ), where
130 *
131 * IROFFA = MOD( IA-1, MB_A ), ICOFFA = MOD( JA-1, NB_A ),
132 * IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
133 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
134 * MpA0 = NUMROC( M+IROFFA, MB_A, MYROW, IAROW, NPROW ),
135 * NqA0 = NUMROC( N+ICOFFA, NB_A, MYCOL, IACOL, NPCOL ),
136 *
137 * INDXG2P and NUMROC are ScaLAPACK tool functions;
138 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
139 * the subroutine BLACS_GRIDINFO.
140 *
141 * If LWORK = -1, then LWORK is global input and a workspace
142 * query is assumed; the routine only calculates the minimum
143 * and optimal size for all work arrays. Each of these
144 * values is returned in the first entry of the corresponding
145 * work array, and no error message is issued by PXERBLA.
146 *
147 *
148 * INFO (global output) INTEGER
149 * = 0: successful exit
150 * < 0: If the i-th argument is an array and the j-entry had
151 * an illegal value, then INFO = -(i*100+j), if the i-th
152 * argument is a scalar and had an illegal value, then
153 * INFO = -i.
154 *
155 * =====================================================================
156 *
157 * .. Parameters ..
158  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
159  $ lld_, mb_, m_, nb_, n_, rsrc_
160  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
161  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
162  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
163  DOUBLE PRECISION ZERO
164  parameter( zero = 0.0d+0 )
165 * ..
166 * .. Local Scalars ..
167  LOGICAL LQUERY
168  CHARACTER COLBTOP, ROWBTOP
169  INTEGER I, IACOL, IAROW, IB, ICTXT, IINFO, IN, IPW,
170  $ lwmin, mpa0, mycol, myrow, npcol, nprow, nqa0
171 * ..
172 * .. Local Arrays ..
173  INTEGER IDUM1( 2 ), IDUM2( 2 )
174 * ..
175 * .. External Subroutines ..
176  EXTERNAL blacs_gridinfo, chk1mat, pchk1mat, pdlarfb,
177  $ pdlarft, pdlaset, pdorgr2, pb_topget,
178  $ pb_topset, pxerbla
179 * ..
180 * .. External Functions ..
181  INTEGER ICEIL, INDXG2P, NUMROC
182  EXTERNAL iceil, indxg2p, numroc
183 * ..
184 * .. Intrinsic Functions ..
185  INTRINSIC dble, min, mod
186 * ..
187 * .. Executable Statements ..
188 *
189 * Get grid parameters
190 *
191  ictxt = desca( ctxt_ )
192  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
193 *
194 * Test the input parameters
195 *
196  info = 0
197  IF( nprow.EQ.-1 ) THEN
198  info = -(700+ctxt_)
199  ELSE
200  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 7, info )
201  IF( info.EQ.0 ) THEN
202  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
203  $ nprow )
204  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
205  $ npcol )
206  mpa0 = numroc( m+mod( ia-1, desca( mb_ ) ), desca( mb_ ),
207  $ myrow, iarow, nprow )
208  nqa0 = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
209  $ mycol, iacol, npcol )
210  lwmin = desca( mb_ ) * ( mpa0 + nqa0 + desca( mb_ ) )
211 *
212  work( 1 ) = dble( lwmin )
213  lquery = ( lwork.EQ.-1 )
214  IF( n.LT.m ) THEN
215  info = -2
216  ELSE IF( k.LT.0 .OR. k.GT.m ) THEN
217  info = -3
218  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
219  info = -10
220  END IF
221  END IF
222  idum1( 1 ) = k
223  idum2( 1 ) = 3
224  IF( lwork.EQ.-1 ) THEN
225  idum1( 2 ) = -1
226  ELSE
227  idum1( 2 ) = 1
228  END IF
229  idum2( 2 ) = 10
230  CALL pchk1mat( m, 1, n, 2, ia, ja, desca, 7, 2, idum1, idum2,
231  $ info )
232  END IF
233 *
234  IF( info.NE.0 ) THEN
235  CALL pxerbla( ictxt, 'PDORGRQ', -info )
236  RETURN
237  ELSE IF( lquery ) THEN
238  RETURN
239  END IF
240 *
241 * Quick return if possible
242 *
243  IF( m.LE.0 )
244  $ RETURN
245 *
246  ipw = desca( mb_ )*desca( mb_ ) + 1
247  in = min( iceil( ia+m-k, desca( mb_ ) )*desca( mb_ ), ia+m-1 )
248  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
249  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
250  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', ' ' )
251  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', 'I-ring' )
252 *
253 * Set A(ia:in,ja+n-m+in-ia+1:ja-n+1) to zero.
254 *
255  CALL pdlaset( 'All', in-ia+1, m-in+ia-1, zero, zero, a, ia,
256  $ ja+n-m+in-ia+1, desca )
257 *
258 * Use unblocked code for the first or only block.
259 *
260  CALL pdorgr2( in-ia+1, n-m+in-ia+1, in-ia-m+k+1, a, ia, ja, desca,
261  $ tau, work, lwork, iinfo )
262 *
263 * Use blocked code
264 *
265  DO 10 i = in+1, ia+m-1, desca( mb_ )
266  ib = min( ia+m-i, desca( mb_ ) )
267 *
268 * Form the triangular factor of the block reflector
269 * H = H(i+ib-1) . . . H(i+1) H(i)
270 *
271  CALL pdlarft( 'Backward', 'Rowwise', n-m+i+ib-ia, ib, a, i, ja,
272  $ desca, tau, work, work( ipw ) )
273 *
274 * Apply H' to A(ia:i-1,ja:ja+n-m+i+ib-ia-1) from the right
275 *
276  CALL pdlarfb( 'Right', 'Transpose', 'Backward', 'Rowwise',
277  $ i-ia, n-m+i+ib-ia, ib, a, i, ja, desca, work, a,
278  $ ia, ja, desca, work( ipw ) )
279 *
280 * Apply H' to columns ja:ja+n-m+i+ib-ia-1 of current block
281 *
282  CALL pdorgr2( ib, n-m+i+ib-ia, ib, a, i, ja, desca, tau, work,
283  $ lwork, iinfo )
284 *
285 * Set rows i:i+ib-1,ja+n-m+i+ib-ia:ja+n-1 of current block to
286 * zero
287 *
288  CALL pdlaset( 'All', ib, m-i-ib+ia, zero, zero, a, i,
289  $ ja+n-m+i+ib-ia, desca )
290 *
291  10 CONTINUE
292 *
293  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
294  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
295 *
296  work( 1 ) = dble( lwmin )
297 *
298  RETURN
299 *
300 * End of PDORGRQ
301 *
302  END
pdorgrq
subroutine pdorgrq(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pdorgrq.f:3
pdlarft
subroutine pdlarft(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pdlarft.f:3
pchk1mat
subroutine pchk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.f:3
pdorgr2
subroutine pdorgr2(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pdorgr2.f:3
pdlaset
subroutine pdlaset(UPLO, M, N, ALPHA, BETA, A, IA, JA, DESCA)
Definition: pdblastst.f:6862
chk1mat
subroutine chk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, INFO)
Definition: chk1mat.f:3
pdlarfb
subroutine pdlarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, IV, JV, DESCV, T, C, IC, JC, DESCC, WORK)
Definition: pdlarfb.f:3
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
min
#define min(A, B)
Definition: pcgemr.c:181