LAPACK  3.4.2 LAPACK: Linear Algebra PACKage
dchksy.f
Go to the documentation of this file.
1 *> \brief \b DCHKSY
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * SUBROUTINE DCHKSY( DOTYPE, NN, NVAL, NNB, NBVAL, NNS, NSVAL,
12 * THRESH, TSTERR, NMAX, A, AFAC, AINV, B, X,
13 * XACT, WORK, RWORK, IWORK, NOUT )
14 *
15 * .. Scalar Arguments ..
16 * LOGICAL TSTERR
17 * INTEGER NMAX, NN, NNB, NNS, NOUT
18 * DOUBLE PRECISION THRESH
19 * ..
20 * .. Array Arguments ..
21 * LOGICAL DOTYPE( * )
22 * INTEGER IWORK( * ), NBVAL( * ), NSVAL( * ), NVAL( * )
23 * DOUBLE PRECISION A( * ), AFAC( * ), AINV( * ), B( * ),
24 * \$ RWORK( * ), WORK( * ), X( * ), XACT( * )
25 * ..
26 *
27 *
28 *> \par Purpose:
29 * =============
30 *>
31 *> \verbatim
32 *>
33 *> DCHKSY tests DSYTRF, -TRI2, -TRS, -TRS2, -RFS, and -CON.
34 *> \endverbatim
35 *
36 * Arguments:
37 * ==========
38 *
39 *> \param[in] DOTYPE
40 *> \verbatim
41 *> DOTYPE is LOGICAL array, dimension (NTYPES)
42 *> The matrix types to be used for testing. Matrices of type j
43 *> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) =
44 *> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used.
45 *> \endverbatim
46 *>
47 *> \param[in] NN
48 *> \verbatim
49 *> NN is INTEGER
50 *> The number of values of N contained in the vector NVAL.
51 *> \endverbatim
52 *>
53 *> \param[in] NVAL
54 *> \verbatim
55 *> NVAL is INTEGER array, dimension (NN)
56 *> The values of the matrix dimension N.
57 *> \endverbatim
58 *>
59 *> \param[in] NNB
60 *> \verbatim
61 *> NNB is INTEGER
62 *> The number of values of NB contained in the vector NBVAL.
63 *> \endverbatim
64 *>
65 *> \param[in] NBVAL
66 *> \verbatim
67 *> NBVAL is INTEGER array, dimension (NBVAL)
68 *> The values of the blocksize NB.
69 *> \endverbatim
70 *>
71 *> \param[in] NNS
72 *> \verbatim
73 *> NNS is INTEGER
74 *> The number of values of NRHS contained in the vector NSVAL.
75 *> \endverbatim
76 *>
77 *> \param[in] NSVAL
78 *> \verbatim
79 *> NSVAL is INTEGER array, dimension (NNS)
80 *> The values of the number of right hand sides NRHS.
81 *> \endverbatim
82 *>
83 *> \param[in] THRESH
84 *> \verbatim
85 *> THRESH is DOUBLE PRECISION
86 *> The threshold value for the test ratios. A result is
87 *> included in the output file if RESULT >= THRESH. To have
88 *> every test ratio printed, use THRESH = 0.
89 *> \endverbatim
90 *>
91 *> \param[in] TSTERR
92 *> \verbatim
93 *> TSTERR is LOGICAL
94 *> Flag that indicates whether error exits are to be tested.
95 *> \endverbatim
96 *>
97 *> \param[in] NMAX
98 *> \verbatim
99 *> NMAX is INTEGER
100 *> The maximum value permitted for N, used in dimensioning the
101 *> work arrays.
102 *> \endverbatim
103 *>
104 *> \param[out] A
105 *> \verbatim
106 *> A is DOUBLE PRECISION array, dimension (NMAX*NMAX)
107 *> \endverbatim
108 *>
109 *> \param[out] AFAC
110 *> \verbatim
111 *> AFAC is DOUBLE PRECISION array, dimension (NMAX*NMAX)
112 *> \endverbatim
113 *>
114 *> \param[out] AINV
115 *> \verbatim
116 *> AINV is DOUBLE PRECISION array, dimension (NMAX*NMAX)
117 *> \endverbatim
118 *>
119 *> \param[out] B
120 *> \verbatim
121 *> B is DOUBLE PRECISION array, dimension (NMAX*NSMAX)
122 *> where NSMAX is the largest entry in NSVAL.
123 *> \endverbatim
124 *>
125 *> \param[out] X
126 *> \verbatim
127 *> X is DOUBLE PRECISION array, dimension (NMAX*NSMAX)
128 *> \endverbatim
129 *>
130 *> \param[out] XACT
131 *> \verbatim
132 *> XACT is DOUBLE PRECISION array, dimension (NMAX*NSMAX)
133 *> \endverbatim
134 *>
135 *> \param[out] WORK
136 *> \verbatim
137 *> WORK is DOUBLE PRECISION array, dimension
138 *> (NMAX*max(3,NSMAX))
139 *> \endverbatim
140 *>
141 *> \param[out] RWORK
142 *> \verbatim
143 *> RWORK is DOUBLE PRECISION array, dimension
144 *> (max(NMAX,2*NSMAX))
145 *> \endverbatim
146 *>
147 *> \param[out] IWORK
148 *> \verbatim
149 *> IWORK is INTEGER array, dimension (2*NMAX)
150 *> \endverbatim
151 *>
152 *> \param[in] NOUT
153 *> \verbatim
154 *> NOUT is INTEGER
155 *> The unit number for output.
156 *> \endverbatim
157 *
158 * Authors:
159 * ========
160 *
161 *> \author Univ. of Tennessee
162 *> \author Univ. of California Berkeley
163 *> \author Univ. of Colorado Denver
164 *> \author NAG Ltd.
165 *
166 *> \date April 2012
167 *
168 *> \ingroup double_lin
169 *
170 * =====================================================================
171  SUBROUTINE dchksy( DOTYPE, NN, NVAL, NNB, NBVAL, NNS, NSVAL,
172  \$ thresh, tsterr, nmax, a, afac, ainv, b, x,
173  \$ xact, work, rwork, iwork, nout )
174 *
175 * -- LAPACK test routine (version 3.4.1) --
176 * -- LAPACK is a software package provided by Univ. of Tennessee, --
177 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
178 * April 2012
179 *
180 * .. Scalar Arguments ..
181  LOGICAL tsterr
182  INTEGER nmax, nn, nnb, nns, nout
183  DOUBLE PRECISION thresh
184 * ..
185 * .. Array Arguments ..
186  LOGICAL dotype( * )
187  INTEGER iwork( * ), nbval( * ), nsval( * ), nval( * )
188  DOUBLE PRECISION a( * ), afac( * ), ainv( * ), b( * ),
189  \$ rwork( * ), work( * ), x( * ), xact( * )
190 * ..
191 *
192 * =====================================================================
193 *
194 * .. Parameters ..
195  DOUBLE PRECISION zero
196  parameter( zero = 0.0d+0 )
197  INTEGER ntypes
198  parameter( ntypes = 10 )
199  INTEGER ntests
200  parameter( ntests = 9 )
201 * ..
202 * .. Local Scalars ..
203  LOGICAL trfcon, zerot
204  CHARACTER dist, type, uplo, xtype
205  CHARACTER*3 path
206  INTEGER i, i1, i2, imat, in, inb, info, ioff, irhs,
207  \$ iuplo, izero, j, k, kl, ku, lda, lwork, mode,
208  \$ n, nb, nerrs, nfail, nimat, nrhs, nrun, nt
209  DOUBLE PRECISION anorm, cndnum, rcond, rcondc
210 * ..
211 * .. Local Arrays ..
212  CHARACTER uplos( 2 )
213  INTEGER iseed( 4 ), iseedy( 4 )
214  DOUBLE PRECISION result( ntests )
215 * ..
216 * .. External Functions ..
217  DOUBLE PRECISION dget06, dlansy
218  EXTERNAL dget06, dlansy
219 * ..
220 * .. External Subroutines ..
221  EXTERNAL alaerh, alahd, alasum, derrsy, dget04, dlacpy,
223  \$ dsycon, dsyrfs, dsyt01, dsytrf,
225 * ..
226 * .. Intrinsic Functions ..
227  INTRINSIC max, min
228 * ..
229 * .. Scalars in Common ..
230  LOGICAL lerr, ok
231  CHARACTER*32 srnamt
232  INTEGER infot, nunit
233 * ..
234 * .. Common blocks ..
235  common / infoc / infot, nunit, ok, lerr
236  common / srnamc / srnamt
237 * ..
238 * .. Data statements ..
239  DATA iseedy / 1988, 1989, 1990, 1991 /
240  DATA uplos / 'U', 'L' /
241 * ..
242 * .. Executable Statements ..
243 *
244 * Initialize constants and the random number seed.
245 *
246  path( 1: 1 ) = 'Double precision'
247  path( 2: 3 ) = 'SY'
248  nrun = 0
249  nfail = 0
250  nerrs = 0
251  DO 10 i = 1, 4
252  iseed( i ) = iseedy( i )
253  10 continue
254 *
255 * Test the error exits
256 *
257  IF( tsterr )
258  \$ CALL derrsy( path, nout )
259  infot = 0
260 *
261 * Set the minimum block size for which the block routine should
262 * be used, which will be later returned by ILAENV
263 *
264  CALL xlaenv( 2, 2 )
265 *
266 * Do for each value of N in NVAL
267 *
268  DO 180 in = 1, nn
269  n = nval( in )
270  lda = max( n, 1 )
271  xtype = 'N'
272  nimat = ntypes
273  IF( n.LE.0 )
274  \$ nimat = 1
275 *
276  izero = 0
277 *
278 * Do for each value of matrix type IMAT
279 *
280  DO 170 imat = 1, nimat
281 *
282 * Do the tests only if DOTYPE( IMAT ) is true.
283 *
284  IF( .NOT.dotype( imat ) )
285  \$ go to 170
286 *
287 * Skip types 3, 4, 5, or 6 if the matrix size is too small.
288 *
289  zerot = imat.GE.3 .AND. imat.LE.6
290  IF( zerot .AND. n.LT.imat-2 )
291  \$ go to 170
292 *
293 * Do first for UPLO = 'U', then for UPLO = 'L'
294 *
295  DO 160 iuplo = 1, 2
296  uplo = uplos( iuplo )
297 *
298 * Begin generate the test matrix A.
299 *
300 * Set up parameters with DLATB4 for the matrix generator
301 * based on the type of matrix to be generated.
302 *
303  CALL dlatb4( path, imat, n, n, type, kl, ku, anorm, mode,
304  \$ cndnum, dist )
305 *
306 * Generate a matrix with DLATMS.
307 *
308  srnamt = 'DLATMS'
309  CALL dlatms( n, n, dist, iseed, type, rwork, mode,
310  \$ cndnum, anorm, kl, ku, uplo, a, lda, work,
311  \$ info )
312 *
313 * Check error code from DLATMS and handle error.
314 *
315  IF( info.NE.0 ) THEN
316  CALL alaerh( path, 'DLATMS', info, 0, uplo, n, n, -1,
317  \$ -1, -1, imat, nfail, nerrs, nout )
318  go to 160
319  END IF
320 *
321 * For matrix types 3-6, zero one or more rows and
322 * columns of the matrix to test that INFO is returned
323 * correctly.
324 *
325  IF( zerot ) THEN
326  IF( imat.EQ.3 ) THEN
327  izero = 1
328  ELSE IF( imat.EQ.4 ) THEN
329  izero = n
330  ELSE
331  izero = n / 2 + 1
332  END IF
333 *
334  IF( imat.LT.6 ) THEN
335 *
336 * Set row and column IZERO to zero.
337 *
338  IF( iuplo.EQ.1 ) THEN
339  ioff = ( izero-1 )*lda
340  DO 20 i = 1, izero - 1
341  a( ioff+i ) = zero
342  20 continue
343  ioff = ioff + izero
344  DO 30 i = izero, n
345  a( ioff ) = zero
346  ioff = ioff + lda
347  30 continue
348  ELSE
349  ioff = izero
350  DO 40 i = 1, izero - 1
351  a( ioff ) = zero
352  ioff = ioff + lda
353  40 continue
354  ioff = ioff - izero
355  DO 50 i = izero, n
356  a( ioff+i ) = zero
357  50 continue
358  END IF
359  ELSE
360  ioff = 0
361  IF( iuplo.EQ.1 ) THEN
362 *
363 * Set the first IZERO rows and columns to zero.
364 *
365  DO 70 j = 1, n
366  i2 = min( j, izero )
367  DO 60 i = 1, i2
368  a( ioff+i ) = zero
369  60 continue
370  ioff = ioff + lda
371  70 continue
372  ELSE
373 *
374 * Set the last IZERO rows and columns to zero.
375 *
376  DO 90 j = 1, n
377  i1 = max( j, izero )
378  DO 80 i = i1, n
379  a( ioff+i ) = zero
380  80 continue
381  ioff = ioff + lda
382  90 continue
383  END IF
384  END IF
385  ELSE
386  izero = 0
387  END IF
388 *
389 * End generate the test matrix A.
390 *
391 * Do for each value of NB in NBVAL
392 *
393  DO 150 inb = 1, nnb
394 *
395 * Set the optimal blocksize, which will be later
396 * returned by ILAENV.
397 *
398  nb = nbval( inb )
399  CALL xlaenv( 1, nb )
400 *
401 * Copy the test matrix A into matrix AFAC which
402 * will be factorized in place. This is needed to
403 * preserve the test matrix A for subsequent tests.
404 *
405  CALL dlacpy( uplo, n, n, a, lda, afac, lda )
406 *
407 * Compute the L*D*L**T or U*D*U**T factorization of the
408 * matrix. IWORK stores details of the interchanges and
409 * the block structure of D. AINV is a work array for
410 * block factorization, LWORK is the length of AINV.
411 *
412  lwork = max( 2, nb )*lda
413  srnamt = 'DSYTRF'
414  CALL dsytrf( uplo, n, afac, lda, iwork, ainv, lwork,
415  \$ info )
416 *
417 * Adjust the expected value of INFO to account for
418 * pivoting.
419 *
420  k = izero
421  IF( k.GT.0 ) THEN
422  100 continue
423  IF( iwork( k ).LT.0 ) THEN
424  IF( iwork( k ).NE.-k ) THEN
425  k = -iwork( k )
426  go to 100
427  END IF
428  ELSE IF( iwork( k ).NE.k ) THEN
429  k = iwork( k )
430  go to 100
431  END IF
432  END IF
433 *
434 * Check error code from DSYTRF and handle error.
435 *
436  IF( info.NE.k )
437  \$ CALL alaerh( path, 'DSYTRF', info, k, uplo, n, n,
438  \$ -1, -1, nb, imat, nfail, nerrs, nout )
439 *
440 * Set the condition estimate flag if the INFO is not 0.
441 *
442  IF( info.NE.0 ) THEN
443  trfcon = .true.
444  ELSE
445  trfcon = .false.
446  END IF
447 *
448 *+ TEST 1
449 * Reconstruct matrix from factors and compute residual.
450 *
451  CALL dsyt01( uplo, n, a, lda, afac, lda, iwork, ainv,
452  \$ lda, rwork, result( 1 ) )
453  nt = 1
454 *
455 *+ TEST 2
456 * Form the inverse and compute the residual,
457 * if the factorization was competed without INFO > 0
458 * (i.e. there is no zero rows and columns).
459 * Do it only for the first block size.
460 *
461  IF( inb.EQ.1 .AND. .NOT.trfcon ) THEN
462  CALL dlacpy( uplo, n, n, afac, lda, ainv, lda )
463  srnamt = 'DSYTRI2'
464  lwork = (n+nb+1)*(nb+3)
465  CALL dsytri2( uplo, n, ainv, lda, iwork, work,
466  \$ lwork, info )
467 *
468 * Check error code from DSYTRI2 and handle error.
469 *
470  IF( info.NE.0 )
471  \$ CALL alaerh( path, 'DSYTRI2', info, -1, uplo, n,
472  \$ n, -1, -1, -1, imat, nfail, nerrs,
473  \$ nout )
474 *
475 * Compute the residual for a symmetric matrix times
476 * its inverse.
477 *
478  CALL dpot03( uplo, n, a, lda, ainv, lda, work, lda,
479  \$ rwork, rcondc, result( 2 ) )
480  nt = 2
481  END IF
482 *
483 * Print information about the tests that did not pass
484 * the threshold.
485 *
486  DO 110 k = 1, nt
487  IF( result( k ).GE.thresh ) THEN
488  IF( nfail.EQ.0 .AND. nerrs.EQ.0 )
489  \$ CALL alahd( nout, path )
490  WRITE( nout, fmt = 9999 )uplo, n, nb, imat, k,
491  \$ result( k )
492  nfail = nfail + 1
493  END IF
494  110 continue
495  nrun = nrun + nt
496 *
497 * Skip the other tests if this is not the first block
498 * size.
499 *
500  IF( inb.GT.1 )
501  \$ go to 150
502 *
503 * Do only the condition estimate if INFO is not 0.
504 *
505  IF( trfcon ) THEN
506  rcondc = zero
507  go to 140
508  END IF
509 *
510  DO 130 irhs = 1, nns
511  nrhs = nsval( irhs )
512 *
513 *+ TEST 3 ( Using TRS)
514 * Solve and compute residual for A * X = B.
515 *
516 * Choose a set of NRHS random solution vectors
517 * stored in XACT and set up the right hand side B
518 *
519  srnamt = 'DLARHS'
520  CALL dlarhs( path, xtype, uplo, ' ', n, n, kl, ku,
521  \$ nrhs, a, lda, xact, lda, b, lda,
522  \$ iseed, info )
523  CALL dlacpy( 'Full', n, nrhs, b, lda, x, lda )
524 *
525  srnamt = 'DSYTRS'
526  CALL dsytrs( uplo, n, nrhs, afac, lda, iwork, x,
527  \$ lda, info )
528 *
529 * Check error code from DSYTRS and handle error.
530 *
531  IF( info.NE.0 )
532  \$ CALL alaerh( path, 'DSYTRS', info, 0, uplo, n,
533  \$ n, -1, -1, nrhs, imat, nfail,
534  \$ nerrs, nout )
535 *
536  CALL dlacpy( 'Full', n, nrhs, b, lda, work, lda )
537 *
538 * Compute the residual for the solution
539 *
540  CALL dpot02( uplo, n, nrhs, a, lda, x, lda, work,
541  \$ lda, rwork, result( 3 ) )
542 *
543 *+ TEST 4 (Using TRS2)
544 *
545 * Solve and compute residual for A * X = B.
546 *
547 * Choose a set of NRHS random solution vectors
548 * stored in XACT and set up the right hand side B
549 *
550  srnamt = 'DLARHS'
551  CALL dlarhs( path, xtype, uplo, ' ', n, n, kl, ku,
552  \$ nrhs, a, lda, xact, lda, b, lda,
553  \$ iseed, info )
554  CALL dlacpy( 'Full', n, nrhs, b, lda, x, lda )
555 *
556  srnamt = 'DSYTRS2'
557  CALL dsytrs2( uplo, n, nrhs, afac, lda, iwork, x,
558  \$ lda, work, info )
559 *
560 * Check error code from DSYTRS2 and handle error.
561 *
562  IF( info.NE.0 )
563  \$ CALL alaerh( path, 'DSYTRS2', info, 0, uplo, n,
564  \$ n, -1, -1, nrhs, imat, nfail,
565  \$ nerrs, nout )
566 *
567  CALL dlacpy( 'Full', n, nrhs, b, lda, work, lda )
568 *
569 * Compute the residual for the solution
570 *
571  CALL dpot02( uplo, n, nrhs, a, lda, x, lda, work,
572  \$ lda, rwork, result( 4 ) )
573 *
574 *+ TEST 5
575 * Check solution from generated exact solution.
576 *
577  CALL dget04( n, nrhs, x, lda, xact, lda, rcondc,
578  \$ result( 5 ) )
579 *
580 *+ TESTS 6, 7, and 8
581 * Use iterative refinement to improve the solution.
582 *
583  srnamt = 'DSYRFS'
584  CALL dsyrfs( uplo, n, nrhs, a, lda, afac, lda,
585  \$ iwork, b, lda, x, lda, rwork,
586  \$ rwork( nrhs+1 ), work, iwork( n+1 ),
587  \$ info )
588 *
589 * Check error code from DSYRFS.
590 *
591  IF( info.NE.0 )
592  \$ CALL alaerh( path, 'DSYRFS', info, 0, uplo, n,
593  \$ n, -1, -1, nrhs, imat, nfail,
594  \$ nerrs, nout )
595 *
596  CALL dget04( n, nrhs, x, lda, xact, lda, rcondc,
597  \$ result( 6 ) )
598  CALL dpot05( uplo, n, nrhs, a, lda, b, lda, x, lda,
599  \$ xact, lda, rwork, rwork( nrhs+1 ),
600  \$ result( 7 ) )
601 *
602 * Print information about the tests that did not pass
603 * the threshold.
604 *
605  DO 120 k = 3, 8
606  IF( result( k ).GE.thresh ) THEN
607  IF( nfail.EQ.0 .AND. nerrs.EQ.0 )
608  \$ CALL alahd( nout, path )
609  WRITE( nout, fmt = 9998 )uplo, n, nrhs,
610  \$ imat, k, result( k )
611  nfail = nfail + 1
612  END IF
613  120 continue
614  nrun = nrun + 6
615  130 continue
616 *
617 *+ TEST 9
618 * Get an estimate of RCOND = 1/CNDNUM.
619 *
620  140 continue
621  anorm = dlansy( '1', uplo, n, a, lda, rwork )
622  srnamt = 'DSYCON'
623  CALL dsycon( uplo, n, afac, lda, iwork, anorm, rcond,
624  \$ work, iwork( n+1 ), info )
625 *
626 * Check error code from DSYCON and handle error.
627 *
628  IF( info.NE.0 )
629  \$ CALL alaerh( path, 'DSYCON', info, 0, uplo, n, n,
630  \$ -1, -1, -1, imat, nfail, nerrs, nout )
631 *
632 * Compute the test ratio to compare to values of RCOND
633 *
634  result( 9 ) = dget06( rcond, rcondc )
635 *
636 * Print information about the tests that did not pass
637 * the threshold.
638 *
639  IF( result( 9 ).GE.thresh ) THEN
640  IF( nfail.EQ.0 .AND. nerrs.EQ.0 )
641  \$ CALL alahd( nout, path )
642  WRITE( nout, fmt = 9997 )uplo, n, imat, 9,
643  \$ result( 9 )
644  nfail = nfail + 1
645  END IF
646  nrun = nrun + 1
647  150 continue
648 *
649  160 continue
650  170 continue
651  180 continue
652 *
653 * Print a summary of the results.
654 *
655  CALL alasum( path, nout, nfail, nrun, nerrs )
656 *
657  9999 format( ' UPLO = ''', a1, ''', N =', i5, ', NB =', i4, ', type ',
658  \$ i2, ', test ', i2, ', ratio =', g12.5 )
659  9998 format( ' UPLO = ''', a1, ''', N =', i5, ', NRHS=', i3, ', type ',
660  \$ i2, ', test(', i2, ') =', g12.5 )
661  9997 format( ' UPLO = ''', a1, ''', N =', i5, ',', 10x, ' type ', i2,
662  \$ ', test(', i2, ') =', g12.5 )
663  return
664 *
665 * End of DCHKSY
666 *
667  END