blob: 66d03c40a58aaf71bbbad3c2bb644802acbaa407 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
2 * kmp_gsupport.c
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
Jim Cownie5e8470a2013-09-27 10:38:44 +000016#include "kmp.h"
17#include "kmp_atomic.h"
18
Andrey Churbanovd7d088f2015-04-29 16:42:24 +000019#if OMPT_SUPPORT
20#include "ompt-specific.h"
21#endif
22
Jim Cownie5e8470a2013-09-27 10:38:44 +000023#ifdef __cplusplus
24 extern "C" {
25#endif // __cplusplus
26
27#define MKLOC(loc,routine) \
28 static ident_t (loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;" };
29
Jim Cownie181b4bb2013-12-23 17:28:57 +000030#include "kmp_ftn_os.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000031
32void
Jim Cownie181b4bb2013-12-23 17:28:57 +000033xexpand(KMP_API_NAME_GOMP_BARRIER)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000034{
35 int gtid = __kmp_entry_gtid();
36 MKLOC(loc, "GOMP_barrier");
37 KA_TRACE(20, ("GOMP_barrier: T#%d\n", gtid));
38 __kmpc_barrier(&loc, gtid);
39}
40
41
Jim Cownie5e8470a2013-09-27 10:38:44 +000042//
43// Mutual exclusion
44//
45
46//
47// The symbol that icc/ifort generates for unnamed for unnamed critical
48// sections - .gomp_critical_user_ - is defined using .comm in any objects
49// reference it. We can't reference it directly here in C code, as the
50// symbol contains a ".".
51//
52// The RTL contains an assembly language definition of .gomp_critical_user_
53// with another symbol __kmp_unnamed_critical_addr initialized with it's
54// address.
55//
56extern kmp_critical_name *__kmp_unnamed_critical_addr;
57
58
59void
Jim Cownie181b4bb2013-12-23 17:28:57 +000060xexpand(KMP_API_NAME_GOMP_CRITICAL_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000061{
62 int gtid = __kmp_entry_gtid();
63 MKLOC(loc, "GOMP_critical_start");
64 KA_TRACE(20, ("GOMP_critical_start: T#%d\n", gtid));
65 __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
66}
67
68
69void
Jim Cownie181b4bb2013-12-23 17:28:57 +000070xexpand(KMP_API_NAME_GOMP_CRITICAL_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000071{
72 int gtid = __kmp_get_gtid();
73 MKLOC(loc, "GOMP_critical_end");
74 KA_TRACE(20, ("GOMP_critical_end: T#%d\n", gtid));
75 __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
76}
77
78
79void
Jim Cownie181b4bb2013-12-23 17:28:57 +000080xexpand(KMP_API_NAME_GOMP_CRITICAL_NAME_START)(void **pptr)
Jim Cownie5e8470a2013-09-27 10:38:44 +000081{
82 int gtid = __kmp_entry_gtid();
83 MKLOC(loc, "GOMP_critical_name_start");
84 KA_TRACE(20, ("GOMP_critical_name_start: T#%d\n", gtid));
85 __kmpc_critical(&loc, gtid, (kmp_critical_name *)pptr);
86}
87
88
89void
Jim Cownie181b4bb2013-12-23 17:28:57 +000090xexpand(KMP_API_NAME_GOMP_CRITICAL_NAME_END)(void **pptr)
Jim Cownie5e8470a2013-09-27 10:38:44 +000091{
92 int gtid = __kmp_get_gtid();
93 MKLOC(loc, "GOMP_critical_name_end");
94 KA_TRACE(20, ("GOMP_critical_name_end: T#%d\n", gtid));
95 __kmpc_end_critical(&loc, gtid, (kmp_critical_name *)pptr);
96}
97
98
99//
100// The Gnu codegen tries to use locked operations to perform atomic updates
101// inline. If it can't, then it calls GOMP_atomic_start() before performing
102// the update and GOMP_atomic_end() afterward, regardless of the data type.
103//
104
105void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000106xexpand(KMP_API_NAME_GOMP_ATOMIC_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000107{
108 int gtid = __kmp_entry_gtid();
109 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000110
111#if OMPT_SUPPORT
112 __ompt_thread_assign_wait_id(0);
113#endif
114
Jim Cownie5e8470a2013-09-27 10:38:44 +0000115 __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
116}
117
118
119void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000120xexpand(KMP_API_NAME_GOMP_ATOMIC_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000121{
122 int gtid = __kmp_get_gtid();
123 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
124 __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
125}
126
127
128int
Jim Cownie181b4bb2013-12-23 17:28:57 +0000129xexpand(KMP_API_NAME_GOMP_SINGLE_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000130{
131 int gtid = __kmp_entry_gtid();
132 MKLOC(loc, "GOMP_single_start");
133 KA_TRACE(20, ("GOMP_single_start: T#%d\n", gtid));
134
135 if (! TCR_4(__kmp_init_parallel))
136 __kmp_parallel_initialize();
137
138 //
139 // 3rd parameter == FALSE prevents kmp_enter_single from pushing a
140 // workshare when USE_CHECKS is defined. We need to avoid the push,
141 // as there is no corresponding GOMP_single_end() call.
142 //
143 return __kmp_enter_single(gtid, &loc, FALSE);
144}
145
146
147void *
Jim Cownie181b4bb2013-12-23 17:28:57 +0000148xexpand(KMP_API_NAME_GOMP_SINGLE_COPY_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000149{
150 void *retval;
151 int gtid = __kmp_entry_gtid();
152 MKLOC(loc, "GOMP_single_copy_start");
153 KA_TRACE(20, ("GOMP_single_copy_start: T#%d\n", gtid));
154
155 if (! TCR_4(__kmp_init_parallel))
156 __kmp_parallel_initialize();
157
158 //
159 // If this is the first thread to enter, return NULL. The generated
160 // code will then call GOMP_single_copy_end() for this thread only,
161 // with the copyprivate data pointer as an argument.
162 //
163 if (__kmp_enter_single(gtid, &loc, FALSE))
164 return NULL;
165
166 //
167 // Wait for the first thread to set the copyprivate data pointer,
168 // and for all other threads to reach this point.
169 //
170 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
171
172 //
173 // Retrieve the value of the copyprivate data point, and wait for all
174 // threads to do likewise, then return.
175 //
176 retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
177 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
178 return retval;
179}
180
181
182void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000183xexpand(KMP_API_NAME_GOMP_SINGLE_COPY_END)(void *data)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000184{
185 int gtid = __kmp_get_gtid();
Jim Cownie5e8470a2013-09-27 10:38:44 +0000186 KA_TRACE(20, ("GOMP_single_copy_end: T#%d\n", gtid));
187
188 //
189 // Set the copyprivate data pointer fo the team, then hit the barrier
190 // so that the other threads will continue on and read it. Hit another
191 // barrier before continuing, so that the know that the copyprivate
192 // data pointer has been propagated to all threads before trying to
193 // reuse the t_copypriv_data field.
194 //
195 __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
196 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
197 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
198}
199
200
201void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000202xexpand(KMP_API_NAME_GOMP_ORDERED_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000203{
204 int gtid = __kmp_entry_gtid();
205 MKLOC(loc, "GOMP_ordered_start");
206 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
207 __kmpc_ordered(&loc, gtid);
208}
209
210
211void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000212xexpand(KMP_API_NAME_GOMP_ORDERED_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000213{
214 int gtid = __kmp_get_gtid();
215 MKLOC(loc, "GOMP_ordered_end");
216 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
217 __kmpc_end_ordered(&loc, gtid);
218}
219
220
Jim Cownie5e8470a2013-09-27 10:38:44 +0000221//
222// Dispatch macro defs
223//
224// They come in two flavors: 64-bit unsigned, and either 32-bit signed
225// (IA-32 architecture) or 64-bit signed (Intel(R) 64).
226//
227
Jim Cownie181b4bb2013-12-23 17:28:57 +0000228#if KMP_ARCH_X86 || KMP_ARCH_ARM
Jim Cownie5e8470a2013-09-27 10:38:44 +0000229# define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
230# define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
231# define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
232#else
233# define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
234# define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
235# define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
236#endif /* KMP_ARCH_X86 */
237
238# define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
239# define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
240# define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
241
242
Jim Cownie5e8470a2013-09-27 10:38:44 +0000243//
244// The parallel contruct
245//
246
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000247#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000248static
249#endif /* KMP_DEBUG */
250void
251__kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
252 void *data)
253{
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000254#if OMPT_SUPPORT
255 kmp_info_t *thr;
256 ompt_frame_t *ompt_frame;
257 ompt_state_t enclosing_state;
258
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000259 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000260 // get pointer to thread data structure
261 thr = __kmp_threads[*gtid];
262
263 // save enclosing task state; set current state for task
264 enclosing_state = thr->th.ompt_thread_info.state;
265 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
266
267 // set task frame
268 ompt_frame = __ompt_get_task_frame_internal(0);
269 ompt_frame->exit_runtime_frame = __builtin_frame_address(0);
270 }
271#endif
272
Jim Cownie5e8470a2013-09-27 10:38:44 +0000273 task(data);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000274
275#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000276 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000277 // clear task frame
278 ompt_frame->exit_runtime_frame = NULL;
279
280 // restore enclosing state
281 thr->th.ompt_thread_info.state = enclosing_state;
282 }
283#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000284}
285
286
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000287#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000288static
289#endif /* KMP_DEBUG */
290void
291__kmp_GOMP_parallel_microtask_wrapper(int *gtid, int *npr,
292 void (*task)(void *), void *data, unsigned num_threads, ident_t *loc,
293 enum sched_type schedule, long start, long end, long incr, long chunk_size)
294{
295 //
296 // Intialize the loop worksharing construct.
297 //
298 KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
299 schedule != kmp_sch_static);
300
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000301#if OMPT_SUPPORT
302 kmp_info_t *thr;
303 ompt_frame_t *ompt_frame;
304 ompt_state_t enclosing_state;
305
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000306 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000307 thr = __kmp_threads[*gtid];
308 // save enclosing task state; set current state for task
309 enclosing_state = thr->th.ompt_thread_info.state;
310 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
311
312 // set task frame
313 ompt_frame = __ompt_get_task_frame_internal(0);
314 ompt_frame->exit_runtime_frame = __builtin_frame_address(0);
315 }
316#endif
317
Jim Cownie5e8470a2013-09-27 10:38:44 +0000318 //
319 // Now invoke the microtask.
320 //
321 task(data);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000322
323#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000324 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000325 // clear task frame
326 ompt_frame->exit_runtime_frame = NULL;
327
328 // reset enclosing state
329 thr->th.ompt_thread_info.state = enclosing_state;
330 }
331#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000332}
333
334
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000335#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000336static
337#endif /* KMP_DEBUG */
338void
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000339__kmp_GOMP_fork_call(ident_t *loc, int gtid, void (*unwrapped_task)(void *), microtask_t wrapper, int argc,...)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000340{
341 int rc;
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000342 kmp_info_t *thr = __kmp_threads[gtid];
343 kmp_team_t *team = thr->th.th_team;
344 int tid = __kmp_tid_from_gtid(gtid);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000345
346 va_list ap;
347 va_start(ap, argc);
348
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000349 rc = __kmp_fork_call(loc, gtid, fork_context_gnu, argc,
350#if OMPT_SUPPORT
351 VOLATILE_CAST(void *) unwrapped_task,
352#endif
353 wrapper, __kmp_invoke_task_func,
Andrey Churbanovcbda8682015-01-13 14:43:35 +0000354#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
Jim Cownie5e8470a2013-09-27 10:38:44 +0000355 &ap
356#else
357 ap
358#endif
359 );
360
361 va_end(ap);
362
363 if (rc) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000364 __kmp_run_before_invoked_task(gtid, tid, thr, team);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000365 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000366
Jonathan Peyton122dd762015-07-13 18:55:45 +0000367#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000368 if (ompt_enabled) {
Jonathan Peyton122dd762015-07-13 18:55:45 +0000369#if OMPT_TRACE
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000370 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
371 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
372
373 // implicit task callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000374 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000375 ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
376 team_info->parallel_id, task_info->task_id);
377 }
Jonathan Peyton122dd762015-07-13 18:55:45 +0000378#endif
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000379 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
380 }
381#endif
382}
383
384static void
385__kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid, void (*task)(void *))
386{
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000387#if OMPT_SUPPORT
Jonas Hahnfeld6c250b72016-03-21 12:37:52 +0000388 ompt_parallel_id_t ompt_parallel_id;
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000389 if (ompt_enabled) {
Jonas Hahnfeld6c250b72016-03-21 12:37:52 +0000390 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
391 task_info->frame.exit_runtime_frame = NULL;
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000392
Jonas Hahnfeld6c250b72016-03-21 12:37:52 +0000393 ompt_parallel_id = __ompt_parallel_id_new(gtid);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000394
395 // parallel region callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000396 if (ompt_callbacks.ompt_callback(ompt_event_parallel_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000397 int team_size = 1;
398 ompt_callbacks.ompt_callback(ompt_event_parallel_begin)(
Jonas Hahnfeld6c250b72016-03-21 12:37:52 +0000399 task_info->task_id, &task_info->frame, ompt_parallel_id,
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000400 team_size, (void *) task,
401 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000402 }
Jonas Hahnfeld6c250b72016-03-21 12:37:52 +0000403 }
404#endif
405
406 __kmp_serialized_parallel(loc, gtid);
407
408#if OMPT_SUPPORT
409 if (ompt_enabled) {
410 kmp_info_t *thr = __kmp_threads[gtid];
411
412 ompt_task_id_t my_ompt_task_id = __ompt_task_id_new(gtid);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000413
414 // set up lightweight task
415 ompt_lw_taskteam_t *lwt = (ompt_lw_taskteam_t *)
416 __kmp_allocate(sizeof(ompt_lw_taskteam_t));
417 __ompt_lw_taskteam_init(lwt, thr, gtid, (void *) task, ompt_parallel_id);
418 lwt->ompt_task_info.task_id = my_ompt_task_id;
419 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
420 __ompt_lw_taskteam_link(lwt, thr);
421
422#if OMPT_TRACE
423 // implicit task callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000424 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000425 ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
426 ompt_parallel_id, my_ompt_task_id);
427 }
428 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
429#endif
430 }
431#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000432}
433
434
435void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000436xexpand(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *), void *data, unsigned num_threads)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000437{
438 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000439
440#if OMPT_SUPPORT
441 ompt_frame_t *parent_frame;
442
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000443 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000444 parent_frame = __ompt_get_task_frame_internal(0);
445 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
446 }
447#endif
448
Jim Cownie5e8470a2013-09-27 10:38:44 +0000449 MKLOC(loc, "GOMP_parallel_start");
450 KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
451
452 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
453 if (num_threads != 0) {
454 __kmp_push_num_threads(&loc, gtid, num_threads);
455 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000456 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +0000457 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
458 }
459 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000460 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000461 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000462
463#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000464 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000465 parent_frame->reenter_runtime_frame = NULL;
466 }
467#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000468}
469
470
471void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000472xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000473{
474 int gtid = __kmp_get_gtid();
Jonathan Peytone8104ad2015-06-08 18:56:33 +0000475 kmp_info_t *thr;
476
477 thr = __kmp_threads[gtid];
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000478
Jim Cownie5e8470a2013-09-27 10:38:44 +0000479 MKLOC(loc, "GOMP_parallel_end");
480 KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
481
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000482
483#if OMPT_SUPPORT
484 ompt_parallel_id_t parallel_id;
485 ompt_frame_t *ompt_frame = NULL;
486
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000487 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000488 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
489 parallel_id = team_info->parallel_id;
490
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000491 // Record that we re-entered the runtime system in the implicit
492 // task frame representing the parallel region.
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000493 ompt_frame = __ompt_get_task_frame_internal(0);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000494 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000495
496#if OMPT_TRACE
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000497 if (ompt_enabled &&
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000498 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
499 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
500 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
501 parallel_id, task_info->task_id);
502 }
503#endif
504
505 // unlink if necessary. no-op if there is not a lightweight task.
506 ompt_lw_taskteam_t *lwt = __ompt_lw_taskteam_unlink(thr);
507 // GOMP allocates/frees lwt since it can't be kept on the stack
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000508 if (lwt) {
509 __kmp_free(lwt);
510
511#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000512 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000513 // Since a lightweight task was destroyed, make sure that the
514 // remaining deepest task knows the stack frame where the runtime
515 // was reentered.
516 ompt_frame = __ompt_get_task_frame_internal(0);
517 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
518 }
519#endif
520 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000521 }
522#endif
523
Jonathan Peyton57d19ce2015-08-26 19:55:13 +0000524 if (! thr->th.th_team->t.t_serialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000525 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
526 thr->th.th_team);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000527
528#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000529 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000530 // Set reenter frame in parent task, which will become current task
531 // in the midst of join. This is needed before the end_parallel callback.
532 ompt_frame = __ompt_get_task_frame_internal(1);
533 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
534 }
535#endif
536
Jonathan Peytonf89fbbb2015-08-31 18:15:00 +0000537 __kmp_join_call(&loc, gtid
538#if OMPT_SUPPORT
539 , fork_context_gnu
540#endif
541 );
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000542#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000543 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000544 ompt_frame->reenter_runtime_frame = NULL;
545 }
546#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000547 }
548 else {
549 __kmpc_end_serialized_parallel(&loc, gtid);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000550
551#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000552 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000553 // Record that we re-entered the runtime system in the frame that
554 // created the parallel region.
555 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
556
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000557 if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000558 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
559 ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000560 parallel_id, task_info->task_id,
561 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000562 }
563
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000564 ompt_frame->reenter_runtime_frame = NULL;
565
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000566 thr->th.ompt_thread_info.state =
567 (((thr->th.th_team)->t.t_serialized) ?
568 ompt_state_work_serial : ompt_state_work_parallel);
569 }
570#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000571 }
572}
573
574
Jim Cownie5e8470a2013-09-27 10:38:44 +0000575//
576// Loop worksharing constructs
577//
578
579//
580// The Gnu codegen passes in an exclusive upper bound for the overall range,
581// but the libguide dispatch code expects an inclusive upper bound, hence the
582// "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
583// argument to __kmp_GOMP_fork_call).
584//
585// Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
586// but the Gnu codegen expects an excluside upper bound, so the adjustment
587// "*p_ub += stride" compenstates for the discrepancy.
588//
589// Correction: the gnu codegen always adjusts the upper bound by +-1, not the
590// stride value. We adjust the dispatch parameters accordingly (by +-1), but
591// we still adjust p_ub by the actual stride value.
592//
593// The "runtime" versions do not take a chunk_sz parameter.
594//
595// The profile lib cannot support construct checking of unordered loops that
596// are predetermined by the compiler to be statically scheduled, as the gcc
597// codegen will not always emit calls to GOMP_loop_static_next() to get the
598// next iteration. Instead, it emits inline code to call omp_get_thread_num()
599// num and calculate the iteration space using the result. It doesn't do this
600// with ordered static loop, so they can be checked.
601//
602
603#define LOOP_START(func,schedule) \
604 int func (long lb, long ub, long str, long chunk_sz, long *p_lb, \
605 long *p_ub) \
606 { \
607 int status; \
608 long stride; \
609 int gtid = __kmp_entry_gtid(); \
610 MKLOC(loc, #func); \
611 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
612 gtid, lb, ub, str, chunk_sz )); \
613 \
614 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
615 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
616 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
617 (schedule) != kmp_sch_static); \
618 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
619 (kmp_int *)p_ub, (kmp_int *)&stride); \
620 if (status) { \
621 KMP_DEBUG_ASSERT(stride == str); \
622 *p_ub += (str > 0) ? 1 : -1; \
623 } \
624 } \
625 else { \
626 status = 0; \
627 } \
628 \
629 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
630 gtid, *p_lb, *p_ub, status)); \
631 return status; \
632 }
633
634
635#define LOOP_RUNTIME_START(func,schedule) \
636 int func (long lb, long ub, long str, long *p_lb, long *p_ub) \
637 { \
638 int status; \
639 long stride; \
640 long chunk_sz = 0; \
641 int gtid = __kmp_entry_gtid(); \
642 MKLOC(loc, #func); \
643 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
644 gtid, lb, ub, str, chunk_sz )); \
645 \
646 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
647 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
648 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
649 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
650 (kmp_int *)p_ub, (kmp_int *)&stride); \
651 if (status) { \
652 KMP_DEBUG_ASSERT(stride == str); \
653 *p_ub += (str > 0) ? 1 : -1; \
654 } \
655 } \
656 else { \
657 status = 0; \
658 } \
659 \
660 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
661 gtid, *p_lb, *p_ub, status)); \
662 return status; \
663 }
664
665
666#define LOOP_NEXT(func,fini_code) \
667 int func(long *p_lb, long *p_ub) \
668 { \
669 int status; \
670 long stride; \
671 int gtid = __kmp_get_gtid(); \
672 MKLOC(loc, #func); \
673 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
674 \
675 fini_code \
676 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
677 (kmp_int *)p_ub, (kmp_int *)&stride); \
678 if (status) { \
679 *p_ub += (stride > 0) ? 1 : -1; \
680 } \
681 \
682 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
683 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
684 return status; \
685 }
686
687
Jim Cownie181b4bb2013-12-23 17:28:57 +0000688LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
689LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
690LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START), kmp_sch_dynamic_chunked)
691LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
692LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_START), kmp_sch_guided_chunked)
693LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
694LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_START), kmp_sch_runtime)
695LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000696
Jim Cownie181b4bb2013-12-23 17:28:57 +0000697LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START), kmp_ord_static)
698LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000699 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000700LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START), kmp_ord_dynamic_chunked)
701LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000702 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000703LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
704LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000705 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000706LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START), kmp_ord_runtime)
707LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000708 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
709
710
711void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000712xexpand(KMP_API_NAME_GOMP_LOOP_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000713{
714 int gtid = __kmp_get_gtid();
715 KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
716
717 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
718
719 KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
720}
721
722
723void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000724xexpand(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000725{
726 KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
727}
728
729
Jim Cownie5e8470a2013-09-27 10:38:44 +0000730//
731// Unsigned long long loop worksharing constructs
732//
733// These are new with gcc 4.4
734//
735
736#define LOOP_START_ULL(func,schedule) \
737 int func (int up, unsigned long long lb, unsigned long long ub, \
738 unsigned long long str, unsigned long long chunk_sz, \
739 unsigned long long *p_lb, unsigned long long *p_ub) \
740 { \
741 int status; \
742 long long str2 = up ? ((long long)str) : -((long long)str); \
743 long long stride; \
744 int gtid = __kmp_entry_gtid(); \
745 MKLOC(loc, #func); \
746 \
747 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
748 gtid, up, lb, ub, str, chunk_sz )); \
749 \
750 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
751 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
752 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
753 (schedule) != kmp_sch_static); \
754 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
755 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
756 if (status) { \
757 KMP_DEBUG_ASSERT(stride == str2); \
758 *p_ub += (str > 0) ? 1 : -1; \
759 } \
760 } \
761 else { \
762 status = 0; \
763 } \
764 \
765 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
766 gtid, *p_lb, *p_ub, status)); \
767 return status; \
768 }
769
770
771#define LOOP_RUNTIME_START_ULL(func,schedule) \
772 int func (int up, unsigned long long lb, unsigned long long ub, \
773 unsigned long long str, unsigned long long *p_lb, \
774 unsigned long long *p_ub) \
775 { \
776 int status; \
777 long long str2 = up ? ((long long)str) : -((long long)str); \
778 unsigned long long stride; \
779 unsigned long long chunk_sz = 0; \
780 int gtid = __kmp_entry_gtid(); \
781 MKLOC(loc, #func); \
782 \
783 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
784 gtid, up, lb, ub, str, chunk_sz )); \
785 \
786 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
787 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
788 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, TRUE); \
789 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
790 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
791 if (status) { \
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000792 KMP_DEBUG_ASSERT((long long)stride == str2); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000793 *p_ub += (str > 0) ? 1 : -1; \
794 } \
795 } \
796 else { \
797 status = 0; \
798 } \
799 \
800 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
801 gtid, *p_lb, *p_ub, status)); \
802 return status; \
803 }
804
805
806#define LOOP_NEXT_ULL(func,fini_code) \
807 int func(unsigned long long *p_lb, unsigned long long *p_ub) \
808 { \
809 int status; \
810 long long stride; \
811 int gtid = __kmp_get_gtid(); \
812 MKLOC(loc, #func); \
813 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
814 \
815 fini_code \
816 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
817 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
818 if (status) { \
819 *p_ub += (stride > 0) ? 1 : -1; \
820 } \
821 \
822 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
823 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
824 return status; \
825 }
826
827
Jim Cownie181b4bb2013-12-23 17:28:57 +0000828LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START), kmp_sch_static)
829LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
830LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START), kmp_sch_dynamic_chunked)
831LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
832LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START), kmp_sch_guided_chunked)
833LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
834LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
835LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000836
Jim Cownie181b4bb2013-12-23 17:28:57 +0000837LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START), kmp_ord_static)
838LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000839 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000840LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START), kmp_ord_dynamic_chunked)
841LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000842 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000843LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
844LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000845 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000846LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START), kmp_ord_runtime)
847LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000848 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
849
850
Jim Cownie5e8470a2013-09-27 10:38:44 +0000851//
852// Combined parallel / loop worksharing constructs
853//
854// There are no ull versions (yet).
855//
856
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000857#define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000858 void func (void (*task) (void *), void *data, unsigned num_threads, \
859 long lb, long ub, long str, long chunk_sz) \
860 { \
861 int gtid = __kmp_entry_gtid(); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000862 MKLOC(loc, #func); \
863 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
864 gtid, lb, ub, str, chunk_sz )); \
865 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000866 ompt_pre(); \
867 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000868 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
869 if (num_threads != 0) { \
870 __kmp_push_num_threads(&loc, gtid, num_threads); \
871 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000872 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000873 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
874 task, data, num_threads, &loc, (schedule), lb, \
875 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
876 } \
877 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000878 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000879 } \
880 \
881 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
882 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
883 (schedule) != kmp_sch_static); \
884 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000885 ompt_post(); \
886 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000887 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
888 }
889
890
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000891
892#if OMPT_SUPPORT
893
894#define OMPT_LOOP_PRE() \
895 ompt_frame_t *parent_frame; \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000896 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000897 parent_frame = __ompt_get_task_frame_internal(0); \
898 parent_frame->reenter_runtime_frame = __builtin_frame_address(0); \
899 }
900
901
902#define OMPT_LOOP_POST() \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000903 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000904 parent_frame->reenter_runtime_frame = NULL; \
905 }
906
907#else
908
909#define OMPT_LOOP_PRE()
910
911#define OMPT_LOOP_POST()
912
913#endif
914
915
916PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
917 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
918PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
919 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
920PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
921 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
922PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
923 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000924
925
Jim Cownie5e8470a2013-09-27 10:38:44 +0000926//
927// Tasking constructs
928//
929
930void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000931xexpand(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data, void (*copy_func)(void *, void *),
Jonas Hahnfeld9dffeff2016-02-09 07:07:30 +0000932 long arg_size, long arg_align, bool if_cond, unsigned gomp_flags)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000933{
934 MKLOC(loc, "GOMP_task");
935 int gtid = __kmp_entry_gtid();
936 kmp_int32 flags = 0;
937 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *) & flags;
938
939 KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
940
941 // The low-order bit is the "tied" flag
942 if (gomp_flags & 1) {
943 input_flags->tiedness = 1;
944 }
Jonathan Peyton33d1d282015-10-13 18:36:22 +0000945 // The second low-order bit is the "final" flag
946 if (gomp_flags & 2) {
947 input_flags->final = 1;
948 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000949 input_flags->native = 1;
950 // __kmp_task_alloc() sets up all other flags
951
952 if (! if_cond) {
953 arg_size = 0;
954 }
955
956 kmp_task_t *task = __kmp_task_alloc(&loc, gtid, input_flags,
957 sizeof(kmp_task_t), arg_size ? arg_size + arg_align - 1 : 0,
958 (kmp_routine_entry_t)func);
959
960 if (arg_size > 0) {
961 if (arg_align > 0) {
962 task->shareds = (void *)((((size_t)task->shareds)
963 + arg_align - 1) / arg_align * arg_align);
964 }
965 //else error??
966
967 if (copy_func) {
968 (*copy_func)(task->shareds, data);
969 }
970 else {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000971 KMP_MEMCPY(task->shareds, data, arg_size);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000972 }
973 }
974
975 if (if_cond) {
976 __kmpc_omp_task(&loc, gtid, task);
977 }
978 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000979#if OMPT_SUPPORT
980 ompt_thread_info_t oldInfo;
981 kmp_info_t *thread;
982 kmp_taskdata_t *taskdata;
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000983 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000984 // Store the threads states and restore them after the task
985 thread = __kmp_threads[ gtid ];
986 taskdata = KMP_TASK_TO_TASKDATA(task);
987 oldInfo = thread->th.ompt_thread_info;
988 thread->th.ompt_thread_info.wait_id = 0;
989 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
990 taskdata->ompt_task_info.frame.exit_runtime_frame =
991 __builtin_frame_address(0);
992 }
993#endif
994
Jim Cownie5e8470a2013-09-27 10:38:44 +0000995 __kmpc_omp_task_begin_if0(&loc, gtid, task);
996 func(data);
997 __kmpc_omp_task_complete_if0(&loc, gtid, task);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000998
999#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001000 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001001 thread->th.ompt_thread_info = oldInfo;
1002 taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
1003 }
1004#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001005 }
1006
1007 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1008}
1009
1010
1011void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001012xexpand(KMP_API_NAME_GOMP_TASKWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001013{
1014 MKLOC(loc, "GOMP_taskwait");
1015 int gtid = __kmp_entry_gtid();
1016
1017 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1018
1019 __kmpc_omp_taskwait(&loc, gtid);
1020
1021 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1022}
1023
1024
Jim Cownie5e8470a2013-09-27 10:38:44 +00001025//
1026// Sections worksharing constructs
1027//
1028
1029//
1030// For the sections construct, we initialize a dynamically scheduled loop
1031// worksharing construct with lb 1 and stride 1, and use the iteration #'s
1032// that its returns as sections ids.
1033//
1034// There are no special entry points for ordered sections, so we always use
1035// the dynamically scheduled workshare, even if the sections aren't ordered.
1036//
1037
1038unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001039xexpand(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001040{
1041 int status;
1042 kmp_int lb, ub, stride;
1043 int gtid = __kmp_entry_gtid();
1044 MKLOC(loc, "GOMP_sections_start");
1045 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1046
1047 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1048
1049 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1050 if (status) {
1051 KMP_DEBUG_ASSERT(stride == 1);
1052 KMP_DEBUG_ASSERT(lb > 0);
1053 KMP_ASSERT(lb == ub);
1054 }
1055 else {
1056 lb = 0;
1057 }
1058
1059 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1060 (unsigned)lb));
1061 return (unsigned)lb;
1062}
1063
1064
1065unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001066xexpand(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001067{
1068 int status;
1069 kmp_int lb, ub, stride;
1070 int gtid = __kmp_get_gtid();
1071 MKLOC(loc, "GOMP_sections_next");
1072 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1073
1074 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1075 if (status) {
1076 KMP_DEBUG_ASSERT(stride == 1);
1077 KMP_DEBUG_ASSERT(lb > 0);
1078 KMP_ASSERT(lb == ub);
1079 }
1080 else {
1081 lb = 0;
1082 }
1083
1084 KA_TRACE(20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid,
1085 (unsigned)lb));
1086 return (unsigned)lb;
1087}
1088
1089
1090void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001091xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(void (*task) (void *), void *data,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001092 unsigned num_threads, unsigned count)
1093{
1094 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001095
1096#if OMPT_SUPPORT
1097 ompt_frame_t *parent_frame;
1098
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001099 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001100 parent_frame = __ompt_get_task_frame_internal(0);
1101 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
1102 }
1103#endif
1104
Jim Cownie5e8470a2013-09-27 10:38:44 +00001105 MKLOC(loc, "GOMP_parallel_sections_start");
1106 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1107
1108 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1109 if (num_threads != 0) {
1110 __kmp_push_num_threads(&loc, gtid, num_threads);
1111 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001112 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001113 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1114 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1115 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1116 }
1117 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001118 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001119 }
1120
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001121#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001122 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001123 parent_frame->reenter_runtime_frame = NULL;
1124 }
1125#endif
1126
Jim Cownie5e8470a2013-09-27 10:38:44 +00001127 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1128
1129 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1130}
1131
1132
1133void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001134xexpand(KMP_API_NAME_GOMP_SECTIONS_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001135{
1136 int gtid = __kmp_get_gtid();
1137 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1138
1139 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1140
1141 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1142}
1143
1144
1145void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001146xexpand(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001147{
1148 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1149}
1150
Jim Cownie181b4bb2013-12-23 17:28:57 +00001151// libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1152void
1153xexpand(KMP_API_NAME_GOMP_TASKYIELD)(void)
1154{
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001155 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1156 return;
Jim Cownie181b4bb2013-12-23 17:28:57 +00001157}
1158
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001159#if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1160
1161void
1162xexpand(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *), void *data, unsigned num_threads, unsigned int flags)
1163{
1164 int gtid = __kmp_entry_gtid();
1165 MKLOC(loc, "GOMP_parallel");
1166 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1167
1168 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1169 if (num_threads != 0) {
1170 __kmp_push_num_threads(&loc, gtid, num_threads);
1171 }
1172 if(flags != 0) {
1173 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1174 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001175 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001176 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
1177 }
1178 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001179 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001180 }
1181 task(data);
1182 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1183}
1184
1185void
1186xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task) (void *), void *data,
1187 unsigned num_threads, unsigned count, unsigned flags)
1188{
1189 int gtid = __kmp_entry_gtid();
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001190 MKLOC(loc, "GOMP_parallel_sections");
1191 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1192
1193 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1194 if (num_threads != 0) {
1195 __kmp_push_num_threads(&loc, gtid, num_threads);
1196 }
1197 if(flags != 0) {
1198 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1199 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001200 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001201 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1202 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1203 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1204 }
1205 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001206 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001207 }
1208
1209 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1210
1211 task(data);
1212 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1213 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1214}
1215
1216#define PARALLEL_LOOP(func, schedule) \
1217 void func (void (*task) (void *), void *data, unsigned num_threads, \
1218 long lb, long ub, long str, long chunk_sz, unsigned flags) \
1219 { \
1220 int gtid = __kmp_entry_gtid(); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001221 MKLOC(loc, #func); \
1222 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1223 gtid, lb, ub, str, chunk_sz )); \
1224 \
1225 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1226 if (num_threads != 0) { \
1227 __kmp_push_num_threads(&loc, gtid, num_threads); \
1228 } \
1229 if (flags != 0) { \
1230 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1231 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001232 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001233 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
1234 task, data, num_threads, &loc, (schedule), lb, \
1235 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1236 } \
1237 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001238 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001239 } \
1240 \
1241 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1242 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1243 (schedule) != kmp_sch_static); \
1244 task(data); \
1245 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1246 \
1247 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
1248 }
1249
1250PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC), kmp_sch_static)
1251PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC), kmp_sch_dynamic_chunked)
1252PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED), kmp_sch_guided_chunked)
1253PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME), kmp_sch_runtime)
1254
1255
1256void
1257xexpand(KMP_API_NAME_GOMP_TASKGROUP_START)(void)
1258{
1259 int gtid = __kmp_get_gtid();
1260 MKLOC(loc, "GOMP_taskgroup_start");
1261 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1262
1263 __kmpc_taskgroup(&loc, gtid);
1264
1265 return;
1266}
1267
1268void
1269xexpand(KMP_API_NAME_GOMP_TASKGROUP_END)(void)
1270{
1271 int gtid = __kmp_get_gtid();
1272 MKLOC(loc, "GOMP_taskgroup_end");
1273 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1274
1275 __kmpc_end_taskgroup(&loc, gtid);
1276
1277 return;
1278}
1279
1280#ifndef KMP_DEBUG
1281static
1282#endif /* KMP_DEBUG */
Jonathan Peyton66338292015-06-01 02:37:28 +00001283kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001284 kmp_int32 cncl_kind = 0;
1285 switch(gomp_kind) {
1286 case 1:
1287 cncl_kind = cancel_parallel;
1288 break;
1289 case 2:
1290 cncl_kind = cancel_loop;
1291 break;
1292 case 4:
1293 cncl_kind = cancel_sections;
1294 break;
1295 case 8:
1296 cncl_kind = cancel_taskgroup;
1297 break;
1298 }
1299 return cncl_kind;
1300}
1301
1302bool
1303xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which)
1304{
1305 if(__kmp_omp_cancellation) {
1306 KMP_FATAL(NoGompCancellation);
1307 }
1308 int gtid = __kmp_get_gtid();
1309 MKLOC(loc, "GOMP_cancellation_point");
1310 KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1311
Jonathan Peyton66338292015-06-01 02:37:28 +00001312 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001313
1314 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1315}
1316
1317bool
1318xexpand(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void)
1319{
1320 if(__kmp_omp_cancellation) {
1321 KMP_FATAL(NoGompCancellation);
1322 }
1323 KMP_FATAL(NoGompCancellation);
1324 int gtid = __kmp_get_gtid();
1325 MKLOC(loc, "GOMP_barrier_cancel");
1326 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1327
1328 return __kmpc_cancel_barrier(&loc, gtid);
1329}
1330
1331bool
1332xexpand(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel)
1333{
1334 if(__kmp_omp_cancellation) {
1335 KMP_FATAL(NoGompCancellation);
1336 } else {
1337 return FALSE;
1338 }
1339
1340 int gtid = __kmp_get_gtid();
1341 MKLOC(loc, "GOMP_cancel");
1342 KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1343
Jonathan Peyton66338292015-06-01 02:37:28 +00001344 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001345
1346 if(do_cancel == FALSE) {
1347 return xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1348 } else {
1349 return __kmpc_cancel(&loc, gtid, cncl_kind);
1350 }
1351}
1352
1353bool
1354xexpand(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void)
1355{
1356 if(__kmp_omp_cancellation) {
1357 KMP_FATAL(NoGompCancellation);
1358 }
1359 int gtid = __kmp_get_gtid();
1360 MKLOC(loc, "GOMP_sections_end_cancel");
1361 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1362
1363 return __kmpc_cancel_barrier(&loc, gtid);
1364}
1365
1366bool
1367xexpand(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void)
1368{
1369 if(__kmp_omp_cancellation) {
1370 KMP_FATAL(NoGompCancellation);
1371 }
1372 int gtid = __kmp_get_gtid();
1373 MKLOC(loc, "GOMP_loop_end_cancel");
1374 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1375
1376 return __kmpc_cancel_barrier(&loc, gtid);
1377}
1378
1379// All target functions are empty as of 2014-05-29
1380void
1381xexpand(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn) (void *), const void *openmp_target,
1382 size_t mapnum, void **hostaddrs, size_t *sizes, unsigned char *kinds)
1383{
1384 return;
1385}
1386
1387void
1388xexpand(KMP_API_NAME_GOMP_TARGET_DATA)(int device, const void *openmp_target, size_t mapnum,
1389 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1390{
1391 return;
1392}
1393
1394void
1395xexpand(KMP_API_NAME_GOMP_TARGET_END_DATA)(void)
1396{
1397 return;
1398}
1399
1400void
1401xexpand(KMP_API_NAME_GOMP_TARGET_UPDATE)(int device, const void *openmp_target, size_t mapnum,
1402 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1403{
1404 return;
1405}
1406
1407void
1408xexpand(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams, unsigned int thread_limit)
1409{
1410 return;
1411}
1412#endif // OMP_40_ENABLED
1413
1414
Jim Cownie181b4bb2013-12-23 17:28:57 +00001415/*
1416 The following sections of code create aliases for the GOMP_* functions,
1417 then create versioned symbols using the assembler directive .symver.
1418 This is only pertinent for ELF .so library
1419 xaliasify and xversionify are defined in kmp_ftn_os.h
1420*/
1421
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001422#ifdef KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001423
1424// GOMP_1.0 aliases
1425xaliasify(KMP_API_NAME_GOMP_ATOMIC_END, 10);
1426xaliasify(KMP_API_NAME_GOMP_ATOMIC_START, 10);
1427xaliasify(KMP_API_NAME_GOMP_BARRIER, 10);
1428xaliasify(KMP_API_NAME_GOMP_CRITICAL_END, 10);
1429xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10);
1430xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10);
1431xaliasify(KMP_API_NAME_GOMP_CRITICAL_START, 10);
1432xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10);
1433xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10);
1434xaliasify(KMP_API_NAME_GOMP_LOOP_END, 10);
1435xaliasify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10);
1436xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10);
1437xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10);
1438xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10);
1439xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10);
1440xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10);
1441xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10);
1442xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10);
1443xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10);
1444xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10);
1445xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10);
1446xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10);
1447xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10);
1448xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10);
1449xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10);
1450xaliasify(KMP_API_NAME_GOMP_ORDERED_END, 10);
1451xaliasify(KMP_API_NAME_GOMP_ORDERED_START, 10);
1452xaliasify(KMP_API_NAME_GOMP_PARALLEL_END, 10);
1453xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10);
1454xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10);
1455xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10);
1456xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10);
1457xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10);
1458xaliasify(KMP_API_NAME_GOMP_PARALLEL_START, 10);
1459xaliasify(KMP_API_NAME_GOMP_SECTIONS_END, 10);
1460xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10);
1461xaliasify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10);
1462xaliasify(KMP_API_NAME_GOMP_SECTIONS_START, 10);
1463xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10);
1464xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10);
1465xaliasify(KMP_API_NAME_GOMP_SINGLE_START, 10);
1466
1467// GOMP_2.0 aliases
Jim Cownie181b4bb2013-12-23 17:28:57 +00001468xaliasify(KMP_API_NAME_GOMP_TASK, 20);
1469xaliasify(KMP_API_NAME_GOMP_TASKWAIT, 20);
Jim Cownie181b4bb2013-12-23 17:28:57 +00001470xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20);
1471xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20);
1472xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20);
1473xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20);
1474xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20);
1475xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20);
1476xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20);
1477xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20);
1478xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20);
1479xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20);
1480xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20);
1481xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20);
1482xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20);
1483xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20);
1484xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20);
1485xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20);
1486
1487// GOMP_3.0 aliases
1488xaliasify(KMP_API_NAME_GOMP_TASKYIELD, 30);
1489
1490// GOMP_4.0 aliases
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001491// The GOMP_parallel* entry points below aren't OpenMP 4.0 related.
1492#if OMP_40_ENABLED
1493xaliasify(KMP_API_NAME_GOMP_PARALLEL, 40);
1494xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40);
1495xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40);
1496xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40);
1497xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40);
1498xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40);
1499xaliasify(KMP_API_NAME_GOMP_TASKGROUP_START, 40);
1500xaliasify(KMP_API_NAME_GOMP_TASKGROUP_END, 40);
1501xaliasify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40);
1502xaliasify(KMP_API_NAME_GOMP_CANCEL, 40);
1503xaliasify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40);
1504xaliasify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40);
1505xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40);
1506xaliasify(KMP_API_NAME_GOMP_TARGET, 40);
1507xaliasify(KMP_API_NAME_GOMP_TARGET_DATA, 40);
1508xaliasify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40);
1509xaliasify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40);
1510xaliasify(KMP_API_NAME_GOMP_TEAMS, 40);
1511#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001512
1513// GOMP_1.0 versioned symbols
1514xversionify(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1515xversionify(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1516xversionify(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1517xversionify(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1518xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1519xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1520xversionify(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1521xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1522xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1523xversionify(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1524xversionify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1525xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1526xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1527xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1528xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10, "GOMP_1.0");
1529xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1530xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1531xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1532xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10, "GOMP_1.0");
1533xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1534xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1535xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1536xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1537xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1538xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1539xversionify(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1540xversionify(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1541xversionify(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1542xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1543xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10, "GOMP_1.0");
1544xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1545xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10, "GOMP_1.0");
1546xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1547xversionify(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1548xversionify(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1549xversionify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1550xversionify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1551xversionify(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1552xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1553xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1554xversionify(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1555
1556// GOMP_2.0 versioned symbols
Jim Cownie181b4bb2013-12-23 17:28:57 +00001557xversionify(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1558xversionify(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
Jim Cownie181b4bb2013-12-23 17:28:57 +00001559xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1560xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1561xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1562xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1563xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20, "GOMP_2.0");
1564xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20, "GOMP_2.0");
1565xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20, "GOMP_2.0");
1566xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20, "GOMP_2.0");
1567xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20, "GOMP_2.0");
1568xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20, "GOMP_2.0");
1569xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20, "GOMP_2.0");
1570xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20, "GOMP_2.0");
1571xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1572xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1573xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1574xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1575
1576// GOMP_3.0 versioned symbols
1577xversionify(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1578
1579// GOMP_4.0 versioned symbols
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001580#if OMP_40_ENABLED
1581xversionify(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1582xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1583xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1584xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1585xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1586xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1587xversionify(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1588xversionify(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1589xversionify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1590xversionify(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1591xversionify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1592xversionify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1593xversionify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1594xversionify(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1595xversionify(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1596xversionify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1597xversionify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1598xversionify(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1599#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001600
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001601#endif // KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001602
Jim Cownie5e8470a2013-09-27 10:38:44 +00001603#ifdef __cplusplus
1604 } //extern "C"
1605#endif // __cplusplus
1606
1607