| 1 |
! { dg-do compile } |
| 2 |
! |
| 3 |
! This failed to compile the declare variant directive due to the C_PTR |
| 4 |
! arguments to foo being recognised as INTEGER(8) |
| 5 |
|
| 6 |
program adjust_args |
| 7 |
use iso_c_binding, only: c_loc |
| 8 |
implicit none |
| 9 |
|
| 10 |
integer, parameter :: N = 1024 |
| 11 |
real, allocatable, target :: av(:), bv(:), cv(:) |
| 12 |
|
| 13 |
call foo(c_loc(bv), c_loc(av), N) |
| 14 |
|
| 15 |
!$omp target data map(to: av(:N)) map(from: cv(:N)) |
| 16 |
!$omp parallel |
| 17 |
call foo(c_loc(cv), c_loc(av), N) |
| 18 |
!$omp end parallel |
| 19 |
!$omp end target data |
| 20 |
|
| 21 |
contains |
| 22 |
subroutine foo_variant(c_d_bv, c_d_av, n) |
| 23 |
use iso_c_binding, only: c_ptr, c_f_pointer |
| 24 |
type(c_ptr), intent(in) :: c_d_bv, c_d_av |
| 25 |
integer, intent(in) :: n |
| 26 |
real, pointer :: f_d_bv(:) |
| 27 |
real, pointer :: f_d_av(:) |
| 28 |
integer :: i |
| 29 |
|
| 30 |
call c_f_pointer(c_d_bv, f_d_bv, [n]) |
| 31 |
call c_f_pointer(c_d_av, f_d_av, [n]) |
| 32 |
!$omp target teams loop is_device_ptr(f_d_bv, f_d_av) |
| 33 |
do i = 1, n |
| 34 |
f_d_bv(i) = f_d_av(i) * i |
| 35 |
end do |
| 36 |
end subroutine |
| 37 |
|
| 38 |
|
| 39 |
subroutine foo(c_bv, c_av, n) |
| 40 |
use iso_c_binding, only: c_ptr, c_f_pointer |
| 41 |
type(c_ptr), intent(in) :: c_bv, c_av |
| 42 |
integer, intent(in) :: n |
| 43 |
real, pointer :: f_bv(:) |
| 44 |
real, pointer :: f_av(:) |
| 45 |
integer :: i |
| 46 |
!$omp declare variant(foo_variant) & |
| 47 |
!$omp match(construct={parallel}) |
| 48 |
|
| 49 |
call c_f_pointer(c_bv, f_bv, [n]) |
| 50 |
call c_f_pointer(c_av, f_av, [n]) |
| 51 |
!$omp parallel loop |
| 52 |
do i = 1, n |
| 53 |
f_bv(i) = f_av(i) * i |
| 54 |
end do |
| 55 |
end subroutine |
| 56 |
end program |