program DepTest
implicit none
integer,parameter :: n=10000
integer(4) :: i
real(8) :: a(n), b(n), c(n), tmp(n)
real(8) :: s

! Initialize
a(:) = 1.0d0
b(:) = 2.0d0
c(:) = 5.0d0

! -- loop 1 -- Flow dependency
!$acc kernels
do i = 2, n
   a(i) =  a(i-1) +  b(i)
end do
!$acc end kernels

! -- loop 2 -- Flow dependency
!$acc kernels
do i = 1, n-1
   a(i+1) =  a(i) + b(i)
end do
!$acc end kernels

! -- loop 3 -- Anti-dependency
!$acc kernels
do i = 2, n
   a(i-1) =  a(i) + b(i)
end do
!$acc end kernels

! -- loop 3-1  -- Vecotorized/Parallelized
!$acc kernels
do i = 1, n
   tmp(i) =  a(i) + b(i)
end do
do i = 2, n
   a(i-1) =  tmp(i)
end do
!$acc end kernels

! -- loop 4 -- Anti-dependency
!$acc kernels
do i = 1, n-1
   a(i) =  a(i+1) + b(i)
end do
!$acc end kernels

! -- loop 5 -- Output Dependency
!$acc kernels
do i = 1, n-2
   a(i)   =  b(i)
   a(i+2) =  c(i)
end do
!$acc end kernels

! -- loop 6 -- Reduction 
s=0.0
!$acc kernels
do i = 1, n
   a(i) = b(i) + c(i)
   s = s + a(i)   
end do
!$acc end kernels

! 
print *, "a()=", a(n-1)
end program
