target7.f90 745 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. ! { dg-do run }
  2. interface
  3. real function foo (x)
  4. !$omp declare target
  5. real, intent(in) :: x
  6. end function foo
  7. end interface
  8. integer, parameter :: n = 1000
  9. integer, parameter :: c = 100
  10. integer :: i, j
  11. real :: a(n)
  12. do i = 1, n
  13. a(i) = i
  14. end do
  15. !$omp parallel
  16. !$omp single
  17. do i = 1, n, c
  18. !$omp task shared(a)
  19. !$omp target map(a(i:i+c-1))
  20. !$omp parallel do
  21. do j = i, i + c - 1
  22. a(j) = foo (a(j))
  23. end do
  24. !$omp end target
  25. !$omp end task
  26. end do
  27. !$omp end single
  28. !$omp end parallel
  29. do i = 1, n
  30. if (a(i) /= i + 1) call abort
  31. end do
  32. end
  33. real function foo (x)
  34. !$omp declare target
  35. real, intent(in) :: x
  36. foo = x + 1
  37. end function foo