ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pcggqrf.f
Go to the documentation of this file.
1  SUBROUTINE pcggqrf( N, M, P, A, IA, JA, DESCA, TAUA, B, IB, JB,
2  $ DESCB, TAUB, WORK, LWORK, 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 1, 1997
8 *
9 * .. Scalar Arguments ..
10  INTEGER IA, IB, INFO, JA, JB, LWORK, M, N, P
11 * ..
12 * .. Array Arguments ..
13  INTEGER DESCA( * ), DESCB( * )
14  COMPLEX A( * ), B( * ), TAUA( * ), TAUB( * ), WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * PCGGQRF computes a generalized QR factorization of
21 * an N-by-M matrix sub( A ) = A(IA:IA+N-1,JA:JA+M-1) and
22 * an N-by-P matrix sub( B ) = B(IB:IB+N-1,JB:JB+P-1):
23 *
24 * sub( A ) = Q*R, sub( B ) = Q*T*Z,
25 *
26 * where Q is an N-by-N unitary matrix, Z is a P-by-P unitary matrix,
27 * and R and T assume one of the forms:
28 *
29 * if N >= M, R = ( R11 ) M , or if N < M, R = ( R11 R12 ) N,
30 * ( 0 ) N-M N M-N
31 * M
32 *
33 * where R11 is upper triangular, and
34 *
35 * if N <= P, T = ( 0 T12 ) N, or if N > P, T = ( T11 ) N-P,
36 * P-N N ( T21 ) P
37 * P
38 *
39 * where T12 or T21 is upper triangular.
40 *
41 * In particular, if sub( B ) is square and nonsingular, the GQR
42 * factorization of sub( A ) and sub( B ) implicitly gives the QR
43 * factorization of inv( sub( B ) )* sub( A ):
44 *
45 * inv( sub( B ) )*sub( A )= Z'*(inv(T)*R)
46 *
47 * where inv( sub( B ) ) denotes the inverse of the matrix sub( B ),
48 * and Z' denotes the conjugate transpose of matrix Z.
49 *
50 * Notes
51 * =====
52 *
53 * Each global data object is described by an associated description
54 * vector. This vector stores the information required to establish
55 * the mapping between an object element and its corresponding process
56 * and memory location.
57 *
58 * Let A be a generic term for any 2D block cyclicly distributed array.
59 * Such a global array has an associated description vector DESCA.
60 * In the following comments, the character _ should be read as
61 * "of the global array".
62 *
63 * NOTATION STORED IN EXPLANATION
64 * --------------- -------------- --------------------------------------
65 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
66 * DTYPE_A = 1.
67 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
68 * the BLACS process grid A is distribu-
69 * ted over. The context itself is glo-
70 * bal, but the handle (the integer
71 * value) may vary.
72 * M_A (global) DESCA( M_ ) The number of rows in the global
73 * array A.
74 * N_A (global) DESCA( N_ ) The number of columns in the global
75 * array A.
76 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
77 * the rows of the array.
78 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
79 * the columns of the array.
80 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
81 * row of the array A is distributed.
82 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
83 * first column of the array A is
84 * distributed.
85 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
86 * array. LLD_A >= MAX(1,LOCr(M_A)).
87 *
88 * Let K be the number of rows or columns of a distributed matrix,
89 * and assume that its process grid has dimension p x q.
90 * LOCr( K ) denotes the number of elements of K that a process
91 * would receive if K were distributed over the p processes of its
92 * process column.
93 * Similarly, LOCc( K ) denotes the number of elements of K that a
94 * process would receive if K were distributed over the q processes of
95 * its process row.
96 * The values of LOCr() and LOCc() may be determined via a call to the
97 * ScaLAPACK tool function, NUMROC:
98 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
99 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
100 * An upper bound for these quantities may be computed by:
101 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
102 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
103 *
104 * Arguments
105 * =========
106 *
107 * N (global input) INTEGER
108 * The number of rows to be operated on i.e the number of rows
109 * of the distributed submatrices sub( A ) and sub( B ). N >= 0.
110 *
111 * M (global input) INTEGER
112 * The number of columns to be operated on i.e the number of
113 * columns of the distributed submatrix sub( A ). M >= 0.
114 *
115 * P (global input) INTEGER
116 * The number of columns to be operated on i.e the number of
117 * columns of the distributed submatrix sub( B ). P >= 0.
118 *
119 * A (local input/local output) COMPLEX pointer into the
120 * local memory to an array of dimension (LLD_A, LOCc(JA+M-1)).
121 * On entry, the local pieces of the N-by-M distributed matrix
122 * sub( A ) which is to be factored. On exit, the elements on
123 * and above the diagonal of sub( A ) contain the min(N,M) by M
124 * upper trapezoidal matrix R (R is upper triangular if N >= M);
125 * the elements below the diagonal, with the array TAUA,
126 * represent the unitary matrix Q as a product of min(N,M)
127 * elementary reflectors (see Further Details).
128 *
129 * IA (global input) INTEGER
130 * The row index in the global array A indicating the first
131 * row of sub( A ).
132 *
133 * JA (global input) INTEGER
134 * The column index in the global array A indicating the
135 * first column of sub( A ).
136 *
137 * DESCA (global and local input) INTEGER array of dimension DLEN_.
138 * The array descriptor for the distributed matrix A.
139 *
140 * TAUA (local output) COMPLEX, array, dimension
141 * LOCc(JA+MIN(N,M)-1). This array contains the scalar factors
142 * TAUA of the elementary reflectors which represent the unitary
143 * matrix Q. TAUA is tied to the distributed matrix A. (see
144 * Further Details).
145 *
146 * B (local input/local output) COMPLEX pointer into the
147 * local memory to an array of dimension (LLD_B, LOCc(JB+P-1)).
148 * On entry, the local pieces of the N-by-P distributed matrix
149 * sub( B ) which is to be factored. On exit, if N <= P, the
150 * upper triangle of B(IB:IB+N-1,JB+P-N:JB+P-1) contains the
151 * N by N upper triangular matrix T; if N > P, the elements on
152 * and above the (N-P)-th subdiagonal contain the N by P upper
153 * trapezoidal matrix T; the remaining elements, with the array
154 * TAUB, represent the unitary matrix Z as a product of
155 * elementary reflectors (see Further Details).
156 *
157 * IB (global input) INTEGER
158 * The row index in the global array B indicating the first
159 * row of sub( B ).
160 *
161 * JB (global input) INTEGER
162 * The column index in the global array B indicating the
163 * first column of sub( B ).
164 *
165 * DESCB (global and local input) INTEGER array of dimension DLEN_.
166 * The array descriptor for the distributed matrix B.
167 *
168 * TAUB (local output) COMPLEX, array, dimension LOCr(IB+N-1)
169 * This array contains the scalar factors of the elementary
170 * reflectors which represent the unitary matrix Z. TAUB is
171 * tied to the distributed matrix B (see Further Details).
172 *
173 * WORK (local workspace/local output) COMPLEX array,
174 * dimension (LWORK)
175 * On exit, WORK(1) returns the minimal and optimal LWORK.
176 *
177 * LWORK (local or global input) INTEGER
178 * The dimension of the array WORK.
179 * LWORK is local input and must be at least
180 * LWORK >= MAX( NB_A * ( NpA0 + MqA0 + NB_A ),
181 * MAX( (NB_A*(NB_A-1))/2, (PqB0 + NpB0)*NB_A ) +
182 * NB_A * NB_A,
183 * MB_B * ( NpB0 + PqB0 + MB_B ) ), where
184 *
185 * IROFFA = MOD( IA-1, MB_A ), ICOFFA = MOD( JA-1, NB_A ),
186 * IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
187 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
188 * NpA0 = NUMROC( N+IROFFA, MB_A, MYROW, IAROW, NPROW ),
189 * MqA0 = NUMROC( M+ICOFFA, NB_A, MYCOL, IACOL, NPCOL ),
190 *
191 * IROFFB = MOD( IB-1, MB_B ), ICOFFB = MOD( JB-1, NB_B ),
192 * IBROW = INDXG2P( IB, MB_B, MYROW, RSRC_B, NPROW ),
193 * IBCOL = INDXG2P( JB, NB_B, MYCOL, CSRC_B, NPCOL ),
194 * NpB0 = NUMROC( N+IROFFB, MB_B, MYROW, IBROW, NPROW ),
195 * PqB0 = NUMROC( P+ICOFFB, NB_B, MYCOL, IBCOL, NPCOL ),
196 *
197 * and NUMROC, INDXG2P are ScaLAPACK tool functions;
198 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
199 * the subroutine BLACS_GRIDINFO.
200 *
201 * If LWORK = -1, then LWORK is global input and a workspace
202 * query is assumed; the routine only calculates the minimum
203 * and optimal size for all work arrays. Each of these
204 * values is returned in the first entry of the corresponding
205 * work array, and no error message is issued by PXERBLA.
206 *
207 * INFO (global output) INTEGER
208 * = 0: successful exit
209 * < 0: If the i-th argument is an array and the j-entry had
210 * an illegal value, then INFO = -(i*100+j), if the i-th
211 * argument is a scalar and had an illegal value, then
212 * INFO = -i.
213 *
214 * Further Details
215 * ===============
216 *
217 * The matrix Q is represented as a product of elementary reflectors
218 *
219 * Q = H(ja) H(ja+1) . . . H(ja+k-1), where k = min(n,m).
220 *
221 * Each H(i) has the form
222 *
223 * H(i) = I - taua * v * v'
224 *
225 * where taua is a complex scalar, and v is a complex vector with
226 * v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in
227 * A(ia+i:ia+n-1,ja+i-1), and taua in TAUA(ja+i-1).
228 * To form Q explicitly, use ScaLAPACK subroutine PCUNGQR.
229 * To use Q to update another matrix, use ScaLAPACK subroutine PCUNMQR.
230 *
231 * The matrix Z is represented as a product of elementary reflectors
232 *
233 * Z = H(ib)' H(ib+1)' . . . H(ib+k-1)', where k = min(n,p).
234 *
235 * Each H(i) has the form
236 *
237 * H(i) = I - taub * v * v'
238 *
239 * where taub is a complex scalar, and v is a complex vector with
240 * v(p-k+i+1:p) = 0 and v(p-k+i) = 1; conjg(v(1:p-k+i-1)) is stored on
241 * exit in B(ib+n-k+i-1,jb:jb+p-k+i-2), and taub in TAUB(ib+n-k+i-1).
242 * To form Z explicitly, use ScaLAPACK subroutine PCUNGRQ.
243 * To use Z to update another matrix, use ScaLAPACK subroutine PCUNMRQ.
244 *
245 * Alignment requirements
246 * ======================
247 *
248 * The distributed submatrices sub( A ) and sub( B ) must verify some
249 * alignment properties, namely the following expression should be true:
250 *
251 * ( MB_A.EQ.MB_B .AND. IROFFA.EQ.IROFFB .AND. IAROW.EQ.IBROW )
252 *
253 * =====================================================================
254 *
255 * .. Parameters ..
256  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
257  $ lld_, mb_, m_, nb_, n_, rsrc_
258  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
259  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
260  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
261 * ..
262 * .. Local Scalars ..
263  LOGICAL LQUERY
264  INTEGER IACOL, IAROW, IBCOL, IBROW, ICOFFA, ICOFFB,
265  $ ictxt, iroffa, iroffb, lwmin, mqa0, mycol,
266  $ myrow, npa0, npb0, npcol, nprow, pqb0
267 * ..
268 * .. External Subroutines ..
269  EXTERNAL blacs_gridinfo, chk1mat, pcgeqrf, pcgerqf,
271 * ..
272 * .. Local Arrays ..
273  INTEGER IDUM1( 1 ), IDUM2( 1 )
274 * ..
275 * .. External Functions ..
276  INTEGER INDXG2P, NUMROC
277  EXTERNAL indxg2p, numroc
278 * ..
279 * .. Intrinsic Functions ..
280  INTRINSIC cmplx, int, max, min, mod, real
281 * ..
282 * .. Executable Statements ..
283 *
284 * Get grid parameters
285 *
286  ictxt = desca( ctxt_ )
287  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
288 *
289 * Test the input parameters
290 *
291  info = 0
292  IF( nprow.EQ.-1 ) THEN
293  info = -707
294  ELSE
295  CALL chk1mat( n, 1, m, 2, ia, ja, desca, 7, info )
296  CALL chk1mat( n, 1, p, 3, ib, jb, descb, 12, info )
297  IF( info.EQ.0 ) THEN
298  iroffa = mod( ia-1, desca( mb_ ) )
299  icoffa = mod( ja-1, desca( nb_ ) )
300  iroffb = mod( ib-1, descb( mb_ ) )
301  icoffb = mod( jb-1, descb( nb_ ) )
302  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
303  $ nprow )
304  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
305  $ npcol )
306  ibrow = indxg2p( ib, descb( mb_ ), myrow, descb( rsrc_ ),
307  $ nprow )
308  ibcol = indxg2p( jb, descb( nb_ ), mycol, descb( csrc_ ),
309  $ npcol )
310  npa0 = numroc( n+iroffa, desca( mb_ ), myrow, iarow, nprow )
311  mqa0 = numroc( m+icoffa, desca( nb_ ), mycol, iacol, npcol )
312  npb0 = numroc( n+iroffb, descb( mb_ ), myrow, ibrow, nprow )
313  pqb0 = numroc( p+icoffb, descb( nb_ ), mycol, ibcol, npcol )
314  lwmin = max( desca( nb_ ) * ( npa0 + mqa0 + desca( nb_ ) ),
315  $ max( max( ( desca( nb_ )*( desca( nb_ ) - 1 ) ) / 2,
316  $ ( pqb0 + npb0 ) * desca( nb_ ) ) +
317  $ desca( nb_ ) * desca( nb_ ),
318  $ descb( mb_ ) * ( npb0 + pqb0 + descb( mb_ ) ) ) )
319 *
320  work( 1 ) = cmplx( real( lwmin ) )
321  lquery = ( lwork.EQ.-1 )
322  IF( iarow.NE.ibrow .OR. iroffa.NE.iroffb ) THEN
323  info = -10
324  ELSE IF( desca( mb_ ).NE.descb( mb_ ) ) THEN
325  info = -1203
326  ELSE IF( ictxt.NE.descb( ctxt_ ) ) THEN
327  info = -1207
328  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
329  info = -15
330  END IF
331  END IF
332  IF( lquery ) THEN
333  idum1( 1 ) = -1
334  ELSE
335  idum1( 1 ) = 1
336  END IF
337  idum2( 1 ) = 15
338  CALL pchk2mat( n, 1, m, 2, ia, ja, desca, 7, n, 1, p, 3, ib,
339  $ jb, descb, 12, 1, idum1, idum2, info )
340  END IF
341 *
342  IF( info.NE.0 ) THEN
343  CALL pxerbla( ictxt, 'PCGGQRF', -info )
344  RETURN
345  ELSE IF( lquery ) THEN
346  RETURN
347  END IF
348 *
349 * QR factorization of N-by-M matrix sub( A ): sub( A ) = Q*R
350 *
351  CALL pcgeqrf( n, m, a, ia, ja, desca, taua, work, lwork, info )
352  lwmin = int( work( 1 ) )
353 *
354 * Update sub( B ) := Q'*sub( B ).
355 *
356  CALL pcunmqr( 'Left', 'Conjugate Transpose', n, p, min( n, m ), a,
357  $ ia, ja, desca, taua, b, ib, jb, descb, work, lwork,
358  $ info )
359  lwmin = min( lwmin, int( work( 1 ) ) )
360 *
361 * RQ factorization of N-by-P matrix sub( B ): sub( B ) = T*Z.
362 *
363  CALL pcgerqf( n, p, b, ib, jb, descb, taub, work, lwork, info )
364  work( 1 ) = cmplx( real( max( lwmin, int( work( 1 ) ) ) ) )
365 *
366  RETURN
367 *
368 * End of PCGGQRF
369 *
370  END
cmplx
float cmplx[2]
Definition: pblas.h:132
pcgerqf
subroutine pcgerqf(M, N, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pcgerqf.f:3
max
#define max(A, B)
Definition: pcgemr.c:180
pchk2mat
subroutine pchk2mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, MB, MBPOS0, NB, NBPOS0, IB, JB, DESCB, DESCBPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.f:175
pcunmqr
subroutine pcunmqr(SIDE, TRANS, M, N, K, A, IA, JA, DESCA, TAU, C, IC, JC, DESCC, WORK, LWORK, INFO)
Definition: pcunmqr.f:3
pcgeqrf
subroutine pcgeqrf(M, N, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pcgeqrf.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
pcggqrf
subroutine pcggqrf(N, M, P, A, IA, JA, DESCA, TAUA, B, IB, JB, DESCB, TAUB, WORK, LWORK, INFO)
Definition: pcggqrf.f:3
min
#define min(A, B)
Definition: pcgemr.c:181