!-------------------------------------------------------------------- 
!                 Test OMP parallelization
!
      INTEGER, PARAMETER           :: NROW=256
      COMMON /AllSeeds/i24A(NROW)
      REAL(8)                      :: SUMM
!$OMP threadprivate (/AllSeeds/)

      Nseed = 121071
      NRAND = Nseed
      DO k = 1, NROW
!         write(*,*) k,NRAND
          Do j=1,NROW
          DO i=1,NROW
             x =GAUSS(NRAND)
            SUMM = SUMM + x**2
          EndDo 
          EndDo 
      EndDo 
write(*,*) ' Summ=',SUMM,x,NRAND
      Nseed = 121071
      CALL SetRandom(Nseed)
      SUMM =0.
!.... Open_MP                                                           
!$OMP PARALLEL DO DEFAULT(SHARED)  &                                     
!$OMP PRIVATE(i,j,k,NRAND,x) &
!$OMP COPYIN(/AllSeeds/) &
!$OMP REDUCTION(+:SUMM)
      DO k = 1, NROW 
            NRAND = i24A(k)
!         write(*,*) k,NRAND
          Do j=1,NROW
          DO i=1,NROW
             x =GAUSS(NRAND)
            SUMM = SUMM + x**2
          EndDo 
          EndDo 
      EndDo 
write(*,*) ' Summ=',SUMM,x,NRAND
            Stop
            End
!--------------------------------------------------                     
!                    :                Store seeds for parallelization 
!                                     of random number generator
!--------------------------------------------------                     
      SUBROUTINE SetRandom(Nseed)
      INTEGER, PARAMETER           :: NROW=256
!$OMP threadprivate (/AllSeeds/)
      COMMON /AllSeeds/i24A(NROW)

    NRAND = Nseed                  
   Do k=1,NROW                               ! gauss and randd
          i24A(k)  = NRAND
          Do j=1,NROW
             Do i=1,NROW
                x = GAUSS(NRAND)
             EndDo
          EndDo
   EndDo

        Return
        End

!--------------------------------------                                 
!				normal random numbers                                              
      FUNCTION GAUSS (M) 
!--------------------------------------                                 
      X = 0. 
      DO I = 1, 5 
      X = X + RANDd (M) 
      EndDo 
      X2 = 1.5491933 * (X - 2.5) 
      GAUSS = X2 * (1. - 0.01 * (3. - X2 * X2) ) 
      RETURN 
      END FUNCTION GAUSS                            
!------------------------------------------------                       
!				                                       random number generator     
      FUNCTION RANDd (M) 
!------------------------------------------------                       
      DATA LC, AM, KI, K1, K2, K3, K4, L1, L2, L3, L4	 / 453815927,     &
      2147483648., 2147483647, 536870912, 131072, 256, 	16777216, 4,    &
      16384, 8388608, 128 /                                             
      ML = M / K1 * K1 
      M1 = (M - ML) * L1 
      ML = M / K2 * K2 
      M2 = (M - ML) * L2 
      ML = M / K3 * K3 
      M3 = (M - ML) * L3 
      ML = M / K4 * K4 
      M4 = (M - ML) * L4 
      M5 = KI - M 
      IF (M1.GE.M5) M1 = M1 - KI - 1 
      ML = M + M1 
      M5 = KI - ML 
      IF (M2.GE.M5) M2 = M2 - KI - 1 
      ML = ML + M2 
      M5 = KI - ML 
      IF (M3.GE.M5) M3 = M3 - KI - 1 
      ML = ML + M3 
      M5 = KI - ML 
      IF (M4.GE.M5) M4 = M4 - KI - 1 
      ML = ML + M4 
      M5 = KI - ML 
      IF (LC.GE.M5) ML = ML - KI - 1 
      M = ML + LC 
      RANDd = M / AM 
      RETURN 
      END FUNCTION RANDd                            
