| 1 |
! The following directives are all 'pure' and should compile |
| 2 |
|
| 3 |
pure logical function func_assume(i) |
| 4 |
implicit none |
| 5 |
integer, value :: i |
| 6 |
!$omp assume holds(i > 5) |
| 7 |
func_assume = i < 3 |
| 8 |
!$omp end assume |
| 9 |
end |
| 10 |
|
| 11 |
pure logical function func_assumes() |
| 12 |
implicit none |
| 13 |
!$omp assumes absent(parallel) |
| 14 |
func_assumes = .false. |
| 15 |
end |
| 16 |
|
| 17 |
pure logical function func_reduction() |
| 18 |
implicit none |
| 19 |
!$omp declare reduction (foo : integer : omp_out = omp_out + omp_in) initializer (omp_priv = 0) |
| 20 |
func_reduction = .false. |
| 21 |
end |
| 22 |
|
| 23 |
pure logical function func_declare_simd() |
| 24 |
implicit none |
| 25 |
!$omp declare simd |
| 26 |
func_declare_simd = .false. |
| 27 |
end |
| 28 |
|
| 29 |
pure logical function func_declare_target() |
| 30 |
implicit none |
| 31 |
!$omp declare target |
| 32 |
func_declare_target = .false. |
| 33 |
end |
| 34 |
|
| 35 |
pure logical function func_error_1() |
| 36 |
implicit none |
| 37 |
!$omp error severity(warning) ! { dg-warning "OMP ERROR encountered" } |
| 38 |
func_error_1 = .false. |
| 39 |
end |
| 40 |
|
| 41 |
pure logical function func_error_2() |
| 42 |
implicit none |
| 43 |
!$omp error severity(warning) at(compilation) ! { dg-warning "OMP ERROR encountered" } |
| 44 |
func_error_2 = .false. |
| 45 |
end |
| 46 |
|
| 47 |
pure logical function func_error_3() |
| 48 |
implicit none |
| 49 |
!$omp error severity(warning) at(execution) ! { dg-error "OpenMP ERROR directive at .1. with 'at\\(execution\\)' clause in a PURE procedure" } |
| 50 |
func_error_3 = .false. |
| 51 |
end |
| 52 |
|
| 53 |
pure logical function func_nothing() |
| 54 |
implicit none |
| 55 |
!$omp nothing |
| 56 |
func_nothing = .false. |
| 57 |
end |
| 58 |
|
| 59 |
pure logical function func_scan(n) |
| 60 |
implicit none |
| 61 |
integer, value :: n |
| 62 |
integer :: i, r |
| 63 |
integer :: A(n) |
| 64 |
integer :: B(n) |
| 65 |
A = 0 |
| 66 |
B = 0 |
| 67 |
r = 0 |
| 68 |
!$omp simd reduction (inscan, +:r) |
| 69 |
do i = 1, 1024 |
| 70 |
r = r + a(i) |
| 71 |
!$omp scan inclusive(r) |
| 72 |
b(i) = i |
| 73 |
end do |
| 74 |
|
| 75 |
func_scan = b(1) == 3 |
| 76 |
end |
| 77 |
|
| 78 |
pure integer function func_simd(n) |
| 79 |
implicit none |
| 80 |
integer, value :: n |
| 81 |
integer :: j, r |
| 82 |
r = 0 |
| 83 |
!$omp simd reduction(+:r) |
| 84 |
do j = 1, n |
| 85 |
r = r + j |
| 86 |
end do |
| 87 |
func_simd = r |
| 88 |
end |
| 89 |
|
| 90 |
pure integer function func_unroll(n) |
| 91 |
implicit none |
| 92 |
integer, value :: n |
| 93 |
integer :: j, r |
| 94 |
r = 0 |
| 95 |
!$omp unroll partial(2) |
| 96 |
do j = 1, n |
| 97 |
r = r + j |
| 98 |
end do |
| 99 |
func_unroll = r |
| 100 |
end |
| 101 |
|
| 102 |
pure integer function func_tile(n) |
| 103 |
implicit none |
| 104 |
integer, value :: n |
| 105 |
integer :: j, r |
| 106 |
r = 0 |
| 107 |
!$omp tile sizes(2) |
| 108 |
do j = 1, n |
| 109 |
r = r + j |
| 110 |
end do |
| 111 |
func_tile = r |
| 112 |
end |
| 113 |
|
| 114 |
pure logical function func_metadirective() |
| 115 |
implicit none |
| 116 |
!$omp metadirective |
| 117 |
func_metadirective = .false. |
| 118 |
end |
| 119 |
|
| 120 |
! not 'parallel' not pure -> invalid in 5.2; + in general invalid in 5.1 |
| 121 |
pure logical function func_metadirective_2 () |
| 122 |
implicit none |
| 123 |
integer :: i, n |
| 124 |
n = 0 |
| 125 |
!$omp metadirective when (device={arch("nvptx")} : parallel do) ! { dg-error "OpenMP directive at .1. is not pure and thus may not appear in a PURE procedure" } |
| 126 |
do i = 1, 5 |
| 127 |
n = n + i |
| 128 |
end do |
| 129 |
end |
| 130 |
|
| 131 |
! unroll is supposed to be pure, so this case is OK |
| 132 |
pure logical function func_metadirective_3() |
| 133 |
implicit none |
| 134 |
integer :: i, n |
| 135 |
|
| 136 |
n = 0 |
| 137 |
!$omp metadirective when(device={arch("nvptx")} : unroll full) |
| 138 |
do i = 1, 5 |
| 139 |
n = n + i |
| 140 |
end do |
| 141 |
end |