This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_loop_bind_device.F90
249 lines (212 loc) · 7.16 KB
/
test_loop_bind_device.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
!===--- test_loop_bind_device.F90 ------------------------------------------===//
!
! OpenMP API Version 5.0 Nov 2018
!
! This test checks the loop directive with the bind(binding) clause. The bind
! clause indicates that the loop construct should apply in the context of the
! given binding, one of teams, parallel, or thread. Each of these bindings
! is tested in an appropriate context and the correctness of results of
! array operations in the nested loop is checked. This test checks these
! directives in a target context.
!
!//===----------------------------------------------------------------------===//
#include "ompvv.F90"
#define N 32
PROGRAM test_loop_bind_device
USE iso_fortran_env
USE ompvv_lib
USE omp_lib
implicit none
OMPVV_TEST_VERBOSE(test_bind_teams() .NE. 0)
OMPVV_TEST_VERBOSE(test_bind_parallel() .NE. 0)
OMPVV_TEST_VERBOSE(test_bind_thread_teams() .NE. 0)
OMPVV_TEST_VERBOSE(test_bind_thread_parallel() .NE. 0)
OMPVV_REPORT_AND_RETURN()
CONTAINS
INTEGER FUNCTION test_bind_teams()
INTEGER,DIMENSION(N,N):: x
INTEGER,DIMENSION(N):: y
INTEGER,DIMENSION(N):: z
INTEGER:: errors, num_teams, i, j
OMPVV_INFOMSG("test_loop_bind_teams")
errors = 0
num_teams = -1
DO i = 1, N
DO j = 1, N
x(j,i) = 1
END DO
y(i) = i
z(i) = 2*i
END DO
!$omp target teams num_teams(OMPVV_NUM_TEAMS_DEVICE) thread_limit(OMPVV_NUM_THREADS_DEVICE) map(tofrom: x, y, z, num_teams)
!$omp loop bind(teams) private(j)
DO i = 1, N
DO j = 1, N
x(j,i) = x(j,i) + y(i)*z(i)
END DO
END DO
!$omp end loop
!$omp parallel if(.FALSE.)
IF ( omp_get_team_num() .EQ. 0 ) THEN
num_teams = omp_get_num_teams()
END IF
!$omp end parallel
!$omp end target teams
DO i = 1, N
DO j = 1, N
OMPVV_TEST_AND_SET(errors, x(j,i) .NE. (1 + y(i)*z(i)))
END DO
END DO
OMPVV_ERROR_IF(errors .NE. 0, "Test generated wrong results on the output array x.")
OMPVV_WARNING_IF(num_teams .EQ. 1, "Test ran with one team, so parallelism of loop construct with bind(teams) can't be guaranteed.")
OMPVV_TEST_AND_SET_VERBOSE(errors, num_teams .LT. 1)
OMPVV_ERROR_IF(num_teams .LT. 1, "omp_get_num_teams() returned an invalid number of teams.")
test_bind_teams = errors
END FUNCTION test_bind_teams
INTEGER FUNCTION test_bind_parallel()
INTEGER,DIMENSION(N,N):: x
INTEGER,DIMENSION(N):: y
INTEGER,DIMENSION(N):: z
INTEGER:: errors, num_threads, i, j
OMPVV_INFOMSG("test_loop_bind_parallel")
errors = 0
num_threads = -1
DO i = 1, N
DO j = 1, N
x(j,i) = 1
END DO
y(i) = i
z(i) = 2*i
END DO
!$omp target parallel num_threads(OMPVV_NUM_THREADS_DEVICE) map(tofrom: x, y, z, num_threads)
!$omp loop bind(parallel)
DO i = 1, N
DO j = 1, N
x(j,i) = x(j,i) + y(i)*z(i)
END DO
END DO
!$omp end loop
IF ( (omp_get_thread_num() .EQ. 0) .AND. (omp_get_team_num() .EQ. 0) ) THEN
num_threads = omp_get_num_threads()
END IF
!$omp end target parallel
DO i = 1, N
DO j = 1, N
OMPVV_TEST_AND_SET(errors, x(j,i) .NE. (1 + y(i)*z(i)))
END DO
END DO
OMPVV_ERROR_IF(errors .NE. 0, "Test generated wrong results on the output array x.")
OMPVV_WARNING_IF(num_threads .EQ. 1, "Test ran with one thread, so parallelism of loop construct can't be guaranteed.")
OMPVV_TEST_AND_SET_VERBOSE(errors, num_threads .LT. 1)
OMPVV_ERROR_IF(num_threads .LT. 1, "omp_get_num_threads() returned an invalid number of threads.")
test_bind_parallel = errors
END FUNCTION test_bind_parallel
INTEGER FUNCTION test_bind_thread_teams()
INTEGER,DIMENSION(N):: y
INTEGER,DIMENSION(N):: z
INTEGER,DIMENSION(OMPVV_NUM_TEAMS_DEVICE,N,N):: outData
INTEGER,DIMENSION(N,N):: x
INTEGER:: errors, num_teams, i, j, k
OMPVV_INFOMSG("test_loop_bind_thread_teams")
errors = 0
num_teams = -1
DO i = 1, N
DO j = 1, N
DO k = 1, OMPVV_NUM_TEAMS_DEVICE
outData(k,j,i) = 1
END DO
END DO
y(i) = i
z(i) = 2*i
END DO
!$omp target teams num_teams(OMPVV_NUM_TEAMS_DEVICE) thread_limit(OMPVV_NUM_THREADS_DEVICE) private(x) map(tofrom: outData, y, z, num_teams)
DO i = 1, N
DO j = 1, N
x(j,i) = 1
END DO
END DO
!$omp loop bind(thread)
DO i = 1, N
DO j = 1, N
x(j,i) = x(j,i) + y(i)*z(i)
END DO
END DO
!$omp end loop
!$omp parallel if(.FALSE.)
IF ( omp_get_team_num() .EQ. 0 ) THEN
num_teams = omp_get_num_teams()
END IF
!$omp end parallel
DO i = 1, N
DO j = 1, N
outData(omp_get_team_num()+1,j,i) = x(j,i)
END DO
END DO
!$omp end target teams
DO i = 1, N
DO j = 1, N
DO k = 1, num_teams
OMPVV_TEST_AND_SET(errors, outData(k,j,i) .NE. (1 + y(i)*z(i)))
END DO
END DO
END DO
OMPVV_ERROR_IF(errors .NE. 0, "Test generated wrong results on the output array outData.")
OMPVV_WARNING_IF(num_teams .EQ. 1, "Test ran with one team, so parallelism of loop construct can't be guaranteed.")
OMPVV_TEST_AND_SET_VERBOSE(errors, num_teams .LT. 1)
OMPVV_ERROR_IF(num_teams .LT. 1, "omp_get_num_teams() returned an invalid number of teams.")
test_bind_thread_teams = errors
END FUNCTION test_bind_thread_teams
INTEGER FUNCTION test_bind_thread_parallel()
INTEGER,DIMENSION(N):: y
INTEGER,DIMENSION(N):: z
INTEGER,DIMENSION(OMPVV_NUM_THREADS_HOST,N,N):: outData
INTEGER,DIMENSION(N,N):: x
INTEGER:: errors, num_threads, i, j, k
OMPVV_INFOMSG("test_loop_bind_thread_parallel")
errors = 0
num_threads = -1
DO i = 1, N
DO j = 1, N
DO k = 1, OMPVV_NUM_THREADS_HOST
outData(k,j,i) = 1
END DO
END DO
y(i) = i
z(i) = 2*i
END DO
!$omp target parallel shared(outData) num_threads(OMPVV_NUM_THREADS_DEVICE) private(x) map(tofrom: outData, y, z, num_threads)
DO i = 1, N
DO j = 1, N
x(j,i) = 1
END DO
END DO
!$omp loop bind(thread)
DO i = 1, N
DO j = 1, N
x(j,i) = x(j,i) + y(i)*z(i)
END DO
END DO
!$omp end loop
IF ( omp_get_thread_num() .EQ. 0 ) THEN
num_threads = omp_get_num_threads()
END IF
DO i = 1, N
DO j = 1, N
outData(omp_get_thread_num()+1,j,i) = x(j,i)
END DO
END DO
!$omp end target parallel
DO i = 1, N
DO j = 1, N
DO k = 1, num_threads
OMPVV_TEST_AND_SET(errors, outData(k,j,i) .NE. (1 + y(i)*z(i)))
END DO
END DO
END DO
OMPVV_ERROR_IF(errors .NE. 0, "Test generated wrong results on the output array outData.")
OMPVV_WARNING_IF(num_threads .EQ. 1, "Test ran with one thread, so parallelism of loop construct can't be guaranteed.")
OMPVV_TEST_AND_SET_VERBOSE(errors, num_threads .LT. 1)
OMPVV_ERROR_IF(num_threads .LT. 1, "omp_get_num_threads() returned an invalid number of threads.")
test_bind_thread_parallel = errors
END FUNCTION test_bind_thread_parallel
END PROGRAM test_loop_bind_device