blob: 406b2795da7ea26efc6f9a3d851a36022825475f [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{
387 __kmp_serialized_parallel(loc, gtid);
388
389#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000390 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000391 ompt_task_id_t ompt_task_id = __ompt_get_task_id_internal(0);
392 ompt_frame_t *ompt_frame = __ompt_get_task_frame_internal(0);
393 kmp_info_t *thr = __kmp_threads[gtid];
394
395 ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(gtid);
396 ompt_task_id_t my_ompt_task_id = __ompt_task_id_new(gtid);
397
398 ompt_frame->exit_runtime_frame = NULL;
399
400 // parallel region callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000401 if (ompt_callbacks.ompt_callback(ompt_event_parallel_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000402 int team_size = 1;
403 ompt_callbacks.ompt_callback(ompt_event_parallel_begin)(
404 ompt_task_id, ompt_frame, ompt_parallel_id,
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000405 team_size, (void *) task,
406 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000407 }
408
409 // set up lightweight task
410 ompt_lw_taskteam_t *lwt = (ompt_lw_taskteam_t *)
411 __kmp_allocate(sizeof(ompt_lw_taskteam_t));
412 __ompt_lw_taskteam_init(lwt, thr, gtid, (void *) task, ompt_parallel_id);
413 lwt->ompt_task_info.task_id = my_ompt_task_id;
414 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
415 __ompt_lw_taskteam_link(lwt, thr);
416
417#if OMPT_TRACE
418 // implicit task callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000419 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000420 ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
421 ompt_parallel_id, my_ompt_task_id);
422 }
423 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
424#endif
425 }
426#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000427}
428
429
430void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000431xexpand(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *), void *data, unsigned num_threads)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000432{
433 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000434
435#if OMPT_SUPPORT
436 ompt_frame_t *parent_frame;
437
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000438 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000439 parent_frame = __ompt_get_task_frame_internal(0);
440 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
441 }
442#endif
443
Jim Cownie5e8470a2013-09-27 10:38:44 +0000444 MKLOC(loc, "GOMP_parallel_start");
445 KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
446
447 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
448 if (num_threads != 0) {
449 __kmp_push_num_threads(&loc, gtid, num_threads);
450 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000451 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +0000452 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
453 }
454 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000455 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000456 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000457
458#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000459 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000460 parent_frame->reenter_runtime_frame = NULL;
461 }
462#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000463}
464
465
466void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000467xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000468{
469 int gtid = __kmp_get_gtid();
Jonathan Peytone8104ad2015-06-08 18:56:33 +0000470 kmp_info_t *thr;
471
472 thr = __kmp_threads[gtid];
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000473
Jim Cownie5e8470a2013-09-27 10:38:44 +0000474 MKLOC(loc, "GOMP_parallel_end");
475 KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
476
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000477
478#if OMPT_SUPPORT
479 ompt_parallel_id_t parallel_id;
480 ompt_frame_t *ompt_frame = NULL;
481
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000482 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000483 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
484 parallel_id = team_info->parallel_id;
485
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000486 // Record that we re-entered the runtime system in the implicit
487 // task frame representing the parallel region.
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000488 ompt_frame = __ompt_get_task_frame_internal(0);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000489 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000490
491#if OMPT_TRACE
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000492 if (ompt_enabled &&
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000493 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
494 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
495 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
496 parallel_id, task_info->task_id);
497 }
498#endif
499
500 // unlink if necessary. no-op if there is not a lightweight task.
501 ompt_lw_taskteam_t *lwt = __ompt_lw_taskteam_unlink(thr);
502 // GOMP allocates/frees lwt since it can't be kept on the stack
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000503 if (lwt) {
504 __kmp_free(lwt);
505
506#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000507 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000508 // Since a lightweight task was destroyed, make sure that the
509 // remaining deepest task knows the stack frame where the runtime
510 // was reentered.
511 ompt_frame = __ompt_get_task_frame_internal(0);
512 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
513 }
514#endif
515 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000516 }
517#endif
518
Jonathan Peyton57d19ce2015-08-26 19:55:13 +0000519 if (! thr->th.th_team->t.t_serialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000520 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
521 thr->th.th_team);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000522
523#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000524 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000525 // Set reenter frame in parent task, which will become current task
526 // in the midst of join. This is needed before the end_parallel callback.
527 ompt_frame = __ompt_get_task_frame_internal(1);
528 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
529 }
530#endif
531
Jonathan Peytonf89fbbb2015-08-31 18:15:00 +0000532 __kmp_join_call(&loc, gtid
533#if OMPT_SUPPORT
534 , fork_context_gnu
535#endif
536 );
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000537#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000538 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000539 ompt_frame->reenter_runtime_frame = NULL;
540 }
541#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000542 }
543 else {
544 __kmpc_end_serialized_parallel(&loc, gtid);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000545
546#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000547 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000548 // Record that we re-entered the runtime system in the frame that
549 // created the parallel region.
550 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
551
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000552 if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000553 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
554 ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000555 parallel_id, task_info->task_id,
556 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000557 }
558
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000559 ompt_frame->reenter_runtime_frame = NULL;
560
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000561 thr->th.ompt_thread_info.state =
562 (((thr->th.th_team)->t.t_serialized) ?
563 ompt_state_work_serial : ompt_state_work_parallel);
564 }
565#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000566 }
567}
568
569
Jim Cownie5e8470a2013-09-27 10:38:44 +0000570//
571// Loop worksharing constructs
572//
573
574//
575// The Gnu codegen passes in an exclusive upper bound for the overall range,
576// but the libguide dispatch code expects an inclusive upper bound, hence the
577// "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
578// argument to __kmp_GOMP_fork_call).
579//
580// Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
581// but the Gnu codegen expects an excluside upper bound, so the adjustment
582// "*p_ub += stride" compenstates for the discrepancy.
583//
584// Correction: the gnu codegen always adjusts the upper bound by +-1, not the
585// stride value. We adjust the dispatch parameters accordingly (by +-1), but
586// we still adjust p_ub by the actual stride value.
587//
588// The "runtime" versions do not take a chunk_sz parameter.
589//
590// The profile lib cannot support construct checking of unordered loops that
591// are predetermined by the compiler to be statically scheduled, as the gcc
592// codegen will not always emit calls to GOMP_loop_static_next() to get the
593// next iteration. Instead, it emits inline code to call omp_get_thread_num()
594// num and calculate the iteration space using the result. It doesn't do this
595// with ordered static loop, so they can be checked.
596//
597
598#define LOOP_START(func,schedule) \
599 int func (long lb, long ub, long str, long chunk_sz, long *p_lb, \
600 long *p_ub) \
601 { \
602 int status; \
603 long stride; \
604 int gtid = __kmp_entry_gtid(); \
605 MKLOC(loc, #func); \
606 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
607 gtid, lb, ub, str, chunk_sz )); \
608 \
609 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
610 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
611 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
612 (schedule) != kmp_sch_static); \
613 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
614 (kmp_int *)p_ub, (kmp_int *)&stride); \
615 if (status) { \
616 KMP_DEBUG_ASSERT(stride == str); \
617 *p_ub += (str > 0) ? 1 : -1; \
618 } \
619 } \
620 else { \
621 status = 0; \
622 } \
623 \
624 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
625 gtid, *p_lb, *p_ub, status)); \
626 return status; \
627 }
628
629
630#define LOOP_RUNTIME_START(func,schedule) \
631 int func (long lb, long ub, long str, long *p_lb, long *p_ub) \
632 { \
633 int status; \
634 long stride; \
635 long chunk_sz = 0; \
636 int gtid = __kmp_entry_gtid(); \
637 MKLOC(loc, #func); \
638 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
639 gtid, lb, ub, str, chunk_sz )); \
640 \
641 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
642 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
643 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
644 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
645 (kmp_int *)p_ub, (kmp_int *)&stride); \
646 if (status) { \
647 KMP_DEBUG_ASSERT(stride == str); \
648 *p_ub += (str > 0) ? 1 : -1; \
649 } \
650 } \
651 else { \
652 status = 0; \
653 } \
654 \
655 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
656 gtid, *p_lb, *p_ub, status)); \
657 return status; \
658 }
659
660
661#define LOOP_NEXT(func,fini_code) \
662 int func(long *p_lb, long *p_ub) \
663 { \
664 int status; \
665 long stride; \
666 int gtid = __kmp_get_gtid(); \
667 MKLOC(loc, #func); \
668 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
669 \
670 fini_code \
671 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
672 (kmp_int *)p_ub, (kmp_int *)&stride); \
673 if (status) { \
674 *p_ub += (stride > 0) ? 1 : -1; \
675 } \
676 \
677 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
678 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
679 return status; \
680 }
681
682
Jim Cownie181b4bb2013-12-23 17:28:57 +0000683LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
684LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
685LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START), kmp_sch_dynamic_chunked)
686LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
687LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_START), kmp_sch_guided_chunked)
688LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
689LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_START), kmp_sch_runtime)
690LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000691
Jim Cownie181b4bb2013-12-23 17:28:57 +0000692LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START), kmp_ord_static)
693LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000694 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000695LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START), kmp_ord_dynamic_chunked)
696LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000697 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000698LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
699LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000700 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000701LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START), kmp_ord_runtime)
702LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000703 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
704
705
706void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000707xexpand(KMP_API_NAME_GOMP_LOOP_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000708{
709 int gtid = __kmp_get_gtid();
710 KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
711
712 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
713
714 KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
715}
716
717
718void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000719xexpand(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000720{
721 KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
722}
723
724
Jim Cownie5e8470a2013-09-27 10:38:44 +0000725//
726// Unsigned long long loop worksharing constructs
727//
728// These are new with gcc 4.4
729//
730
731#define LOOP_START_ULL(func,schedule) \
732 int func (int up, unsigned long long lb, unsigned long long ub, \
733 unsigned long long str, unsigned long long chunk_sz, \
734 unsigned long long *p_lb, unsigned long long *p_ub) \
735 { \
736 int status; \
737 long long str2 = up ? ((long long)str) : -((long long)str); \
738 long long stride; \
739 int gtid = __kmp_entry_gtid(); \
740 MKLOC(loc, #func); \
741 \
742 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
743 gtid, up, lb, ub, str, chunk_sz )); \
744 \
745 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
746 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
747 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
748 (schedule) != kmp_sch_static); \
749 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
750 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
751 if (status) { \
752 KMP_DEBUG_ASSERT(stride == str2); \
753 *p_ub += (str > 0) ? 1 : -1; \
754 } \
755 } \
756 else { \
757 status = 0; \
758 } \
759 \
760 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
761 gtid, *p_lb, *p_ub, status)); \
762 return status; \
763 }
764
765
766#define LOOP_RUNTIME_START_ULL(func,schedule) \
767 int func (int up, unsigned long long lb, unsigned long long ub, \
768 unsigned long long str, unsigned long long *p_lb, \
769 unsigned long long *p_ub) \
770 { \
771 int status; \
772 long long str2 = up ? ((long long)str) : -((long long)str); \
773 unsigned long long stride; \
774 unsigned long long chunk_sz = 0; \
775 int gtid = __kmp_entry_gtid(); \
776 MKLOC(loc, #func); \
777 \
778 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
779 gtid, up, lb, ub, str, chunk_sz )); \
780 \
781 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
782 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
783 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, TRUE); \
784 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
785 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
786 if (status) { \
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000787 KMP_DEBUG_ASSERT((long long)stride == str2); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000788 *p_ub += (str > 0) ? 1 : -1; \
789 } \
790 } \
791 else { \
792 status = 0; \
793 } \
794 \
795 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
796 gtid, *p_lb, *p_ub, status)); \
797 return status; \
798 }
799
800
801#define LOOP_NEXT_ULL(func,fini_code) \
802 int func(unsigned long long *p_lb, unsigned long long *p_ub) \
803 { \
804 int status; \
805 long long stride; \
806 int gtid = __kmp_get_gtid(); \
807 MKLOC(loc, #func); \
808 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
809 \
810 fini_code \
811 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
812 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
813 if (status) { \
814 *p_ub += (stride > 0) ? 1 : -1; \
815 } \
816 \
817 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
818 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
819 return status; \
820 }
821
822
Jim Cownie181b4bb2013-12-23 17:28:57 +0000823LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START), kmp_sch_static)
824LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
825LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START), kmp_sch_dynamic_chunked)
826LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
827LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START), kmp_sch_guided_chunked)
828LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
829LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
830LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000831
Jim Cownie181b4bb2013-12-23 17:28:57 +0000832LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START), kmp_ord_static)
833LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000834 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000835LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START), kmp_ord_dynamic_chunked)
836LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000837 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000838LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
839LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000840 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000841LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START), kmp_ord_runtime)
842LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000843 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
844
845
Jim Cownie5e8470a2013-09-27 10:38:44 +0000846//
847// Combined parallel / loop worksharing constructs
848//
849// There are no ull versions (yet).
850//
851
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000852#define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000853 void func (void (*task) (void *), void *data, unsigned num_threads, \
854 long lb, long ub, long str, long chunk_sz) \
855 { \
856 int gtid = __kmp_entry_gtid(); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000857 MKLOC(loc, #func); \
858 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
859 gtid, lb, ub, str, chunk_sz )); \
860 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000861 ompt_pre(); \
862 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000863 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
864 if (num_threads != 0) { \
865 __kmp_push_num_threads(&loc, gtid, num_threads); \
866 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000867 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000868 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
869 task, data, num_threads, &loc, (schedule), lb, \
870 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
871 } \
872 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000873 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000874 } \
875 \
876 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
877 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
878 (schedule) != kmp_sch_static); \
879 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000880 ompt_post(); \
881 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000882 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
883 }
884
885
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000886
887#if OMPT_SUPPORT
888
889#define OMPT_LOOP_PRE() \
890 ompt_frame_t *parent_frame; \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000891 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000892 parent_frame = __ompt_get_task_frame_internal(0); \
893 parent_frame->reenter_runtime_frame = __builtin_frame_address(0); \
894 }
895
896
897#define OMPT_LOOP_POST() \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000898 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000899 parent_frame->reenter_runtime_frame = NULL; \
900 }
901
902#else
903
904#define OMPT_LOOP_PRE()
905
906#define OMPT_LOOP_POST()
907
908#endif
909
910
911PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
912 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
913PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
914 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
915PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
916 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
917PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
918 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000919
920
Jim Cownie5e8470a2013-09-27 10:38:44 +0000921//
922// Tasking constructs
923//
924
925void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000926xexpand(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data, void (*copy_func)(void *, void *),
Jonas Hahnfeld9dffeff2016-02-09 07:07:30 +0000927 long arg_size, long arg_align, bool if_cond, unsigned gomp_flags)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000928{
929 MKLOC(loc, "GOMP_task");
930 int gtid = __kmp_entry_gtid();
931 kmp_int32 flags = 0;
932 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *) & flags;
933
934 KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
935
936 // The low-order bit is the "tied" flag
937 if (gomp_flags & 1) {
938 input_flags->tiedness = 1;
939 }
Jonathan Peyton33d1d282015-10-13 18:36:22 +0000940 // The second low-order bit is the "final" flag
941 if (gomp_flags & 2) {
942 input_flags->final = 1;
943 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000944 input_flags->native = 1;
945 // __kmp_task_alloc() sets up all other flags
946
947 if (! if_cond) {
948 arg_size = 0;
949 }
950
951 kmp_task_t *task = __kmp_task_alloc(&loc, gtid, input_flags,
952 sizeof(kmp_task_t), arg_size ? arg_size + arg_align - 1 : 0,
953 (kmp_routine_entry_t)func);
954
955 if (arg_size > 0) {
956 if (arg_align > 0) {
957 task->shareds = (void *)((((size_t)task->shareds)
958 + arg_align - 1) / arg_align * arg_align);
959 }
960 //else error??
961
962 if (copy_func) {
963 (*copy_func)(task->shareds, data);
964 }
965 else {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000966 KMP_MEMCPY(task->shareds, data, arg_size);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000967 }
968 }
969
970 if (if_cond) {
971 __kmpc_omp_task(&loc, gtid, task);
972 }
973 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000974#if OMPT_SUPPORT
975 ompt_thread_info_t oldInfo;
976 kmp_info_t *thread;
977 kmp_taskdata_t *taskdata;
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000978 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000979 // Store the threads states and restore them after the task
980 thread = __kmp_threads[ gtid ];
981 taskdata = KMP_TASK_TO_TASKDATA(task);
982 oldInfo = thread->th.ompt_thread_info;
983 thread->th.ompt_thread_info.wait_id = 0;
984 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
985 taskdata->ompt_task_info.frame.exit_runtime_frame =
986 __builtin_frame_address(0);
987 }
988#endif
989
Jim Cownie5e8470a2013-09-27 10:38:44 +0000990 __kmpc_omp_task_begin_if0(&loc, gtid, task);
991 func(data);
992 __kmpc_omp_task_complete_if0(&loc, gtid, task);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000993
994#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000995 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000996 thread->th.ompt_thread_info = oldInfo;
997 taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
998 }
999#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001000 }
1001
1002 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1003}
1004
1005
1006void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001007xexpand(KMP_API_NAME_GOMP_TASKWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001008{
1009 MKLOC(loc, "GOMP_taskwait");
1010 int gtid = __kmp_entry_gtid();
1011
1012 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1013
1014 __kmpc_omp_taskwait(&loc, gtid);
1015
1016 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1017}
1018
1019
Jim Cownie5e8470a2013-09-27 10:38:44 +00001020//
1021// Sections worksharing constructs
1022//
1023
1024//
1025// For the sections construct, we initialize a dynamically scheduled loop
1026// worksharing construct with lb 1 and stride 1, and use the iteration #'s
1027// that its returns as sections ids.
1028//
1029// There are no special entry points for ordered sections, so we always use
1030// the dynamically scheduled workshare, even if the sections aren't ordered.
1031//
1032
1033unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001034xexpand(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001035{
1036 int status;
1037 kmp_int lb, ub, stride;
1038 int gtid = __kmp_entry_gtid();
1039 MKLOC(loc, "GOMP_sections_start");
1040 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1041
1042 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1043
1044 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1045 if (status) {
1046 KMP_DEBUG_ASSERT(stride == 1);
1047 KMP_DEBUG_ASSERT(lb > 0);
1048 KMP_ASSERT(lb == ub);
1049 }
1050 else {
1051 lb = 0;
1052 }
1053
1054 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1055 (unsigned)lb));
1056 return (unsigned)lb;
1057}
1058
1059
1060unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001061xexpand(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001062{
1063 int status;
1064 kmp_int lb, ub, stride;
1065 int gtid = __kmp_get_gtid();
1066 MKLOC(loc, "GOMP_sections_next");
1067 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1068
1069 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1070 if (status) {
1071 KMP_DEBUG_ASSERT(stride == 1);
1072 KMP_DEBUG_ASSERT(lb > 0);
1073 KMP_ASSERT(lb == ub);
1074 }
1075 else {
1076 lb = 0;
1077 }
1078
1079 KA_TRACE(20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid,
1080 (unsigned)lb));
1081 return (unsigned)lb;
1082}
1083
1084
1085void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001086xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(void (*task) (void *), void *data,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001087 unsigned num_threads, unsigned count)
1088{
1089 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001090
1091#if OMPT_SUPPORT
1092 ompt_frame_t *parent_frame;
1093
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001094 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001095 parent_frame = __ompt_get_task_frame_internal(0);
1096 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
1097 }
1098#endif
1099
Jim Cownie5e8470a2013-09-27 10:38:44 +00001100 MKLOC(loc, "GOMP_parallel_sections_start");
1101 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1102
1103 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1104 if (num_threads != 0) {
1105 __kmp_push_num_threads(&loc, gtid, num_threads);
1106 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001107 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001108 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1109 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1110 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1111 }
1112 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001113 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001114 }
1115
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001116#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001117 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001118 parent_frame->reenter_runtime_frame = NULL;
1119 }
1120#endif
1121
Jim Cownie5e8470a2013-09-27 10:38:44 +00001122 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1123
1124 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1125}
1126
1127
1128void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001129xexpand(KMP_API_NAME_GOMP_SECTIONS_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001130{
1131 int gtid = __kmp_get_gtid();
1132 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1133
1134 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1135
1136 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1137}
1138
1139
1140void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001141xexpand(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001142{
1143 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1144}
1145
Jim Cownie181b4bb2013-12-23 17:28:57 +00001146// libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1147void
1148xexpand(KMP_API_NAME_GOMP_TASKYIELD)(void)
1149{
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001150 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1151 return;
Jim Cownie181b4bb2013-12-23 17:28:57 +00001152}
1153
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001154#if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1155
1156void
1157xexpand(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *), void *data, unsigned num_threads, unsigned int flags)
1158{
1159 int gtid = __kmp_entry_gtid();
1160 MKLOC(loc, "GOMP_parallel");
1161 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1162
1163 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1164 if (num_threads != 0) {
1165 __kmp_push_num_threads(&loc, gtid, num_threads);
1166 }
1167 if(flags != 0) {
1168 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1169 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001170 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001171 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
1172 }
1173 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001174 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001175 }
1176 task(data);
1177 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1178}
1179
1180void
1181xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task) (void *), void *data,
1182 unsigned num_threads, unsigned count, unsigned flags)
1183{
1184 int gtid = __kmp_entry_gtid();
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001185 MKLOC(loc, "GOMP_parallel_sections");
1186 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1187
1188 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1189 if (num_threads != 0) {
1190 __kmp_push_num_threads(&loc, gtid, num_threads);
1191 }
1192 if(flags != 0) {
1193 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1194 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001195 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001196 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1197 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1198 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1199 }
1200 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001201 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001202 }
1203
1204 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1205
1206 task(data);
1207 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1208 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1209}
1210
1211#define PARALLEL_LOOP(func, schedule) \
1212 void func (void (*task) (void *), void *data, unsigned num_threads, \
1213 long lb, long ub, long str, long chunk_sz, unsigned flags) \
1214 { \
1215 int gtid = __kmp_entry_gtid(); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001216 MKLOC(loc, #func); \
1217 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1218 gtid, lb, ub, str, chunk_sz )); \
1219 \
1220 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1221 if (num_threads != 0) { \
1222 __kmp_push_num_threads(&loc, gtid, num_threads); \
1223 } \
1224 if (flags != 0) { \
1225 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1226 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001227 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001228 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
1229 task, data, num_threads, &loc, (schedule), lb, \
1230 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1231 } \
1232 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001233 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001234 } \
1235 \
1236 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1237 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1238 (schedule) != kmp_sch_static); \
1239 task(data); \
1240 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1241 \
1242 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
1243 }
1244
1245PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC), kmp_sch_static)
1246PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC), kmp_sch_dynamic_chunked)
1247PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED), kmp_sch_guided_chunked)
1248PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME), kmp_sch_runtime)
1249
1250
1251void
1252xexpand(KMP_API_NAME_GOMP_TASKGROUP_START)(void)
1253{
1254 int gtid = __kmp_get_gtid();
1255 MKLOC(loc, "GOMP_taskgroup_start");
1256 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1257
1258 __kmpc_taskgroup(&loc, gtid);
1259
1260 return;
1261}
1262
1263void
1264xexpand(KMP_API_NAME_GOMP_TASKGROUP_END)(void)
1265{
1266 int gtid = __kmp_get_gtid();
1267 MKLOC(loc, "GOMP_taskgroup_end");
1268 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1269
1270 __kmpc_end_taskgroup(&loc, gtid);
1271
1272 return;
1273}
1274
1275#ifndef KMP_DEBUG
1276static
1277#endif /* KMP_DEBUG */
Jonathan Peyton66338292015-06-01 02:37:28 +00001278kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001279 kmp_int32 cncl_kind = 0;
1280 switch(gomp_kind) {
1281 case 1:
1282 cncl_kind = cancel_parallel;
1283 break;
1284 case 2:
1285 cncl_kind = cancel_loop;
1286 break;
1287 case 4:
1288 cncl_kind = cancel_sections;
1289 break;
1290 case 8:
1291 cncl_kind = cancel_taskgroup;
1292 break;
1293 }
1294 return cncl_kind;
1295}
1296
1297bool
1298xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which)
1299{
1300 if(__kmp_omp_cancellation) {
1301 KMP_FATAL(NoGompCancellation);
1302 }
1303 int gtid = __kmp_get_gtid();
1304 MKLOC(loc, "GOMP_cancellation_point");
1305 KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1306
Jonathan Peyton66338292015-06-01 02:37:28 +00001307 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001308
1309 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1310}
1311
1312bool
1313xexpand(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void)
1314{
1315 if(__kmp_omp_cancellation) {
1316 KMP_FATAL(NoGompCancellation);
1317 }
1318 KMP_FATAL(NoGompCancellation);
1319 int gtid = __kmp_get_gtid();
1320 MKLOC(loc, "GOMP_barrier_cancel");
1321 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1322
1323 return __kmpc_cancel_barrier(&loc, gtid);
1324}
1325
1326bool
1327xexpand(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel)
1328{
1329 if(__kmp_omp_cancellation) {
1330 KMP_FATAL(NoGompCancellation);
1331 } else {
1332 return FALSE;
1333 }
1334
1335 int gtid = __kmp_get_gtid();
1336 MKLOC(loc, "GOMP_cancel");
1337 KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1338
Jonathan Peyton66338292015-06-01 02:37:28 +00001339 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001340
1341 if(do_cancel == FALSE) {
1342 return xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1343 } else {
1344 return __kmpc_cancel(&loc, gtid, cncl_kind);
1345 }
1346}
1347
1348bool
1349xexpand(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void)
1350{
1351 if(__kmp_omp_cancellation) {
1352 KMP_FATAL(NoGompCancellation);
1353 }
1354 int gtid = __kmp_get_gtid();
1355 MKLOC(loc, "GOMP_sections_end_cancel");
1356 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1357
1358 return __kmpc_cancel_barrier(&loc, gtid);
1359}
1360
1361bool
1362xexpand(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void)
1363{
1364 if(__kmp_omp_cancellation) {
1365 KMP_FATAL(NoGompCancellation);
1366 }
1367 int gtid = __kmp_get_gtid();
1368 MKLOC(loc, "GOMP_loop_end_cancel");
1369 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1370
1371 return __kmpc_cancel_barrier(&loc, gtid);
1372}
1373
1374// All target functions are empty as of 2014-05-29
1375void
1376xexpand(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn) (void *), const void *openmp_target,
1377 size_t mapnum, void **hostaddrs, size_t *sizes, unsigned char *kinds)
1378{
1379 return;
1380}
1381
1382void
1383xexpand(KMP_API_NAME_GOMP_TARGET_DATA)(int device, const void *openmp_target, size_t mapnum,
1384 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1385{
1386 return;
1387}
1388
1389void
1390xexpand(KMP_API_NAME_GOMP_TARGET_END_DATA)(void)
1391{
1392 return;
1393}
1394
1395void
1396xexpand(KMP_API_NAME_GOMP_TARGET_UPDATE)(int device, const void *openmp_target, size_t mapnum,
1397 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1398{
1399 return;
1400}
1401
1402void
1403xexpand(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams, unsigned int thread_limit)
1404{
1405 return;
1406}
1407#endif // OMP_40_ENABLED
1408
1409
Jim Cownie181b4bb2013-12-23 17:28:57 +00001410/*
1411 The following sections of code create aliases for the GOMP_* functions,
1412 then create versioned symbols using the assembler directive .symver.
1413 This is only pertinent for ELF .so library
1414 xaliasify and xversionify are defined in kmp_ftn_os.h
1415*/
1416
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001417#ifdef KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001418
1419// GOMP_1.0 aliases
1420xaliasify(KMP_API_NAME_GOMP_ATOMIC_END, 10);
1421xaliasify(KMP_API_NAME_GOMP_ATOMIC_START, 10);
1422xaliasify(KMP_API_NAME_GOMP_BARRIER, 10);
1423xaliasify(KMP_API_NAME_GOMP_CRITICAL_END, 10);
1424xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10);
1425xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10);
1426xaliasify(KMP_API_NAME_GOMP_CRITICAL_START, 10);
1427xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10);
1428xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10);
1429xaliasify(KMP_API_NAME_GOMP_LOOP_END, 10);
1430xaliasify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10);
1431xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10);
1432xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10);
1433xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10);
1434xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10);
1435xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10);
1436xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10);
1437xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10);
1438xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10);
1439xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10);
1440xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10);
1441xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10);
1442xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10);
1443xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10);
1444xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10);
1445xaliasify(KMP_API_NAME_GOMP_ORDERED_END, 10);
1446xaliasify(KMP_API_NAME_GOMP_ORDERED_START, 10);
1447xaliasify(KMP_API_NAME_GOMP_PARALLEL_END, 10);
1448xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10);
1449xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10);
1450xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10);
1451xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10);
1452xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10);
1453xaliasify(KMP_API_NAME_GOMP_PARALLEL_START, 10);
1454xaliasify(KMP_API_NAME_GOMP_SECTIONS_END, 10);
1455xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10);
1456xaliasify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10);
1457xaliasify(KMP_API_NAME_GOMP_SECTIONS_START, 10);
1458xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10);
1459xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10);
1460xaliasify(KMP_API_NAME_GOMP_SINGLE_START, 10);
1461
1462// GOMP_2.0 aliases
Jim Cownie181b4bb2013-12-23 17:28:57 +00001463xaliasify(KMP_API_NAME_GOMP_TASK, 20);
1464xaliasify(KMP_API_NAME_GOMP_TASKWAIT, 20);
Jim Cownie181b4bb2013-12-23 17:28:57 +00001465xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20);
1466xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20);
1467xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20);
1468xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20);
1469xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20);
1470xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20);
1471xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20);
1472xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20);
1473xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20);
1474xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20);
1475xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20);
1476xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20);
1477xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20);
1478xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20);
1479xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20);
1480xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20);
1481
1482// GOMP_3.0 aliases
1483xaliasify(KMP_API_NAME_GOMP_TASKYIELD, 30);
1484
1485// GOMP_4.0 aliases
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001486// The GOMP_parallel* entry points below aren't OpenMP 4.0 related.
1487#if OMP_40_ENABLED
1488xaliasify(KMP_API_NAME_GOMP_PARALLEL, 40);
1489xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40);
1490xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40);
1491xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40);
1492xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40);
1493xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40);
1494xaliasify(KMP_API_NAME_GOMP_TASKGROUP_START, 40);
1495xaliasify(KMP_API_NAME_GOMP_TASKGROUP_END, 40);
1496xaliasify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40);
1497xaliasify(KMP_API_NAME_GOMP_CANCEL, 40);
1498xaliasify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40);
1499xaliasify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40);
1500xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40);
1501xaliasify(KMP_API_NAME_GOMP_TARGET, 40);
1502xaliasify(KMP_API_NAME_GOMP_TARGET_DATA, 40);
1503xaliasify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40);
1504xaliasify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40);
1505xaliasify(KMP_API_NAME_GOMP_TEAMS, 40);
1506#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001507
1508// GOMP_1.0 versioned symbols
1509xversionify(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1510xversionify(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1511xversionify(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1512xversionify(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1513xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1514xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1515xversionify(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1516xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1517xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1518xversionify(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1519xversionify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1520xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1521xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1522xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1523xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10, "GOMP_1.0");
1524xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1525xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1526xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1527xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10, "GOMP_1.0");
1528xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1529xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1530xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1531xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1532xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1533xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1534xversionify(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1535xversionify(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1536xversionify(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1537xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1538xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10, "GOMP_1.0");
1539xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1540xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10, "GOMP_1.0");
1541xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1542xversionify(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1543xversionify(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1544xversionify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1545xversionify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1546xversionify(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1547xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1548xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1549xversionify(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1550
1551// GOMP_2.0 versioned symbols
Jim Cownie181b4bb2013-12-23 17:28:57 +00001552xversionify(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1553xversionify(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
Jim Cownie181b4bb2013-12-23 17:28:57 +00001554xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1555xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1556xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1557xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1558xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20, "GOMP_2.0");
1559xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20, "GOMP_2.0");
1560xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20, "GOMP_2.0");
1561xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20, "GOMP_2.0");
1562xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20, "GOMP_2.0");
1563xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20, "GOMP_2.0");
1564xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20, "GOMP_2.0");
1565xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20, "GOMP_2.0");
1566xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1567xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1568xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1569xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1570
1571// GOMP_3.0 versioned symbols
1572xversionify(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1573
1574// GOMP_4.0 versioned symbols
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001575#if OMP_40_ENABLED
1576xversionify(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1577xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1578xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1579xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1580xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1581xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1582xversionify(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1583xversionify(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1584xversionify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1585xversionify(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1586xversionify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1587xversionify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1588xversionify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1589xversionify(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1590xversionify(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1591xversionify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1592xversionify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1593xversionify(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1594#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001595
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001596#endif // KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001597
Jim Cownie5e8470a2013-09-27 10:38:44 +00001598#ifdef __cplusplus
1599 } //extern "C"
1600#endif // __cplusplus
1601
1602