ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
psdtlaschk.f
Go to the documentation of this file.
1  SUBROUTINE psdtlaschk( SYMM, UPLO, TRANS, N, BWL, BWU, NRHS, X,
2  $ IX, JX, DESCX, IASEED, A, IA, JA, DESCA,
3  $ IBSEED, ANORM, RESID, WORK, WORKSIZ )
4 *
5 *
6 * -- ScaLAPACK routine (version 1.7) --
7 * University of Tennessee, Knoxville, Oak Ridge National Laboratory,
8 * and University of California, Berkeley.
9 * November 15, 1997
10 *
11 * .. Scalar Arguments ..
12  CHARACTER SYMM, TRANS, UPLO
13  INTEGER BWL, BWU, IA, IASEED, IBSEED,
14  $ ix, ja, jx, n, nrhs, worksiz
15  REAL ANORM, RESID
16 * ..
17 * .. Array Arguments ..
18  INTEGER DESCA( * ), DESCX( * )
19  REAL A( * ), WORK( * ), X( * )
20 * .. External Functions ..
21  LOGICAL LSAME
22 * ..
23 *
24 * Purpose
25 * =======
26 *
27 * PSDTLASCHK computes the residual
28 * || sub( A )*sub( X ) - B || / (|| sub( A ) ||*|| sub( X ) ||*eps*N)
29 * to check the accuracy of the factorization and solve steps in the
30 * LU and Cholesky decompositions, where sub( A ) denotes
31 * A(IA:IA+N-1,JA,JA+N-1), sub( X ) denotes X(IX:IX+N-1, JX:JX+NRHS-1).
32 *
33 * Notes
34 * =====
35 *
36 * Each global data object is described by an associated description
37 * vector. This vector stores the information required to establish
38 * the mapping between an object element and its corresponding process
39 * and memory location.
40 *
41 * Let A be a generic term for any 2D block cyclicly distributed array.
42 * Such a global array has an associated description vector DESCA.
43 * In the following comments, the character _ should be read as
44 * "of the global array".
45 *
46 * NOTATION STORED IN EXPLANATION
47 * --------------- -------------- --------------------------------------
48 * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case,
49 * DTYPE_A = 1.
50 * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
51 * the BLACS process grid A is distribu-
52 * ted over. The context itself is glo-
53 * bal, but the handle (the integer
54 * value) may vary.
55 * M_A (global) DESCA( M_ ) The number of rows in the global
56 * array A.
57 * N_A (global) DESCA( N_ ) The number of columns in the global
58 * array A.
59 * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute
60 * the rows of the array.
61 * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute
62 * the columns of the array.
63 * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
64 * row of the array A is distributed.
65 * CSRC_A (global) DESCA( CSRC_ ) The process column over which the
66 * first column of the array A is
67 * distributed.
68 * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local
69 * array. LLD_A >= MAX(1,LOCr(M_A)).
70 *
71 * Let K be the number of rows or columns of a distributed matrix,
72 * and assume that its process grid has dimension p x q.
73 * LOCr( K ) denotes the number of elements of K that a process
74 * would receive if K were distributed over the p processes of its
75 * process column.
76 * Similarly, LOCc( K ) denotes the number of elements of K that a
77 * process would receive if K were distributed over the q processes of
78 * its process row.
79 * The values of LOCr() and LOCc() may be determined via a call to the
80 * ScaLAPACK tool function, NUMROC:
81 * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
82 * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
83 * An upper bound for these quantities may be computed by:
84 * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
85 * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
86 *
87 * Arguments
88 * =========
89 *
90 * SYMM (global input) CHARACTER
91 * if SYMM = 'S', sub( A ) is a symmetric distributed band
92 * matrix, otherwise sub( A ) is a general distributed matrix.
93 *
94 * UPLO (global input) CHARACTER
95 * if SYMM = 'S', then
96 * if UPLO = 'L', the lower half of the matrix is stored
97 * if UPLO = 'U', the upper half of the matrix is stored
98 * if SYMM != 'S' or 'H', then
99 * if UPLO = 'D', the matrix is stable during factorization
100 * without interchanges
101 * if UPLO != 'D', the matrix is general
102 *
103 * TRANS if TRANS= 'T', A 'Transpose' is used as the
104 * coefficient matrix in the solve.
105 *
106 * N (global input) INTEGER
107 * The number of columns to be operated on, i.e. the number of
108 * columns of the distributed submatrix sub( A ). N >= 0.
109 *
110 * NRHS (global input) INTEGER
111 * The number of right-hand-sides, i.e the number of columns
112 * of the distributed matrix sub( X ). NRHS >= 1.
113 *
114 * X (local input) REAL pointer into the local memory
115 * to an array of dimension (LLD_X,LOCq(JX+NRHS-1). This array
116 * contains the local pieces of the answer vector(s) sub( X ) of
117 * sub( A ) sub( X ) - B, split up over a column of processes.
118 *
119 * IX (global input) INTEGER
120 * The row index in the global array X indicating the first
121 * row of sub( X ).
122 *
123 * DESCX (global and local input) INTEGER array of dimension DLEN_.
124 * The array descriptor for the distributed matrix X.
125 *
126 * IASEED (global input) INTEGER
127 * The seed number to generate the original matrix Ao.
128 *
129 * JA (global input) INTEGER
130 * The column index in the global array A indicating the
131 * first column of sub( A ).
132 *
133 * DESCA (global and local input) INTEGER array of dimension DLEN_.
134 * The array descriptor for the distributed matrix A.
135 *
136 * IBSEED (global input) INTEGER
137 * The seed number to generate the original matrix B.
138 *
139 * ANORM (global input) REAL
140 * The 1-norm or infinity norm of the distributed matrix
141 * sub( A ).
142 *
143 * RESID (global output) REAL
144 * The residual error:
145 * ||sub( A )*sub( X )-B|| / (||sub( A )||*||sub( X )||*eps*N).
146 *
147 * WORK (local workspace) REAL array, dimension (LWORK)
148 * IF SYMM='S'
149 * LWORK >= max(5,NB)+2*NB
150 * IF SYMM!='S' or 'H'
151 * LWORK >= max(5,NB)+2*NB
152 *
153 * WORKSIZ (local input) size of WORK.
154 *
155 * =====================================================================
156 *
157 * Code Developer: Andrew J. Cleary, University of Tennessee.
158 * Current address: Lawrence Livermore National Labs.
159 * This version released: August, 2001.
160 *
161 * =====================================================================
162 *
163 * .. Parameters ..
164  REAL ZERO, ONE
165  PARAMETER ( ONE = 1.0e+0, zero = 0.0e+0 )
166  INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
167  $ lld_, mb_, m_, nb_, n_, rsrc_
168  parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
169  $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
170  $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
171  INTEGER INT_ONE
172  PARAMETER ( INT_ONE = 1 )
173 * ..
174 * .. Local Scalars ..
175  INTEGER IACOL, IAROW, ICTXT,
176  $ IIA, IIX, IPB, IPW,
177  $ ixcol, ixrow, j, jja, jjx, lda,
178  $ mycol, myrow, nb, np, npcol, nprow, nq
179  INTEGER I, START
180  INTEGER BW, INFO, IPPRODUCT, WORK_MIN
181  REAL DIVISOR, EPS, RESID1, NORMX
182 * ..
183 * .. Local Arrays ..
184 * ..
185 * .. External Subroutines ..
186  EXTERNAL blacs_gridinfo, pbstran, psmatgen,
187  $ sgamx2d, sgebr2d, sgebs2d, sgemm,
188  $ sgerv2d, sgesd2d, sgsum2d, slaset
189 * ..
190 * .. External Functions ..
191  INTEGER ISAMAX, NUMROC
192  REAL PSLAMCH
193  EXTERNAL isamax, numroc, pslamch
194 * ..
195 * .. Intrinsic Functions ..
196  INTRINSIC abs, max, min, mod, real
197 * ..
198 * .. Executable Statements ..
199 *
200 * Get needed initial parameters
201 *
202  ictxt = desca( ctxt_ )
203  nb = desca( nb_ )
204 *
205  IF( lsame( symm, 'S' ) ) THEN
206  bw = bwl
207  start = 1
208  work_min = max(5,nb)+2*nb
209  ELSE
210  bw = max(bwl, bwu)
211  IF( lsame( uplo, 'D' )) THEN
212  start = 1
213  ELSE
214  start = 2
215  ENDIF
216  work_min = max(5,nb)+2*nb
217  ENDIF
218 *
219  IF ( worksiz .LT. work_min ) THEN
220  CALL pxerbla( ictxt, 'PSTLASCHK', -18 )
221  RETURN
222  END IF
223 *
224  CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
225 *
226  eps = pslamch( ictxt, 'eps' )
227  resid = 0.0e+0
228  divisor = anorm * eps * real( n )
229 *
230  CALL infog2l( ia, ja, desca, nprow, npcol, myrow, mycol, iia, jja,
231  $ iarow, iacol )
232  CALL infog2l( ix, jx, descx, nprow, npcol, myrow, mycol, iix, jjx,
233  $ ixrow, ixcol )
234  np = numroc( (3), desca( mb_ ), myrow, 0, nprow )
235  nq = numroc( n, desca( nb_ ), mycol, 0, npcol )
236 *
237  ipb = 1
238  ipproduct = 1 + desca( nb_ )
239  ipw = 1 + 2*desca( nb_ )
240 *
241  lda = desca( lld_ )
242 *
243 * Regenerate A
244 *
245  IF( lsame( symm, 'S' )) THEN
246  CALL psbmatgen( ictxt, uplo, 'D', bw, bw, n, bw+1,
247  $ desca( nb_ ), a, desca( lld_ ), 0, 0,
248  $ iaseed, myrow, mycol, nprow, npcol )
249  ELSE
250 *
251  CALL psbmatgen( ictxt, 'N', uplo, bwl, bwu, n,
252  $ desca( mb_ ), desca( nb_ ), a,
253  $ desca( lld_ ), 0, 0, iaseed, myrow,
254  $ mycol, nprow, npcol )
255  ENDIF
256 *
257 * Matrix formed above has the diagonals shifted from what was
258 * input to the tridiagonal routine. Shift them back.
259 *
260 * Send elements to neighboring processors
261 *
262  IF( mycol.GT.0 ) THEN
263  CALL sgesd2d( ictxt, 1, 1, a( start+2), lda,
264  $ myrow, mycol-1 )
265  ENDIF
266 *
267  IF( mycol.LT.npcol-1 ) THEN
268  CALL sgesd2d( ictxt, 1, 1,
269  $ a( start+( desca( nb_ )-1 )*lda ),
270  $ lda, myrow, mycol+1 )
271  ENDIF
272 *
273 * Shift local elements
274 *
275  DO 220 i=0,desca( nb_ )-1
276  a( start+2+(i)*lda ) = a( start+2+(i+1)*lda )
277  220 CONTINUE
278 *
279  DO 230 i=desca( nb_ )-1,0,-1
280  a( start+(i+1)*lda ) = a( start+(i)*lda )
281  230 CONTINUE
282 *
283 * Receive elements from neighboring processors
284 *
285  IF( mycol.LT.npcol-1 ) THEN
286  CALL sgerv2d( ictxt, 1, 1,
287  $ a( start+2+( desca( nb_ )-1 )*lda ),
288  $ lda, myrow, mycol+1 )
289  ENDIF
290 *
291  IF( mycol.GT.0 ) THEN
292  CALL sgerv2d( ictxt, 1, 1, a( start), lda,
293  $ myrow, mycol-1 )
294  ENDIF
295 *
296 * Loop over the rhs
297 *
298  resid = 0.0
299 *
300  DO 40 j = 1, nrhs
301 *
302 * Multiply A * current column of X
303 *
304 *
305  CALL psgbdcmv( bwl+bwu+1, bwl, bwu, trans, n, a, 1, desca,
306  $ 1, x( 1 + (j-1)*descx( lld_ )), 1, descx,
307  $ work( ipproduct ), work( ipw ),
308  $ (int_one+2)*int_one, info )
309 *
310 *
311 * Regenerate column of B
312 *
313  CALL psmatgen( descx( ctxt_ ), 'No', 'No', descx( m_ ),
314  $ descx( n_ ), descx( mb_ ), descx( nb_ ),
315  $ work( ipb ), descx( lld_ ), descx( rsrc_ ),
316  $ descx( csrc_ ), ibseed, 0, nq, j-1, 1, mycol,
317  $ myrow, npcol, nprow )
318 *
319 * Figure || A * X - B || & || X ||
320 *
321  CALL psaxpy( n, -one, work( ipproduct ), 1, 1, descx, 1,
322  $ work( ipb ), 1, 1, descx, 1 )
323 *
324  CALL psnrm2( n, normx,
325  $ x, 1, j, descx, 1 )
326 *
327  CALL psnrm2( n, resid1,
328  $ work( ipb ), 1, 1, descx, 1 )
329 *
330 *
331 * Calculate residual = ||Ax-b|| / (||x||*||A||*eps*N)
332 *
333  resid1 = resid1 / ( normx*divisor )
334 *
335  resid = max( resid, resid1 )
336 *
337  40 CONTINUE
338 *
339  RETURN
340 *
341 * End of PSTLASCHK
342 *
343  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
psgbdcmv
subroutine psgbdcmv(LDBW, BWL, BWU, TRANS, N, A, JA, DESCA, NRHS, B, IB, DESCB, X, WORK, LWORK, INFO)
Definition: psdbmv1.f:3
psmatgen
subroutine psmatgen(ICTXT, AFORM, DIAG, M, N, MB, NB, A, LDA, IAROW, IACOL, ISEED, IROFF, IRNUM, ICOFF, ICNUM, MYROW, MYCOL, NPROW, NPCOL)
Definition: psmatgen.f:4
psdtlaschk
subroutine psdtlaschk(SYMM, UPLO, TRANS, N, BWL, BWU, NRHS, X, IX, JX, DESCX, IASEED, A, IA, JA, DESCA, IBSEED, ANORM, RESID, WORK, WORKSIZ)
Definition: psdtlaschk.f:4
psbmatgen
subroutine psbmatgen(ICTXT, AFORM, AFORM2, BWL, BWU, N, MB, NB, A, LDA, IAROW, IACOL, ISEED, MYROW, MYCOL, NPROW, NPCOL)
Definition: psbmatgen.f:5
pbstran
subroutine pbstran(ICONTXT, ADIST, TRANS, M, N, NB, A, LDA, BETA, C, LDC, IAROW, IACOL, ICROW, ICCOL, WORK)
Definition: pbstran.f:3
pxerbla
subroutine pxerbla(ICTXT, SRNAME, INFO)
Definition: pxerbla.f:2
min
#define min(A, B)
Definition: pcgemr.c:181