ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
psgeql2.f
Go to the documentation of this file.
1  SUBROUTINE psgeql2( 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 * PSGEQL2 computes a QL factorization of a real distributed M-by-N
21 * matrix sub( A ) = A(IA:IA+M-1,JA:JA+N-1) = Q * L.
22 *
23 * Notes
24 * =====
25 *
26 * Each global data object is described by an associated description
27 * vector. This vector stores the information required to establish
28 * the mapping between an object element and its corresponding process
29 * and memory location.
30 *
31 * Let A be a generic term for any 2D block cyclicly distributed array.
32 * Such a global array has an associated description vector DESCA.
33 * In the following comments, the character _ should be read as
34 * "of the global array".
35 *
36 * NOTATION STORED IN EXPLANATION
37 * --------------- -------------- --------------------------------------
38 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
39 * DTYPE_A = 1.
40 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
41 * the BLACS process grid A is distribu-
42 * ted over. The context itself is glo-
43 * bal, but the handle (the integer
44 * value) may vary.
45 * M_A (global) DESCA( M_ ) The number of rows in the global
46 * array A.
47 * N_A (global) DESCA( N_ ) The number of columns in the global
48 * array A.
49 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
50 * the rows of the array.
51 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
52 * the columns of the array.
53 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
54 * row of the array A is distributed.
55 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
56 * first column of the array A is
57 * distributed.
58 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
59 * array. LLD_A >= MAX(1,LOCr(M_A)).
60 *
61 * Let K be the number of rows or columns of a distributed matrix,
62 * and assume that its process grid has dimension p x q.
63 * LOCr( K ) denotes the number of elements of K that a process
64 * would receive if K were distributed over the p processes of its
65 * process column.
66 * Similarly, LOCc( K ) denotes the number of elements of K that a
67 * process would receive if K were distributed over the q processes of
68 * its process row.
69 * The values of LOCr() and LOCc() may be determined via a call to the
70 * ScaLAPACK tool function, NUMROC:
71 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
72 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
73 * An upper bound for these quantities may be computed by:
74 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
75 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
76 *
77 * Arguments
78 * =========
79 *
80 * M (global input) INTEGER
81 * The number of rows to be operated on, i.e. the number of rows
82 * of the distributed submatrix sub( A ). M >= 0.
83 *
84 * N (global input) INTEGER
85 * The number of columns to be operated on, i.e. the number of
86 * columns of the distributed submatrix sub( A ). N >= 0.
87 *
88 * A (local input/local output) REAL pointer into the
89 * local memory to an array of dimension (LLD_A, LOCc(JA+N-1)).
90 * On entry, the local pieces of the M-by-N distributed matrix
91 * sub( A ) which is to be factored. On exit, if M >= N, the
92 * lower triangle of the distributed submatrix
93 * A( IA+M-N:IA+M-1, JA:JA+N-1 ) contains the N-by-N lower
94 * triangular matrix L; if M <= N, the elements on and below
95 * the (N-M)-th superdiagonal contain the M by N lower
96 * trapezoidal matrix L; the remaining elements, with the
97 * array TAU, represent the orthogonal matrix Q as a product of
98 * elementary reflectors (see Further Details).
99 *
100 * IA (global input) INTEGER
101 * The row index in the global array A indicating the first
102 * row of sub( A ).
103 *
104 * JA (global input) INTEGER
105 * The column index in the global array A indicating the
106 * first column of sub( A ).
107 *
108 * DESCA (global and local input) INTEGER array of dimension DLEN_.
109 * The array descriptor for the distributed matrix A.
110 *
111 * TAU (local output) REAL, array, dimension LOCc(JA+N-1)
112 * This array contains the scalar factors of the elementary
113 * reflectors. TAU is tied to the distributed matrix A.
114 *
115 * WORK (local workspace/local output) REAL array,
116 * dimension (LWORK)
117 * On exit, WORK(1) returns the minimal and optimal LWORK.
118 *
119 * LWORK (local or global input) INTEGER
120 * The dimension of the array WORK.
121 * LWORK is local input and must be at least
122 * LWORK >= Mp0 + MAX( 1, Nq0 ), where
123 *
124 * IROFF = MOD( IA-1, MB_A ), ICOFF = MOD( JA-1, NB_A ),
125 * IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
126 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
127 * Mp0 = NUMROC( M+IROFF, MB_A, MYROW, IAROW, NPROW ),
128 * Nq0 = NUMROC( N+ICOFF, NB_A, MYCOL, IACOL, NPCOL ),
129 *
130 * and NUMROC, INDXG2P are ScaLAPACK tool functions;
131 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
132 * the subroutine BLACS_GRIDINFO.
133 *
134 * If LWORK = -1, then LWORK is global input and a workspace
135 * query is assumed; the routine only calculates the minimum
136 * and optimal size for all work arrays. Each of these
137 * values is returned in the first entry of the corresponding
138 * work array, and no error message is issued by PXERBLA.
139 *
140 * INFO (local output) INTEGER
141 * = 0: successful exit
142 * < 0: If the i-th argument is an array and the j-entry had
143 * an illegal value, then INFO = -(i*100+j), if the i-th
144 * argument is a scalar and had an illegal value, then
145 * INFO = -i.
146 *
147 * Further Details
148 * ===============
149 *
150 * The matrix Q is represented as a product of elementary reflectors
151 *
152 * Q = H(ja+k-1) . . . H(ja+1) H(ja), where k = min(m,n).
153 *
154 * Each H(i) has the form
155 *
156 * H(i) = I - tau * v * v'
157 *
158 * where tau is a real scalar, and v is a real vector with
159 * v(m-k+i+1:m) = 0 and v(m-k+i) = 1; v(1:m-k+i-1) is stored on exit in
160 * A(ia:ia+m-k+i-2,ja+n-k+i-1), and tau in TAU(ja+n-k+i-1).
161 *
162 * =====================================================================
163 *
164 * .. Parameters ..
165  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
166  $ lld_, mb_, m_, nb_, n_, rsrc_
167  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
168  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
169  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
170  REAL ONE
171  parameter( one = 1.0e+0 )
172 * ..
173 * .. Local Scalars ..
174  LOGICAL LQUERY
175  CHARACTER COLBTOP, ROWBTOP
176  INTEGER I, IACOL, IAROW, ICTXT, II, J, JJ, K, LWMIN,
177  $ mp, mycol, myrow, npcol, nprow, nq
178  REAL AJJ, ALPHA
179 * ..
180 * .. External Subroutines ..
181  EXTERNAL blacs_abort, blacs_gridinfo, chk1mat, infog2l,
182  $ pselset, pslarf, pslarfg, pb_topget,
183  $ pb_topset, pxerbla, sgebr2d, sgebs2d,
184  $ slarfg, sscal
185 * ..
186 * .. External Functions ..
187  INTEGER INDXG2P, NUMROC
188  EXTERNAL indxg2p, numroc
189 * ..
190 * .. Intrinsic Functions ..
191  INTRINSIC max, min, mod, real
192 * ..
193 * .. Executable Statements ..
194 *
195 * Get grid parameters
196 *
197  ictxt = desca( ctxt_ )
198  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
199 *
200 * Test the input parameters
201 *
202  info = 0
203  IF( nprow.EQ.-1 ) THEN
204  info = -(600+ctxt_)
205  ELSE
206  CALL chk1mat( m, 1, n, 2, ia, ja, desca, 6, info )
207  IF( info.EQ.0 ) THEN
208  iarow = indxg2p( ia, desca( mb_ ), myrow, desca( rsrc_ ),
209  $ nprow )
210  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
211  $ npcol )
212  mp = numroc( m+mod( ia-1, desca( mb_ ) ), desca( mb_ ),
213  $ myrow, iarow, nprow )
214  nq = numroc( n+mod( ja-1, desca( nb_ ) ), desca( nb_ ),
215  $ mycol, iacol, npcol )
216  lwmin = mp + max( 1, nq )
217 *
218  work( 1 ) = real( lwmin )
219  lquery = ( lwork.EQ.-1 )
220  IF( lwork.LT.lwmin .AND. .NOT.lquery )
221  $ info = -9
222  END IF
223  END IF
224 *
225  IF( info.NE.0 ) THEN
226  CALL pxerbla( ictxt, 'PSGEQL2', -info )
227  CALL blacs_abort( ictxt, 1 )
228  RETURN
229  ELSE IF( lquery ) THEN
230  RETURN
231  END IF
232 *
233 * Quick return if possible
234 *
235  IF( m.EQ.0 .OR. n.EQ.0 )
236  $ RETURN
237 *
238  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
239  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
240  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', 'D-ring' )
241  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', ' ' )
242 *
243  IF( desca( m_ ).EQ.1 ) THEN
244  IF( mycol.EQ.iacol )
245  $ nq = nq - mod( ja-1, desca( nb_ ) )
246  CALL infog2l( ia, ja, desca, nprow, npcol, myrow, mycol, ii,
247  $ jj, iarow, iacol )
248  iacol = indxg2p( ja+n-1, desca( nb_ ), mycol, desca( csrc_ ),
249  $ npcol )
250  IF( myrow.EQ.iarow ) THEN
251  IF( mycol.EQ.iacol ) THEN
252  i = ii+(jj+nq-2)*desca( lld_ )
253  ajj = a( i )
254  CALL slarfg( 1, ajj, a( i ), 1, tau( jj+nq-1 ) )
255  IF( n.GT.1 ) THEN
256  alpha = one - tau( jj+nq-1 )
257  CALL sgebs2d( ictxt, 'Rowwise', ' ', 1, 1, alpha, 1 )
258  CALL sscal( nq-1, alpha, a( ii+(jj-1)*desca( lld_ ) ),
259  $ desca( lld_ ) )
260  END IF
261  CALL sgebs2d( ictxt, 'Columnwise', ' ', 1, 1,
262  $ tau( jj+nq-1 ), 1 )
263  a( i ) = ajj
264  ELSE
265  IF( n.GT.1 ) THEN
266  CALL sgebr2d( ictxt, 'Rowwise', ' ', 1, 1, alpha,
267  $ 1, iarow, iacol )
268  CALL sscal( nq, alpha, a( ii+(jj-1)*desca( lld_ ) ),
269  $ desca( lld_ ) )
270  END IF
271  END IF
272  ELSE IF( mycol.EQ.iacol ) THEN
273  CALL sgebr2d( ictxt, 'Columnwise', ' ', 1, 1,
274  $ tau( jj+nq-1 ), 1, iarow, iacol )
275  END IF
276 *
277  ELSE
278 *
279  k = min( m, n )
280  DO 10 j = ja+k-1, ja, -1
281  i = ia + j - ja
282 *
283 * Generate elementary reflector H(j) to annihilate
284 * A(ia:i+m-k-1,j+n-k)
285 *
286  CALL pslarfg( m-k+i-ia+1, ajj, m-k+i, n-k+j, a, ia,
287  $ n-k+j, desca, 1, tau )
288 *
289 * Apply H(j) to A(ia:i+m-k,ja:j+n-k-1) from the left
290 *
291  CALL pselset( a, i+m-k, j+n-k, desca, one )
292  CALL pslarf( 'Left', m-k+i-ia+1, n-k+j-ja, a, ia, n-k+j,
293  $ desca, 1, tau, a, ia, ja, desca, work )
294  CALL pselset( a, i+m-k, j+n-k, desca, ajj )
295 *
296  10 CONTINUE
297 *
298  END IF
299 *
300  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
301  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
302 *
303  work( 1 ) = real( lwmin )
304 *
305  RETURN
306 *
307 * End of PSGEQL2
308 *
309  END
max
#define max(A, B)
Definition: pcgemr.c:180
infog2l
subroutine infog2l(GRINDX, GCINDX, DESC, NPROW, NPCOL, MYROW, MYCOL, LRINDX, LCINDX, RSRC, CSRC)
Definition: infog2l.f:3
pselset
subroutine pselset(A, IA, JA, DESCA, ALPHA)
Definition: pselset.f:2
pslarfg
subroutine pslarfg(N, ALPHA, IAX, JAX, X, IX, JX, DESCX, INCX, TAU)
Definition: pslarfg.f:3
pslarf
subroutine pslarf(SIDE, M, N, V, IV, JV, DESCV, INCV, TAU, C, IC, JC, DESCC, WORK)
Definition: pslarf.f:3
chk1mat
subroutine chk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, INFO)
Definition: chk1mat.f:3
psgeql2
subroutine psgeql2(M, N, A, IA, JA, DESCA, TAU, WORK, LWORK, INFO)
Definition: psgeql2.f:3
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
min
#define min(A, B)
Definition: pcgemr.c:181