LLVM OpenMP
kmp_integer_8_apis.f90
Go to the documentation of this file.
1! REQUIRES: flang
2! RUN: %flang %flags %openmp_flags %s -o %t.exe
3! RUN: %t.exe
4
5! Fortran coverage of the 64-bit integer libomp entry points.
6!
7! The specific kmp_*_8 procedures are never named here. Every call uses the
8! generic omp_*/kmp_* name with integer(8) actual arguments, so generic
9! resolution in omp_lib is what selects the kmp_*_8 entry points. The 32-bit
10! getters are used to verify the effects.
11
13 use omp_lib
14 implicit none
15 integer :: fails, i
16 integer, parameter :: repetitions = 10
17
18 fails = 0
19
20 call test_disp_num_buffers()
21 call test_stacksize()
22 call test_blocktime()
23 call test_library()
24
25 do i = 1, repetitions
26 call test_num_threads_and_team()
27 call test_schedule()
28 call test_max_active_levels()
29 call test_teams()
30 call test_default_device()
31 call test_places()
32 call test_affinity_mask()
33 end do
34
35 call test_pause_resource()
36
37 if (fails /= 0) then
38 print *, fails, ' check(s) failed'
39 error stop 1
40 end if
41 print *, 'passed'
42
43contains
44
45 subroutine check(cond, msg)
46 logical, intent(in) :: cond
47 character(len=*), intent(in) :: msg
48 if (.not. cond) then
49 print *, 'FAIL: ', trim(msg)
50 fails = fails + 1
51 end if
52 end subroutine check
53
54 subroutine test_disp_num_buffers()
56 end subroutine test_disp_num_buffers
57
58 subroutine test_stacksize()
59 integer(8) :: want
60 integer(kmp_size_t_kind) :: got_s
61 want = 8_8 * 1024_8 * 1024_8
62 call kmp_set_stacksize(want)
63 call check(kmp_get_stacksize() == int(want, kind=omp_integer_kind), &
64 'kmp_set_stacksize(integer(8)) vs kmp_get_stacksize')
65 got_s = kmp_get_stacksize_s()
66 call check(got_s == int(want, kind=kmp_size_t_kind), &
67 'kmp_set_stacksize(integer(8)) vs kmp_get_stacksize_s')
68 end subroutine test_stacksize
69
70 subroutine test_blocktime()
71 call kmp_set_blocktime(200_8)
72 call check(kmp_get_blocktime() == 200, 'kmp_set_blocktime(integer(8))')
73 end subroutine test_blocktime
74
75 subroutine test_library()
76 ! enum library_type: none=0, serial=1, turnaround=2, throughput=3
77 call kmp_set_library(3_8)
78 call check(kmp_get_library() == 3, 'kmp_set_library(integer(8)) throughput')
79 call kmp_set_library(2_8)
80 call check(kmp_get_library() == 2, 'kmp_set_library(integer(8)) turnaround')
81 end subroutine test_library
82
83 subroutine test_num_threads_and_team()
84 integer :: nthreads, nthreads_lib, team_err
85 integer(8) :: level0, level1
86
87 nthreads = 0
88 nthreads_lib = -1
89 team_err = 0
90 level0 = 0_8
91 level1 = 1_8
92
93 call omp_set_dynamic(.false.)
94 call omp_set_num_threads(2_8)
95 call check(omp_get_max_threads() == 2, &
96 'omp_set_num_threads(integer(8)) max_threads')
97
98 call check(omp_get_ancestor_thread_num(level0) == 0, &
99 'omp_get_ancestor_thread_num(0_8) serial')
100 call check(omp_get_team_size(level0) == 1, &
101 'omp_get_team_size(0_8) serial')
102
103 !$omp parallel
104 if (omp_get_ancestor_thread_num(level1) /= omp_get_thread_num() .or. &
105 omp_get_team_size(level1) /= omp_get_num_threads() .or. &
106 omp_get_ancestor_thread_num(level0) /= 0 .or. &
107 omp_get_team_size(level0) /= 1) then
108 !$omp atomic
109 team_err = team_err + 1
110 end if
111 !$omp atomic
112 nthreads = nthreads + 1
113 !$omp single
114 nthreads_lib = omp_get_num_threads()
115 !$omp end single
116 !$omp end parallel
117
118 call check(team_err == 0, &
119 'omp_get_ancestor_thread_num / omp_get_team_size with integer(8)')
120 call check(nthreads == 2 .and. nthreads_lib == 2, 'parallel team size')
121
122 call omp_set_num_threads(int(huge(0_4), kind=8) + 1000_8)
123 call check(omp_get_max_threads() == huge(0_4), &
124 'omp_set_num_threads(integer(8)) clamp to INT_MAX')
125 call omp_set_num_threads(2_8)
126 end subroutine test_num_threads_and_team
127
128 subroutine test_schedule()
129 integer(omp_sched_kind) :: kind
130 integer(8) :: chunk
131
132 kind = omp_sched_static
133 chunk = 0_8
135 call omp_get_schedule(kind, chunk)
136 call check(kind == omp_sched_dynamic .and. chunk == 7_8, &
137 'omp_set/get_schedule with integer(8) chunk, dynamic')
138
140 call omp_get_schedule(kind, chunk)
141 call check(kind == omp_sched_guided .and. chunk == 1_8, &
142 'omp_set/get_schedule with integer(8) chunk, guided')
143 end subroutine test_schedule
144
145 subroutine test_max_active_levels()
147 call check(omp_get_max_active_levels() == 1, &
148 'omp_set_max_active_levels(1_8)')
150 call check(omp_get_max_active_levels() >= 1, &
151 'omp_set_max_active_levels(2_8)')
152 end subroutine test_max_active_levels
153
154 subroutine test_teams()
155 call omp_set_num_teams(5_8)
156 call check(omp_get_max_teams() == 5, 'omp_set_num_teams(5_8)')
157 call omp_set_teams_thread_limit(7_8)
158 call check(omp_get_teams_thread_limit() == 7, &
159 'omp_set_teams_thread_limit(7_8)')
160 end subroutine test_teams
161
162 subroutine test_default_device()
163 integer :: orig, after8, after32
164 orig = omp_get_default_device()
165 call omp_set_default_device(0_8)
166 after8 = omp_get_default_device()
167 call omp_set_default_device(0)
168 after32 = omp_get_default_device()
169 call check(after8 == after32, &
170 'omp_set_default_device: integer(8) vs default integer')
171 call omp_set_default_device(orig)
172 end subroutine test_default_device
173
174 subroutine test_places()
175 integer :: nplaces, n32, n8, npart, i
176 integer(omp_integer_kind), allocatable :: ids32(:), p32(:)
177 integer(8), allocatable :: ids8(:), p8(:)
178 integer(8) :: dummy(1)
179
180 nplaces = omp_get_num_places()
181 if (nplaces > 0) then
182 n32 = omp_get_place_num_procs(0)
183 n8 = omp_get_place_num_procs(0_8)
184 call check(n32 == n8, 'omp_get_place_num_procs(0_8)')
185 if (n32 > 0) then
186 allocate(ids32(n32), ids8(n32))
187 call omp_get_place_proc_ids(0, ids32)
188 call omp_get_place_proc_ids(0_8, ids8)
189 do i = 1, n32
190 call check(ids32(i) == int(ids8(i), kind=omp_integer_kind), &
191 'omp_get_place_proc_ids with integer(8) element')
192 end do
193 deallocate(ids32, ids8)
194 end if
195 else
196 call check(omp_get_place_num_procs(0_8) == omp_get_place_num_procs(0), &
197 'omp_get_place_num_procs(0_8) with no places')
198 end if
199
200 npart = omp_get_partition_num_places()
201 if (npart > 0) then
202 allocate(p32(npart), p8(npart))
203 call omp_get_partition_place_nums(p32)
204 call omp_get_partition_place_nums(p8)
205 do i = 1, npart
206 call check(p32(i) == int(p8(i), kind=omp_integer_kind), &
207 'omp_get_partition_place_nums with integer(8) element')
208 end do
209 deallocate(p32, p8)
210 else
211 dummy(1) = -1_8
212 call omp_get_partition_place_nums(dummy)
213 end if
214 end subroutine test_places
215
216 subroutine test_affinity_mask()
217 integer(kmp_affinity_mask_kind) :: mask
218 integer :: max_proc, rc_set, rc_set32
219 integer(8) :: proc0
220
221 proc0 = 0_8
222 call kmp_create_affinity_mask(mask)
223 max_proc = kmp_get_affinity_max_proc()
224 rc_set = kmp_set_affinity_mask_proc(proc0, mask)
225 rc_set32 = kmp_set_affinity_mask_proc(0, mask)
226 call check(rc_set == rc_set32, &
227 'kmp_set_affinity_mask_proc: integer(8) vs default integer')
228 if (rc_set == 0 .and. max_proc > 0) then
229 call check(kmp_get_affinity_mask_proc(proc0, mask) == 1, &
230 'kmp_get_affinity_mask_proc(integer(8)) after set')
231 call check(kmp_unset_affinity_mask_proc(proc0, mask) == 0, &
232 'kmp_unset_affinity_mask_proc(integer(8))')
233 call check(kmp_get_affinity_mask_proc(proc0, mask) == 0, &
234 'kmp_get_affinity_mask_proc(integer(8)) after unset')
235 else
236 rc_set = kmp_get_affinity_mask_proc(proc0, mask)
237 rc_set = kmp_unset_affinity_mask_proc(proc0, mask)
238 end if
239 call kmp_destroy_affinity_mask(mask)
240 end subroutine test_affinity_mask
241
242 subroutine test_pause_resource()
243 integer :: my_dev, nthreads
244 integer(8) :: device8
245
246 my_dev = omp_get_initial_device()
247 device8 = int(my_dev, kind=8)
248 nthreads = 0
249 !$omp parallel
250 !$omp single
251 nthreads = omp_get_num_threads()
252 !$omp end single
253 !$omp end parallel
254 call check(nthreads > 0, 'threads before pause')
255
256 call check(omp_pause_resource(omp_pause_soft, device8) == 0, &
257 'omp_pause_resource(integer(8) device) soft')
258 nthreads = 0
259 !$omp parallel
260 !$omp single
261 nthreads = omp_get_num_threads()
262 !$omp end single
263 !$omp end parallel
264 call check(nthreads > 0, 'threads after pause soft')
265
266 call check(omp_pause_resource(omp_pause_hard, device8) == 0, &
267 'omp_pause_resource(integer(8) device) hard')
268 nthreads = 0
269 !$omp parallel
270 !$omp single
271 nthreads = omp_get_num_threads()
272 !$omp end single
273 !$omp end parallel
274 call check(nthreads > 0, 'threads after pause hard')
275 end subroutine test_pause_resource
276
277end program kmp_integer_8_apis
void stop(char *errorMsg)
@ omp_sched_dynamic
Definition kmp.h:4491
@ omp_sched_guided
Definition kmp.h:4492
@ omp_sched_static
Definition kmp.h:4490
program kmp_integer_8_apis
#define kmp_set_disp_num_buffers
Definition kmp_stub.cpp:47
#define i
Definition kmp_stub.cpp:88
#define omp_set_max_active_levels
Definition kmp_stub.cpp:29
#define omp_set_num_threads
Definition kmp_stub.cpp:34
#define omp_set_schedule
Definition kmp_stub.cpp:30
#define omp_get_team_size
Definition kmp_stub.cpp:32
#define omp_get_ancestor_thread_num
Definition kmp_stub.cpp:31
#define omp_set_dynamic
Definition kmp_stub.cpp:36
#define kmp_set_blocktime
Definition kmp_stub.cpp:44
#define kmp_set_library
Definition kmp_stub.cpp:45
#define kmp_set_stacksize
Definition kmp_stub.cpp:42
Definition check.py:1
int omp_get_max_threads()
int omp_get_num_threads()