ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pdorgqr.f
Go to the documentation of this file.
1  SUBROUTINE pdorgqr( 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 * PDORGQR generates an M-by-N real distributed matrix Q denoting
21 * A(IA:IA+M-1,JA:JA+N-1) with orthonormal columns, which is defined as
22 * the first N columns of a product of K elementary reflectors of order
23 * M
24 *
25 * Q = H(1) H(2) . . . H(k)
26 *
27 * as returned by PDGEQRF.
28 *
29 * Notes
30 * =====
31 *
32 * Each global data object is described by an associated description
33 * vector. This vector stores the information required to establish
34 * the mapping between an object element and its corresponding process
35 * and memory location.
36 *
37 * Let A be a generic term for any 2D block cyclicly distributed array.
38 * Such a global array has an associated description vector DESCA.
39 * In the following comments, the character _ should be read as
40 * "of the global array".
41 *
42 * NOTATION STORED IN EXPLANATION
43 * --------------- -------------- --------------------------------------
44 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
45 * DTYPE_A = 1.
46 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
47 * the BLACS process grid A is distribu-
48 * ted over. The context itself is glo-
49 * bal, but the handle (the integer
50 * value) may vary.
51 * M_A (global) DESCA( M_ ) The number of rows in the global
52 * array A.
53 * N_A (global) DESCA( N_ ) The number of columns in the global
54 * array A.
55 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
56 * the rows of the array.
57 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
58 * the columns of the array.
59 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
60 * row of the array A is distributed.
61 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
62 * first column of the array A is
63 * distributed.
64 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
65 * array. LLD_A >= MAX(1,LOCr(M_A)).
66 *
67 * Let K be the number of rows or columns of a distributed matrix,
68 * and assume that its process grid has dimension p x q.
69 * LOCr( K ) denotes the number of elements of K that a process
70 * would receive if K were distributed over the p processes of its
71 * process column.
72 * Similarly, LOCc( K ) denotes the number of elements of K that a
73 * process would receive if K were distributed over the q processes of
74 * its process row.
75 * The values of LOCr() and LOCc() may be determined via a call to the
76 * ScaLAPACK tool function, NUMROC:
77 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
78 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
79 * An upper bound for these quantities may be computed by:
80 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
81 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
82 *
83 * Arguments
84 * =========
85 *
86 * M (global input) INTEGER
87 * The number of rows to be operated on i.e the number of rows
88 * of the distributed submatrix Q. M >= 0.
89 *
90 * N (global input) INTEGER
91 * The number of columns to be operated on i.e the number of
92 * columns of the distributed submatrix Q. M >= N >= 0.
93 *
94 * K (global input) INTEGER
95 * The number of elementary reflectors whose product defines the
96 * matrix Q. N >= 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 j-th column must contain the vector which
101 * defines the elementary reflector H(j), JA <= j <= JA+K-1, as
102 * returned by PDGEQRF in the K columns of its distributed
103 * matrix argument A(IA:*,JA:JA+K-1). 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 LOCc(JA+K-1)
118 * This array contains the scalar factors TAU(j) of the
119 * elementary reflectors H(j) as returned by PDGEQRF.
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 >= NB_A * ( NqA0 + MpA0 + NB_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, ICTXT, IINFO, IPW, J, JB, JL,
170  $ jn, lwmin, mpa0, mycol, myrow, npcol, nprow,
171  $ nqa0
172 * ..
173 * .. Local Arrays ..
174  INTEGER IDUM1( 2 ), IDUM2( 2 )
175 * ..
176 * .. External Subroutines ..
177  EXTERNAL blacs_gridinfo, chk1mat, pchk1mat, pdlarfb,
178  $ pdlarft, pdlaset, pdorg2r, pb_topget,
179  $ pb_topset, pxerbla
180 * ..
181 * .. External Functions ..
182  INTEGER ICEIL, INDXG2P, NUMROC
183  EXTERNAL iceil, indxg2p, numroc
184 * ..
185 * .. Intrinsic Functions ..
186  INTRINSIC dble, max, min, mod
187 * ..
188 * .. Executable Statements ..
189 *
190 * Get grid parameters
191 *
192  ictxt = desca( ctxt_ )
193  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
194 *
195 * Test the input parameters
196 *
197  info = 0
198  IF( nprow.EQ.-1 ) THEN
199  info = -(700+ctxt_)
200  ELSE
201  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 7, info )
202  IF( info.EQ.0 ) THEN
203  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
204  $ nprow )
205  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
206  $ npcol )
207  mpa0 = numroc( m+mod( ia-1, desca( mb_ ) ), desca( mb_ ),
208  $ myrow, iarow, nprow )
209  nqa0 = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
210  $ mycol, iacol, npcol )
211  lwmin = desca( nb_ ) * ( mpa0 + nqa0 + desca( nb_ ) )
212 *
213  work( 1 ) = dble( lwmin )
214  lquery = ( lwork.EQ.-1 )
215  IF( n.GT.m ) THEN
216  info = -2
217  ELSE IF( k.LT.0 .OR. k.GT.n ) THEN
218  info = -3
219  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
220  info = -10
221  END IF
222  END IF
223  idum1( 1 ) = k
224  idum2( 1 ) = 3
225  IF( lwork.EQ.-1 ) THEN
226  idum1( 2 ) = -1
227  ELSE
228  idum1( 2 ) = 1
229  END IF
230  idum2( 2 ) = 10
231  CALL pchk1mat( m, 1, n, 2, ia, ja, desca, 7, 2, idum1, idum2,
232  $ info )
233  END IF
234 *
235  IF( info.NE.0 ) THEN
236  CALL pxerbla( ictxt, 'PDORGQR', -info )
237  RETURN
238  ELSE IF( lquery ) THEN
239  RETURN
240  END IF
241 *
242 * Quick return if possible
243 *
244  IF( n.LE.0 )
245  $ RETURN
246 *
247  ipw = desca( nb_ )*desca( nb_ ) + 1
248  jn = min( iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+k-1 )
249  jl = max( ( (ja+k-2) / desca( nb_ ) ) * desca( nb_ ) + 1, ja )
250  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
251  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
252  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', 'D-ring' )
253  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', ' ' )
254 *
255  CALL pdlaset( 'All', jl-ja, ja+n-jl, zero, zero, a, ia, jl,
256  $ desca )
257 *
258 * Use unblocked code for the last or only block.
259 *
260  CALL pdorg2r( m-jl+ja, ja+n-jl, ja+k-jl, a, ia+jl-ja, jl, desca,
261  $ tau, work, lwork, iinfo )
262 *
263 * Is there at least one block of columns to loop over ?
264 *
265  IF( jl.GT.jn+1 ) THEN
266 *
267 * Use blocked code
268 *
269  DO 10 j = jl-desca( nb_ ), jn+1, -desca( nb_ )
270  jb = min( desca( nb_ ), ja+n-j )
271  i = ia + j - ja
272 *
273  IF( j+jb.LE.ja+n-1 ) THEN
274 *
275 * Form the triangular factor of the block reflector
276 * H = H(j) H(j+1) . . . H(j+jb-1)
277 *
278  CALL pdlarft( 'Forward', 'Columnwise', m-i+ia, jb, a, i,
279  $ j, desca, tau, work, work( ipw ) )
280 *
281 * Apply H to A(i:ia+m-1,j+jb:ja+n-1) from the left
282 *
283  CALL pdlarfb( 'Left', 'No transpose', 'Forward',
284  $ 'Columnwise', m-i+ia, n-j-jb+ja, jb, a, i,
285  $ j, desca, work, a, i, j+jb, desca,
286  $ work( ipw ) )
287  END IF
288 *
289 * Apply H to rows i:ia+m-1 of current block
290 *
291  CALL pdorg2r( m-i+ia, jb, jb, a, i, j, desca, tau, work,
292  $ lwork, iinfo )
293 *
294 * Set rows ia:i-1 of current block to zero
295 *
296  CALL pdlaset( 'All', i-ia, jb, zero, zero, a, ia, j, desca )
297 *
298  10 CONTINUE
299 *
300  END IF
301 *
302 * Handle first block separately
303 *
304  IF( jl.GT.ja ) THEN
305 *
306  jb = jn - ja + 1
307 *
308 * Form the triangular factor of the block reflector
309 * H = H(j) H(j+1) . . . H(j+jb-1)
310 *
311  CALL pdlarft( 'Forward', 'Columnwise', m, jb, a, ia, ja, desca,
312  $ tau, work, work( ipw ) )
313 *
314 * Apply H to A(ia:ia+m-1,ja+jb:ja+n-1) from the left
315 *
316  CALL pdlarfb( 'Left', 'No transpose', 'Forward', 'Columnwise',
317  $ m, n-jb, jb, a, ia, ja, desca, work, a, ia,
318  $ ja+jb, desca, work( ipw ) )
319 *
320 * Apply H to rows ia:ia+m-1 of current block
321 *
322  CALL pdorg2r( m, jb, jb, a, ia, ja, desca, tau, work, lwork,
323  $ iinfo )
324 *
325  END IF
326 *
327  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
328  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
329 *
330  work( 1 ) = dble( lwmin )
331 *
332  RETURN
333 *
334 * End of PDORGQR
335 *
336  END
max
#define max(A, B)
Definition: pcgemr.c:180
pdorg2r
subroutine pdorg2r(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pdorg2r.f:3
pdlarft
subroutine pdlarft(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pdlarft.f:3
pdorgqr
subroutine pdorgqr(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pdorgqr.f:3
pchk1mat
subroutine pchk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.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