blob: 2a89aa2f942dffc049447a66c08d4eae5ce8781c [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 }
Jonathan Peyton33d1d282015-10-13 18:36:22 +0000943 // The second low-order bit is the "final" flag
944 if (gomp_flags & 2) {
945 input_flags->final = 1;
946 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000947 input_flags->native = 1;
948 // __kmp_task_alloc() sets up all other flags
949
950 if (! if_cond) {
951 arg_size = 0;
952 }
953
954 kmp_task_t *task = __kmp_task_alloc(&loc, gtid, input_flags,
955 sizeof(kmp_task_t), arg_size ? arg_size + arg_align - 1 : 0,
956 (kmp_routine_entry_t)func);
957
958 if (arg_size > 0) {
959 if (arg_align > 0) {
960 task->shareds = (void *)((((size_t)task->shareds)
961 + arg_align - 1) / arg_align * arg_align);
962 }
963 //else error??
964
965 if (copy_func) {
966 (*copy_func)(task->shareds, data);
967 }
968 else {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000969 KMP_MEMCPY(task->shareds, data, arg_size);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000970 }
971 }
972
973 if (if_cond) {
974 __kmpc_omp_task(&loc, gtid, task);
975 }
976 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000977#if OMPT_SUPPORT
978 ompt_thread_info_t oldInfo;
979 kmp_info_t *thread;
980 kmp_taskdata_t *taskdata;
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000981 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000982 // Store the threads states and restore them after the task
983 thread = __kmp_threads[ gtid ];
984 taskdata = KMP_TASK_TO_TASKDATA(task);
985 oldInfo = thread->th.ompt_thread_info;
986 thread->th.ompt_thread_info.wait_id = 0;
987 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
988 taskdata->ompt_task_info.frame.exit_runtime_frame =
989 __builtin_frame_address(0);
990 }
991#endif
992
Jim Cownie5e8470a2013-09-27 10:38:44 +0000993 __kmpc_omp_task_begin_if0(&loc, gtid, task);
994 func(data);
995 __kmpc_omp_task_complete_if0(&loc, gtid, task);
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000996
997#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +0000998 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +0000999 thread->th.ompt_thread_info = oldInfo;
1000 taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
1001 }
1002#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001003 }
1004
1005 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1006}
1007
1008
1009void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001010xexpand(KMP_API_NAME_GOMP_TASKWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001011{
1012 MKLOC(loc, "GOMP_taskwait");
1013 int gtid = __kmp_entry_gtid();
1014
1015 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1016
1017 __kmpc_omp_taskwait(&loc, gtid);
1018
1019 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1020}
1021
1022
Jim Cownie5e8470a2013-09-27 10:38:44 +00001023//
1024// Sections worksharing constructs
1025//
1026
1027//
1028// For the sections construct, we initialize a dynamically scheduled loop
1029// worksharing construct with lb 1 and stride 1, and use the iteration #'s
1030// that its returns as sections ids.
1031//
1032// There are no special entry points for ordered sections, so we always use
1033// the dynamically scheduled workshare, even if the sections aren't ordered.
1034//
1035
1036unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001037xexpand(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001038{
1039 int status;
1040 kmp_int lb, ub, stride;
1041 int gtid = __kmp_entry_gtid();
1042 MKLOC(loc, "GOMP_sections_start");
1043 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1044
1045 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1046
1047 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1048 if (status) {
1049 KMP_DEBUG_ASSERT(stride == 1);
1050 KMP_DEBUG_ASSERT(lb > 0);
1051 KMP_ASSERT(lb == ub);
1052 }
1053 else {
1054 lb = 0;
1055 }
1056
1057 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1058 (unsigned)lb));
1059 return (unsigned)lb;
1060}
1061
1062
1063unsigned
Jim Cownie181b4bb2013-12-23 17:28:57 +00001064xexpand(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001065{
1066 int status;
1067 kmp_int lb, ub, stride;
1068 int gtid = __kmp_get_gtid();
1069 MKLOC(loc, "GOMP_sections_next");
1070 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1071
1072 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1073 if (status) {
1074 KMP_DEBUG_ASSERT(stride == 1);
1075 KMP_DEBUG_ASSERT(lb > 0);
1076 KMP_ASSERT(lb == ub);
1077 }
1078 else {
1079 lb = 0;
1080 }
1081
1082 KA_TRACE(20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid,
1083 (unsigned)lb));
1084 return (unsigned)lb;
1085}
1086
1087
1088void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001089xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(void (*task) (void *), void *data,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001090 unsigned num_threads, unsigned count)
1091{
1092 int gtid = __kmp_entry_gtid();
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001093
1094#if OMPT_SUPPORT
1095 ompt_frame_t *parent_frame;
1096
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001097 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001098 parent_frame = __ompt_get_task_frame_internal(0);
1099 parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
1100 }
1101#endif
1102
Jim Cownie5e8470a2013-09-27 10:38:44 +00001103 MKLOC(loc, "GOMP_parallel_sections_start");
1104 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1105
1106 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1107 if (num_threads != 0) {
1108 __kmp_push_num_threads(&loc, gtid, num_threads);
1109 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001110 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001111 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1112 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1113 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1114 }
1115 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001116 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001117 }
1118
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001119#if OMPT_SUPPORT
Jonathan Peytonb68a85d2015-09-21 18:11:22 +00001120 if (ompt_enabled) {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001121 parent_frame->reenter_runtime_frame = NULL;
1122 }
1123#endif
1124
Jim Cownie5e8470a2013-09-27 10:38:44 +00001125 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1126
1127 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1128}
1129
1130
1131void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001132xexpand(KMP_API_NAME_GOMP_SECTIONS_END)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001133{
1134 int gtid = __kmp_get_gtid();
1135 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1136
1137 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1138
1139 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1140}
1141
1142
1143void
Jim Cownie181b4bb2013-12-23 17:28:57 +00001144xexpand(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001145{
1146 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1147}
1148
Jim Cownie181b4bb2013-12-23 17:28:57 +00001149// libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1150void
1151xexpand(KMP_API_NAME_GOMP_TASKYIELD)(void)
1152{
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001153 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1154 return;
Jim Cownie181b4bb2013-12-23 17:28:57 +00001155}
1156
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001157#if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1158
1159void
1160xexpand(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *), void *data, unsigned num_threads, unsigned int flags)
1161{
1162 int gtid = __kmp_entry_gtid();
1163 MKLOC(loc, "GOMP_parallel");
1164 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1165
1166 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1167 if (num_threads != 0) {
1168 __kmp_push_num_threads(&loc, gtid, num_threads);
1169 }
1170 if(flags != 0) {
1171 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1172 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001173 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001174 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
1175 }
1176 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001177 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001178 }
1179 task(data);
1180 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1181}
1182
1183void
1184xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task) (void *), void *data,
1185 unsigned num_threads, unsigned count, unsigned flags)
1186{
1187 int gtid = __kmp_entry_gtid();
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001188 MKLOC(loc, "GOMP_parallel_sections");
1189 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1190
1191 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1192 if (num_threads != 0) {
1193 __kmp_push_num_threads(&loc, gtid, num_threads);
1194 }
1195 if(flags != 0) {
1196 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1197 }
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001198 __kmp_GOMP_fork_call(&loc, gtid, task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001199 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
1200 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
1201 (kmp_int)count, (kmp_int)1, (kmp_int)1);
1202 }
1203 else {
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001204 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001205 }
1206
1207 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1208
1209 task(data);
1210 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)();
1211 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1212}
1213
1214#define PARALLEL_LOOP(func, schedule) \
1215 void func (void (*task) (void *), void *data, unsigned num_threads, \
1216 long lb, long ub, long str, long chunk_sz, unsigned flags) \
1217 { \
1218 int gtid = __kmp_entry_gtid(); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001219 MKLOC(loc, #func); \
1220 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1221 gtid, lb, ub, str, chunk_sz )); \
1222 \
1223 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1224 if (num_threads != 0) { \
1225 __kmp_push_num_threads(&loc, gtid, num_threads); \
1226 } \
1227 if (flags != 0) { \
1228 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1229 } \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001230 __kmp_GOMP_fork_call(&loc, gtid, task, \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001231 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
1232 task, data, num_threads, &loc, (schedule), lb, \
1233 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1234 } \
1235 else { \
Andrey Churbanovd7d088f2015-04-29 16:42:24 +00001236 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001237 } \
1238 \
1239 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1240 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1241 (schedule) != kmp_sch_static); \
1242 task(data); \
1243 xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1244 \
1245 KA_TRACE(20, ( #func " exit: T#%d\n", gtid)); \
1246 }
1247
1248PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC), kmp_sch_static)
1249PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC), kmp_sch_dynamic_chunked)
1250PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED), kmp_sch_guided_chunked)
1251PARALLEL_LOOP(xexpand(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME), kmp_sch_runtime)
1252
1253
1254void
1255xexpand(KMP_API_NAME_GOMP_TASKGROUP_START)(void)
1256{
1257 int gtid = __kmp_get_gtid();
1258 MKLOC(loc, "GOMP_taskgroup_start");
1259 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1260
1261 __kmpc_taskgroup(&loc, gtid);
1262
1263 return;
1264}
1265
1266void
1267xexpand(KMP_API_NAME_GOMP_TASKGROUP_END)(void)
1268{
1269 int gtid = __kmp_get_gtid();
1270 MKLOC(loc, "GOMP_taskgroup_end");
1271 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1272
1273 __kmpc_end_taskgroup(&loc, gtid);
1274
1275 return;
1276}
1277
1278#ifndef KMP_DEBUG
1279static
1280#endif /* KMP_DEBUG */
Jonathan Peyton66338292015-06-01 02:37:28 +00001281kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001282 kmp_int32 cncl_kind = 0;
1283 switch(gomp_kind) {
1284 case 1:
1285 cncl_kind = cancel_parallel;
1286 break;
1287 case 2:
1288 cncl_kind = cancel_loop;
1289 break;
1290 case 4:
1291 cncl_kind = cancel_sections;
1292 break;
1293 case 8:
1294 cncl_kind = cancel_taskgroup;
1295 break;
1296 }
1297 return cncl_kind;
1298}
1299
1300bool
1301xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which)
1302{
1303 if(__kmp_omp_cancellation) {
1304 KMP_FATAL(NoGompCancellation);
1305 }
1306 int gtid = __kmp_get_gtid();
1307 MKLOC(loc, "GOMP_cancellation_point");
1308 KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1309
Jonathan Peyton66338292015-06-01 02:37:28 +00001310 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001311
1312 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1313}
1314
1315bool
1316xexpand(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void)
1317{
1318 if(__kmp_omp_cancellation) {
1319 KMP_FATAL(NoGompCancellation);
1320 }
1321 KMP_FATAL(NoGompCancellation);
1322 int gtid = __kmp_get_gtid();
1323 MKLOC(loc, "GOMP_barrier_cancel");
1324 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1325
1326 return __kmpc_cancel_barrier(&loc, gtid);
1327}
1328
1329bool
1330xexpand(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel)
1331{
1332 if(__kmp_omp_cancellation) {
1333 KMP_FATAL(NoGompCancellation);
1334 } else {
1335 return FALSE;
1336 }
1337
1338 int gtid = __kmp_get_gtid();
1339 MKLOC(loc, "GOMP_cancel");
1340 KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1341
Jonathan Peyton66338292015-06-01 02:37:28 +00001342 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001343
1344 if(do_cancel == FALSE) {
1345 return xexpand(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1346 } else {
1347 return __kmpc_cancel(&loc, gtid, cncl_kind);
1348 }
1349}
1350
1351bool
1352xexpand(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void)
1353{
1354 if(__kmp_omp_cancellation) {
1355 KMP_FATAL(NoGompCancellation);
1356 }
1357 int gtid = __kmp_get_gtid();
1358 MKLOC(loc, "GOMP_sections_end_cancel");
1359 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1360
1361 return __kmpc_cancel_barrier(&loc, gtid);
1362}
1363
1364bool
1365xexpand(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void)
1366{
1367 if(__kmp_omp_cancellation) {
1368 KMP_FATAL(NoGompCancellation);
1369 }
1370 int gtid = __kmp_get_gtid();
1371 MKLOC(loc, "GOMP_loop_end_cancel");
1372 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1373
1374 return __kmpc_cancel_barrier(&loc, gtid);
1375}
1376
1377// All target functions are empty as of 2014-05-29
1378void
1379xexpand(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn) (void *), const void *openmp_target,
1380 size_t mapnum, void **hostaddrs, size_t *sizes, unsigned char *kinds)
1381{
1382 return;
1383}
1384
1385void
1386xexpand(KMP_API_NAME_GOMP_TARGET_DATA)(int device, const void *openmp_target, size_t mapnum,
1387 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1388{
1389 return;
1390}
1391
1392void
1393xexpand(KMP_API_NAME_GOMP_TARGET_END_DATA)(void)
1394{
1395 return;
1396}
1397
1398void
1399xexpand(KMP_API_NAME_GOMP_TARGET_UPDATE)(int device, const void *openmp_target, size_t mapnum,
1400 void **hostaddrs, size_t *sizes, unsigned char *kinds)
1401{
1402 return;
1403}
1404
1405void
1406xexpand(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams, unsigned int thread_limit)
1407{
1408 return;
1409}
1410#endif // OMP_40_ENABLED
1411
1412
Jim Cownie181b4bb2013-12-23 17:28:57 +00001413/*
1414 The following sections of code create aliases for the GOMP_* functions,
1415 then create versioned symbols using the assembler directive .symver.
1416 This is only pertinent for ELF .so library
1417 xaliasify and xversionify are defined in kmp_ftn_os.h
1418*/
1419
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001420#ifdef KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001421
1422// GOMP_1.0 aliases
1423xaliasify(KMP_API_NAME_GOMP_ATOMIC_END, 10);
1424xaliasify(KMP_API_NAME_GOMP_ATOMIC_START, 10);
1425xaliasify(KMP_API_NAME_GOMP_BARRIER, 10);
1426xaliasify(KMP_API_NAME_GOMP_CRITICAL_END, 10);
1427xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10);
1428xaliasify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10);
1429xaliasify(KMP_API_NAME_GOMP_CRITICAL_START, 10);
1430xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10);
1431xaliasify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10);
1432xaliasify(KMP_API_NAME_GOMP_LOOP_END, 10);
1433xaliasify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10);
1434xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10);
1435xaliasify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10);
1436xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10);
1437xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10);
1438xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10);
1439xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10);
1440xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10);
1441xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10);
1442xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10);
1443xaliasify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10);
1444xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10);
1445xaliasify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10);
1446xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10);
1447xaliasify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10);
1448xaliasify(KMP_API_NAME_GOMP_ORDERED_END, 10);
1449xaliasify(KMP_API_NAME_GOMP_ORDERED_START, 10);
1450xaliasify(KMP_API_NAME_GOMP_PARALLEL_END, 10);
1451xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10);
1452xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10);
1453xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10);
1454xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10);
1455xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10);
1456xaliasify(KMP_API_NAME_GOMP_PARALLEL_START, 10);
1457xaliasify(KMP_API_NAME_GOMP_SECTIONS_END, 10);
1458xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10);
1459xaliasify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10);
1460xaliasify(KMP_API_NAME_GOMP_SECTIONS_START, 10);
1461xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10);
1462xaliasify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10);
1463xaliasify(KMP_API_NAME_GOMP_SINGLE_START, 10);
1464
1465// GOMP_2.0 aliases
Jim Cownie181b4bb2013-12-23 17:28:57 +00001466xaliasify(KMP_API_NAME_GOMP_TASK, 20);
1467xaliasify(KMP_API_NAME_GOMP_TASKWAIT, 20);
Jim Cownie181b4bb2013-12-23 17:28:57 +00001468xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20);
1469xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20);
1470xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20);
1471xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20);
1472xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20);
1473xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20);
1474xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20);
1475xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20);
1476xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20);
1477xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20);
1478xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20);
1479xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20);
1480xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20);
1481xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20);
1482xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20);
1483xaliasify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20);
1484
1485// GOMP_3.0 aliases
1486xaliasify(KMP_API_NAME_GOMP_TASKYIELD, 30);
1487
1488// GOMP_4.0 aliases
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001489// The GOMP_parallel* entry points below aren't OpenMP 4.0 related.
1490#if OMP_40_ENABLED
1491xaliasify(KMP_API_NAME_GOMP_PARALLEL, 40);
1492xaliasify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40);
1493xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40);
1494xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40);
1495xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40);
1496xaliasify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40);
1497xaliasify(KMP_API_NAME_GOMP_TASKGROUP_START, 40);
1498xaliasify(KMP_API_NAME_GOMP_TASKGROUP_END, 40);
1499xaliasify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40);
1500xaliasify(KMP_API_NAME_GOMP_CANCEL, 40);
1501xaliasify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40);
1502xaliasify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40);
1503xaliasify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40);
1504xaliasify(KMP_API_NAME_GOMP_TARGET, 40);
1505xaliasify(KMP_API_NAME_GOMP_TARGET_DATA, 40);
1506xaliasify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40);
1507xaliasify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40);
1508xaliasify(KMP_API_NAME_GOMP_TEAMS, 40);
1509#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001510
1511// GOMP_1.0 versioned symbols
1512xversionify(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1513xversionify(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1514xversionify(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1515xversionify(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1516xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1517xversionify(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1518xversionify(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1519xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1520xversionify(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1521xversionify(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1522xversionify(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1523xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1524xversionify(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1525xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1526xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10, "GOMP_1.0");
1527xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1528xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1529xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1530xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10, "GOMP_1.0");
1531xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1532xversionify(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1533xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1534xversionify(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1535xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1536xversionify(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1537xversionify(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1538xversionify(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1539xversionify(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1540xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1541xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10, "GOMP_1.0");
1542xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1543xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10, "GOMP_1.0");
1544xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1545xversionify(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1546xversionify(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1547xversionify(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1548xversionify(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1549xversionify(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1550xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1551xversionify(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1552xversionify(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1553
1554// GOMP_2.0 versioned symbols
Jim Cownie181b4bb2013-12-23 17:28:57 +00001555xversionify(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1556xversionify(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
Jim Cownie181b4bb2013-12-23 17:28:57 +00001557xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1558xversionify(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1559xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1560xversionify(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1561xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20, "GOMP_2.0");
1562xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20, "GOMP_2.0");
1563xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20, "GOMP_2.0");
1564xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20, "GOMP_2.0");
1565xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20, "GOMP_2.0");
1566xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20, "GOMP_2.0");
1567xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20, "GOMP_2.0");
1568xversionify(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20, "GOMP_2.0");
1569xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1570xversionify(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1571xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1572xversionify(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1573
1574// GOMP_3.0 versioned symbols
1575xversionify(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1576
1577// GOMP_4.0 versioned symbols
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001578#if OMP_40_ENABLED
1579xversionify(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1580xversionify(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1581xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1582xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1583xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1584xversionify(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1585xversionify(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1586xversionify(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1587xversionify(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1588xversionify(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1589xversionify(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1590xversionify(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1591xversionify(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1592xversionify(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1593xversionify(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1594xversionify(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1595xversionify(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1596xversionify(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1597#endif
Jim Cownie181b4bb2013-12-23 17:28:57 +00001598
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001599#endif // KMP_USE_VERSION_SYMBOLS
Jim Cownie181b4bb2013-12-23 17:28:57 +00001600
Jim Cownie5e8470a2013-09-27 10:38:44 +00001601#ifdef __cplusplus
1602 } //extern "C"
1603#endif // __cplusplus
1604
1605