ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
psormrq.f
Go to the documentation of this file.
1  SUBROUTINE psormrq( SIDE, TRANS, M, N, K, A, IA, JA, DESCA, TAU,
2  $ C, IC, JC, DESCC, 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 25, 2001
8 *
9 * .. Scalar Arguments ..
10  CHARACTER SIDE, TRANS
11  INTEGER IA, IC, INFO, JA, JC, K, LWORK, M, N
12 * ..
13 * .. Array Arguments ..
14  INTEGER DESCA( * ), DESCC( * )
15  REAL A( * ), C( * ), TAU( * ), WORK( * )
16 * ..
17 *
18 * Purpose
19 * =======
20 *
21 * PSORMRQ overwrites the general real M-by-N distributed matrix
22 * sub( C ) = C(IC:IC+M-1,JC:JC+N-1) with
23 *
24 * SIDE = 'L' SIDE = 'R'
25 * TRANS = 'N': Q * sub( C ) sub( C ) * Q
26 * TRANS = 'T': Q**T * sub( C ) sub( C ) * Q**T
27 *
28 * where Q is a real orthogonal distributed matrix defined as the
29 * product of K elementary reflectors
30 *
31 * Q = H(1) H(2) . . . H(k)
32 *
33 * as returned by PSGERQF. Q is of order M if SIDE = 'L' and of order N
34 * if SIDE = 'R'.
35 *
36 * Notes
37 * =====
38 *
39 * Each global data object is described by an associated description
40 * vector. This vector stores the information required to establish
41 * the mapping between an object element and its corresponding process
42 * and memory location.
43 *
44 * Let A be a generic term for any 2D block cyclicly distributed array.
45 * Such a global array has an associated description vector DESCA.
46 * In the following comments, the character _ should be read as
47 * "of the global array".
48 *
49 * NOTATION STORED IN EXPLANATION
50 * --------------- -------------- --------------------------------------
51 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
52 * DTYPE_A = 1.
53 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
54 * the BLACS process grid A is distribu-
55 * ted over. The context itself is glo-
56 * bal, but the handle (the integer
57 * value) may vary.
58 * M_A (global) DESCA( M_ ) The number of rows in the global
59 * array A.
60 * N_A (global) DESCA( N_ ) The number of columns in the global
61 * array A.
62 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
63 * the rows of the array.
64 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
65 * the columns of the array.
66 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
67 * row of the array A is distributed.
68 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
69 * first column of the array A is
70 * distributed.
71 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
72 * array. LLD_A >= MAX(1,LOCr(M_A)).
73 *
74 * Let K be the number of rows or columns of a distributed matrix,
75 * and assume that its process grid has dimension p x q.
76 * LOCr( K ) denotes the number of elements of K that a process
77 * would receive if K were distributed over the p processes of its
78 * process column.
79 * Similarly, LOCc( K ) denotes the number of elements of K that a
80 * process would receive if K were distributed over the q processes of
81 * its process row.
82 * The values of LOCr() and LOCc() may be determined via a call to the
83 * ScaLAPACK tool function, NUMROC:
84 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
85 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
86 * An upper bound for these quantities may be computed by:
87 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
88 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
89 *
90 * Arguments
91 * =========
92 *
93 * SIDE (global input) CHARACTER
94 * = 'L': apply Q or Q**T from the Left;
95 * = 'R': apply Q or Q**T from the Right.
96 *
97 * TRANS (global input) CHARACTER
98 * = 'N': No transpose, apply Q;
99 * = 'T': Transpose, apply Q**T.
100 *
101 * M (global input) INTEGER
102 * The number of rows to be operated on i.e the number of rows
103 * of the distributed submatrix sub( C ). M >= 0.
104 *
105 * N (global input) INTEGER
106 * The number of columns to be operated on i.e the number of
107 * columns of the distributed submatrix sub( C ). N >= 0.
108 *
109 * K (global input) INTEGER
110 * The number of elementary reflectors whose product defines the
111 * matrix Q. If SIDE = 'L', M >= K >= 0, if SIDE = 'R',
112 * N >= K >= 0.
113 *
114 * A (local input) REAL pointer into the local memory
115 * to an array of dimension (LLD_A,LOCc(JA+M-1)) if SIDE='L',
116 * and (LLD_A,LOCc(JA+N-1)) if SIDE='R', where
117 * LLD_A >= MAX(1,LOCr(IA+K-1)); On entry, the i-th row must
118 * contain the vector which defines the elementary reflector
119 * H(i), IA <= i <= IA+K-1, as returned by PSGERQF in the
120 * K rows of its distributed matrix argument A(IA:IA+K-1,JA:*).
121 * A(IA:IA+K-1,JA:*) is modified by the routine but restored on
122 * exit.
123 *
124 * IA (global input) INTEGER
125 * The row index in the global array A indicating the first
126 * row of sub( A ).
127 *
128 * JA (global input) INTEGER
129 * The column index in the global array A indicating the
130 * first column of sub( A ).
131 *
132 * DESCA (global and local input) INTEGER array of dimension DLEN_.
133 * The array descriptor for the distributed matrix A.
134 *
135 * TAU (local input) REAL, array, dimension LOCc(IA+K-1).
136 * This array contains the scalar factors TAU(i) of the
137 * elementary reflectors H(i) as returned by PSGERQF.
138 * TAU is tied to the distributed matrix A.
139 *
140 * C (local input/local output) REAL pointer into the
141 * local memory to an array of dimension (LLD_C,LOCc(JC+N-1)).
142 * On entry, the local pieces of the distributed matrix sub(C).
143 * On exit, sub( C ) is overwritten by Q*sub( C ) or Q'*sub( C )
144 * or sub( C )*Q' or sub( C )*Q.
145 *
146 * IC (global input) INTEGER
147 * The row index in the global array C indicating the first
148 * row of sub( C ).
149 *
150 * JC (global input) INTEGER
151 * The column index in the global array C indicating the
152 * first column of sub( C ).
153 *
154 * DESCC (global and local input) INTEGER array of dimension DLEN_.
155 * The array descriptor for the distributed matrix C.
156 *
157 * WORK (local workspace/local output) REAL array,
158 * dimension (LWORK)
159 * On exit, WORK(1) returns the minimal and optimal LWORK.
160 *
161 * LWORK (local or global input) INTEGER
162 * The dimension of the array WORK.
163 * LWORK is local input and must be at least
164 * if SIDE = 'L',
165 * LWORK >= MAX( (MB_A*(MB_A-1))/2, ( MpC0 + MAX( MqA0 +
166 * NUMROC( NUMROC( M+IROFFC, MB_A, 0, 0, NPROW ),
167 * MB_A, 0, 0, LCMP ), NqC0 ) )*MB_A ) +
168 * MB_A * MB_A
169 * else if SIDE = 'R',
170 * LWORK >= MAX( (MB_A*(MB_A-1))/2, (MpC0 + NqC0)*MB_A ) +
171 * MB_A * MB_A
172 * end if
173 *
174 * where LCMP = LCM / NPROW with LCM = ICLM( NPROW, NPCOL ),
175 *
176 * IROFFA = MOD( IA-1, MB_A ), ICOFFA = MOD( JA-1, NB_A ),
177 * IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
178 * MqA0 = NUMROC( M+ICOFFA, NB_A, MYCOL, IACOL, NPCOL ),
179 *
180 * IROFFC = MOD( IC-1, MB_C ), ICOFFC = MOD( JC-1, NB_C ),
181 * ICROW = INDXG2P( IC, MB_C, MYROW, RSRC_C, NPROW ),
182 * ICCOL = INDXG2P( JC, NB_C, MYCOL, CSRC_C, NPCOL ),
183 * MpC0 = NUMROC( M+IROFFC, MB_C, MYROW, ICROW, NPROW ),
184 * NqC0 = NUMROC( N+ICOFFC, NB_C, MYCOL, ICCOL, NPCOL ),
185 *
186 * ILCM, INDXG2P and NUMROC are ScaLAPACK tool functions;
187 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
188 * the subroutine BLACS_GRIDINFO.
189 *
190 * If LWORK = -1, then LWORK is global input and a workspace
191 * query is assumed; the routine only calculates the minimum
192 * and optimal size for all work arrays. Each of these
193 * values is returned in the first entry of the corresponding
194 * work array, and no error message is issued by PXERBLA.
195 *
196 *
197 * INFO (global output) INTEGER
198 * = 0: successful exit
199 * < 0: If the i-th argument is an array and the j-entry had
200 * an illegal value, then INFO = -(i*100+j), if the i-th
201 * argument is a scalar and had an illegal value, then
202 * INFO = -i.
203 *
204 * Alignment requirements
205 * ======================
206 *
207 * The distributed submatrices A(IA:*, JA:*) and C(IC:IC+M-1,JC:JC+N-1)
208 * must verify some alignment properties, namely the following
209 * expressions should be true:
210 *
211 * If SIDE = 'L',
212 * ( NB_A.EQ.MB_C .AND. ICOFFA.EQ.IROFFC )
213 * If SIDE = 'R',
214 * ( NB_A.EQ.NB_C .AND. ICOFFA.EQ.ICOFFC .AND. IACOL.EQ.ICCOL )
215 *
216 * =====================================================================
217 *
218 * .. Parameters ..
219  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
220  $ lld_, mb_, m_, nb_, n_, rsrc_
221  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
222  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
223  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
224 * ..
225 * .. Local Scalars ..
226  LOGICAL LEFT, LQUERY, NOTRAN, RIGHT, TRAN
227  CHARACTER COLBTOP, ROWBTOP, TRANST
228  INTEGER I, I1, I2, I3, IACOL, IB, ICCOL, ICOFFA,
229  $ icoffc, icrow, ictxt, iinfo, ipw, iroffc, lcm,
230  $ lcmp, lwmin, mi, mpc0, mqa0, mycol, myrow, ni,
231  $ npcol, nprow, nq, nqc0
232 * ..
233 * .. Local Arrays ..
234  INTEGER IDUM1( 4 ), IDUM2( 4 )
235 * ..
236 * .. External Subroutines ..
237  EXTERNAL blacs_gridinfo, chk1mat, pchk2mat, pslarfb,
238  $ pslarft, psormr2, pb_topget, pb_topset, pxerbla
239 * ..
240 * .. External Functions ..
241  LOGICAL LSAME
242  INTEGER ICEIL, ILCM, INDXG2P, NUMROC
243  EXTERNAL iceil, ilcm, indxg2p, lsame, numroc
244 * ..
245 * .. Intrinsic Functions ..
246  INTRINSIC ichar, max, min, mod, real
247 * ..
248 * .. Executable Statements ..
249 *
250 * Get grid parameters
251 *
252  ictxt = desca( ctxt_ )
253  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
254 *
255 * Test the input parameters
256 *
257  info = 0
258  IF( nprow.EQ.-1 ) THEN
259  info = -(900+ctxt_)
260  ELSE
261  IF( lsame( side, 'L' ) ) THEN
262  left = .true.
263  right = .false.
264  ELSE
265  left = .false.
266  right = .true.
267  END IF
268  IF( lsame( trans, 'N' ) ) THEN
269  notran = .true.
270  tran = .false.
271  ELSE
272  notran = .false.
273  tran = .true.
274  END IF
275 *
276 * NQ is the order of Q
277 *
278  IF( left ) THEN
279  nq = m
280  CALL chk1mat( k, 5, m, 3, ia, ja, desca, 9, info )
281  ELSE
282  nq = n
283  CALL chk1mat( k, 5, n, 4, ia, ja, desca, 9, info )
284  END IF
285  CALL chk1mat( m, 3, n, 4, ic, jc, descc, 14, info )
286  IF( info.EQ.0 ) THEN
287  icoffa = mod( ja-1, desca( nb_ ) )
288  iroffc = mod( ic-1, descc( mb_ ) )
289  icoffc = mod( jc-1, descc( nb_ ) )
290  iacol = indxg2p( ja, desca( nb_ ), mycol, desca( csrc_ ),
291  $ npcol )
292  icrow = indxg2p( ic, descc( mb_ ), myrow, descc( rsrc_ ),
293  $ nprow )
294  iccol = indxg2p( jc, descc( nb_ ), mycol, descc( csrc_ ),
295  $ npcol )
296  mpc0 = numroc( m+iroffc, descc( mb_ ), myrow, icrow, nprow )
297  nqc0 = numroc( n+icoffc, descc( nb_ ), mycol, iccol, npcol )
298 *
299  IF( left ) THEN
300  mqa0 = numroc( m+icoffa, desca( nb_ ), mycol, iacol,
301  $ npcol )
302  lcm = ilcm( nprow, npcol )
303  lcmp = lcm / nprow
304  lwmin = max( ( desca( mb_ ) * ( desca( mb_ ) - 1 ) )
305  $ / 2, ( mpc0 + max( mqa0 + numroc( numroc(
306  $ m+iroffc, desca( mb_ ), 0, 0, nprow ),
307  $ desca( mb_ ), 0, 0, lcmp ), nqc0 ) ) *
308  $ desca( mb_ ) ) + desca( mb_ ) * desca( mb_ )
309  ELSE
310  lwmin = max( ( desca( mb_ ) * ( desca( mb_ ) - 1 ) ) / 2,
311  $ ( mpc0 + nqc0 ) * desca( mb_ ) ) +
312  $ desca( mb_ ) * desca( mb_ )
313  END IF
314 *
315  work( 1 ) = real( lwmin )
316  lquery = ( lwork.EQ.-1 )
317  IF( .NOT.left .AND. .NOT.lsame( side, 'R' ) ) THEN
318  info = -1
319  ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) ) THEN
320  info = -2
321  ELSE IF( k.LT.0 .OR. k.GT.nq ) THEN
322  info = -5
323  ELSE IF( left .AND. desca( nb_ ).NE.descc( mb_ ) ) THEN
324  info = -(900+nb_)
325  ELSE IF( left .AND. icoffa.NE.iroffc ) THEN
326  info = -12
327  ELSE IF( .NOT.left .AND. icoffa.NE.icoffc ) THEN
328  info = -13
329  ELSE IF( .NOT.left .AND. iacol.NE.iccol ) THEN
330  info = -13
331  ELSE IF( .NOT.left .AND. desca( nb_ ).NE.descc( nb_ ) ) THEN
332  info = -(1400+nb_)
333  ELSE IF( ictxt.NE.descc( ctxt_ ) ) THEN
334  info = -(1400+ctxt_)
335  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
336  info = -16
337  END IF
338  END IF
339  IF( left ) THEN
340  idum1( 1 ) = ichar( 'L' )
341  ELSE
342  idum1( 1 ) = ichar( 'R' )
343  END IF
344  idum2( 1 ) = 1
345  IF( notran ) THEN
346  idum1( 2 ) = ichar( 'N' )
347  ELSE
348  idum1( 2 ) = ichar( 'T' )
349  END IF
350  idum2( 2 ) = 2
351  idum1( 3 ) = k
352  idum2( 3 ) = 5
353  IF( lwork.EQ.-1 ) THEN
354  idum1( 4 ) = -1
355  ELSE
356  idum1( 4 ) = 1
357  END IF
358  idum2( 4 ) = 16
359  IF( left ) THEN
360  CALL pchk2mat( k, 5, m, 3, ia, ja, desca, 9, m, 3, n, 4,
361  $ ic, jc, descc, 14, 4, idum1, idum2, info )
362  ELSE
363  CALL pchk2mat( k, 5, n, 4, ia, ja, desca, 9, m, 3, n, 4,
364  $ ic, jc, descc, 14, 4, idum1, idum2, info )
365  END IF
366  END IF
367 *
368  IF( info.NE.0 ) THEN
369  CALL pxerbla( ictxt, 'PSORMRQ', -info )
370  RETURN
371  ELSE IF( lquery ) THEN
372  RETURN
373  END IF
374 *
375 * Quick return if possible
376 *
377  IF( m.EQ.0 .OR. n.EQ.0 .OR. k.EQ.0 )
378  $ RETURN
379 *
380  CALL pb_topget( ictxt, 'Broadcast', 'Rowwise', rowbtop )
381  CALL pb_topget( ictxt, 'Broadcast', 'Columnwise', colbtop )
382 *
383  IF( ( left .AND. .NOT.notran ) .OR.
384  $ ( .NOT.left .AND. notran ) ) THEN
385  i1 = min( iceil( ia, desca( mb_ ) ) * desca( mb_ ), ia+k-1 )
386  $ + 1
387  i2 = ia + k - 1
388  i3 = desca( mb_ )
389  ELSE
390  i1 = max( ( (ia+k-2) / desca( mb_ ) ) * desca( mb_ ) + 1, ia )
391  i2 = min( iceil( ia, desca( mb_ ) ) * desca( mb_ ), ia+k-1 )
392  $ + 1
393  i3 = -desca( mb_ )
394  END IF
395 *
396  IF( left ) THEN
397  ni = n
398  ELSE
399  mi = m
400  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', ' ' )
401  IF( notran ) THEN
402  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', 'I-ring' )
403  ELSE
404  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', 'D-ring' )
405  END IF
406  END IF
407 *
408  IF( notran ) THEN
409  transt = 'T'
410  ELSE
411  transt = 'N'
412  END IF
413 *
414  IF( ( left .AND. .NOT.notran ) .OR.
415  $ ( .NOT.left .AND. notran ) ) THEN
416  ib = i1 - ia
417  IF( left ) THEN
418  mi = m - k + ib
419  ELSE
420  ni = n - k + ib
421  END IF
422  CALL psormr2( side, trans, mi, ni, ib, a, ia, ja, desca, tau,
423  $ c, ic, jc, descc, work, lwork, iinfo )
424  END IF
425 *
426  ipw = desca( mb_ )*desca( mb_ ) + 1
427  DO 10 i = i1, i2, i3
428  ib = min( desca( mb_ ), k-i+ia )
429 *
430 * Form the triangular factor of the block reflector
431 * H = H(i+ib-1) . . . H(i+1) H(i)
432 *
433  CALL pslarft( 'Backward', 'Rowwise', nq-k+i+ib-ia, ib,
434  $ a, i, ja, desca, tau, work, work( ipw ) )
435  IF( left ) THEN
436 *
437 * H or H' is applied to C(ic:ic+m-k+i+ib-ia-1,jc:jc+n-1)
438 *
439  mi = m - k + i + ib - ia
440  ELSE
441 *
442 * H or H' is applied to C(ic:ic+m-1,jc:jc+n-k+i+ib-ia-1)
443 *
444  ni = n - k + i + ib - ia
445  END IF
446 *
447 * Apply H or H'
448 *
449  CALL pslarfb( side, transt, 'Backward', 'Rowwise', mi, ni,
450  $ ib, a, i, ja, desca, work, c, ic, jc, descc,
451  $ work( ipw ) )
452  10 CONTINUE
453 *
454  IF( ( right .AND. tran ) .OR.
455  $ ( left .AND. notran ) ) THEN
456  ib = i2 - ia
457  IF( left ) THEN
458  mi = m - k + ib
459  ELSE
460  ni = n - k + ib
461  END IF
462  CALL psormr2( side, trans, mi, ni, ib, a, ia, ja, desca, tau,
463  $ c, ic, jc, descc, work, lwork, iinfo )
464  END IF
465 *
466  CALL pb_topset( ictxt, 'Broadcast', 'Rowwise', rowbtop )
467  CALL pb_topset( ictxt, 'Broadcast', 'Columnwise', colbtop )
468 *
469  work( 1 ) = real( lwmin )
470 *
471  RETURN
472 *
473 * End of PSORMRQ
474 *
475  END
max
#define max(A, B)
Definition: pcgemr.c:180
psormr2
subroutine psormr2(SIDE, TRANS, M, N, K, A, IA, JA, DESCA, TAU, C, IC, JC, DESCC, WORK, LWORK, INFO)
Definition: psormr2.f:3
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
chk1mat
subroutine chk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, INFO)
Definition: chk1mat.f:3
pslarfb
subroutine pslarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, IV, JV, DESCV, T, C, IC, JC, DESCC, WORK)
Definition: pslarfb.f:3
pslarft
subroutine pslarft(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pslarft.f:3
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
psormrq
subroutine psormrq(SIDE, TRANS, M, N, K, A, IA, JA, DESCA, TAU, C, IC, JC, DESCC, WORK, LWORK, INFO)
Definition: psormrq.f:3
min
#define min(A, B)
Definition: pcgemr.c:181