1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
      SUBROUTINE CLAHILBNNRHSALDAXLDXBLDBWORK
     $     INFOPATH)
!
!  -- LAPACK auxiliary test routine (version 3.2.2) --
!     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
!     Courant Institute, Argonne National Lab, and Rice University
*     June 2010
!
!     David Vu 
!     Yozo Hida 
!     Jason Riedy 
!     D. Halligan 
!
      IMPLICIT NONE
!     .. Scalar Arguments ..
      INTEGER NNRHSLDALDXLDBINFO
!     .. Array Arguments ..
      REAL WORK(N)
      COMPLEX A(LDA,N), X(LDXNRHS), B(LDBNRHS)
      CHARACTER*3        PATH
!     ..
!
!  Purpose
!  =======
!
!  CLAHILB generates an N by N scaled Hilbert matrix in A along with
!  NRHS right-hand sides in B and solutions in X such that A*X=B.
!
!  The Hilbert matrix is scaled by M = LCM(1, 2, ..., 2*N-1) so that all
!  entries are integers.  The right-hand sides are the first NRHS
!  columns of M * the identity matrix, and the solutions are the
!  first NRHS columns of the inverse Hilbert matrix.
!
!  The condition number of the Hilbert matrix grows exponentially with
!  its size, roughly as O(e ** (3.5*N)).  Additionally, the inverse
!  Hilbert matrices beyond a relatively small dimension cannot be
!  generated exactly without extra precision.  Precision is exhausted
!  when the largest entry in the inverse Hilbert matrix is greater than
!  2 to the power of the number of bits in the fraction of the data type
!  used plus one, which is 24 for single precision.
!
!  In single, the generated solution is exact for N <= 6 and has
!  small componentwise error for 7 <= N <= 11.
!
!  Arguments
!  =========
!
!  N       (input) INTEGER
!          The dimension of the matrix A.
!
!  NRHS    (input) INTEGER
!          The requested number of right-hand sides.
!
!  A       (output) COMPLEX array, dimension (LDA, N)
!          The generated scaled Hilbert matrix.
!
!  LDA     (input) INTEGER
!          The leading dimension of the array A.  LDA >= N.
!
!  X       (output) COMPLEX array, dimension (LDX, NRHS)
!          The generated exact solutions.  Currently, the first NRHS
!          columns of the inverse Hilbert matrix.
!
!  LDX     (input) INTEGER
!          The leading dimension of the array X.  LDX >= N.
!
!  B       (output) REAL array, dimension (LDB, NRHS)
!          The generated right-hand sides.  Currently, the first NRHS
!          columns of LCM(1, 2, ..., 2*N-1) * the identity matrix.
!
!  LDB     (input) INTEGER
!          The leading dimension of the array B.  LDB >= N.
!
!  WORK    (workspace) REAL array, dimension (N)
!
!
!  INFO    (output) INTEGER
!          = 0: successful exit
!          = 1: N is too large; the data is still generated but may not
!               be not exact.
!          < 0: if INFO = -i, the i-th argument had an illegal value
!
!  =====================================================================

!     .. Local Scalars ..
      INTEGER TMTIR
      INTEGER M
      INTEGER IJ
      COMPLEX TMP
      CHARACTER*2 C2

!     .. Parameters ..
!     NMAX_EXACT   the largest dimension where the generated data is
!                  exact.
!     NMAX_APPROX  the largest dimension where the generated data has
!                  a small componentwise relative error.
!     ??? complex uses how many bits ???
      INTEGER NMAX_EXACTNMAX_APPROXSIZE_D
      PARAMETER (NMAX_EXACT = 6NMAX_APPROX = 11SIZE_D = 8)

