ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pcung2r.f
Go to the documentation of this file.
1  SUBROUTINE pcung2r( 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 * PCUNG2R 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 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 PCGEQRF.
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) COMPLEX 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 PCGEQRF in the K columns of its array
103 * argument A(IA:*,JA:JA+K-1). On exit, this array contains
104 * 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) COMPLEX, 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 PCGEQRF.
120 * TAU is tied to the distributed matrix A.
121 *
122 * WORK (local workspace/local output) COMPLEX 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 >= MpA0 + MAX( 1, NqA0 ), 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 (local 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  COMPLEX ONE, ZERO
164  parameter( one = ( 1.0e+0, 0.0e+0 ),
165  $ zero = ( 0.0e+0, 0.0e+0 ) )
166 * ..
167 * .. Local Scalars ..
168  LOGICAL LQUERY
169  CHARACTER COLBTOP, ROWBTOP
170  INTEGER IACOL, IAROW, ICTXT, J, JJ, KQ, LWMIN, MPA0,
171  $ mycol, myrow, npcol, nprow, nqa0
172  COMPLEX TAUJ
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL blacs_abort, blacs_gridinfo, chk1mat, pcelset,
176  $ pclarf, pclaset, pcscal, pb_topget,
177  $ pb_topset, pxerbla
178 * ..
179 * .. External Functions ..
180  INTEGER INDXG2L, INDXG2P, NUMROC
181  EXTERNAL indxg2l, indxg2p, numroc
182 * ..
183 * .. Intrinsic Functions ..
184  INTRINSIC cmplx, max, 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 = mpa0 + max( 1, nqa0 )
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  END IF
222  IF( info.NE.0 ) THEN
223  CALL pxerbla( ictxt, 'PCUNG2R', -info )
224  CALL blacs_abort( ictxt, 1 )
225  RETURN
226  ELSE IF( lquery ) THEN
227  RETURN
228  END IF
229 *
230 * Quick return if possible
231 *
232  IF( n.LE.0 )
233  $ RETURN
234 *
235  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
236  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
237  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', 'D-ring' )
238  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', ' ' )
239 *
240 * Initialise columns ja+k:ja+n-1 to columns of the unit matrix
241 *
242  CALL pclaset( 'All', k, n-k, zero, zero, a, ia, ja+k, desca )
243  CALL pclaset( 'All', m-k, n-k, zero, one, a, ia+k, ja+k, desca )
244 *
245  tauj = zero
246  kq = max( 1, numroc( ja+k-1, desca( nb_ ), mycol, desca( csrc_ ),
247  $ npcol ) )
248  DO 10 j = ja+k-1, ja, -1
249 *
250 * Apply H(j) to A(ia+j-ja:ia+m-1,j:ja+n-1) from the left
251 *
252  IF( j.LT.ja+n-1 ) THEN
253  CALL pcelset( a, ia+j-ja, j, desca, one )
254  CALL pclarf( 'Left', m-j+ja, ja+n-j-1, a, ia+j-ja, j, desca,
255  $ 1, tau, a, ia+j-ja, j+1, desca, work )
256  END IF
257 *
258  jj = indxg2l( j, desca( nb_ ), mycol, desca( csrc_ ), npcol )
259  iacol = indxg2p( j, desca( nb_ ), mycol, desca( csrc_ ),
260  $ npcol )
261  IF( mycol.EQ.iacol )
262  $ tauj = tau( min( jj, kq ) )
263  IF( j-ja.LT.m-1 )
264  $ CALL pcscal( m-j+ja-1, -tauj, a, ia+j-ja+1, j, desca, 1 )
265  CALL pcelset( a, ia+j-ja, j, desca, one-tauj )
266 *
267 * Set A(ia:ia+j-ja-1,j) to zero
268 *
269  CALL pclaset( 'All', j-ja, 1, zero, zero, a, ia, j, desca )
270 *
271  10 CONTINUE
272 *
273  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
274  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
275 *
276  work( 1 ) = cmplx( real( lwmin ) )
277 *
278  RETURN
279 *
280 * End of PCUNG2R
281 *
282  END
cmplx
float cmplx[2]
Definition: pblas.h:132
max
#define max(A, B)
Definition: pcgemr.c:180
pcelset
subroutine pcelset(A, IA, JA, DESCA, ALPHA)
Definition: pcelset.f:2
pclarf
subroutine pclarf(SIDE, M, N, V, IV, JV, DESCV, INCV, TAU, C, IC, JC, DESCC, WORK)
Definition: pclarf.f:3
pclaset
subroutine pclaset(UPLO, M, N, ALPHA, BETA, A, IA, JA, DESCA)
Definition: pcblastst.f:7508
pcung2r
subroutine pcung2r(M, N, K, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pcung2r.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
min
#define min(A, B)
Definition: pcgemr.c:181