! To test parallel Ziggurat performance with OpenMP

program main
use omp_lib
use par_zig_mod
integer :: grainsize = 32
real(8) :: t1, t2, ru
real(4) :: r
integer :: i, j, len, status, kpar, npar, nt = 1000000
integer, allocatable :: seed(:)
character*(8) :: str

call get_command_argument(1, str, len, status)
read(str,'(i2)') npar
write(*,*) 'Use npar: ',npar
allocate(seed(npar))
call omp_set_num_threads(npar)
do i = 1,npar
    call random_number(r)
    seed(i) = 123456789*r
enddo
call par_zigset(npar, seed, grainsize)
t1 = omp_get_wtime()

!$omp parallel do private(j, ru, kpar)
do i = 1,1000
    kpar = omp_get_thread_num()
    do j = 1,nt
        ru = par_uni(kpar)
    enddo
enddo
!$omp end parallel do

t2 = omp_get_wtime()
write(*,*) 'Time: ',t2-t1
end

