optional-data-copyin.f90 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ! Test OpenACC data regions with a copy-in of optional arguments.
  2. ! { dg-do run }
  3. program test
  4. implicit none
  5. integer, parameter :: n = 64
  6. integer :: i
  7. integer :: a_int, b_int, c_int, res_int
  8. integer :: a_arr(n), b_arr(n), c_arr(n), res_arr(n)
  9. integer, allocatable :: a_alloc(:), b_alloc(:), c_alloc(:), res_alloc(:)
  10. a_int = 7
  11. b_int = 3
  12. c_int = 11
  13. call test_int(res_int, a_int)
  14. if (res_int .ne. a_int) stop 1
  15. call test_int(res_int, a_int, b_int)
  16. if (res_int .ne. a_int * b_int) stop 2
  17. call test_int(res_int, a_int, b_int, c_int)
  18. if (res_int .ne. a_int * b_int + c_int) stop 3
  19. do i = 1, n
  20. a_arr(i) = i
  21. b_arr(i) = n - i + 1
  22. c_arr(i) = i * 3
  23. end do
  24. call test_array(res_arr, a_arr)
  25. do i = 1, n
  26. if (res_arr(i) .ne. a_arr(i)) stop 4
  27. end do
  28. call test_array(res_arr, a_arr, b_arr)
  29. do i = 1, n
  30. if (res_arr(i) .ne. a_arr(i) * b_arr(i)) stop 5
  31. end do
  32. call test_array(res_arr, a_arr, b_arr, c_arr)
  33. do i = 1, n
  34. if (res_arr(i) .ne. a_arr(i) * b_arr(i) + c_arr(i)) stop 6
  35. end do
  36. allocate (a_alloc(n))
  37. allocate (b_alloc(n))
  38. allocate (c_alloc(n))
  39. allocate (res_alloc(n))
  40. do i = 1, n
  41. a_alloc(i) = i
  42. b_alloc(i) = n - i + 1
  43. c_alloc(i) = i * 3
  44. end do
  45. call test_allocatable(res_alloc, a_alloc)
  46. do i = 1, n
  47. if (res_alloc(i) .ne. a_alloc(i)) stop 7
  48. end do
  49. call test_allocatable(res_alloc, a_alloc, b_alloc)
  50. do i = 1, n
  51. if (res_alloc(i) .ne. a_alloc(i) * b_alloc(i)) stop 8
  52. end do
  53. call test_allocatable(res_alloc, a_alloc, b_alloc, c_alloc)
  54. do i = 1, n
  55. if (res_alloc(i) .ne. a_alloc(i) * b_alloc(i) + c_alloc(i)) stop 9
  56. end do
  57. deallocate (a_alloc)
  58. deallocate (b_alloc)
  59. deallocate (c_alloc)
  60. deallocate (res_alloc)
  61. contains
  62. subroutine test_int(res, a, b, c)
  63. integer :: res
  64. integer :: a
  65. integer, optional :: b, c
  66. !$acc data copyin(a, b, c) copyout(res)
  67. !$acc parallel
  68. res = a
  69. if (present(b)) res = res * b
  70. if (present(c)) res = res + c
  71. !$acc end parallel
  72. !$acc end data
  73. end subroutine test_int
  74. subroutine test_array(res, a, b, c)
  75. integer :: res(n)
  76. integer :: a(n)
  77. integer, optional :: b(n), c(n)
  78. !$acc data copyin(a, b, c) copyout(res)
  79. !$acc parallel loop
  80. do i = 1, n
  81. res(i) = a(i)
  82. end do
  83. !$acc parallel loop
  84. do i = 1, n
  85. if (present(b)) res(i) = res(i) * b(i)
  86. end do
  87. !$acc parallel loop
  88. do i = 1, n
  89. if (present(c)) res(i) = res(i) + c(i)
  90. end do
  91. !$acc end data
  92. end subroutine test_array
  93. subroutine test_allocatable(res, a, b, c)
  94. integer, allocatable :: res(:)
  95. integer, allocatable :: a(:)
  96. integer, allocatable, optional :: b(:), c(:)
  97. !$acc data copyin(a, b, c) copyout(res)
  98. !$acc parallel loop
  99. do i = 1, n
  100. res(i) = a(i)
  101. end do
  102. !$acc parallel loop
  103. do i = 1, n
  104. if (present(b)) res(i) = res(i) * b(i)
  105. end do
  106. !$acc parallel loop
  107. do i = 1, n
  108. if (present(c)) res(i) = res(i) + c(i)
  109. end do
  110. !$acc end data
  111. end subroutine test_allocatable
  112. end program test