e.51.7.f90 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ! { dg-do run }
  2. ! { dg-require-effective-target offload_device }
  3. module e_51_7_mod
  4. integer, parameter :: THRESHOLD = 500
  5. contains
  6. subroutine init (v1, v2, N)
  7. integer :: i, N
  8. real :: v1(N), v2(N)
  9. do i = 1, N
  10. v1(i) = i + 2.0
  11. v2(i) = i - 3.0
  12. end do
  13. end subroutine
  14. subroutine check (p, N)
  15. integer :: i, N
  16. real, parameter :: EPS = 0.00001
  17. real :: diff, p(N)
  18. do i = 1, N
  19. diff = p(i) - (i + 2.0) * (i - 3.0)
  20. if (diff > EPS .or. -diff > EPS) call abort
  21. end do
  22. end subroutine
  23. subroutine vec_mult (N)
  24. use omp_lib, only: omp_is_initial_device
  25. real :: p(N), v1(N), v2(N)
  26. integer :: i, N
  27. call init (v1, v2, N)
  28. !$omp target data if(N > THRESHOLD) map(to: v1, v2) map(from: p)
  29. !$omp target
  30. if (omp_is_initial_device ()) call abort
  31. !$omp parallel do
  32. do i = 1, N
  33. p(i) = v1(i) * v2(i)
  34. end do
  35. !$omp end target
  36. !$omp end target data
  37. call check (p, N)
  38. end subroutine
  39. end module
  40. program e_51_7
  41. use e_51_7_mod, only : vec_mult
  42. integer :: n
  43. n = 1000
  44. call vec_mult (n)
  45. end program