blob: 48487a3ffd3b88f06d19e28433300725b6aa4867 [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
Andrey Churbanovcbda8682015-01-13 14:43:35 +000016#if defined(__x86_64) || defined (__powerpc64__) || defined(__aarch64__)
Jim Cownie5e8470a2013-09-27 10:38:44 +000017# define KMP_I8
18#endif
19#include "kmp.h"
20#include "kmp_atomic.h"
21
Andrey Churbanovd7d088f2015-04-29 16:42:24 +000022#if OMPT_SUPPORT
23#include "ompt-specific.h"
24#endif
25
Jim Cownie5e8470a2013-09-27 10:38:44 +000026#ifdef __cplusplus
27 extern "C" {
28#endif // __cplusplus
29
30#define MKLOC(loc,routine) \
31 static ident_t (loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;" };
32
Jim Cownie181b4bb2013-12-23 17:28:57 +000033#include "kmp_ftn_os.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000034
35void
Jim Cownie181b4bb2013-12-23 17:28:57 +000036xexpand(KMP_API_NAME_GOMP_BARRIER)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000037{
38 int gtid = __kmp_entry_gtid();
39 MKLOC(loc, "GOMP_barrier");
40 KA_TRACE(20, ("GOMP_barrier: T#%d\n", gtid));
41 __kmpc_barrier(&loc, gtid);
42}
43
44
Jim Cownie5e8470a2013-09-27 10:38:44 +000045//
46// Mutual exclusion
47//
48
49//
50// The symbol that icc/ifort generates for unnamed for unnamed critical
51// sections - .gomp_critical_user_ - is defined using .comm in any objects
52// reference it. We can't reference it directly here in C code, as the
53// symbol contains a ".".
54//
55// The RTL contains an assembly language definition of .gomp_critical_user_
56// with another symbol __kmp_unnamed_critical_addr initialized with it's
57// address.
58//
59extern kmp_critical_name *__kmp_unnamed_critical_addr;
60
61
62void
Jim Cownie181b4bb2013-12-23 17:28:57 +000063xexpand(KMP_API_NAME_GOMP_CRITICAL_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000064{
65 int gtid = __kmp_entry_gtid();
66 MKLOC(loc, "GOMP_critical_start");
67 KA_TRACE(20, ("GOMP_critical_start: T#%d\n", gtid));
68 __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
69}
70
71
72void
Jim Cownie181b4bb2013-12-23 17:28:57 +000073xexpand(KMP_API_NAME_GOMP_CRITICAL_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +000074{
75 int gtid = __kmp_get_gtid();
76 MKLOC(loc, "GOMP_critical_end");
77 KA_TRACE(20, ("GOMP_critical_end: T#%d\n", gtid));
78 __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
79}
80
81
82void
Jim Cownie181b4bb2013-12-23 17:28:57 +000083xexpand(KMP_API_NAME_GOMP_CRITICAL_NAME_START)(void **pptr)
Jim Cownie5e8470a2013-09-27 10:38:44 +000084{
85 int gtid = __kmp_entry_gtid();
86 MKLOC(loc, "GOMP_critical_name_start");
87 KA_TRACE(20, ("GOMP_critical_name_start: T#%d\n", gtid));
88 __kmpc_critical(&loc, gtid, (kmp_critical_name *)pptr);
89}
90
91
92void
Jim Cownie181b4bb2013-12-23 17:28:57 +000093xexpand(KMP_API_NAME_GOMP_CRITICAL_NAME_END)(void **pptr)
Jim Cownie5e8470a2013-09-27 10:38:44 +000094{
95 int gtid = __kmp_get_gtid();
96 MKLOC(loc, "GOMP_critical_name_end");
97 KA_TRACE(20, ("GOMP_critical_name_end: T#%d\n", gtid));
98 __kmpc_end_critical(&loc, gtid, (kmp_critical_name *)pptr);
99}
100
101
102//
103// The Gnu codegen tries to use locked operations to perform atomic updates
104// inline. If it can't, then it calls GOMP_atomic_start() before performing
105// the update and GOMP_atomic_end() afterward, regardless of the data type.
106//
107
108void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000109xexpand(KMP_API_NAME_GOMP_ATOMIC_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000110{
111 int gtid = __kmp_entry_gtid();
112 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000113
114#if OMPT_SUPPORT
115 __ompt_thread_assign_wait_id(0);
116#endif
117
Jim Cownie5e8470a2013-09-27 10:38:44 +0000118 __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
119}
120
121
122void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000123xexpand(KMP_API_NAME_GOMP_ATOMIC_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000124{
125 int gtid = __kmp_get_gtid();
126 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
127 __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
128}
129
130
131int
Jim Cownie181b4bb2013-12-23 17:28:57 +0000132xexpand(KMP_API_NAME_GOMP_SINGLE_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000133{
134 int gtid = __kmp_entry_gtid();
135 MKLOC(loc, "GOMP_single_start");
136 KA_TRACE(20, ("GOMP_single_start: T#%d\n", gtid));
137
138 if (! TCR_4(__kmp_init_parallel))
139 __kmp_parallel_initialize();
140
141 //
142 // 3rd parameter == FALSE prevents kmp_enter_single from pushing a
143 // workshare when USE_CHECKS is defined. We need to avoid the push,
144 // as there is no corresponding GOMP_single_end() call.
145 //
146 return __kmp_enter_single(gtid, &loc, FALSE);
147}
148
149
150void *
Jim Cownie181b4bb2013-12-23 17:28:57 +0000151xexpand(KMP_API_NAME_GOMP_SINGLE_COPY_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000152{
153 void *retval;
154 int gtid = __kmp_entry_gtid();
155 MKLOC(loc, "GOMP_single_copy_start");
156 KA_TRACE(20, ("GOMP_single_copy_start: T#%d\n", gtid));
157
158 if (! TCR_4(__kmp_init_parallel))
159 __kmp_parallel_initialize();
160
161 //
162 // If this is the first thread to enter, return NULL. The generated
163 // code will then call GOMP_single_copy_end() for this thread only,
164 // with the copyprivate data pointer as an argument.
165 //
166 if (__kmp_enter_single(gtid, &loc, FALSE))
167 return NULL;
168
169 //
170 // Wait for the first thread to set the copyprivate data pointer,
171 // and for all other threads to reach this point.
172 //
173 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
174
175 //
176 // Retrieve the value of the copyprivate data point, and wait for all
177 // threads to do likewise, then return.
178 //
179 retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
180 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
181 return retval;
182}
183
184
185void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000186xexpand(KMP_API_NAME_GOMP_SINGLE_COPY_END)(void *data)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000187{
188 int gtid = __kmp_get_gtid();
Jim Cownie5e8470a2013-09-27 10:38:44 +0000189 KA_TRACE(20, ("GOMP_single_copy_end: T#%d\n", gtid));
190
191 //
192 // Set the copyprivate data pointer fo the team, then hit the barrier
193 // so that the other threads will continue on and read it. Hit another
194 // barrier before continuing, so that the know that the copyprivate
195 // data pointer has been propagated to all threads before trying to
196 // reuse the t_copypriv_data field.
197 //
198 __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
199 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
200 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
201}
202
203
204void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000205xexpand(KMP_API_NAME_GOMP_ORDERED_START)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000206{
207 int gtid = __kmp_entry_gtid();
208 MKLOC(loc, "GOMP_ordered_start");
209 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
210 __kmpc_ordered(&loc, gtid);
211}
212
213
214void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000215xexpand(KMP_API_NAME_GOMP_ORDERED_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000216{
217 int gtid = __kmp_get_gtid();
218 MKLOC(loc, "GOMP_ordered_end");
219 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
220 __kmpc_end_ordered(&loc, gtid);
221}
222
223
Jim Cownie5e8470a2013-09-27 10:38:44 +0000224//
225// Dispatch macro defs
226//
227// They come in two flavors: 64-bit unsigned, and either 32-bit signed
228// (IA-32 architecture) or 64-bit signed (Intel(R) 64).
229//
230
Jim Cownie181b4bb2013-12-23 17:28:57 +0000231#if KMP_ARCH_X86 || KMP_ARCH_ARM
Jim Cownie5e8470a2013-09-27 10:38:44 +0000232# define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
233# define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
234# define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
235#else
236# define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
237# define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
238# define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
239#endif /* KMP_ARCH_X86 */
240
241# define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
242# define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
243# define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
244
245
Jim Cownie5e8470a2013-09-27 10:38:44 +0000246//
247// The parallel contruct
248//
249
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000250#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000251static
252#endif /* KMP_DEBUG */
253void
254__kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
255 void *data)
256{
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000257#if OMPT_SUPPORT
258 kmp_info_t *thr;
259 ompt_frame_t *ompt_frame;
260 ompt_state_t enclosing_state;
261
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000262 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000263 // get pointer to thread data structure
264 thr = __kmp_threads[*gtid];
265
266 // save enclosing task state; set current state for task
267 enclosing_state = thr->th.ompt_thread_info.state;
268 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
269
270 // set task frame
271 ompt_frame = __ompt_get_task_frame_internal(0);
272 ompt_frame->exit_runtime_frame = __builtin_frame_address(0);
273 }
274#endif
275
Jim Cownie5e8470a2013-09-27 10:38:44 +0000276 task(data);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000277
278#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000279 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000280 // clear task frame
281 ompt_frame->exit_runtime_frame = NULL;
282
283 // restore enclosing state
284 thr->th.ompt_thread_info.state = enclosing_state;
285 }
286#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000287}
288
289
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000290#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000291static
292#endif /* KMP_DEBUG */
293void
294__kmp_GOMP_parallel_microtask_wrapper(int *gtid, int *npr,
295 void (*task)(void *), void *data, unsigned num_threads, ident_t *loc,
296 enum sched_type schedule, long start, long end, long incr, long chunk_size)
297{
298 //
299 // Intialize the loop worksharing construct.
300 //
301 KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
302 schedule != kmp_sch_static);
303
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000304#if OMPT_SUPPORT
305 kmp_info_t *thr;
306 ompt_frame_t *ompt_frame;
307 ompt_state_t enclosing_state;
308
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000309 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000310 thr = __kmp_threads[*gtid];
311 // save enclosing task state; set current state for task
312 enclosing_state = thr->th.ompt_thread_info.state;
313 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
314
315 // set task frame
316 ompt_frame = __ompt_get_task_frame_internal(0);
317 ompt_frame->exit_runtime_frame = __builtin_frame_address(0);
318 }
319#endif
320
Jim Cownie5e8470a2013-09-27 10:38:44 +0000321 //
322 // Now invoke the microtask.
323 //
324 task(data);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000325
326#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000327 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000328 // clear task frame
329 ompt_frame->exit_runtime_frame = NULL;
330
331 // reset enclosing state
332 thr->th.ompt_thread_info.state = enclosing_state;
333 }
334#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000335}
336
337
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000338#ifndef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000339static
340#endif /* KMP_DEBUG */
341void
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000342__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 +0000343{
344 int rc;
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000345 kmp_info_t *thr = __kmp_threads[gtid];
346 kmp_team_t *team = thr->th.th_team;
347 int tid = __kmp_tid_from_gtid(gtid);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000348
349 va_list ap;
350 va_start(ap, argc);
351
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000352 rc = __kmp_fork_call(loc, gtid, fork_context_gnu, argc,
353#if OMPT_SUPPORT
354 VOLATILE_CAST(void *) unwrapped_task,
355#endif
356 wrapper, __kmp_invoke_task_func,
Andrey Churbanovcbda8682015-01-13 14:43:35 +0000357#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
Jim Cownie5e8470a2013-09-27 10:38:44 +0000358 &ap
359#else
360 ap
361#endif
362 );
363
364 va_end(ap);
365
366 if (rc) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000367 __kmp_run_before_invoked_task(gtid, tid, thr, team);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000368 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000369
Jonathan Peyton122dd762015-07-13 18:55:45 +0000370#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000371 if (ompt_enabled) {
Jonathan Peyton122dd762015-07-13 18:55:45 +0000372#if OMPT_TRACE
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000373 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
374 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
375
376 // implicit task callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000377 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000378 ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
379 team_info->parallel_id, task_info->task_id);
380 }
Jonathan Peyton122dd762015-07-13 18:55:45 +0000381#endif
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000382 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
383 }
384#endif
385}
386
387static void
388__kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid, void (*task)(void *))
389{
390 __kmp_serialized_parallel(loc, gtid);
391
392#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000393 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000394 ompt_task_id_t ompt_task_id = __ompt_get_task_id_internal(0);
395 ompt_frame_t *ompt_frame = __ompt_get_task_frame_internal(0);
396 kmp_info_t *thr = __kmp_threads[gtid];
397
398 ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(gtid);
399 ompt_task_id_t my_ompt_task_id = __ompt_task_id_new(gtid);
400
401 ompt_frame->exit_runtime_frame = NULL;
402
403 // parallel region callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000404 if (ompt_callbacks.ompt_callback(ompt_event_parallel_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000405 int team_size = 1;
406 ompt_callbacks.ompt_callback(ompt_event_parallel_begin)(
407 ompt_task_id, ompt_frame, ompt_parallel_id,
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000408 team_size, (void *) task,
409 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000410 }
411
412 // set up lightweight task
413 ompt_lw_taskteam_t *lwt = (ompt_lw_taskteam_t *)
414 __kmp_allocate(sizeof(ompt_lw_taskteam_t));
415 __ompt_lw_taskteam_init(lwt, thr, gtid, (void *) task, ompt_parallel_id);
416 lwt->ompt_task_info.task_id = my_ompt_task_id;
417 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
418 __ompt_lw_taskteam_link(lwt, thr);
419
420#if OMPT_TRACE
421 // implicit task callback
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000422 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000423 ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
424 ompt_parallel_id, my_ompt_task_id);
425 }
426 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
427#endif
428 }
429#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000430}
431
432
433void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000434xexpand(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *), void *data, unsigned num_threads)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000435{
436 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000437
438#if OMPT_SUPPORT
439 ompt_frame_t *parent_frame;
440
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000441 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000442 parent_frame = __ompt_get_task_frame_internal(0);
443 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
444 }
445#endif
446
Jim Cownie5e8470a2013-09-27 10:38:44 +0000447 MKLOC(loc, "GOMP_parallel_start");
448 KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
449
450 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
451 if (num_threads != 0) {
452 __kmp_push_num_threads(&loc, gtid, num_threads);
453 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000454 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +0000455 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
456 }
457 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000458 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000459 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000460
461#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000462 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000463 parent_frame->reenter_runtime_frame = NULL;
464 }
465#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000466}
467
468
469void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000470xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000471{
472 int gtid = __kmp_get_gtid();
Jonathan Peytone8104ad2015-06-08 18:56:33 +0000473 kmp_info_t *thr;
474
475 thr = __kmp_threads[gtid];
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000476
Jim Cownie5e8470a2013-09-27 10:38:44 +0000477 MKLOC(loc, "GOMP_parallel_end");
478 KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
479
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000480
481#if OMPT_SUPPORT
482 ompt_parallel_id_t parallel_id;
483 ompt_frame_t *ompt_frame = NULL;
484
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000485 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000486 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
487 parallel_id = team_info->parallel_id;
488
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000489 // Record that we re-entered the runtime system in the implicit
490 // task frame representing the parallel region.
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000491 ompt_frame = __ompt_get_task_frame_internal(0);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000492 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000493
494#if OMPT_TRACE
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000495 if (ompt_enabled &&
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000496 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
497 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
498 ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
499 parallel_id, task_info->task_id);
500 }
501#endif
502
503 // unlink if necessary. no-op if there is not a lightweight task.
504 ompt_lw_taskteam_t *lwt = __ompt_lw_taskteam_unlink(thr);
505 // GOMP allocates/frees lwt since it can't be kept on the stack
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000506 if (lwt) {
507 __kmp_free(lwt);
508
509#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000510 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000511 // Since a lightweight task was destroyed, make sure that the
512 // remaining deepest task knows the stack frame where the runtime
513 // was reentered.
514 ompt_frame = __ompt_get_task_frame_internal(0);
515 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
516 }
517#endif
518 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000519 }
520#endif
521
Jonathan Peyton57d19ce2015-08-26 19:55:13 +0000522 if (! thr->th.th_team->t.t_serialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000523 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
524 thr->th.th_team);
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000525
526#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000527 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000528 // Set reenter frame in parent task, which will become current task
529 // in the midst of join. This is needed before the end_parallel callback.
530 ompt_frame = __ompt_get_task_frame_internal(1);
531 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
532 }
533#endif
534
Jonathan Peytonf89fbbb2015-08-31 18:15:00 +0000535 __kmp_join_call(&loc, gtid
536#if OMPT_SUPPORT
537 , fork_context_gnu
538#endif
539 );
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000540#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000541 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000542 ompt_frame->reenter_runtime_frame = NULL;
543 }
544#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000545 }
546 else {
547 __kmpc_end_serialized_parallel(&loc, gtid);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000548
549#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000550 if (ompt_enabled) {
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000551 // Record that we re-entered the runtime system in the frame that
552 // created the parallel region.
553 ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
554
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000555 if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000556 ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
557 ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000558 parallel_id, task_info->task_id,
559 OMPT_INVOKER(fork_context_gnu));
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000560 }
561
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000562 ompt_frame->reenter_runtime_frame = NULL;
563
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000564 thr->th.ompt_thread_info.state =
565 (((thr->th.th_team)->t.t_serialized) ?
566 ompt_state_work_serial : ompt_state_work_parallel);
567 }
568#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000569 }
570}
571
572
Jim Cownie5e8470a2013-09-27 10:38:44 +0000573//
574// Loop worksharing constructs
575//
576
577//
578// The Gnu codegen passes in an exclusive upper bound for the overall range,
579// but the libguide dispatch code expects an inclusive upper bound, hence the
580// "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
581// argument to __kmp_GOMP_fork_call).
582//
583// Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
584// but the Gnu codegen expects an excluside upper bound, so the adjustment
585// "*p_ub += stride" compenstates for the discrepancy.
586//
587// Correction: the gnu codegen always adjusts the upper bound by +-1, not the
588// stride value. We adjust the dispatch parameters accordingly (by +-1), but
589// we still adjust p_ub by the actual stride value.
590//
591// The "runtime" versions do not take a chunk_sz parameter.
592//
593// The profile lib cannot support construct checking of unordered loops that
594// are predetermined by the compiler to be statically scheduled, as the gcc
595// codegen will not always emit calls to GOMP_loop_static_next() to get the
596// next iteration. Instead, it emits inline code to call omp_get_thread_num()
597// num and calculate the iteration space using the result. It doesn't do this
598// with ordered static loop, so they can be checked.
599//
600
601#define LOOP_START(func,schedule) \
602 int func (long lb, long ub, long str, long chunk_sz, long *p_lb, \
603 long *p_ub) \
604 { \
605 int status; \
606 long stride; \
607 int gtid = __kmp_entry_gtid(); \
608 MKLOC(loc, #func); \
609 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
610 gtid, lb, ub, str, chunk_sz )); \
611 \
612 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
613 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
614 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
615 (schedule) != kmp_sch_static); \
616 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
617 (kmp_int *)p_ub, (kmp_int *)&stride); \
618 if (status) { \
619 KMP_DEBUG_ASSERT(stride == str); \
620 *p_ub += (str > 0) ? 1 : -1; \
621 } \
622 } \
623 else { \
624 status = 0; \
625 } \
626 \
627 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
628 gtid, *p_lb, *p_ub, status)); \
629 return status; \
630 }
631
632
633#define LOOP_RUNTIME_START(func,schedule) \
634 int func (long lb, long ub, long str, long *p_lb, long *p_ub) \
635 { \
636 int status; \
637 long stride; \
638 long chunk_sz = 0; \
639 int gtid = __kmp_entry_gtid(); \
640 MKLOC(loc, #func); \
641 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
642 gtid, lb, ub, str, chunk_sz )); \
643 \
644 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
645 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
646 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
647 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
648 (kmp_int *)p_ub, (kmp_int *)&stride); \
649 if (status) { \
650 KMP_DEBUG_ASSERT(stride == str); \
651 *p_ub += (str > 0) ? 1 : -1; \
652 } \
653 } \
654 else { \
655 status = 0; \
656 } \
657 \
658 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
659 gtid, *p_lb, *p_ub, status)); \
660 return status; \
661 }
662
663
664#define LOOP_NEXT(func,fini_code) \
665 int func(long *p_lb, long *p_ub) \
666 { \
667 int status; \
668 long stride; \
669 int gtid = __kmp_get_gtid(); \
670 MKLOC(loc, #func); \
671 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
672 \
673 fini_code \
674 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
675 (kmp_int *)p_ub, (kmp_int *)&stride); \
676 if (status) { \
677 *p_ub += (stride > 0) ? 1 : -1; \
678 } \
679 \
680 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
681 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
682 return status; \
683 }
684
685
Jim Cownie181b4bb2013-12-23 17:28:57 +0000686LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
687LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
688LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START), kmp_sch_dynamic_chunked)
689LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
690LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_START), kmp_sch_guided_chunked)
691LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
692LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_START), kmp_sch_runtime)
693LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000694
Jim Cownie181b4bb2013-12-23 17:28:57 +0000695LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START), kmp_ord_static)
696LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_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_DYNAMIC_START), kmp_ord_dynamic_chunked)
699LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000700 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000701LOOP_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
702LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000703 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000704LOOP_RUNTIME_START(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START), kmp_ord_runtime)
705LOOP_NEXT(xexpand(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000706 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
707
708
709void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000710xexpand(KMP_API_NAME_GOMP_LOOP_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000711{
712 int gtid = __kmp_get_gtid();
713 KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
714
715 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
716
717 KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
718}
719
720
721void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000722xexpand(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000723{
724 KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
725}
726
727
Jim Cownie5e8470a2013-09-27 10:38:44 +0000728//
729// Unsigned long long loop worksharing constructs
730//
731// These are new with gcc 4.4
732//
733
734#define LOOP_START_ULL(func,schedule) \
735 int func (int up, unsigned long long lb, unsigned long long ub, \
736 unsigned long long str, unsigned long long chunk_sz, \
737 unsigned long long *p_lb, unsigned long long *p_ub) \
738 { \
739 int status; \
740 long long str2 = up ? ((long long)str) : -((long long)str); \
741 long long stride; \
742 int gtid = __kmp_entry_gtid(); \
743 MKLOC(loc, #func); \
744 \
745 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
746 gtid, up, lb, ub, str, chunk_sz )); \
747 \
748 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
749 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
750 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
751 (schedule) != kmp_sch_static); \
752 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
753 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
754 if (status) { \
755 KMP_DEBUG_ASSERT(stride == str2); \
756 *p_ub += (str > 0) ? 1 : -1; \
757 } \
758 } \
759 else { \
760 status = 0; \
761 } \
762 \
763 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
764 gtid, *p_lb, *p_ub, status)); \
765 return status; \
766 }
767
768
769#define LOOP_RUNTIME_START_ULL(func,schedule) \
770 int func (int up, unsigned long long lb, unsigned long long ub, \
771 unsigned long long str, unsigned long long *p_lb, \
772 unsigned long long *p_ub) \
773 { \
774 int status; \
775 long long str2 = up ? ((long long)str) : -((long long)str); \
776 unsigned long long stride; \
777 unsigned long long chunk_sz = 0; \
778 int gtid = __kmp_entry_gtid(); \
779 MKLOC(loc, #func); \
780 \
781 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
782 gtid, up, lb, ub, str, chunk_sz )); \
783 \
784 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
785 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
786 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, TRUE); \
787 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
788 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
789 if (status) { \
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000790 KMP_DEBUG_ASSERT((long long)stride == str2); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000791 *p_ub += (str > 0) ? 1 : -1; \
792 } \
793 } \
794 else { \
795 status = 0; \
796 } \
797 \
798 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
799 gtid, *p_lb, *p_ub, status)); \
800 return status; \
801 }
802
803
804#define LOOP_NEXT_ULL(func,fini_code) \
805 int func(unsigned long long *p_lb, unsigned long long *p_ub) \
806 { \
807 int status; \
808 long long stride; \
809 int gtid = __kmp_get_gtid(); \
810 MKLOC(loc, #func); \
811 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
812 \
813 fini_code \
814 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
815 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
816 if (status) { \
817 *p_ub += (stride > 0) ? 1 : -1; \
818 } \
819 \
820 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
821 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
822 return status; \
823 }
824
825
Jim Cownie181b4bb2013-12-23 17:28:57 +0000826LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START), kmp_sch_static)
827LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
828LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START), kmp_sch_dynamic_chunked)
829LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
830LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START), kmp_sch_guided_chunked)
831LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
832LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
833LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
Jim Cownie5e8470a2013-09-27 10:38:44 +0000834
Jim Cownie181b4bb2013-12-23 17:28:57 +0000835LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START), kmp_ord_static)
836LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_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_DYNAMIC_START), kmp_ord_dynamic_chunked)
839LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000840 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000841LOOP_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START), kmp_ord_guided_chunked)
842LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000843 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
Jim Cownie181b4bb2013-12-23 17:28:57 +0000844LOOP_RUNTIME_START_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START), kmp_ord_runtime)
845LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT), \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000846 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
847
848
Jim Cownie5e8470a2013-09-27 10:38:44 +0000849//
850// Combined parallel / loop worksharing constructs
851//
852// There are no ull versions (yet).
853//
854
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000855#define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000856 void func (void (*task) (void *), void *data, unsigned num_threads, \
857 long lb, long ub, long str, long chunk_sz) \
858 { \
859 int gtid = __kmp_entry_gtid(); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000860 MKLOC(loc, #func); \
861 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
862 gtid, lb, ub, str, chunk_sz )); \
863 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000864 ompt_pre(); \
865 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000866 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
867 if (num_threads != 0) { \
868 __kmp_push_num_threads(&loc, gtid, num_threads); \
869 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000870 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000871 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
872 task, data, num_threads, &loc, (schedule), lb, \
873 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
874 } \
875 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000876 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000877 } \
878 \
879 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
880 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
881 (schedule) != kmp_sch_static); \
882 \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000883 ompt_post(); \
884 \
Jim Cownie5e8470a2013-09-27 10:38:44 +0000885 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
886 }
887
888
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000889
890#if OMPT_SUPPORT
891
892#define OMPT_LOOP_PRE() \
893 ompt_frame_t *parent_frame; \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000894 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000895 parent_frame = __ompt_get_task_frame_internal(0); \
896 parent_frame->reenter_runtime_frame = __builtin_frame_address(0); \
897 }
898
899
900#define OMPT_LOOP_POST() \
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000901 if (ompt_enabled) { \
Jonathan Peyton3fdf3292015-07-21 18:03:30 +0000902 parent_frame->reenter_runtime_frame = NULL; \
903 }
904
905#else
906
907#define OMPT_LOOP_PRE()
908
909#define OMPT_LOOP_POST()
910
911#endif
912
913
914PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
915 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
916PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
917 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
918PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
919 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
920PARALLEL_LOOP_START(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
921 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000922
923
Jim Cownie5e8470a2013-09-27 10:38:44 +0000924//
925// Tasking constructs
926//
927
928void
Jim Cownie181b4bb2013-12-23 17:28:57 +0000929xexpand(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data, void (*copy_func)(void *, void *),
Jim Cownie5e8470a2013-09-27 10:38:44 +0000930 long arg_size, long arg_align, int if_cond, unsigned gomp_flags)
931{
932 MKLOC(loc, "GOMP_task");
933 int gtid = __kmp_entry_gtid();
934 kmp_int32 flags = 0;
935 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *) & flags;
936
937 KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
938
939 // The low-order bit is the "tied" flag
940 if (gomp_flags & 1) {
941 input_flags->tiedness = 1;
942 }
943 input_flags->native = 1;
944 // __kmp_task_alloc() sets up all other flags
945
946 if (! if_cond) {
947 arg_size = 0;
948 }
949
950 kmp_task_t *task = __kmp_task_alloc(&loc, gtid, input_flags,
951 sizeof(kmp_task_t), arg_size ? arg_size + arg_align - 1 : 0,
952 (kmp_routine_entry_t)func);
953
954 if (arg_size > 0) {
955 if (arg_align > 0) {
956 task->shareds = (void *)((((size_t)task->shareds)
957 + arg_align - 1) / arg_align * arg_align);
958 }
959 //else error??
960
961 if (copy_func) {
962 (*copy_func)(task->shareds, data);
963 }
964 else {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000965 KMP_MEMCPY(task->shareds, data, arg_size);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000966 }
967 }
968
969 if (if_cond) {
970 __kmpc_omp_task(&loc, gtid, task);
971 }
972 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000973#if OMPT_SUPPORT
974 ompt_thread_info_t oldInfo;
975 kmp_info_t *thread;
976 kmp_taskdata_t *taskdata;
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000977 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000978 // Store the threads states and restore them after the task
979 thread = __kmp_threads[ gtid ];
980 taskdata = KMP_TASK_TO_TASKDATA(task);
981 oldInfo = thread->th.ompt_thread_info;
982 thread->th.ompt_thread_info.wait_id = 0;
983 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
984 taskdata->ompt_task_info.frame.exit_runtime_frame =
985 __builtin_frame_address(0);
986 }
987#endif
988
Jim Cownie5e8470a2013-09-27 10:38:44 +0000989 __kmpc_omp_task_begin_if0(&loc, gtid, task);
990 func(data);
991 __kmpc_omp_task_complete_if0(&loc, gtid, task);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000992
993#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000994 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000995 thread->th.ompt_thread_info = oldInfo;
996 taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
997 }
998#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000999 }
1000
1001 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1002}
1003
1004
1005void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001006xexpand(KMP_API_NAME_GOMP_TASKWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001007{
1008 MKLOC(loc, "GOMP_taskwait");
1009 int gtid = __kmp_entry_gtid();
1010
1011 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1012
1013 __kmpc_omp_taskwait(&loc, gtid);
1014
1015 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1016}
1017
1018
Jim Cownie5e8470a2013-09-27 10:38:44 +00001019//
1020// Sections worksharing constructs
1021//
1022
1023//
1024// For the sections construct, we initialize a dynamically scheduled loop
1025// worksharing construct with lb 1 and stride 1, and use the iteration #'s
1026// that its returns as sections ids.
1027//
1028// There are no special entry points for ordered sections, so we always use
1029// the dynamically scheduled workshare, even if the sections aren't ordered.
1030//
1031
1032unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001033xexpand(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001034{
1035 int status;
1036 kmp_int lb, ub, stride;
1037 int gtid = __kmp_entry_gtid();
1038 MKLOC(loc, "GOMP_sections_start");
1039 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1040
1041 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1042
1043 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1044 if (status) {
1045 KMP_DEBUG_ASSERT(stride == 1);
1046 KMP_DEBUG_ASSERT(lb > 0);
1047 KMP_ASSERT(lb == ub);
1048 }
1049 else {
1050 lb = 0;
1051 }
1052
1053 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1054 (unsigned)lb));
1055 return (unsigned)lb;
1056}
1057
1058
1059unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001060xexpand(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001061{
1062 int status;
1063 kmp_int lb, ub, stride;
1064 int gtid = __kmp_get_gtid();
1065 MKLOC(loc, "GOMP_sections_next");
1066 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1067
1068 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1069 if (status) {
1070 KMP_DEBUG_ASSERT(stride == 1);
1071 KMP_DEBUG_ASSERT(lb > 0);
1072 KMP_ASSERT(lb == ub);
1073 }
1074 else {
1075 lb = 0;
1076 }
1077
1078 KA_TRACE(20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid,
1079 (unsigned)lb));
1080 return (unsigned)lb;
1081}
1082
1083
1084void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001085xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(void (*task) (void *), void *data,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001086 unsigned num_threads, unsigned count)
1087{
1088 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001089
1090#if OMPT_SUPPORT
1091 ompt_frame_t *parent_frame;
1092
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001093 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001094 parent_frame = __ompt_get_task_frame_internal(0);
1095 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
1096 }
1097#endif
1098
Jim Cownie5e8470a2013-09-27 10:38:44 +00001099 MKLOC(loc, "GOMP_parallel_sections_start");
1100 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1101
1102 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1103 if (num_threads != 0) {
1104 __kmp_push_num_threads(&loc, gtid, num_threads);
1105 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001106 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001107 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1108 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1109 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1110 }
1111 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001112 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001113 }
1114
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001115#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001116 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001117 parent_frame->reenter_runtime_frame = NULL;
1118 }
1119#endif
1120
Jim Cownie5e8470a2013-09-27 10:38:44 +00001121 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1122
1123 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1124}
1125
1126
1127void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001128xexpand(KMP_API_NAME_GOMP_SECTIONS_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001129{
1130 int gtid = __kmp_get_gtid();
1131 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1132
1133 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1134
1135 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1136}
1137
1138
1139void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001140xexpand(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001141{
1142 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1143}
1144
Jim Cownie181b4bb2013-12-23 17:28:57 +00001145// libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1146void
1147xexpand(KMP_API_NAME_GOMP_TASKYIELD)(void)
1148{
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001149 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1150 return;
Jim Cownie181b4bb2013-12-23 17:28:57 +00001151}
1152
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001153#if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1154
1155void
1156xexpand(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *), void *data, unsigned num_threads, unsigned int flags)
1157{
1158 int gtid = __kmp_entry_gtid();
1159 MKLOC(loc, "GOMP_parallel");
1160 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1161
1162 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1163 if (num_threads != 0) {
1164 __kmp_push_num_threads(&loc, gtid, num_threads);
1165 }
1166 if(flags != 0) {
1167 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1168 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001169 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001170 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
1171 }
1172 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001173 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001174 }
1175 task(data);
1176 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1177}
1178
1179void
1180xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task) (void *), void *data,
1181 unsigned num_threads, unsigned count, unsigned flags)
1182{
1183 int gtid = __kmp_entry_gtid();
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001184 MKLOC(loc, "GOMP_parallel_sections");
1185 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1186
1187 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1188 if (num_threads != 0) {
1189 __kmp_push_num_threads(&loc, gtid, num_threads);
1190 }
1191 if(flags != 0) {
1192 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1193 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001194 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001195 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1196 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1197 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1198 }
1199 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001200 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001201 }
1202
1203 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1204
1205 task(data);
1206 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1207 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1208}
1209
1210#define PARALLEL_LOOP(func, schedule) \
1211 void func (void (*task) (void *), void *data, unsigned num_threads, \
1212 long lb, long ub, long str, long chunk_sz, unsigned flags) \
1213 { \
1214 int gtid = __kmp_entry_gtid(); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001215 MKLOC(loc, #func); \
1216 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1217 gtid, lb, ub, str, chunk_sz )); \
1218 \
1219 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1220 if (num_threads != 0) { \
1221 __kmp_push_num_threads(&loc, gtid, num_threads); \
1222 } \
1223 if (flags != 0) { \
1224 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1225 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001226 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001227 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
1228 task, data, num_threads, &loc, (schedule), lb, \
1229 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1230 } \
1231 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001232 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001233 } \
1234 \
1235 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1236 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1237 (schedule) != kmp_sch_static); \
1238 task(data); \
1239 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1240 \
1241 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
1242 }
1243
1244PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC), kmp_sch_static)
1245PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC), kmp_sch_dynamic_chunked)
1246PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED), kmp_sch_guided_chunked)
1247PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME), kmp_sch_runtime)
1248
1249
1250void
1251xexpand(KMP_API_NAME_GOMP_TASKGROUP_START)(void)
1252{
1253 int gtid = __kmp_get_gtid();
1254 MKLOC(loc, "GOMP_taskgroup_start");
1255 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1256
1257 __kmpc_taskgroup(&loc, gtid);
1258
1259 return;
1260}
1261
1262void
1263xexpand(KMP_API_NAME_GOMP_TASKGROUP_END)(void)
1264{
1265 int gtid = __kmp_get_gtid();
1266 MKLOC(loc, "GOMP_taskgroup_end");
1267 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1268
1269 __kmpc_end_taskgroup(&loc, gtid);
1270
1271 return;
1272}
1273
1274#ifndef KMP_DEBUG
1275static
1276#endif /* KMP_DEBUG */
Jonathan Peyton66338292015-06-01 02:37:28 +00001277kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001278 kmp_int32 cncl_kind = 0;
1279 switch(gomp_kind) {
1280 case 1:
1281 cncl_kind = cancel_parallel;
1282 break;
1283 case 2:
1284 cncl_kind = cancel_loop;
1285 break;
1286 case 4:
1287 cncl_kind = cancel_sections;
1288 break;
1289 case 8:
1290 cncl_kind = cancel_taskgroup;
1291 break;
1292 }
1293 return cncl_kind;
1294}
1295
1296bool
1297xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which)
1298{
1299 if(__kmp_omp_cancellation) {
1300 KMP_FATAL(NoGompCancellation);
1301 }
1302 int gtid = __kmp_get_gtid();
1303 MKLOC(loc, "GOMP_cancellation_point");
1304 KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1305
Jonathan Peyton66338292015-06-01 02:37:28 +00001306 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001307
1308 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1309}
1310
1311bool
1312xexpand(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void)
1313{
1314 if(__kmp_omp_cancellation) {
1315 KMP_FATAL(NoGompCancellation);
1316 }
1317 KMP_FATAL(NoGompCancellation);
1318 int gtid = __kmp_get_gtid();
1319 MKLOC(loc, "GOMP_barrier_cancel");
1320 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1321
1322 return __kmpc_cancel_barrier(&loc, gtid);
1323}
1324
1325bool
1326xexpand(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel)
1327{
1328 if(__kmp_omp_cancellation) {
1329 KMP_FATAL(NoGompCancellation);
1330 } else {
1331 return FALSE;
1332 }
1333
1334 int gtid = __kmp_get_gtid();
1335 MKLOC(loc, "GOMP_cancel");
1336 KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1337
Jonathan Peyton66338292015-06-01 02:37:28 +00001338 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001339
1340 if(do_cancel == FALSE) {
1341 return xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1342 } else {
1343 return __kmpc_cancel(&loc, gtid, cncl_kind);
1344 }
1345}
1346
1347bool
1348xexpand(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void)
1349{
1350 if(__kmp_omp_cancellation) {
1351 KMP_FATAL(NoGompCancellation);
1352 }
1353 int gtid = __kmp_get_gtid();
1354 MKLOC(loc, "GOMP_sections_end_cancel");
1355 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1356
1357 return __kmpc_cancel_barrier(&loc, gtid);
1358}
1359
1360bool
1361xexpand(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void)
1362{
1363 if(__kmp_omp_cancellation) {
1364 KMP_FATAL(NoGompCancellation);
1365 }
1366 int gtid = __kmp_get_gtid();
1367 MKLOC(loc, "GOMP_loop_end_cancel");
1368 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1369
1370 return __kmpc_cancel_barrier(&loc, gtid);
1371}
1372
1373// All target functions are empty as of 2014-05-29
1374void
1375xexpand(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn) (void *), const void *openmp_target,
1376 size_t mapnum, void **hostaddrs, size_t *sizes, unsigned char *kinds)
1377{
1378 return;
1379}
1380
1381void
1382xexpand(KMP_API_NAME_GOMP_TARGET_DATA)(int device, const void *openmp_target, size_t mapnum,
1383 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1384{
1385 return;
1386}
1387
1388void
1389xexpand(KMP_API_NAME_GOMP_TARGET_END_DATA)(void)
1390{
1391 return;
1392}
1393
1394void
1395xexpand(KMP_API_NAME_GOMP_TARGET_UPDATE)(int device, const void *openmp_target, size_t mapnum,
1396 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1397{
1398 return;
1399}
1400
1401void
1402xexpand(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams, unsigned int thread_limit)
1403{
1404 return;
1405}
1406#endif // OMP_40_ENABLED
1407
1408
Jim Cownie181b4bb2013-12-23 17:28:57 +00001409/*
1410 The following sections of code create aliases for the GOMP_* functions,
1411 then create versioned symbols using the assembler directive .symver.
1412 This is only pertinent for ELF .so library
1413 xaliasify and xversionify are defined in kmp_ftn_os.h
1414*/
1415
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001416#ifdef KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001417
1418// GOMP_1.0 aliases
1419xaliasify(KMP_API_NAME_GOMP_ATOMIC_END, 10);
1420xaliasify(KMP_API_NAME_GOMP_ATOMIC_START, 10);
1421xaliasify(KMP_API_NAME_GOMP_BARRIER, 10);
1422xaliasify(KMP_API_NAME_GOMP_CRITICAL_END, 10);
1423xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10);
1424xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10);
1425xaliasify(KMP_API_NAME_GOMP_CRITICAL_START, 10);
1426xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10);
1427xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10);
1428xaliasify(KMP_API_NAME_GOMP_LOOP_END, 10);
1429xaliasify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10);
1430xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10);
1431xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10);
1432xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10);
1433xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10);
1434xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10);
1435xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10);
1436xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10);
1437xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10);
1438xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10);
1439xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10);
1440xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10);
1441xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10);
1442xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10);
1443xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10);
1444xaliasify(KMP_API_NAME_GOMP_ORDERED_END, 10);
1445xaliasify(KMP_API_NAME_GOMP_ORDERED_START, 10);
1446xaliasify(KMP_API_NAME_GOMP_PARALLEL_END, 10);
1447xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10);
1448xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10);
1449xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10);
1450xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10);
1451xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10);
1452xaliasify(KMP_API_NAME_GOMP_PARALLEL_START, 10);
1453xaliasify(KMP_API_NAME_GOMP_SECTIONS_END, 10);
1454xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10);
1455xaliasify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10);
1456xaliasify(KMP_API_NAME_GOMP_SECTIONS_START, 10);
1457xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10);
1458xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10);
1459xaliasify(KMP_API_NAME_GOMP_SINGLE_START, 10);
1460
1461// GOMP_2.0 aliases
Jim Cownie181b4bb2013-12-23 17:28:57 +00001462xaliasify(KMP_API_NAME_GOMP_TASK, 20);
1463xaliasify(KMP_API_NAME_GOMP_TASKWAIT, 20);
Jim Cownie181b4bb2013-12-23 17:28:57 +00001464xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20);
1465xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20);
1466xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20);
1467xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20);
1468xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20);
1469xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20);
1470xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20);
1471xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20);
1472xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20);
1473xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20);
1474xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20);
1475xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20);
1476xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20);
1477xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20);
1478xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20);
1479xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20);
1480
1481// GOMP_3.0 aliases
1482xaliasify(KMP_API_NAME_GOMP_TASKYIELD, 30);
1483
1484// GOMP_4.0 aliases
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001485// The GOMP_parallel* entry points below aren't OpenMP 4.0 related.
1486#if OMP_40_ENABLED
1487xaliasify(KMP_API_NAME_GOMP_PARALLEL, 40);
1488xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40);
1489xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40);
1490xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40);
1491xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40);
1492xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40);
1493xaliasify(KMP_API_NAME_GOMP_TASKGROUP_START, 40);
1494xaliasify(KMP_API_NAME_GOMP_TASKGROUP_END, 40);
1495xaliasify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40);
1496xaliasify(KMP_API_NAME_GOMP_CANCEL, 40);
1497xaliasify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40);
1498xaliasify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40);
1499xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40);
1500xaliasify(KMP_API_NAME_GOMP_TARGET, 40);
1501xaliasify(KMP_API_NAME_GOMP_TARGET_DATA, 40);
1502xaliasify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40);
1503xaliasify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40);
1504xaliasify(KMP_API_NAME_GOMP_TEAMS, 40);
1505#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001506
1507// GOMP_1.0 versioned symbols
1508xversionify(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1509xversionify(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1510xversionify(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1511xversionify(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1512xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1513xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1514xversionify(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1515xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1516xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1517xversionify(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1518xversionify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1519xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1520xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1521xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1522xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10, "GOMP_1.0");
1523xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1524xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1525xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1526xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10, "GOMP_1.0");
1527xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1528xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1529xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1530xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1531xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1532xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1533xversionify(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1534xversionify(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1535xversionify(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1536xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1537xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10, "GOMP_1.0");
1538xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1539xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10, "GOMP_1.0");
1540xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1541xversionify(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1542xversionify(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1543xversionify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1544xversionify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1545xversionify(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1546xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1547xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1548xversionify(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1549
1550// GOMP_2.0 versioned symbols
Jim Cownie181b4bb2013-12-23 17:28:57 +00001551xversionify(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1552xversionify(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
Jim Cownie181b4bb2013-12-23 17:28:57 +00001553xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1554xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1555xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1556xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1557xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20, "GOMP_2.0");
1558xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20, "GOMP_2.0");
1559xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20, "GOMP_2.0");
1560xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20, "GOMP_2.0");
1561xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20, "GOMP_2.0");
1562xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20, "GOMP_2.0");
1563xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20, "GOMP_2.0");
1564xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20, "GOMP_2.0");
1565xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1566xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1567xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1568xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1569
1570// GOMP_3.0 versioned symbols
1571xversionify(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1572
1573// GOMP_4.0 versioned symbols
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001574#if OMP_40_ENABLED
1575xversionify(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1576xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1577xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1578xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1579xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1580xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1581xversionify(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1582xversionify(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1583xversionify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1584xversionify(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1585xversionify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1586xversionify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1587xversionify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1588xversionify(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1589xversionify(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1590xversionify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1591xversionify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1592xversionify(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1593#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001594
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001595#endif // KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001596
Jim Cownie5e8470a2013-09-27 10:38:44 +00001597#ifdef __cplusplus
1598 } //extern "C"
1599#endif // __cplusplus
1600
1601