ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pstzrzf.f
Go to the documentation of this file.
1  SUBROUTINE pstzrzf( M, N, 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, LWORK, M, N
11 * ..
12 * .. Array Arguments ..
13  INTEGER DESCA( * )
14  REAL A( * ), TAU( * ), WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * PSTZRZF reduces the M-by-N ( M<=N ) real upper trapezoidal matrix
21 * sub( A ) = A(IA:IA+M-1,JA:JA+N-1) to upper triangular form by means
22 * of orthogonal transformations.
23 *
24 * The upper trapezoidal matrix sub( A ) is factored as
25 *
26 * sub( A ) = ( R 0 ) * Z,
27 *
28 * where Z is an N-by-N orthogonal matrix and R is an M-by-M upper
29 * triangular matrix.
30 *
31 * Notes
32 * =====
33 *
34 * Each global data object is described by an associated description
35 * vector. This vector stores the information required to establish
36 * the mapping between an object element and its corresponding process
37 * and memory location.
38 *
39 * Let A be a generic term for any 2D block cyclicly distributed array.
40 * Such a global array has an associated description vector DESCA.
41 * In the following comments, the character _ should be read as
42 * "of the global array".
43 *
44 * NOTATION STORED IN EXPLANATION
45 * --------------- -------------- --------------------------------------
46 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
47 * DTYPE_A = 1.
48 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
49 * the BLACS process grid A is distribu-
50 * ted over. The context itself is glo-
51 * bal, but the handle (the integer
52 * value) may vary.
53 * M_A (global) DESCA( M_ ) The number of rows in the global
54 * array A.
55 * N_A (global) DESCA( N_ ) The number of columns in the global
56 * array A.
57 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
58 * the rows of the array.
59 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
60 * the columns of the array.
61 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
62 * row of the array A is distributed.
63 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
64 * first column of the array A is
65 * distributed.
66 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
67 * array. LLD_A >= MAX(1,LOCr(M_A)).
68 *
69 * Let K be the number of rows or columns of a distributed matrix,
70 * and assume that its process grid has dimension p x q.
71 * LOCr( K ) denotes the number of elements of K that a process
72 * would receive if K were distributed over the p processes of its
73 * process column.
74 * Similarly, LOCc( K ) denotes the number of elements of K that a
75 * process would receive if K were distributed over the q processes of
76 * its process row.
77 * The values of LOCr() and LOCc() may be determined via a call to the
78 * ScaLAPACK tool function, NUMROC:
79 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
80 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
81 * An upper bound for these quantities may be computed by:
82 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
83 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
84 *
85 * Arguments
86 * =========
87 *
88 * M (global input) INTEGER
89 * The number of rows to be operated on, i.e. the number of rows
90 * of the distributed submatrix sub( A ). M >= 0.
91 *
92 * N (global input) INTEGER
93 * The number of columns to be operated on, i.e. the number of
94 * columns of the distributed submatrix sub( A ). N >= 0.
95 *
96 * A (local input/local output) REAL pointer into the
97 * local memory to an array of dimension (LLD_A, LOCc(JA+N-1)).
98 * On entry, the local pieces of the M-by-N distributed matrix
99 * sub( A ) which is to be factored. On exit, the leading M-by-M
100 * upper triangular part of sub( A ) contains the upper trian-
101 * gular matrix R, and elements M+1 to N of the first M rows of
102 * sub( A ), with the array TAU, represent the orthogonal matrix
103 * Z as a product of M elementary reflectors.
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 output) REAL, array, dimension LOCr(IA+M-1)
117 * This array contains the scalar factors of the elementary
118 * reflectors. TAU is tied to the distributed matrix A.
119 *
120 * WORK (local workspace/local output) REAL array,
121 * dimension (LWORK)
122 * On exit, WORK(1) returns the minimal and optimal LWORK.
123 *
124 * LWORK (local or global input) INTEGER
125 * The dimension of the array WORK.
126 * LWORK is local input and must be at least
127 * LWORK >= MB_A * ( Mp0 + Nq0 + MB_A ), where
128 *
129 * IROFF = MOD( IA-1, MB_A ), ICOFF = MOD( JA-1, NB_A ),
130 * IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
131 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
132 * Mp0 = NUMROC( M+IROFF, MB_A, MYROW, IAROW, NPROW ),
133 * Nq0 = NUMROC( N+ICOFF, NB_A, MYCOL, IACOL, NPCOL ),
134 *
135 * and NUMROC, INDXG2P are ScaLAPACK tool functions;
136 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
137 * the subroutine BLACS_GRIDINFO.
138 *
139 * If LWORK = -1, then LWORK is global input and a workspace
140 * query is assumed; the routine only calculates the minimum
141 * and optimal size for all work arrays. Each of these
142 * values is returned in the first entry of the corresponding
143 * work array, and no error message is issued by PXERBLA.
144 *
145 * INFO (global output) INTEGER
146 * = 0: successful exit
147 * < 0: If the i-th argument is an array and the j-entry had
148 * an illegal value, then INFO = -(i*100+j), if the i-th
149 * argument is a scalar and had an illegal value, then
150 * INFO = -i.
151 *
152 * Further Details
153 * ===============
154 *
155 * The factorization is obtained by Householder's method. The kth
156 * transformation matrix, Z( k ), which is used to introduce zeros into
157 * the (m - k + 1)th row of sub( A ), is given in the form
158 *
159 * Z( k ) = ( I 0 ),
160 * ( 0 T( k ) )
161 *
162 * where
163 *
164 * T( k ) = I - tau*u( k )*u( k )', u( k ) = ( 1 ),
165 * ( 0 )
166 * ( z( k ) )
167 *
168 * tau is a scalar and z( k ) is an ( n - m ) element vector.
169 * tau and z( k ) are chosen to annihilate the elements of the kth row
170 * of sub( A ).
171 *
172 * The scalar tau is returned in the kth element of TAU and the vector
173 * u( k ) in the kth row of sub( A ), such that the elements of z( k )
174 * are in a( k, m + 1 ), ..., a( k, n ). The elements of R are returned
175 * in the upper triangular part of sub( A ).
176 *
177 * Z is given by
178 *
179 * Z = Z( 1 ) * Z( 2 ) * ... * Z( m ).
180 *
181 * =====================================================================
182 *
183 * .. Parameters ..
184  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
185  $ lld_, mb_, m_, nb_, n_, rsrc_
186  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
187  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
188  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
189  REAL ZERO
190  parameter( zero = 0.0e+0 )
191 * ..
192 * .. Local Scalars ..
193  LOGICAL LQUERY
194  CHARACTER COLBTOP, ROWBTOP
195  INTEGER I, IACOL, IAROW, IB, ICTXT, IIA, IL, IN, IPW,
196  $ iroffa, j, jm1, l, lwmin, mp0, mycol, myrow,
197  $ npcol, nprow, nq0
198 * ..
199 * .. Local Arrays ..
200  INTEGER IDUM1( 1 ), IDUM2( 1 )
201 * ..
202 * .. External Subroutines ..
203  EXTERNAL blacs_gridinfo, chk1mat, infog1l, pchk1mat,
204  $ pslatrz, pslarzb, pslarzt, pb_topget,
205  $ pb_topset, pxerbla
206 * ..
207 * .. External Functions ..
208  INTEGER ICEIL, INDXG2P, NUMROC
209  EXTERNAL iceil, indxg2p, numroc
210 * ..
211 * .. Intrinsic Functions ..
212  INTRINSIC max, min, mod, real
213 * ..
214 * .. Executable Statements ..
215 *
216 * Get grid parameters
217 *
218  ictxt = desca( ctxt_ )
219  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
220 *
221 * Test the input parameters
222 *
223  info = 0
224  IF( nprow.EQ.-1 ) THEN
225  info = -(600+ctxt_)
226  ELSE
227  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 6, info )
228  IF( info.EQ.0 ) THEN
229  iroffa = mod( ia-1, desca( mb_ ) )
230  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
231  $ nprow )
232  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
233  $ npcol )
234  mp0 = numroc( m+iroffa, desca( mb_ ), myrow, iarow, nprow )
235  nq0 = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
236  $ mycol, iacol, npcol )
237  lwmin = desca( mb_ ) * ( mp0 + nq0 + desca( mb_ ) )
238 *
239  work( 1 ) = real( lwmin )
240  lquery = ( lwork.EQ.-1 )
241  IF( n.LT.m ) THEN
242  info = -2
243  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
244  info = -9
245  END IF
246  END IF
247  IF( lquery ) THEN
248  idum1( 1 ) = -1
249  ELSE
250  idum1( 1 ) = 1
251  END IF
252  idum2( 1 ) = 9
253  CALL pchk1mat( m, 1, n, 2, ia, ja, desca, 6, 1, idum1, idum2,
254  $ info )
255  END IF
256 *
257  IF( info.NE.0 ) THEN
258  CALL pxerbla( ictxt, 'PSTZRZF', -info )
259  RETURN
260  ELSE IF( lquery ) THEN
261  RETURN
262  END IF
263 *
264 * Quick return if possible
265 *
266  IF( m.EQ.0 .OR. n.EQ.0 )
267  $ RETURN
268 *
269  IF( m.EQ.n ) THEN
270 *
271  CALL infog1l( ia, desca( mb_ ), nprow, myrow, desca( rsrc_ ),
272  $ iia, iarow )
273  IF( myrow.EQ.iarow )
274  $ mp0 = mp0 - iroffa
275  DO 10 i = iia, iia+mp0-1
276  tau( i ) = zero
277  10 CONTINUE
278 *
279  ELSE
280 *
281  l = n-m
282  jm1 = ja + min( m+1, n ) - 1
283  ipw = desca( mb_ ) * desca( mb_ ) + 1
284  in = min( iceil( ia, desca( mb_ ) ) * desca( mb_ ), ia+m-1 )
285  il = max( ( (ia+m-2) / desca( mb_ ) ) * desca( mb_ ) + 1, ia )
286  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
287  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
288  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', ' ' )
289  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', 'D-ring' )
290 *
291 * Use blocked code initially
292 *
293  DO 20 i = il, in+1, -desca( mb_ )
294  ib = min( ia+m-i, desca( mb_ ) )
295  j = ja + i - ia
296 *
297 * Compute the complete orthogonal factorization of the current
298 * block A(i:i+ib-1,j:ja+n-1)
299 *
300  CALL pslatrz( ib, ja+n-j, l, a, i, j, desca, tau, work )
301 *
302  IF( i.GT.ia ) THEN
303 *
304 * Form the triangular factor of the block reflector
305 * H = H(i+ib-1) . . . H(i+1) H(i)
306 *
307  CALL pslarzt( 'Backward', 'Rowwise', l, ib, a, i, jm1,
308  $ desca, tau, work, work( ipw ) )
309 *
310 * Apply H to A(ia:i-1,j:ja+n-1) from the right
311 *
312  CALL pslarzb( 'Right', 'No transpose', 'Backward',
313  $ 'Rowwise', i-ia, ja+n-j, ib, l, a, i, jm1,
314  $ desca, work, a, ia, j, desca, work( ipw ) )
315  END IF
316 *
317  20 CONTINUE
318 *
319 * Use unblocked code to factor the last or only block
320 *
321  CALL pslatrz( in-ia+1, n, n-m, a, ia, ja, desca, tau, work )
322 *
323  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
324  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
325 *
326  END IF
327 *
328  work( 1 ) = real( lwmin )
329 *
330  RETURN
331 *
332 * End of PSTZRZF
333 *
334  END
max
#define max(A, B)
Definition: pcgemr.c:180
pslatrz
subroutine pslatrz(M, N, L, A, IA, JA, DESCA, TAU, WORK)
Definition: pslatrz.f:2
infog1l
subroutine infog1l(GINDX, NB, NPROCS, MYROC, ISRCPROC, LINDX, ROCSRC)
Definition: infog1l.f:3
pslarzt
subroutine pslarzt(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pslarzt.f:3
pslarzb
subroutine pslarzb(SIDE, TRANS, DIRECT, STOREV, M, N, K, L, V, IV, JV, DESCV, T, C, IC, JC, DESCC, WORK)
Definition: pslarzb.f:3
pchk1mat
subroutine pchk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.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
pstzrzf
subroutine pstzrzf(M, N, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: pstzrzf.f:3
min
#define min(A, B)
Definition: pcgemr.c:181