
* ACML version 3.5 Copyright AMD,NAG 2006
*
      PROGRAM MAIN
      IMPLICIT         NONE
*     .. Parameters ..
      INTEGER          MAXNN, MAXN, NN
      PARAMETER        (MAXNN=50,MAXN=10000000,NN=11)
      INTEGER          MSEED, MSTATE
      PARAMETER        (MSEED=624,MSTATE=633)
*     .. Local Scalars ..
      INTEGER          GENID, INFO, J, LSEED, LSTATE, N, SUBID
*     .. Local Arrays ..
      INTEGER          ENS(NN), SEED(MSEED), STATE(MSTATE)
*     .. External Subroutines ..
      EXTERNAL         DOTIME, DRANDINITIALIZE
*     .. Data statements ..
      DATA             ENS/2, 5, 10, 20, 50, 100, 200, 500, 1000, 5000,
     *                 20000/
*     .. Executable Statements ..
      CONTINUE
*
*     Use the Mersenne twister generator as the base generator
*
      GENID = 3
      SUBID = 1
*
      LSTATE = MSTATE
      LSEED = 1
      SEED(1) = 1071958
*
      DO 20 J = 1, NN
*
         N = ENS(J)
*
*        To time different data, change ENS, NN, and MAXN, above,
*        accordingly.
*
         IF (N.GT.MAXN) THEN
            WRITE (*,FMT=*) 'N too large; increase MAXN.'
         ELSE
*
*           Initialize the Mersenne twister base generator
*
            CALL DRANDINITIALIZE(GENID,SUBID,SEED,LSEED,STATE,LSTATE,
     *                           INFO)
*
            CALL DOTIME(N,STATE)
*
         END IF
*
   20 CONTINUE
*
      END
*
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
*
      SUBROUTINE DOTIME(N,STATE)
*     .. Scalar Arguments ..
      INTEGER          N
*     .. Array Arguments ..
      INTEGER          STATE(*)
*     .. Local Scalars ..
      DOUBLE PRECISION A, AVTIME, B, TX, TX0, TX1
      INTEGER          I, INFO
*     .. Local Arrays ..
      DOUBLE PRECISION X(N)
*     .. External Functions ..
      DOUBLE PRECISION DSECND
      EXTERNAL         DSECND
*     .. External Subroutines ..
      EXTERNAL         DRANDUNIFORM
*     .. Intrinsic Functions ..
      INTRINSIC        DBLE, MIN
*     .. Executable Statements ..
      CONTINUE
*
*     Parameters for uniform distribution
*
      A = 0.0D0
      B = 1.0D0
*
*     Using DRANDUNIFORM
*
      TX = 1.0D30
      DO 20 I = 1, 1000
         TX0 = DSECND()
         CALL DRANDUNIFORM(N,A,B,STATE,X,INFO)
         TX1 = DSECND()
         IF (TX1-TX0.GT.0.0D0) TX = MIN(TX1-TX0,TX)
   20 CONTINUE
*
*     Print the results. Convert the times into milliseconds
*
      IF (INFO.EQ.0) THEN
         IF (TX.LE.0.0D0) THEN
            AVTIME = 0.0D0
         ELSE
            TX = DBLE(1000)*TX
            AVTIME = N/TX
         END IF
         WRITE (*,FMT=*) N, AVTIME
      ELSE
         WRITE (*,FMT=*) 'DRANDUNIFORM failed with INFO = ', INFO
      END IF
*
      RETURN
      END