!     d's are generated from random permuation of those eight elements.
      COMPLEX D1(8), D2(8), INVD1(8), INVD2(8
      DATA D1 /(-1,0),(0,1),(-1,-1),(0,-1),(1,0),(-1,1),(1,1),(1,-1)/
      DATA D2 /(-1,0),(0,-1),(-1,1),(0,1),(1,0),(-1,-1),(1,-1),(1,1)/
      
      DATA INVD1 /(-1,0),(0,-1),(-.5,.5),(0,1),(1,0),
     $     (-.5,-.5),(.5,-.5),(.5,.5)/
      DATA INVD2 /(-1,0),(0,1),(-.5,-.5),(0,-1),(1,0),
     $     (-.5,.5),(.5,.5),(.5,-.5)/
      
!     ..
!     .. External Functions
      EXTERNAL CLASETLSAMEN
      INTRINSIC REAL
      LOGICAL LSAMEN
!     ..
!     .. Executable Statements ..
      C2 = PATH23 )
!
!     Test the input arguments
!
      INFO = 0
      IF (N .LT. 0 .OR. N .GT. NMAX_APPROXTHEN
         INFO = -1
      ELSE IF (NRHS .LT. 0THEN
         INFO = -2
      ELSE IF (LDA .LT. NTHEN
         INFO = -4
      ELSE IF (LDX .LT. NTHEN
         INFO = -6
      ELSE IF (LDB .LT. NTHEN
         INFO = -8
      END IF
      IF (INFO .LT. 0THEN
         CALL XERBLA('CLAHILB'-INFO)
         RETURN
      END IF
      IF (N .GT. NMAX_EXACTTHEN
         INFO = 1
      END IF

!     Compute M = the LCM of the integers [1, 2*N-1].  The largest
!     reasonable N is small enough that integers suffice (up to N = 11).
      M = 1
      DO I = 2, (2*N-1)
         TM = M
         TI = I
         R = MOD(TMTI)
         DO WHILE (R .NE. 0)
            TM = TI
            TI = R
            R = MOD(TMTI)
         END DO
         M = (M / TI* I
      END DO

!     Generate the scaled Hilbert matrix in A
!     If we are testing SY routines, take 
!          D1_i = D2_i, else, D1_i = D2_i*
      IF ( LSAMEN2C2'SY' ) ) THEN
         DO J = 1N
            DO I = 1N
               A(IJ= D1(MOD(J,SIZE_D)+1* (REAL(M/ (I + J - 1))
     $              * D1(MOD(I,SIZE_D)+1)
            END DO
         END DO
      ELSE
         DO J = 1N
            DO I = 1N
               A(IJ= D1(MOD(J,SIZE_D)+1* (REAL(M/ (I + J - 1))
     $              * D2(MOD(I,SIZE_D)+1)
            END DO
         END DO
      END IF

!     Generate matrix B as simply the first NRHS columns of M * the
!     identity.
      TMP = REAL(M)
      CALL CLASET('Full'NNRHS, (0.0,0.0), TMPBLDB)

!     Generate the true solutions in X.  Because B = the first NRHS
!     columns of M*I, the true solutions are just the first NRHS columns
!     of the inverse Hilbert matrix.
      WORK(1= N
      DO J = 2N
         WORK(J= (  ( (WORK(J-1)/(J-1)) * (J-1 - N) ) /(J-1)  )
     $        * (N +J -1)
      END DO
      
!     If we are testing SY routines, 
!            take D1_i = D2_i, else, D1_i = D2_i*
      IF ( LSAMEN2C2'SY' ) ) THEN
         DO J = 1NRHS
            DO I = 1N
               X(IJ= 
     $              INVD1(MOD(J,SIZE_D)+1*
     $              ((WORK(I)*WORK(J)) / (I + J - 1)) 
     $              * INVD1(MOD(I,SIZE_D)+1)
            END DO
         END DO
      ELSE
         DO J = 1NRHS
            DO I = 1N
               X(IJ=
     $              INVD2(MOD(J,SIZE_D)+1*
     $              ((WORK(I)*WORK(J)) / (I + J - 1))
     $              * INVD1(MOD(I,SIZE_D)+1)
            END DO
         END DO
      END IF
      END