| 1 |
! { dg-do run } |
| 2 |
|
| 3 |
program main |
| 4 |
use omp_lib |
| 5 |
|
| 6 |
implicit none |
| 7 |
|
| 8 |
integer, parameter :: N = 100 |
| 9 |
integer :: a(N) |
| 10 |
integer :: on_device_count = 0 |
| 11 |
integer :: i |
| 12 |
|
| 13 |
do i = 1, N |
| 14 |
a(i) = i |
| 15 |
end do |
| 16 |
|
| 17 |
do i = 0, omp_get_num_devices () |
| 18 |
on_device_count = on_device_count + f (a, i) |
| 19 |
end do |
| 20 |
|
| 21 |
if (on_device_count .ne. omp_get_num_devices ()) stop 1 |
| 22 |
|
| 23 |
do i = 1, N |
| 24 |
if (a(i) .ne. 2 * i) stop 2; |
| 25 |
end do |
| 26 |
contains |
| 27 |
integer function f (a, num) |
| 28 |
integer, intent(inout) :: a(N) |
| 29 |
integer, intent(in) :: num |
| 30 |
integer :: on_device |
| 31 |
integer :: i |
| 32 |
|
| 33 |
on_device = 0 |
| 34 |
!$omp metadirective & |
| 35 |
!$omp& when (target_device={device_num(num), kind("gpu")}: & |
| 36 |
!$omp& target parallel do map(to: a(1:N)), map(from: on_device)) & |
| 37 |
!$omp& default (parallel do private(on_device)) |
| 38 |
do i = 1, N |
| 39 |
a(i) = a(i) + i |
| 40 |
on_device = 1 |
| 41 |
end do |
| 42 |
f = on_device; |
| 43 |
end function |
| 44 |
end program |