ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pdorg2r.f
Go to the documentation of this file.
1  SUBROUTINE pdorg2r( 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 * PDORG2R 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 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) 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 >= 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  DOUBLE PRECISION ONE, ZERO
164  parameter( one = 1.0d+0, zero = 0.0d+0 )
165 * ..
166 * .. Local Scalars ..
167  LOGICAL LQUERY
168  CHARACTER COLBTOP, ROWBTOP
169  INTEGER IACOL, IAROW, ICTXT, J, JJ, KQ, LWMIN, MPA0,
170  $ mycol, myrow, npcol, nprow, nqa0
171  DOUBLE PRECISION TAUJ
172 * ..
173 * .. External Subroutines ..
174  EXTERNAL blacs_abort, blacs_gridinfo, chk1mat, pdelset,
175  $ pdlarf, pdlaset, pdscal, pb_topget,
176  $ pb_topset, pxerbla
177 * ..
178 * .. External Functions ..
179  INTEGER INDXG2L, INDXG2P, NUMROC
180  EXTERNAL indxg2l, indxg2p, numroc
181 * ..
182 * .. Intrinsic Functions ..
183  INTRINSIC dble, max, min, mod
184 * ..
185 * .. Executable Statements ..
186 *
187 * Get grid parameters
188 *
189  ictxt = desca( ctxt_ )
190  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
191 *
192 * Test the input parameters
193 *
194  info = 0
195  IF( nprow.EQ.-1 ) THEN
196  info = -(700+ctxt_)
197  ELSE
198  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 7, info )
199  IF( info.EQ.0 ) THEN
200  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
201  $ nprow )
202  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
203  $ npcol )
204  mpa0 = numroc( m+mod( ia-1, desca( mb_ ) ), desca( mb_ ),
205  $ myrow, iarow, nprow )
206  nqa0 = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
207  $ mycol, iacol, npcol )
208  lwmin = mpa0 + max( 1, nqa0 )
209 *
210  work( 1 ) = dble( lwmin )
211  lquery = ( lwork.EQ.-1 )
212  IF( n.GT.m ) THEN
213  info = -2
214  ELSE IF( k.LT.0 .OR. k.GT.n ) THEN
215  info = -3
216  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
217  info = -10
218  END IF
219  END IF
220  END IF
221  IF( info.NE.0 ) THEN
222  CALL pxerbla( ictxt, 'PDORG2R', -info )
223  CALL blacs_abort( ictxt, 1 )
224  RETURN
225  ELSE IF( lquery ) THEN
226  RETURN
227  END IF
228 *
229 * Quick return if possible
230 *
231  IF( n.LE.0 )
232  $ RETURN
233 *
234  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
235  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
236  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', 'D-ring' )
237  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', ' ' )
238 *
239 * Initialise columns ja+k:ja+n-1 to columns of the unit matrix
240 *
241  CALL pdlaset( 'All', k, n-k, zero, zero, a, ia, ja+k, desca )
242  CALL pdlaset( 'All', m-k, n-k, zero, one, a, ia+k, ja+k, desca )
243 *
244  tauj = zero
245  kq = max( 1, numroc( ja+k-1, desca( nb_ ), mycol, desca( csrc_ ),
246  $ npcol ) )
247  DO 10 j = ja+k-1, ja, -1
248 *
249 * Apply H(j) to A(ia+j-ja:ia+m-1,j:ja+n-1) from the left
250 *
251  IF( j.LT.ja+n-1 ) THEN
252  CALL pdelset( a, ia+j-ja, j, desca, one )
253  CALL pdlarf( 'Left', m-j+ja, ja+n-j-1, a, ia+j-ja, j, desca,
254  $ 1, tau, a, ia+j-ja, j+1, desca, work )
255  END IF
256 *
257  jj = indxg2l( j, desca( nb_ ), mycol, desca( csrc_ ), npcol )
258  iacol = indxg2p( j, desca( nb_ ), mycol, desca( csrc_ ),
259  $ npcol )
260  IF( mycol.EQ.iacol )
261  $ tauj = tau( min( jj, kq ) )
262  IF( j-ja.LT.m-1 )
263  $ CALL pdscal( m-j+ja-1, -tauj, a, ia+j-ja+1, j, desca, 1 )
264  CALL pdelset( a, ia+j-ja, j, desca, one-tauj )
265 *
266 * Set A(ia:ia+j-ja-1,j) to zero
267 *
268  CALL pdlaset( 'All', j-ja, 1, zero, zero, a, ia, j, desca )
269 *
270  10 CONTINUE
271 *
272  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
273  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
274 *
275  work( 1 ) = dble( lwmin )
276 *
277  RETURN
278 *
279 * End of PDORG2R
280 *
281  END
pdlarf
subroutine pdlarf(SIDE, M, N, V, IV, JV, DESCV, INCV, TAU, C, IC, JC, DESCC, WORK)
Definition: pdlarf.f:3
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
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
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
pdelset
subroutine pdelset(A, IA, JA, DESCA, ALPHA)
Definition: pdelset.f:2
min
#define min(A, B)
Definition: pcgemr.c:181