! Collection of code snippets by Arne Vajhøj 
! (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
program pararrayloops
    use omp_lib
    parameter (n=10000000)
    real(kind=8) x(4,n)
    integer(kind=4) i,j,t1,t2
    !!!!call omp_set_num_threads(4)
    call system_clock(t1)
    !$omp parallel num_threads(4) private(i,j) shared(x)
    !$omp do
    do i = 1,4
        x(i,1)=1
        do j=2,n
            x(i,j)=sqrt(x(i,j-1)+i)
        end do
        !$omp critical
        write(*,*) omp_get_thread_num(),' of ',omp_get_num_threads(),' doing ', i
        !$omp end critical
        !$omp flush(x)
    end do
    !$omp end do
    !$omp end parallel
    call system_clock(t2)
    write(*,*) (x(i,n),i=1,4)
    write(*,*) t2-t1
end
