ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pchetdrv.f
Go to the documentation of this file.
1  SUBROUTINE pchetdrv( UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK,
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 1, 1997
8 *
9 * .. Scalar Arguments ..
10  CHARACTER UPLO
11  INTEGER IA, INFO, JA, N
12 * ..
13 * .. Array Arguments ..
14  INTEGER DESCA( * )
15  REAL D( * ), E( * )
16  COMPLEX A( * ), TAU( * ), WORK( * )
17 * ..
18 *
19 * Purpose
20 * =======
21 *
22 * PCHETDRV computes sub( A ) = A(IA:IA+N-1,JA:JA+N-1) from Q, the
23 * Hermitian tridiagonal matrix T (or D and E), and TAU, which were
24 * computed by PCHETRD: sub( A ) := Q * T * Q'.
25 *
26 * Notes
27 * =====
28 *
29 * Each global data object is described by an associated description
30 * vector. This vector stores the information required to establish
31 * the mapping between an object element and its corresponding process
32 * and memory location.
33 *
34 * Let A be a generic term for any 2D block cyclicly distributed array.
35 * Such a global array has an associated description vector DESCA.
36 * In the following comments, the character _ should be read as
37 * "of the global array".
38 *
39 * NOTATION STORED IN EXPLANATION
40 * --------------- -------------- --------------------------------------
41 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
42 * DTYPE_A = 1.
43 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
44 * the BLACS process grid A is distribu-
45 * ted over. The context itself is glo-
46 * bal, but the handle (the integer
47 * value) may vary.
48 * M_A (global) DESCA( M_ ) The number of rows in the global
49 * array A.
50 * N_A (global) DESCA( N_ ) The number of columns in the global
51 * array A.
52 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
53 * the rows of the array.
54 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
55 * the columns of the array.
56 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
57 * row of the array A is distributed.
58 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
59 * first column of the array A is
60 * distributed.
61 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
62 * array. LLD_A >= MAX(1,LOCr(M_A)).
63 *
64 * Let K be the number of rows or columns of a distributed matrix,
65 * and assume that its process grid has dimension p x q.
66 * LOCr( K ) denotes the number of elements of K that a process
67 * would receive if K were distributed over the p processes of its
68 * process column.
69 * Similarly, LOCc( K ) denotes the number of elements of K that a
70 * process would receive if K were distributed over the q processes of
71 * its process row.
72 * The values of LOCr() and LOCc() may be determined via a call to the
73 * ScaLAPACK tool function, NUMROC:
74 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
75 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
76 * An upper bound for these quantities may be computed by:
77 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
78 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
79 *
80 * Arguments
81 * =========
82 *
83 * UPLO (global input) CHARACTER
84 * Specifies whether the upper or lower triangular part of the
85 * Hermitian matrix sub( A ) is stored:
86 * = 'U': Upper triangular
87 * = 'L': Lower triangular
88 *
89 * N (global input) INTEGER
90 * The number of rows and columns to be operated on, i.e. the
91 * order of the distributed submatrix sub( A ). N >= 0.
92 *
93 * A (local input/local output) COMPLEX pointer into the
94 * local memory to an array of dimension (LLD_A,LOCc(JA+N-1)).
95 * This array contains the local pieces of sub( A ). On entry,
96 * if UPLO='U', the diagonal and first superdiagonal of sub( A )
97 * have the corresponding elements of the tridiagonal matrix T,
98 * and the elements above the first superdiagonal, with the
99 * array TAU, represent the unitary matrix Q as a product of
100 * elementary reflectors, and the strictly lower triangular part
101 * of sub( A ) is not referenced. If UPLO='L', the diagonal and
102 * first subdiagonal of sub( A ) have the corresponding elements
103 * of the tridiagonal matrix T, and the elements below the first
104 * subdiagonal, with the array TAU, represent the unitary
105 * matrix Q as a product of elementary reflectors, and the
106 * strictly upper triangular part of sub( A ) is not referenced.
107 * On exit, if UPLO = 'U', the upper triangular part of the
108 * distributed Hermitian matrix sub( A ) is recovered.
109 * If UPLO='L', the lower triangular part of the distributed
110 * Hermitian matrix sub( A ) is recovered.
111 *
112 * IA (global input) INTEGER
113 * The row index in the global array A indicating the first
114 * row of sub( A ).
115 *
116 * JA (global input) INTEGER
117 * The column index in the global array A indicating the
118 * first column of sub( A ).
119 *
120 * DESCA (global and local input) INTEGER array of dimension DLEN_.
121 * The array descriptor for the distributed matrix A.
122 *
123 * D (local input) REAL array, dimension LOCc(JA+N-1)
124 * The diagonal elements of the tridiagonal matrix T:
125 * D(i) = A(i,i). D is tied to the distributed matrix A.
126 *
127 * E (local input) REAL array, dimension LOCc(JA+N-1)
128 * if UPLO = 'U', LOCc(JA+N-2) otherwise. The off-diagonal
129 * elements of the tridiagonal matrix T: E(i) = A(i,i+1) if
130 * UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. E is tied to the
131 * distributed matrix A.
132 *
133 * TAU (local input) COMPLEX, array, dimension
134 * LOCc(JA+N-1). This array contains the scalar factors TAU of
135 * the elementary reflectors. TAU is tied to the distributed
136 * matrix A.
137 *
138 * WORK (local workspace) COMPLEX array, dimension (LWORK)
139 * LWORK >= 2 * NB *( NB + NP )
140 *
141 * where NB = MB_A = NB_A,
142 * NP = NUMROC( N, NB, MYROW, IAROW, NPROW ),
143 * IAROW = INDXG2P( IA, NB, MYROW, RSRC_A, NPROW ).
144 *
145 * INDXG2P and NUMROC are ScaLAPACK tool functions;
146 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
147 * the subroutine BLACS_GRIDINFO.
148 *
149 * INFO (global output) INTEGER
150 * On exit, if INFO <> 0, a discrepancy has been found between
151 * the diagonal and off-diagonal elements of A and the copies
152 * contained in the arrays D and E.
153 *
154 * =====================================================================
155 *
156 * .. Parameters ..
157  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
158  $ lld_, mb_, m_, nb_, n_, rsrc_
159  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
160  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
161  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
162  REAL REIGHT, RONE, RZERO
163  parameter( reight = 8.0e+0, rone = 1.0e+0,
164  $ rzero = 0.0e+0 )
165  COMPLEX HALF, ONE, ZERO
166  parameter( half = ( 0.5e+0, 0.0e+0 ),
167  $ one = ( 1.0e+0, 0.0e+0 ),
168  $ zero = ( 0.0e+0, 0.0e+0 ) )
169 * ..
170 * .. Local Scalars ..
171  LOGICAL UPPER
172  INTEGER I, IACOL, IAROW, ICTXT, II, IPT, IPV, IPX,
173  $ ipy, j, jb, jj, jl, k, mycol, myrow, nb, np,
174  $ npcol, nprow
175  REAL ADDBND, D2, E2
176  COMPLEX D1, E1
177 * ..
178 * .. Local Arrays ..
179  INTEGER DESCD( DLEN_ ), DESCE( DLEN_ ), DESCV( DLEN_ ),
180  $ desct( dlen_ )
181 * ..
182 * .. External Functions ..
183  LOGICAL LSAME
184  INTEGER INDXG2P, NUMROC
185  REAL PSLAMCH
186  EXTERNAL indxg2p, lsame, numroc, pslamch
187 * ..
188 * .. External Subroutines ..
189  EXTERNAL blacs_gridinfo, descset, infog2l, igsum2d,
190  $ pcelget, pcgemm, pchemm,
191  $ pcher2k, pclacpy, pclarft,
192  $ pclaset, pctrmm, pselget
193 * ..
194 * .. Intrinsic Functions ..
195  INTRINSIC abs, cmplx, max, min, mod
196 * ..
197 * .. Executable statements ..
198 *
199  ictxt = desca( ctxt_ )
200  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
201 *
202  info = 0
203  nb = desca( mb_ )
204  upper = lsame( uplo, 'U' )
205  CALL infog2l( ia, ja, desca, nprow, npcol, myrow, mycol, ii, jj,
206  $ iarow, iacol )
207  np = numroc( n, nb, myrow, iarow, nprow )
208 *
209  ipt = 1
210  ipv = nb * nb + ipt
211  ipx = nb * np + ipv
212  ipy = nb * np + ipx
213 *
214  CALL descset( descd, 1, ja+n-1, 1, desca( nb_ ), myrow,
215  $ desca( csrc_ ), desca( ctxt_ ), 1 )
216 *
217  addbnd = reight * pslamch( ictxt, 'eps' )
218 *
219  IF( upper ) THEN
220 *
221  CALL descset( desce, 1, ja+n-1, 1, desca( nb_ ), myrow,
222  $ desca( csrc_ ), desca( ctxt_ ), 1 )
223 *
224  DO 10 j = 0, n-1
225  d1 = zero
226  e1 = zero
227  d2 = rzero
228  e2 = rzero
229  CALL pselget( ' ', ' ', d2, d, 1, ja+j, descd )
230  CALL pcelget( 'Columnwise', ' ', d1, a, ia+j, ja+j, desca )
231  IF( j.LT.(n-1) ) THEN
232  CALL pselget( ' ', ' ', e2, e, 1, ja+j+1, desce )
233  CALL pcelget( 'Columnwise', ' ', e1, a, ia+j, ja+j+1,
234  $ desca )
235  END IF
236 *
237  IF( ( abs( d1 - cmplx( d2 ) ).GT.( abs( d2 )*addbnd ) ) .OR.
238  $ ( abs( e1 - cmplx( e2 ) ).GT.( abs( e2 )*addbnd ) ) )
239  $ info = info + 1
240  10 CONTINUE
241 *
242 * Compute the upper triangle of sub( A ).
243 *
244  CALL descset( descv, n, nb, nb, nb, iarow, iacol, ictxt,
245  $ max( 1, np ) )
246  CALL descset( desct, nb, nb, nb, nb, iarow, iacol, ictxt, nb )
247 *
248  DO 20 k = 0, n-1, nb
249  jb = min( nb, n-k )
250  i = ia + k
251  j = ja + k
252 *
253 * Compute the lower triangular matrix T.
254 *
255  CALL pclarft( 'Backward', 'Columnwise', k+jb-1, jb, a, ia,
256  $ j, desca, tau, work( ipt ), work( ipv ) )
257 *
258 * Copy Householder vectors into WORK( IPV ).
259 *
260  CALL pclacpy( 'All', k+jb-1, jb, a, ia, j, desca,
261  $ work( ipv ), 1, 1, descv )
262 *
263  IF( k.GT.0 ) THEN
264  CALL pclaset( 'Lower', jb+1, jb, zero, one, work( ipv ),
265  $ k, 1, descv )
266  ELSE
267  CALL pclaset( 'Lower', jb, jb-1, zero, one, work( ipv ),
268  $ 1, 2, descv )
269  CALL pclaset( 'Ge', jb, 1, zero, zero, work( ipv ), 1,
270  $ 1, descv )
271  END IF
272 *
273 * Zero out the strict upper triangular part of A.
274 *
275  IF( k.GT.0 ) THEN
276  CALL pclaset( 'Ge', k-1, jb, zero, zero, a, ia, j,
277  $ desca )
278  CALL pclaset( 'Upper', jb-1, jb-1, zero, zero, a, i-1,
279  $ j+1, desca )
280  ELSE IF( jb.GT.1 ) THEN
281  CALL pclaset( 'Upper', jb-2, jb-2, zero, zero, a, ia,
282  $ j+2, desca )
283  END IF
284 *
285 * (1) X := A * V * T'
286 *
287  CALL pchemm( 'Left', 'Upper', k+jb, jb, one, a, ia, ja,
288  $ desca, work( ipv ), 1, 1, descv, zero,
289  $ work( ipx ), 1, 1, descv )
290  CALL pctrmm( 'Right', 'Lower', 'Conjugate transpose',
291  $ 'Non-Unit', k+jb, jb, one, work( ipt ), 1, 1,
292  $ desct, work( ipx ), 1, 1, descv )
293 *
294 * (2) X := X - 1/2 * V * (T * V' * X)
295 *
296  CALL pcgemm( 'Conjugate transpose', 'No transpose', jb, jb,
297  $ k+jb, one, work( ipv ), 1, 1, descv,
298  $ work( ipx ), 1, 1, descv, zero, work( ipy ),
299  $ 1, 1, desct )
300  CALL pctrmm( 'Left', 'Lower', 'No transpose', 'Non-Unit',
301  $ jb, jb, one, work( ipt ), 1, 1, desct,
302  $ work( ipy ), 1, 1, desct )
303  CALL pcgemm( 'No tranpose', 'No transpose', k+jb, jb, jb,
304  $ -half, work( ipv ), 1, 1, descv, work( ipy ),
305  $ 1, 1, desct, one, work( ipx ), 1, 1, descv )
306 *
307 * (3) A := A - X * V' - V * X'
308 *
309  CALL pcher2k( 'Upper', 'No transpose', k+jb, jb, -one,
310  $ work( ipv ), 1, 1, descv, work( ipx ), 1, 1,
311  $ descv, rone, a, ia, ja, desca )
312 *
313  descv( csrc_ ) = mod( descv( csrc_ ) + 1, npcol )
314  desct( csrc_ ) = mod( desct( csrc_ ) + 1, npcol )
315 *
316  20 CONTINUE
317 *
318  ELSE
319 *
320  CALL descset( desce, 1, ja+n-2, 1, desca( nb_ ), myrow,
321  $ desca( csrc_ ), desca( ctxt_ ), 1 )
322 *
323  DO 30 j = 0, n-1
324  d1 = zero
325  e1 = zero
326  d2 = rzero
327  e2 = rzero
328  CALL pselget( ' ', ' ', d2, d, 1, ja+j, descd )
329  CALL pcelget( 'Columnwise', ' ', d1, a, ia+j, ja+j, desca )
330  IF( j.LT.(n-1) ) THEN
331  CALL pselget( ' ', ' ', e2, e, 1, ja+j, desce )
332  CALL pcelget( 'Columnwise', ' ', e1, a, ia+j+1, ja+j,
333  $ desca )
334  END IF
335 *
336  IF( ( abs( d1 - cmplx( d2 ) ).GT.( abs( d2 )*addbnd ) ) .OR.
337  $ ( abs( e1 - cmplx( e2 ) ).GT.( abs( e2 )*addbnd ) ) )
338  $ info = info + 1
339  30 CONTINUE
340 *
341 * Compute the lower triangle of sub( A ).
342 *
343  jl = max( ( ( ja+n-2 ) / nb ) * nb + 1, ja )
344  iacol = indxg2p( jl, nb, mycol, desca( csrc_ ), npcol )
345  CALL descset( descv, n, nb, nb, nb, iarow, iacol, ictxt,
346  $ max( 1, np ) )
347  CALL descset( desct, nb, nb, nb, nb, indxg2p( ia+jl-ja+1, nb,
348  $ myrow, desca( rsrc_ ), nprow ), iacol, ictxt,
349  $ nb )
350 *
351  DO 40 j = jl, ja, -nb
352  k = j - ja + 1
353  i = ia + k - 1
354  jb = min( n-k+1, nb )
355 *
356 * Compute upper triangular matrix T from TAU.
357 *
358  CALL pclarft( 'Forward', 'Columnwise', n-k, jb, a, i+1, j,
359  $ desca, tau, work( ipt ), work( ipv ) )
360 *
361 * Copy Householder vectors into WORK( IPV ).
362 *
363  CALL pclacpy( 'Lower', n-k, jb, a, i+1, j, desca,
364  $ work( ipv ), k+1, 1, descv )
365  CALL pclaset( 'Upper', n-k, jb, zero, one, work( ipv ),
366  $ k+1, 1, descv )
367  CALL pclaset( 'Ge', 1, jb, zero, zero, work( ipv ), k, 1,
368  $ descv )
369 *
370 * Zero out the strict lower triangular part of A.
371 *
372  CALL pclaset( 'Lower', n-k-1, jb, zero, zero, a, i+2, j,
373  $ desca )
374 *
375 * (1) X := A * V * T'
376 *
377  CALL pchemm( 'Left', 'Lower', n-k+1, jb, one, a, i, j,
378  $ desca, work( ipv ), k, 1, descv, zero,
379  $ work( ipx ), k, 1, descv )
380  CALL pctrmm( 'Right', 'Upper', 'Conjugate transpose',
381  $ 'Non-Unit', n-k+1, jb, one, work( ipt ), 1, 1,
382  $ desct, work( ipx ), k, 1, descv )
383 *
384 * (2) X := X - 1/2 * V * (T * V' * X)
385 *
386  CALL pcgemm( 'Conjugate transpose', 'No transpose', jb, jb,
387  $ n-k+1, one, work( ipv ), k, 1, descv,
388  $ work( ipx ), k, 1, descv, zero, work( ipy ),
389  $ 1, 1, desct )
390  CALL pctrmm( 'Left', 'Upper', 'No transpose', 'Non-Unit',
391  $ jb, jb, one, work( ipt ), 1, 1, desct,
392  $ work( ipy ), 1, 1, desct )
393  CALL pcgemm( 'No transpose', 'No transpose', n-k+1, jb, jb,
394  $ -half, work( ipv ), k, 1, descv, work( ipy ),
395  $ 1, 1, desct, one, work( ipx ), k, 1, descv )
396 *
397 * (3) A := A - X * V' - V * X'
398 *
399  CALL pcher2k( 'Lower', 'No tranpose', n-k+1, jb, -one,
400  $ work( ipv ), k, 1, descv, work( ipx ), k, 1,
401  $ descv, rone, a, i, j, desca )
402 *
403  descv( csrc_ ) = mod( descv( csrc_ ) + npcol - 1, npcol )
404  desct( rsrc_ ) = mod( desct( rsrc_ ) + nprow - 1, nprow )
405  desct( csrc_ ) = mod( desct( csrc_ ) + npcol - 1, npcol )
406 *
407  40 CONTINUE
408 *
409  END IF
410 *
411  CALL igsum2d( ictxt, 'All', ' ', 1, 1, info, 1, -1, 0 )
412 *
413  RETURN
414 *
415 * End of PCHETDRV
416 *
417  END
cmplx
float cmplx[2]
Definition: pblas.h:132
max
#define max(A, B)
Definition: pcgemr.c:180
pcelget
subroutine pcelget(SCOPE, TOP, ALPHA, A, IA, JA, DESCA)
Definition: pcelget.f:2
infog2l
subroutine infog2l(GRINDX, GCINDX, DESC, NPROW, NPCOL, MYROW, MYCOL, LRINDX, LCINDX, RSRC, CSRC)
Definition: infog2l.f:3
descset
subroutine descset(DESC, M, N, MB, NB, IRSRC, ICSRC, ICTXT, LLD)
Definition: descset.f:3
pclaset
subroutine pclaset(UPLO, M, N, ALPHA, BETA, A, IA, JA, DESCA)
Definition: pcblastst.f:7508
pclacpy
subroutine pclacpy(UPLO, M, N, A, IA, JA, DESCA, B, IB, JB, DESCB)
Definition: pclacpy.f:3
pselget
subroutine pselget(SCOPE, TOP, ALPHA, A, IA, JA, DESCA)
Definition: pselget.f:2
pchetdrv
subroutine pchetdrv(UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK, INFO)
Definition: pchetdrv.f:3
pclarft
subroutine pclarft(DIRECT, STOREV, N, K, V, IV, JV, DESCV, TAU, T, WORK)
Definition: pclarft.f:3
min
#define min(A, B)
Definition: pcgemr.c:181