ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pcungql.f
Go to the documentation of this file.
1  SUBROUTINE pcungql( 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  COMPLEX A( * ), TAU( * ), WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * PCUNGQL generates an M-by-N complex distributed matrix Q denoting
21 * A(IA:IA+M-1,JA:JA+N-1) with orthonormal columns, which is defined as
22 * the last N columns of a product of K elementary reflectors of order M
23 *
24 * Q = H(k) . . . H(2) H(1)
25 *
26 * as returned by PCGEQLF.
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. M >= N >= 0.
92 *
93 * K (global input) INTEGER
94 * The number of elementary reflectors whose product defines the
95 * matrix Q. N >= K >= 0.
96 *
97 * A (local input/local output) COMPLEX pointer into the
98 * local memory to an array of dimension (LLD_A,LOCc(JA+N-1)).
99 * On entry, the j-th column must contain the vector which
100 * defines the elementary reflector H(j), JA+N-K <= j <= JA+N-1,
101 * as returned by PCGEQLF in the K columns of its distributed
102 * matrix argument A(IA:*,JA+N-K:JA+N-1). On exit, this array
103 * contains the local pieces of the M-by-N distributed matrix Q.
104 *
105 * IA (global input) INTEGER
106 * The row index in the global array A indicating the first
107 * row of sub( A ).
108 *
109 * JA (global input) INTEGER
110 * The column index in the global array A indicating the
111 * first column of sub( A ).
112 *
113 * DESCA (global and local input) INTEGER array of dimension DLEN_.
114 * The array descriptor for the distributed matrix A.
115 *
116 * TAU (local input) COMPLEX, array, dimension LOCc(JA+N-1)
117 * This array contains the scalar factors TAU(j) of the
118 * elementary reflectors H(j) as returned by PCGEQLF.
119 * TAU is tied to the distributed matrix A.
120 *
121 * WORK (local workspace/local output) COMPLEX array,
122 * dimension (LWORK)
123 * On exit, WORK(1) returns the minimal and optimal LWORK.
124 *
125 * LWORK (local or global input) INTEGER
126 * The dimension of the array WORK.
127 * LWORK is local input and must be at least
128 * LWORK >= NB_A * ( NqA0 + MpA0 + NB_A ), where
129 *
130 * IROFFA = MOD( IA-1, MB_A ), ICOFFA = MOD( JA-1, NB_A ),
131 * IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
132 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
133 * MpA0 = NUMROC( M+IROFFA, MB_A, MYROW, IAROW, NPROW ),
134 * NqA0 = NUMROC( N+ICOFFA, NB_A, MYCOL, IACOL, NPCOL ),
135 *
136 * INDXG2P and NUMROC are ScaLAPACK tool functions;
137 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
138 * the subroutine BLACS_GRIDINFO.
139 *
140 * If LWORK = -1, then LWORK is global input and a workspace
141 * query is assumed; the routine only calculates the minimum
142 * and optimal size for all work arrays. Each of these
143 * values is returned in the first entry of the corresponding
144 * work array, and no error message is issued by PXERBLA.
145 *
146 *
147 * INFO (global output) INTEGER
148 * = 0: successful exit
149 * < 0: If the i-th argument is an array and the j-entry had
150 * an illegal value, then INFO = -(i*100+j), if the i-th
151 * argument is a scalar and had an illegal value, then
152 * INFO = -i.
153 *
154 * =====================================================================
155 *
156 * .. Parameters ..
157  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
158  $ lld_, mb_, m_, nb_, n_, rsrc_
159  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
160  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
161  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
162  COMPLEX ZERO
163  parameter( zero = ( 0.0e+0, 0.0e+0 ) )
164 * ..
165 * .. Local Scalars ..
166  LOGICAL LQUERY
167  CHARACTER COLBTOP, ROWBTOP
168  INTEGER IACOL, IAROW, ICTXT, IINFO, IPW, J, JB, JN,
169  $ lwmin, mpa0, mycol, myrow, npcol, nprow, nqa0
170 * ..
171 * .. Local Arrays ..
172  INTEGER IDUM1( 2 ), IDUM2( 2 )
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL blacs_gridinfo, chk1mat, pchk1mat, pclarfb,
176  $ pclarft, pclaset, pcung2l, pb_topget,
177  $ pb_topset, pxerbla
178 * ..
179 * .. External Functions ..
180  INTEGER ICEIL, INDXG2P, NUMROC
181  EXTERNAL iceil, indxg2p, numroc
182 * ..
183 * .. Intrinsic Functions ..
184  INTRINSIC cmplx, min, mod, real
185 * ..
186 * .. Executable Statements ..
187 *
188 * Get grid parameters
189 *
190  ictxt = desca( ctxt_ )
191  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
192 *
193 * Test the input parameters
194 *
195  info = 0
196  IF( nprow.EQ.-1 ) THEN
197  info = -(700+ctxt_)
198  ELSE
199  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 7, info )
200  IF( info.EQ.0 ) THEN
201  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
202  $ nprow )
203  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
204  $ npcol )
205  mpa0 = numroc( m+mod( ia-1, desca( mb_ ) ), desca( mb_ ),
206  $ myrow, iarow, nprow )
207  nqa0 = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
208  $ mycol, iacol, npcol )
209  lwmin = desca( nb_ ) * ( mpa0 + nqa0 + desca( nb_ ) )
210 *
211  work( 1 ) = cmplx( real( lwmin ) )
212  lquery = ( lwork.EQ.-1 )
213  IF( n.GT.m ) THEN
214  info = -2
215  ELSE IF( k.LT.0 .OR. k.GT.n ) THEN
216  info = -3
217  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
218  info = -10
219  END IF
220  END IF
221  idum1( 1 ) = k
222  idum2( 1 ) = 3
223  IF( lwork.EQ.-1 ) THEN
224  idum1( 2 ) = -1
225  ELSE
226  idum1( 2 ) = 1
227  END IF
228  idum2( 2 ) = 10
229  CALL pchk1mat( m, 1, n, 2, ia, ja, desca, 7, 2, idum1, idum2,
230  $ info )
231  END IF
232  IF( info.NE.0 ) THEN
233  CALL pxerbla( ictxt, 'PCUNGQL', -info )
234  RETURN
235  ELSE IF( lquery ) THEN
236  RETURN
237  END IF
238 *
239 * Quick return if possible
240 *
241  IF( n.LE.0 )
242  $ RETURN
243 *
244  ipw = desca( nb_ )*desca( nb_ ) + 1
245  jn = min( iceil( ja+n-k, desca( nb_ ) )*desca( nb_ ), ja+n-1 )
246  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
247  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
248  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', 'I-ring' )
249  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', ' ' )
250 *
251 * Set A(ia+m-n+jn-ja+1:ia-m+1,ja:jn) to zero.
252 *
253  CALL pclaset( 'All', n-jn+ja-1, jn-ja+1, zero, zero, a,
254  $ ia+m-n+jn-ja+1, ja, desca )
255 *
256 * Use unblocked code for the first or only block.
257 *
258  CALL pcung2l( m-n+jn-ja+1, jn-ja+1, jn-ja-n+k+1, a, ia, ja, desca,
259  $ tau, work, lwork, iinfo )
260 *
261 * Use blocked code
262 *
263  DO 10 j = jn+1, ja+n-1, desca( nb_ )
264  jb = min( ja+n-j, desca( nb_ ) )
265 *
266 * Form the triangular factor of the block reflector
267 * H = H(j+jb-1) . . . H(j+1) H(j)
268 *
269  CALL pclarft( 'Backward', 'Columnwise', m-n+j+jb-ja, jb,
270  $ a, ia, j, desca, tau, work, work( ipw ) )
271 *
272 * Apply H to A(ia:ia+m-n+j+jb-ja-1,ja:j-1) from the left
273 *
274  CALL pclarfb( 'Left', 'No transpose', 'Backward',
275  $ 'Columnwise', m-n+j+jb-ja, j-ja, jb, a, ia,
276  $ j, desca, work, a, ia, ja, desca, work( ipw ) )
277 *
278 * Apply H to rows ia:m-k+i+ib-1 of current block
279 *
280  CALL pcung2l( m-n+j+jb-ja, jb, jb, a, ia, j, desca, tau, work,
281  $ lwork, iinfo )
282 *
283 * Set rows ia+m-n+j+jb-ja:ia+m-1,j:j+jb-1 of current block to
284 * zero
285 *
286  CALL pclaset( 'All', n-j-jb+ja, jb, zero, zero, a,
287  $ ia+m-n+j+jb-ja, j, desca )
288 *
289  10 CONTINUE
290 *
291  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
292  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
293 *
294  work( 1 ) = cmplx( real( lwmin ) )
295 *
296  RETURN
297 *
298 * End of PCUNGQL
299 *
300  END
cmplx
float cmplx[2]
Definition: pblas.h:132
pcungql
subroutine pcungql(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pcungql.f:3
pclarfb
subroutine pclarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, IV, JV, DESCV, T, C, IC, JC, DESCC, WORK)
Definition: pclarfb.f:3
pchk1mat
subroutine pchk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.f:3
pclaset
subroutine pclaset(UPLO, M, N, ALPHA, BETA, A, IA, JA, DESCA)
Definition: pcblastst.f:7508
pcung2l
subroutine pcung2l(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pcung2l.f:3
chk1mat
subroutine chk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, INFO)
Definition: chk1mat.f:3
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
pclarft
subroutine pclarft(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pclarft.f:3
min
#define min(A, B)
Definition: pcgemr.c:181