ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pssytrd.f
Go to the documentation of this file.
1  SUBROUTINE pssytrd( UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK,
2  $ 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 UPLO
11  INTEGER IA, INFO, JA, LWORK, N
12 * ..
13 * .. Array Arguments ..
14  INTEGER DESCA( * )
15  REAL A( * ), D( * ), E( * ), TAU( * ), WORK( * )
16 * ..
17 *
18 * Purpose
19 * =======
20 *
21 * PSSYTRD reduces a real symmetric matrix sub( A ) to symmetric
22 * tridiagonal form T by an orthogonal similarity transformation:
23 * Q' * sub( A ) * Q = T, where sub( A ) = A(IA:IA+N-1,JA:JA+N-1).
24 *
25 * Notes
26 * =====
27 *
28 * Each global data object is described by an associated description
29 * vector. This vector stores the information required to establish
30 * the mapping between an object element and its corresponding process
31 * and memory location.
32 *
33 * Let A be a generic term for any 2D block cyclicly distributed array.
34 * Such a global array has an associated description vector DESCA.
35 * In the following comments, the character _ should be read as
36 * "of the global array".
37 *
38 * NOTATION STORED IN EXPLANATION
39 * --------------- -------------- --------------------------------------
40 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
41 * DTYPE_A = 1.
42 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
43 * the BLACS process grid A is distribu-
44 * ted over. The context itself is glo-
45 * bal, but the handle (the integer
46 * value) may vary.
47 * M_A (global) DESCA( M_ ) The number of rows in the global
48 * array A.
49 * N_A (global) DESCA( N_ ) The number of columns in the global
50 * array A.
51 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
52 * the rows of the array.
53 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
54 * the columns of the array.
55 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
56 * row of the array A is distributed.
57 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
58 * first column of the array A is
59 * distributed.
60 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
61 * array. LLD_A >= MAX(1,LOCr(M_A)).
62 *
63 * Let K be the number of rows or columns of a distributed matrix,
64 * and assume that its process grid has dimension p x q.
65 * LOCr( K ) denotes the number of elements of K that a process
66 * would receive if K were distributed over the p processes of its
67 * process column.
68 * Similarly, LOCc( K ) denotes the number of elements of K that a
69 * process would receive if K were distributed over the q processes of
70 * its process row.
71 * The values of LOCr() and LOCc() may be determined via a call to the
72 * ScaLAPACK tool function, NUMROC:
73 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
74 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
75 * An upper bound for these quantities may be computed by:
76 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
77 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
78 *
79 * Arguments
80 * =========
81 *
82 * UPLO (global input) CHARACTER
83 * Specifies whether the upper or lower triangular part of the
84 * symmetric matrix sub( A ) is stored:
85 * = 'U': Upper triangular
86 * = 'L': Lower triangular
87 *
88 * N (global input) INTEGER
89 * The number of rows and columns to be operated on, i.e. the
90 * order of the distributed submatrix sub( A ). N >= 0.
91 *
92 * A (local input/local output) REAL pointer into the
93 * local memory to an array of dimension (LLD_A,LOCc(JA+N-1)).
94 * On entry, this array contains the local pieces of the
95 * symmetric distributed matrix sub( A ). If UPLO = 'U', the
96 * leading N-by-N upper triangular part of sub( A ) contains
97 * the upper triangular part of the matrix, and its strictly
98 * lower triangular part is not referenced. If UPLO = 'L', the
99 * leading N-by-N lower triangular part of sub( A ) contains the
100 * lower triangular part of the matrix, and its strictly upper
101 * triangular part is not referenced. On exit, if UPLO = 'U',
102 * the diagonal and first superdiagonal of sub( A ) are over-
103 * written by the corresponding elements of the tridiagonal
104 * matrix T, and the elements above the first superdiagonal,
105 * with the array TAU, represent the orthogonal matrix Q as a
106 * product of elementary reflectors; if UPLO = 'L', the diagonal
107 * and first subdiagonal of sub( A ) are overwritten by the
108 * corresponding elements of the tridiagonal matrix T, and the
109 * elements below the first subdiagonal, with the array TAU,
110 * represent the orthogonal matrix Q as a product of elementary
111 * reflectors. See Further Details.
112 *
113 * IA (global input) INTEGER
114 * The row index in the global array A indicating the first
115 * row of sub( A ).
116 *
117 * JA (global input) INTEGER
118 * The column index in the global array A indicating the
119 * first column of sub( A ).
120 *
121 * DESCA (global and local input) INTEGER array of dimension DLEN_.
122 * The array descriptor for the distributed matrix A.
123 *
124 * D (local output) REAL array, dimension LOCc(JA+N-1)
125 * The diagonal elements of the tridiagonal matrix T:
126 * D(i) = A(i,i). D is tied to the distributed matrix A.
127 *
128 * E (local output) REAL array, dimension LOCc(JA+N-1)
129 * if UPLO = 'U', LOCc(JA+N-2) otherwise. The off-diagonal
130 * elements of the tridiagonal matrix T: E(i) = A(i,i+1) if
131 * UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. E is tied to the
132 * distributed matrix A.
133 *
134 * TAU (local output) REAL, array, dimension
135 * LOCc(JA+N-1). This array contains the scalar factors TAU of
136 * the elementary reflectors. TAU is tied to the distributed
137 * matrix A.
138 *
139 * WORK (local workspace/local output) REAL array,
140 * dimension (LWORK)
141 * On exit, WORK( 1 ) returns the minimal and optimal LWORK.
142 *
143 * LWORK (local or global input) INTEGER
144 * The dimension of the array WORK.
145 * LWORK is local input and must be at least
146 * LWORK >= MAX( NB * ( NP +1 ), 3 * NB )
147 *
148 * where NB = MB_A = NB_A,
149 * NP = NUMROC( N, NB, MYROW, IAROW, NPROW ),
150 * IAROW = INDXG2P( IA, NB, MYROW, RSRC_A, NPROW ).
151 *
152 * INDXG2P and NUMROC are ScaLAPACK tool functions;
153 * MYROW, MYCOL, NPROW and NPCOL can be determined by calling
154 * the subroutine BLACS_GRIDINFO.
155 *
156 * If LWORK = -1, then LWORK is global input and a workspace
157 * query is assumed; the routine only calculates the minimum
158 * and optimal size for all work arrays. Each of these
159 * values is returned in the first entry of the corresponding
160 * work array, and no error message is issued by PXERBLA.
161 *
162 * INFO (global output) INTEGER
163 * = 0: successful exit
164 * < 0: If the i-th argument is an array and the j-entry had
165 * an illegal value, then INFO = -(i*100+j), if the i-th
166 * argument is a scalar and had an illegal value, then
167 * INFO = -i.
168 *
169 * Further Details
170 * ===============
171 *
172 * If UPLO = 'U', the matrix Q is represented as a product of elementary
173 * reflectors
174 *
175 * Q = H(n-1) . . . H(2) H(1).
176 *
177 * Each H(i) has the form
178 *
179 * H(i) = I - tau * v * v'
180 *
181 * where tau is a real scalar, and v is a real vector with
182 * v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
183 * A(ia:ia+i-2,ja+i), and tau in TAU(ja+i-1).
184 *
185 * If UPLO = 'L', the matrix Q is represented as a product of elementary
186 * reflectors
187 *
188 * Q = H(1) H(2) . . . H(n-1).
189 *
190 * Each H(i) has the form
191 *
192 * H(i) = I - tau * v * v'
193 *
194 * where tau is a real scalar, and v is a real vector with
195 * v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in
196 * A(ia+i+1:ia+n-1,ja+i-1), and tau in TAU(ja+i-1).
197 *
198 * The contents of sub( A ) on exit are illustrated by the following
199 * examples with n = 5:
200 *
201 * if UPLO = 'U': if UPLO = 'L':
202 *
203 * ( d e v2 v3 v4 ) ( d )
204 * ( d e v3 v4 ) ( e d )
205 * ( d e v4 ) ( v1 e d )
206 * ( d e ) ( v1 v2 e d )
207 * ( d ) ( v1 v2 v3 e d )
208 *
209 * where d and e denote diagonal and off-diagonal elements of T, and vi
210 * denotes an element of the vector defining H(i).
211 *
212 * Alignment requirements
213 * ======================
214 *
215 * The distributed submatrix sub( A ) must verify some alignment proper-
216 * ties, namely the following expression should be true:
217 * ( MB_A.EQ.NB_A .AND. IROFFA.EQ.ICOFFA .AND. IROFFA.EQ.0 ) with
218 * IROFFA = MOD( IA-1, MB_A ) and ICOFFA = MOD( JA-1, NB_A ).
219 *
220 * =====================================================================
221 *
222 * .. Parameters ..
223  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
224  $ lld_, mb_, m_, nb_, n_, rsrc_
225  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
226  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
227  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
228  REAL ONE
229  parameter( one = 1.0e+0 )
230 * ..
231 * .. Local Scalars ..
232  LOGICAL LQUERY, UPPER
233  CHARACTER COLCTOP, ROWCTOP
234  INTEGER I, IACOL, IAROW, ICOFFA, ICTXT, IINFO, IPW,
235  $ iroffa, j, jb, jx, k, kk, lwmin, mycol, myrow,
236  $ nb, np, npcol, nprow, nq
237 * ..
238 * .. Local Arrays ..
239  INTEGER DESCW( DLEN_ ), IDUM1( 2 ), IDUM2( 2 )
240 * ..
241 * .. External Subroutines ..
242  EXTERNAL blacs_gridinfo, chk1mat, descset, pchk1mat,
243  $ pslatrd, pssyr2k, pssytd2, pb_topget,
244  $ pb_topset, pxerbla
245 * ..
246 * .. External Functions ..
247  LOGICAL LSAME
248  INTEGER INDXG2L, INDXG2P, NUMROC
249  EXTERNAL lsame, indxg2l, indxg2p, numroc
250 * ..
251 * .. Intrinsic Functions ..
252  INTRINSIC ichar, max, min, mod, real
253 * ..
254 * .. Executable Statements ..
255 *
256 * Get grid parameters
257 *
258  ictxt = desca( ctxt_ )
259  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
260 *
261 * Test the input parameters
262 *
263  info = 0
264  IF( nprow.EQ.-1 ) THEN
265  info = -(600+ctxt_)
266  ELSE
267  CALL chk1mat( n, 2, n, 2, ia, ja, desca, 6, info )
268  upper = lsame( uplo, 'U' )
269  IF( info.EQ.0 ) THEN
270  nb = desca( nb_ )
271  iroffa = mod( ia-1, desca( mb_ ) )
272  icoffa = mod( ja-1, desca( nb_ ) )
273  iarow = indxg2p( ia, nb, myrow, desca( rsrc_ ), nprow )
274  iacol = indxg2p( ja, nb, mycol, desca( csrc_ ), npcol )
275  np = numroc( n, nb, myrow, iarow, nprow )
276  nq = max( 1, numroc( n+ja-1, nb, mycol, desca( csrc_ ),
277  $ npcol ) )
278  lwmin = max( (np+1)*nb, 3*nb )
279 *
280  work( 1 ) = real( lwmin )
281  lquery = ( lwork.EQ.-1 )
282  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
283  info = -1
284  ELSE IF( iroffa.NE.icoffa .OR. icoffa.NE.0 ) THEN
285  info = -5
286  ELSE IF( desca( mb_ ).NE.desca( nb_ ) ) THEN
287  info = -(600+nb_)
288  ELSE IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
289  info = -11
290  END IF
291  END IF
292  IF( upper ) THEN
293  idum1( 1 ) = ichar( 'U' )
294  ELSE
295  idum1( 1 ) = ichar( 'L' )
296  END IF
297  idum2( 1 ) = 1
298  IF( lwork.EQ.-1 ) THEN
299  idum1( 2 ) = -1
300  ELSE
301  idum1( 2 ) = 1
302  END IF
303  idum2( 2 ) = 11
304  CALL pchk1mat( n, 2, n, 2, ia, ja, desca, 6, 2, idum1, idum2,
305  $ info )
306  END IF
307 *
308  IF( info.NE.0 ) THEN
309  CALL pxerbla( ictxt, 'PSSYTRD', -info )
310  RETURN
311  ELSE IF( lquery ) THEN
312  RETURN
313  END IF
314 *
315 * Quick return if possible
316 *
317  IF( n.EQ.0 )
318  $ RETURN
319 *
320  CALL pb_topget( ictxt, 'Combine', 'Columnwise', colctop )
321  CALL pb_topget( ictxt, 'Combine', 'Rowwise', rowctop )
322  CALL pb_topset( ictxt, 'Combine', 'Columnwise', '1-tree' )
323  CALL pb_topset( ictxt, 'Combine', 'Rowwise', '1-tree' )
324 *
325  ipw = np * nb + 1
326 *
327  IF( upper ) THEN
328 *
329 * Reduce the upper triangle of sub( A ).
330 *
331  kk = mod( ja+n-1, nb )
332  IF( kk.EQ.0 )
333  $ kk = nb
334  CALL descset( descw, n, nb, nb, nb, iarow, indxg2p( ja+n-kk,
335  $ nb, mycol, desca( csrc_ ), npcol ), ictxt,
336  $ max( 1, np ) )
337 *
338  DO 10 k = n-kk+1, nb+1, -nb
339  jb = min( n-k+1, nb )
340  i = ia + k - 1
341  j = ja + k - 1
342 *
343 * Reduce columns I:I+NB-1 to tridiagonal form and form
344 * the matrix W which is needed to update the unreduced part of
345 * the matrix
346 *
347  CALL pslatrd( uplo, k+jb-1, jb, a, ia, ja, desca, d, e, tau,
348  $ work, 1, 1, descw, work( ipw ) )
349 *
350 * Update the unreduced submatrix A(IA:I-1,JA:J-1), using an
351 * update of the form:
352 * A(IA:I-1,JA:J-1) := A(IA:I-1,JA:J-1) - V*W' - W*V'
353 *
354  CALL pssyr2k( uplo, 'No transpose', k-1, jb, -one, a, ia, j,
355  $ desca, work, 1, 1, descw, one, a, ia, ja,
356  $ desca )
357 *
358 * Copy last superdiagonal element back into sub( A )
359 *
360  jx = min( indxg2l( j, nb, 0, iacol, npcol ), nq )
361  CALL pselset( a, i-1, j, desca, e( jx ) )
362 *
363  descw( csrc_ ) = mod( descw( csrc_ ) + npcol - 1, npcol )
364 *
365  10 CONTINUE
366 *
367 * Use unblocked code to reduce the last or only block
368 *
369  CALL pssytd2( uplo, min( n, nb ), a, ia, ja, desca, d, e,
370  $ tau, work, lwork, iinfo )
371 *
372  ELSE
373 *
374 * Reduce the lower triangle of sub( A )
375 *
376  kk = mod( ja+n-1, nb )
377  IF( kk.EQ.0 )
378  $ kk = nb
379  CALL descset( descw, n, nb, nb, nb, iarow, iacol, ictxt,
380  $ max( 1, np ) )
381 *
382  DO 20 k = 1, n-nb, nb
383  i = ia + k - 1
384  j = ja + k - 1
385 *
386 * Reduce columns I:I+NB-1 to tridiagonal form and form
387 * the matrix W which is needed to update the unreduced part
388 * of the matrix
389 *
390  CALL pslatrd( uplo, n-k+1, nb, a, i, j, desca, d, e, tau,
391  $ work, k, 1, descw, work( ipw ) )
392 *
393 * Update the unreduced submatrix A(I+NB:IA+N-1,I+NB:IA+N-1),
394 * using an update of the form: A(I+NB:IA+N-1,I+NB:IA+N-1) :=
395 * A(I+NB:IA+N-1,I+NB:IA+N-1) - V*W' - W*V'
396 *
397  CALL pssyr2k( uplo, 'No transpose', n-k-nb+1, nb, -one, a,
398  $ i+nb, j, desca, work, k+nb, 1, descw, one, a,
399  $ i+nb, j+nb, desca )
400 *
401 * Copy last subdiagonal element back into sub( A )
402 *
403  jx = min( indxg2l( j+nb-1, nb, 0, iacol, npcol ), nq )
404  CALL pselset( a, i+nb, j+nb-1, desca, e( jx ) )
405 *
406  descw( csrc_ ) = mod( descw( csrc_ ) + 1, npcol )
407 *
408  20 CONTINUE
409 *
410 * Use unblocked code to reduce the last or only block
411 *
412  CALL pssytd2( uplo, kk, a, ia+k-1, ja+k-1, desca, d, e,
413  $ tau, work, lwork, iinfo )
414  END IF
415 *
416  CALL pb_topset( ictxt, 'Combine', 'Columnwise', colctop )
417  CALL pb_topset( ictxt, 'Combine', 'Rowwise', rowctop )
418 *
419  work( 1 ) = real( lwmin )
420 *
421  RETURN
422 *
423 * End of PSSYTRD
424 *
425  END
pssytd2
subroutine pssytd2(UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK, LWORK, INFO)
Definition: pssytd2.f:3
max
#define max(A, B)
Definition: pcgemr.c:180
pssytrd
subroutine pssytrd(UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK, LWORK, INFO)
Definition: pssytrd.f:3
pselset
subroutine pselset(A, IA, JA, DESCA, ALPHA)
Definition: pselset.f:2
pslatrd
subroutine pslatrd(UPLO, N, NB, A, IA, JA, DESCA, D, E, TAU, W, IW, JW, DESCW, WORK)
Definition: pslatrd.f:3
pchk1mat
subroutine pchk1mat(MA, MAPOS0, NA, NAPOS0, IA, JA, DESCA, DESCAPOS0, NEXTRA, EX, EXPOS, INFO)
Definition: pchkxmat.f:3
descset
subroutine descset(DESC, M, N, MB, NB, IRSRC, ICSRC, ICTXT, LLD)
Definition: descset.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
min
#define min(A, B)
Definition: pcgemr.c:181