14 INTEGER dblesz, intgsz, memsiz, totmem
15 parameter( dblesz = 8, intgsz = 4, totmem = 2000000,
16 $ memsiz = totmem / dblesz )
17 INTEGER block_cyclic_2d, csrc_, ctxt_, dlen_, dt_,
18 $ lld_, mb_, m_, nb_, n_, rsrc_
19 parameter( block_cyclic_2d = 1, dlen_ = 9, dt_ = 1,
20 $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
21 $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
23 parameter( one = 1.0d+0 )
27 INTEGER iam, ictxt, info, ipa, ipacpy, ipb, ippiv, ipx,
28 $ ipw, lipiv, mycol, myrow, n, nb, nout, npcol,
29 $ nprocs, nprow, np, nq, nqrhs, nrhs, worksiz
30 DOUBLE PRECISION anorm, bnorm, eps, xnorm, resid
33 INTEGER desca( dlen_ ), descb( dlen_ ), descx( dlen_ )
34 DOUBLE PRECISION mem( memsiz )
37 EXTERNAL blacs_exit, blacs_get, blacs_gridexit,
38 $ blacs_gridinfo, blacs_gridinit, blacs_pinfo,
54 CALL blacs_pinfo( iam, nprocs )
55 CALL pdscaexinfo( outfile, nout, n, nrhs, nb, nprow, npcol, mem,
60 CALL blacs_get( -1, 0, ictxt )
61 CALL blacs_gridinit( ictxt,
'Row-major', nprow, npcol )
62 CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
67 IF( myrow.GE.nprow .OR. mycol.GE.npcol )
70 np =
numroc( n, nb, myrow, 0, nprow )
71 nq =
numroc( n, nb, mycol, 0, npcol )
72 nqrhs =
numroc( nrhs, nb, mycol, 0, npcol )
76 CALL descinit( desca, n, n, nb, nb, 0, 0, ictxt,
max( 1, np ),
78 CALL descinit( descb, n, nrhs, nb, nb, 0, 0, ictxt,
max( 1, np ),
80 CALL descinit( descx, n, nrhs, nb, nb, 0, 0, ictxt,
max( 1, np ),
87 ipacpy = ipa + desca( lld_ )*nq
88 ipb = ipacpy + desca( lld_ )*nq
89 ipx = ipb + descb( lld_ )*nqrhs
90 ippiv = ipx + descb( lld_ )*nqrhs
91 lipiv =
iceil( intgsz*( np+nb ), dblesz )
92 ipw = ippiv +
max( np, lipiv )
99 IF( ipw+worksiz.GT.memsiz )
THEN
101 $
WRITE( nout, fmt = 9998 )
'test', ( ipw+worksiz )*dblesz
107 CALL igsum2d( ictxt,
'All',
' ', 1, 1, info, 1, -1, 0 )
110 $
WRITE( nout, fmt = 9999 )
'MEMORY'
116 CALL pdlaread(
'DSCAEXMAT.dat', mem( ipa ), desca, 0, 0,
118 CALL pdlaread(
'DSCAEXRHS.dat', mem( ipb ), descb, 0, 0,
123 CALL pdlacpy(
'All', n, n, mem( ipa ), 1, 1, desca,
124 $ mem( ipacpy ), 1, 1, desca )
125 CALL pdlacpy(
'All', n, nrhs, mem( ipb ), 1, 1, descb,
126 $ mem( ipx ), 1, 1, descx )
133 WRITE( nout, fmt = * )
134 WRITE( nout, fmt = * )
135 $
'***********************************************'
136 WRITE( nout, fmt = * )
137 $
'Example of ScaLAPACK routine call: (PDGESV)'
138 WRITE( nout, fmt = * )
139 $
'***********************************************'
140 WRITE( nout, fmt = * )
141 WRITE( nout, fmt = * )
'A * X = B, Matrix A:'
142 WRITE( nout, fmt = * )
144 CALL pdlaprnt( n, n, mem( ipa ), 1, 1, desca, 0, 0,
145 $
'A', nout, mem( ipw ) )
147 WRITE( nout, fmt = * )
148 WRITE( nout, fmt = * )
'Matrix B:'
149 WRITE( nout, fmt = * )
151 CALL pdlaprnt( n, nrhs, mem( ipb ), 1, 1, descb, 0, 0,
152 $
'B', nout, mem( ipw ) )
154 CALL pdgesv( n, nrhs, mem( ipa ), 1, 1, desca, mem( ippiv ),
155 $ mem( ipb ), 1, 1, descb, info )
157 IF( myrow.EQ.0 .AND. mycol.EQ.0 )
THEN
158 WRITE( nout, fmt = * )
159 WRITE( nout, fmt = * )
'INFO code returned by PDGESV = ', info
160 WRITE( nout, fmt = * )
161 WRITE( nout, fmt = * )
'Matrix X = A^{-1} * B'
162 WRITE( nout, fmt = * )
164 CALL pdlaprnt( n, nrhs, mem( ipb ), 1, 1, descb, 0, 0,
'X', nout,
166 CALL pdlawrite(
'DSCAEXSOL.dat', n, nrhs, mem( ipb ), 1, 1, descb,
171 eps =
pdlamch( ictxt,
'Epsilon' )
172 anorm =
pdlange(
'I', n, n, mem( ipa ), 1, 1, desca, mem( ipw ) )
173 bnorm =
pdlange(
'I', n, nrhs, mem( ipb ), 1, 1, descb,
175 CALL pdgemm(
'No transpose',
'No transpose', n, nrhs, n, one,
176 $ mem( ipacpy ), 1, 1, desca, mem( ipb ), 1, 1, descb,
177 $ -one, mem( ipx ), 1, 1, descx )
178 xnorm =
pdlange(
'I', n, nrhs, mem( ipx ), 1, 1, descx,
180 resid = xnorm / ( anorm * bnorm * eps * dble( n ) )
182 IF( myrow.EQ.0 .AND. mycol.EQ.0 )
THEN
183 WRITE( nout, fmt = * )
184 WRITE( nout, fmt = * )
185 $
'||A * X - B|| / ( ||X|| * ||A|| * eps * N ) = ', resid
186 WRITE( nout, fmt = * )
187 IF( resid.LT.10.0d+0 )
THEN
188 WRITE( nout, fmt = * )
'The answer is correct.'
190 WRITE( nout, fmt = * )
'The answer is suspicious.'
196 CALL blacs_gridexit( ictxt )
203 WRITE( nout, fmt = * )
204 WRITE( nout, fmt = * )
205 WRITE( nout, fmt = 9997 )
206 WRITE( nout, fmt = * )
207 IF( nout.NE.6 .AND. nout.NE.0 )
213 9999
FORMAT(
'Bad ', a6,
' parameters: going on to next test case.' )
214 9998
FORMAT(
'Unable to perform ', a,
': need TOTMEM of at least',
216 9997
FORMAT(
'END OF TESTS.' )