1 SUBROUTINE PCPTLASCHK( SYMM, UPLO, N, BWL, BWU, NRHS, X, IX, JX, 2 $ DESCX, IASEED, A, IA, JA, DESCA, IBSEED, 3 $ 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, 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 COMPLEX A( * ), WORK( * ), X( * ) 20* .. External Functions .. 21 LOGICAL LSAME 22* .. 23* 24* Purpose 25* ======= 26* 27* PCPTLASCHK 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 = 'H', sub( A ) is a hermitian distributed band 92* matrix, otherwise sub( A ) is a general distributed matrix. 93* 94* UPLO (global input) CHARACTER 95* if SYMM = 'H', 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* N (global input) INTEGER 104* The number of columns to be operated on, i.e. the number of 105* columns of the distributed submatrix sub( A ). N >= 0. 106* 107* NRHS (global input) INTEGER 108* The number of right-hand-sides, i.e the number of columns 109* of the distributed matrix sub( X ). NRHS >= 1. 110* 111* X (local input) COMPLEX pointer into the local memory 112* to an array of dimension (LLD_X,LOCq(JX+NRHS-1). This array 113* contains the local pieces of the answer vector(s) sub( X ) of 114* sub( A ) sub( X ) - B, split up over a column of processes. 115* 116* IX (global input) INTEGER 117* The row index in the global array X indicating the first 118* row of sub( X ). 119* 120* DESCX (global and local input) INTEGER array of dimension DLEN_. 121* The array descriptor for the distributed matrix X. 122* 123* IASEED (global input) INTEGER 124* The seed number to generate the original matrix Ao. 125* 126* JA (global input) INTEGER 127* The column index in the global array A indicating the 128* first column of sub( A ). 129* 130* DESCA (global and local input) INTEGER array of dimension DLEN_. 131* The array descriptor for the distributed matrix A. 132* 133* IBSEED (global input) INTEGER 134* The seed number to generate the original matrix B. 135* 136* ANORM (global input) REAL 137* The 1-norm or infinity norm of the distributed matrix 138* sub( A ). 139* 140* RESID (global output) REAL 141* The residual error: 142* ||sub( A )*sub( X )-B|| / (||sub( A )||*||sub( X )||*eps*N). 143* 144* WORK (local workspace) COMPLEX array, dimension (LWORK) 145* IF SYMM='S' 146* LWORK >= max(5,NB)+2*NB 147* IF SYMM!='S' or 'H' 148* LWORK >= max(5,NB)+2*NB 149* 150* WORKSIZ (local input) size of WORK. 151* 152* ===================================================================== 153* 154* Code Developer: Andrew J. Cleary, University of Tennessee. 155* Current address: Lawrence Livermore National Labs. 156* This version released: August, 2001. 157* 158* ===================================================================== 159* 160* .. Parameters .. 161 COMPLEX ZERO, ONE 162 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ), 163 $ ZERO = ( 0.0E+0, 0.0E+0 ) ) 164 INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_, 165 $ LLD_, MB_, M_, NB_, N_, RSRC_ 166 PARAMETER ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1, 167 $ CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6, 168 $ RSRC_ = 7, CSRC_ = 8, LLD_ = 9 ) 169 INTEGER INT_ONE 170 PARAMETER ( INT_ONE = 1 ) 171* .. 172* .. Local Scalars .. 173 INTEGER IACOL, IAROW, ICTXT, 174 $ IIA, IIX, IPB, IPW, 175 $ IXCOL, IXROW, J, JJA, JJX, LDA, 176 $ MYCOL, MYROW, NB, NP, NPCOL, NPROW, NQ 177 INTEGER I, START 178 INTEGER BW, INFO, IPPRODUCT, WORK_MIN 179 REAL DIVISOR, EPS, RESID1, NORMX 180* .. 181* .. Local Arrays .. 182* .. 183* .. External Subroutines .. 184 EXTERNAL BLACS_GRIDINFO, CGAMX2D, CGEMM, CGSUM2D, 185 $ CLASET, PBCTRAN, PCMATGEN, SGEBR2D, 186 $ SGEBS2D, SGERV2D, SGESD2D 187* .. 188* .. External Functions .. 189 INTEGER ICAMAX, NUMROC 190 REAL PSLAMCH 191 EXTERNAL ICAMAX, NUMROC, PSLAMCH 192* .. 193* .. Intrinsic Functions .. 194 INTRINSIC ABS, MAX, MIN, MOD, REAL 195* .. 196* .. Executable Statements .. 197* 198* Get needed initial parameters 199* 200 ICTXT = DESCA( CTXT_ ) 201 NB = DESCA( NB_ ) 202* 203 IF( LSAME( SYMM, 'H' ) ) THEN 204 BW = BWL 205 START = 1 206 WORK_MIN = MAX(5,NB)+2*NB 207 ELSE 208 BW = MAX(BWL, BWU) 209 IF( LSAME( UPLO, 'D' )) THEN 210 START = 1 211 ELSE 212 START = 2 213 ENDIF 214 WORK_MIN = MAX(5,NB)+2*NB 215 ENDIF 216* 217 IF ( WORKSIZ .LT. WORK_MIN ) THEN 218 CALL PXERBLA( ICTXT, 'PCTLASCHK', -18 ) 219 RETURN 220 END IF 221* 222 CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL ) 223* 224 EPS = PSLAMCH( ICTXT, 'eps' ) 225 RESID = 0.0E+0 226 DIVISOR = ANORM * EPS * REAL( N ) 227* 228 CALL INFOG2L( IA, JA, DESCA, NPROW, NPCOL, MYROW, MYCOL, IIA, JJA, 229 $ IAROW, IACOL ) 230 CALL INFOG2L( IX, JX, DESCX, NPROW, NPCOL, MYROW, MYCOL, IIX, JJX, 231 $ IXROW, IXCOL ) 232 NP = NUMROC( (2), DESCA( MB_ ), MYROW, 0, NPROW ) 233 NQ = NUMROC( N, DESCA( NB_ ), MYCOL, 0, NPCOL ) 234* 235 IPB = 1 236 IPPRODUCT = 1 + DESCA( NB_ ) 237 IPW = 1 + 2*DESCA( NB_ ) 238* 239 LDA = DESCA( LLD_ ) 240* 241* Regenerate A 242* 243 IF( LSAME( SYMM, 'H' )) THEN 244 CALL PCBMATGEN( ICTXT, UPLO, 'D', BW, BW, N, BW+1, 245 $ DESCA( NB_ ), A, DESCA( LLD_ ), 0, 0, 246 $ IASEED, MYROW, MYCOL, NPROW, NPCOL ) 247 ELSE 248* 249 CALL PCBMATGEN( ICTXT, 'N', UPLO, BWL, BWU, N, 250 $ DESCA( MB_ ), DESCA( NB_ ), A, 251 $ DESCA( LLD_ ), 0, 0, IASEED, MYROW, 252 $ MYCOL, NPROW, NPCOL ) 253 ENDIF 254 IF( LSAME( UPLO, 'U' ) ) THEN 255* 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.LT.NPCOL-1 ) THEN 263 CALL CGESD2D( ICTXT, 1, 1, 264 $ A( START+( DESCA( NB_ )-1 )*LDA ), 265 $ LDA, MYROW, MYCOL+1 ) 266 ENDIF 267* 268* Shift local elements 269* 270 DO 230 I=DESCA( NB_ )-1,0,-1 271 A( START+(I+1)*LDA ) = A( START+(I)*LDA ) 272 230 CONTINUE 273* 274* Receive elements from neighboring processors 275* 276 IF( MYCOL.GT.0 ) THEN 277 CALL CGERV2D( ICTXT, 1, 1, A( START), LDA, 278 $ MYROW, MYCOL-1 ) 279 ENDIF 280* 281 ENDIF 282* 283* Loop over the rhs 284* 285 RESID = 0.0 286* 287 DO 40 J = 1, NRHS 288* 289* Multiply A * current column of X 290* 291* 292 CALL PCPBDCMV( BW+1, BW, UPLO, N, A, 1, DESCA, 293 $ 1, X( 1 + (J-1)*DESCX( LLD_ )), 1, DESCX, 294 $ WORK( IPPRODUCT ), WORK( IPW ), (BW+2)*BW, INFO ) 295* 296* 297* Regenerate column of B 298* 299 CALL PCMATGEN( DESCX( CTXT_ ), 'No', 'No', DESCX( M_ ), 300 $ DESCX( N_ ), DESCX( MB_ ), DESCX( NB_ ), 301 $ WORK( IPB ), DESCX( LLD_ ), DESCX( RSRC_ ), 302 $ DESCX( CSRC_ ), IBSEED, 0, NQ, J-1, 1, MYCOL, 303 $ MYROW, NPCOL, NPROW ) 304* 305* Figure || A * X - B || & || X || 306* 307 CALL PCAXPY( N, -ONE, WORK( IPPRODUCT ), 1, 1, DESCX, 1, 308 $ WORK( IPB ), 1, 1, DESCX, 1 ) 309* 310 CALL PSCNRM2( N, NORMX, 311 $ X, 1, J, DESCX, 1 ) 312* 313 CALL PSCNRM2( N, RESID1, 314 $ WORK( IPB ), 1, 1, DESCX, 1 ) 315* 316* 317* Calculate residual = ||Ax-b|| / (||x||*||A||*eps*N) 318* 319 RESID1 = RESID1 / ( NORMX*DIVISOR ) 320* 321 RESID = MAX( RESID, RESID1 ) 322* 323 40 CONTINUE 324* 325 RETURN 326* 327* End of PCTLASCHK 328* 329 END 330