5 //===----------------------------------------------------------------------===//
7 // The LLVM Compiler Infrastructure
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
12 //===----------------------------------------------------------------------===//
15 #include "kmp_atomic.h"
18 #include "ompt-specific.h"
25 #define MKLOC(loc, routine) \
26 static ident_t(loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;"};
28 #include "kmp_ftn_os.h"
30 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER)(void) {
31 int gtid = __kmp_entry_gtid();
32 MKLOC(loc, "GOMP_barrier");
33 KA_TRACE(20, ("GOMP_barrier: T#%d\n", gtid));
34 #if OMPT_SUPPORT && OMPT_OPTIONAL
35 ompt_frame_t *ompt_frame;
36 if (ompt_enabled.enabled) {
37 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
38 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
39 OMPT_STORE_RETURN_ADDRESS(gtid);
42 __kmpc_barrier(&loc, gtid);
43 #if OMPT_SUPPORT && OMPT_OPTIONAL
44 if (ompt_enabled.enabled) {
45 ompt_frame->enter_frame = ompt_data_none;
52 // The symbol that icc/ifort generates for unnamed for unnamed critical sections
53 // - .gomp_critical_user_ - is defined using .comm in any objects reference it.
54 // We can't reference it directly here in C code, as the symbol contains a ".".
56 // The RTL contains an assembly language definition of .gomp_critical_user_
57 // with another symbol __kmp_unnamed_critical_addr initialized with it's
59 extern kmp_critical_name *__kmp_unnamed_critical_addr;
61 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_START)(void) {
62 int gtid = __kmp_entry_gtid();
63 MKLOC(loc, "GOMP_critical_start");
64 KA_TRACE(20, ("GOMP_critical_start: T#%d\n", gtid));
65 #if OMPT_SUPPORT && OMPT_OPTIONAL
66 OMPT_STORE_RETURN_ADDRESS(gtid);
68 __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
71 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_END)(void) {
72 int gtid = __kmp_get_gtid();
73 MKLOC(loc, "GOMP_critical_end");
74 KA_TRACE(20, ("GOMP_critical_end: T#%d\n", gtid));
75 #if OMPT_SUPPORT && OMPT_OPTIONAL
76 OMPT_STORE_RETURN_ADDRESS(gtid);
78 __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
81 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_START)(void **pptr) {
82 int gtid = __kmp_entry_gtid();
83 MKLOC(loc, "GOMP_critical_name_start");
84 KA_TRACE(20, ("GOMP_critical_name_start: T#%d\n", gtid));
85 __kmpc_critical(&loc, gtid, (kmp_critical_name *)pptr);
88 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_END)(void **pptr) {
89 int gtid = __kmp_get_gtid();
90 MKLOC(loc, "GOMP_critical_name_end");
91 KA_TRACE(20, ("GOMP_critical_name_end: T#%d\n", gtid));
92 __kmpc_end_critical(&loc, gtid, (kmp_critical_name *)pptr);
95 // The Gnu codegen tries to use locked operations to perform atomic updates
96 // inline. If it can't, then it calls GOMP_atomic_start() before performing
97 // the update and GOMP_atomic_end() afterward, regardless of the data type.
98 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_START)(void) {
99 int gtid = __kmp_entry_gtid();
100 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
103 __ompt_thread_assign_wait_id(0);
106 __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
109 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_END)(void) {
110 int gtid = __kmp_get_gtid();
111 KA_TRACE(20, ("GOMP_atomic_end: T#%d\n", gtid));
112 __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
115 int KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_START)(void) {
116 int gtid = __kmp_entry_gtid();
117 MKLOC(loc, "GOMP_single_start");
118 KA_TRACE(20, ("GOMP_single_start: T#%d\n", gtid));
120 if (!TCR_4(__kmp_init_parallel))
121 __kmp_parallel_initialize();
123 // 3rd parameter == FALSE prevents kmp_enter_single from pushing a
124 // workshare when USE_CHECKS is defined. We need to avoid the push,
125 // as there is no corresponding GOMP_single_end() call.
126 kmp_int32 rc = __kmp_enter_single(gtid, &loc, FALSE);
128 #if OMPT_SUPPORT && OMPT_OPTIONAL
129 kmp_info_t *this_thr = __kmp_threads[gtid];
130 kmp_team_t *team = this_thr->th.th_team;
131 int tid = __kmp_tid_from_gtid(gtid);
133 if (ompt_enabled.enabled) {
135 if (ompt_enabled.ompt_callback_work) {
136 ompt_callbacks.ompt_callback(ompt_callback_work)(
137 ompt_work_single_executor, ompt_scope_begin,
138 &(team->t.ompt_team_info.parallel_data),
139 &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
140 1, OMPT_GET_RETURN_ADDRESS(0));
143 if (ompt_enabled.ompt_callback_work) {
144 ompt_callbacks.ompt_callback(ompt_callback_work)(
145 ompt_work_single_other, ompt_scope_begin,
146 &(team->t.ompt_team_info.parallel_data),
147 &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
148 1, OMPT_GET_RETURN_ADDRESS(0));
149 ompt_callbacks.ompt_callback(ompt_callback_work)(
150 ompt_work_single_other, ompt_scope_end,
151 &(team->t.ompt_team_info.parallel_data),
152 &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
153 1, OMPT_GET_RETURN_ADDRESS(0));
162 void *KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_START)(void) {
164 int gtid = __kmp_entry_gtid();
165 MKLOC(loc, "GOMP_single_copy_start");
166 KA_TRACE(20, ("GOMP_single_copy_start: T#%d\n", gtid));
168 if (!TCR_4(__kmp_init_parallel))
169 __kmp_parallel_initialize();
171 // If this is the first thread to enter, return NULL. The generated code will
172 // then call GOMP_single_copy_end() for this thread only, with the
173 // copyprivate data pointer as an argument.
174 if (__kmp_enter_single(gtid, &loc, FALSE))
177 // Wait for the first thread to set the copyprivate data pointer,
178 // and for all other threads to reach this point.
180 #if OMPT_SUPPORT && OMPT_OPTIONAL
181 ompt_frame_t *ompt_frame;
182 if (ompt_enabled.enabled) {
183 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
184 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
185 OMPT_STORE_RETURN_ADDRESS(gtid);
188 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
190 // Retrieve the value of the copyprivate data point, and wait for all
191 // threads to do likewise, then return.
192 retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
193 #if OMPT_SUPPORT && OMPT_OPTIONAL
194 if (ompt_enabled.enabled) {
195 OMPT_STORE_RETURN_ADDRESS(gtid);
198 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
199 #if OMPT_SUPPORT && OMPT_OPTIONAL
200 if (ompt_enabled.enabled) {
201 ompt_frame->enter_frame = ompt_data_none;
207 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_END)(void *data) {
208 int gtid = __kmp_get_gtid();
209 KA_TRACE(20, ("GOMP_single_copy_end: T#%d\n", gtid));
211 // Set the copyprivate data pointer fo the team, then hit the barrier so that
212 // the other threads will continue on and read it. Hit another barrier before
213 // continuing, so that the know that the copyprivate data pointer has been
214 // propagated to all threads before trying to reuse the t_copypriv_data field.
215 __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
216 #if OMPT_SUPPORT && OMPT_OPTIONAL
217 ompt_frame_t *ompt_frame;
218 if (ompt_enabled.enabled) {
219 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
220 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
221 OMPT_STORE_RETURN_ADDRESS(gtid);
224 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
225 #if OMPT_SUPPORT && OMPT_OPTIONAL
226 if (ompt_enabled.enabled) {
227 OMPT_STORE_RETURN_ADDRESS(gtid);
230 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
231 #if OMPT_SUPPORT && OMPT_OPTIONAL
232 if (ompt_enabled.enabled) {
233 ompt_frame->enter_frame = ompt_data_none;
238 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_START)(void) {
239 int gtid = __kmp_entry_gtid();
240 MKLOC(loc, "GOMP_ordered_start");
241 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
242 #if OMPT_SUPPORT && OMPT_OPTIONAL
243 OMPT_STORE_RETURN_ADDRESS(gtid);
245 __kmpc_ordered(&loc, gtid);
248 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_END)(void) {
249 int gtid = __kmp_get_gtid();
250 MKLOC(loc, "GOMP_ordered_end");
251 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
252 #if OMPT_SUPPORT && OMPT_OPTIONAL
253 OMPT_STORE_RETURN_ADDRESS(gtid);
255 __kmpc_end_ordered(&loc, gtid);
258 // Dispatch macro defs
260 // They come in two flavors: 64-bit unsigned, and either 32-bit signed
261 // (IA-32 architecture) or 64-bit signed (Intel(R) 64).
263 #if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
264 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
265 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
266 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
268 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
269 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
270 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
271 #endif /* KMP_ARCH_X86 */
273 #define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
274 #define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
275 #define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
277 // The parallel contruct
281 #endif /* KMP_DEBUG */
283 __kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
287 ompt_frame_t *ompt_frame;
288 ompt_state_t enclosing_state;
290 if (ompt_enabled.enabled) {
291 // get pointer to thread data structure
292 thr = __kmp_threads[*gtid];
294 // save enclosing task state; set current state for task
295 enclosing_state = thr->th.ompt_thread_info.state;
296 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
299 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
300 ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
307 if (ompt_enabled.enabled) {
309 ompt_frame->exit_frame = ompt_data_none;
311 // restore enclosing state
312 thr->th.ompt_thread_info.state = enclosing_state;
319 #endif /* KMP_DEBUG */
321 __kmp_GOMP_parallel_microtask_wrapper(int *gtid, int *npr,
322 void (*task)(void *), void *data,
323 unsigned num_threads, ident_t *loc,
324 enum sched_type schedule, long start,
327 // Intialize the loop worksharing construct.
329 KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
330 schedule != kmp_sch_static);
334 ompt_frame_t *ompt_frame;
335 ompt_state_t enclosing_state;
337 if (ompt_enabled.enabled) {
338 thr = __kmp_threads[*gtid];
339 // save enclosing task state; set current state for task
340 enclosing_state = thr->th.ompt_thread_info.state;
341 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
344 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
345 ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
349 // Now invoke the microtask.
353 if (ompt_enabled.enabled) {
355 ompt_frame->exit_frame = ompt_data_none;
357 // reset enclosing state
358 thr->th.ompt_thread_info.state = enclosing_state;
365 #endif /* KMP_DEBUG */
367 __kmp_GOMP_fork_call(ident_t *loc, int gtid, void (*unwrapped_task)(void *),
368 microtask_t wrapper, int argc, ...) {
370 kmp_info_t *thr = __kmp_threads[gtid];
371 kmp_team_t *team = thr->th.th_team;
372 int tid = __kmp_tid_from_gtid(gtid);
377 rc = __kmp_fork_call(loc, gtid, fork_context_gnu, argc, wrapper,
378 __kmp_invoke_task_func,
379 #if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
389 __kmp_run_before_invoked_task(gtid, tid, thr, team);
394 if (ompt_enabled.enabled) {
395 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
396 ompt_task_info_t *task_info = __ompt_get_task_info_object(0);
398 // implicit task callback
399 if (ompt_enabled.ompt_callback_implicit_task) {
400 ompt_team_size = __kmp_team_from_gtid(gtid)->t.t_nproc;
401 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
402 ompt_scope_begin, &(team_info->parallel_data),
403 &(task_info->task_data), ompt_team_size, __kmp_tid_from_gtid(gtid), ompt_task_implicit); // TODO: Can this be ompt_task_initial?
404 task_info->thread_num = __kmp_tid_from_gtid(gtid);
406 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
411 static void __kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid,
412 void (*task)(void *)) {
414 OMPT_STORE_RETURN_ADDRESS(gtid);
416 __kmp_serialized_parallel(loc, gtid);
419 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *),
421 unsigned num_threads) {
422 int gtid = __kmp_entry_gtid();
425 ompt_frame_t *parent_frame, *frame;
427 if (ompt_enabled.enabled) {
428 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
429 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
430 OMPT_STORE_RETURN_ADDRESS(gtid);
434 MKLOC(loc, "GOMP_parallel_start");
435 KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
437 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
438 if (num_threads != 0) {
439 __kmp_push_num_threads(&loc, gtid, num_threads);
441 __kmp_GOMP_fork_call(&loc, gtid, task,
442 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
445 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
449 if (ompt_enabled.enabled) {
450 __ompt_get_task_info_internal(0, NULL, NULL, &frame, NULL, NULL);
451 frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
456 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(void) {
457 int gtid = __kmp_get_gtid();
460 thr = __kmp_threads[gtid];
462 MKLOC(loc, "GOMP_parallel_end");
463 KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
465 if (!thr->th.th_team->t.t_serialized) {
466 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
470 if (ompt_enabled.enabled) {
471 // Implicit task is finished here, in the barrier we might schedule
473 // these don't see the implicit task on the stack
474 OMPT_CUR_TASK_INFO(thr)->frame.exit_frame = ompt_data_none;
478 __kmp_join_call(&loc, gtid
485 __kmpc_end_serialized_parallel(&loc, gtid);
489 // Loop worksharing constructs
491 // The Gnu codegen passes in an exclusive upper bound for the overall range,
492 // but the libguide dispatch code expects an inclusive upper bound, hence the
493 // "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
494 // argument to __kmp_GOMP_fork_call).
496 // Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
497 // but the Gnu codegen expects an excluside upper bound, so the adjustment
498 // "*p_ub += stride" compenstates for the discrepancy.
500 // Correction: the gnu codegen always adjusts the upper bound by +-1, not the
501 // stride value. We adjust the dispatch parameters accordingly (by +-1), but
502 // we still adjust p_ub by the actual stride value.
504 // The "runtime" versions do not take a chunk_sz parameter.
506 // The profile lib cannot support construct checking of unordered loops that
507 // are predetermined by the compiler to be statically scheduled, as the gcc
508 // codegen will not always emit calls to GOMP_loop_static_next() to get the
509 // next iteration. Instead, it emits inline code to call omp_get_thread_num()
510 // num and calculate the iteration space using the result. It doesn't do this
511 // with ordered static loop, so they can be checked.
514 #define IF_OMPT_SUPPORT(code) code
516 #define IF_OMPT_SUPPORT(code)
519 #define LOOP_START(func, schedule) \
520 int func(long lb, long ub, long str, long chunk_sz, long *p_lb, \
524 int gtid = __kmp_entry_gtid(); \
525 MKLOC(loc, KMP_STR(func)); \
529 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
530 gtid, lb, ub, str, chunk_sz)); \
532 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
533 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
534 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
535 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
536 (schedule) != kmp_sch_static); \
537 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
538 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
539 (kmp_int *)p_ub, (kmp_int *)&stride); \
541 KMP_DEBUG_ASSERT(stride == str); \
542 *p_ub += (str > 0) ? 1 : -1; \
551 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
552 gtid, *p_lb, *p_ub, status)); \
556 #define LOOP_RUNTIME_START(func, schedule) \
557 int func(long lb, long ub, long str, long *p_lb, long *p_ub) { \
561 int gtid = __kmp_entry_gtid(); \
562 MKLOC(loc, KMP_STR(func)); \
565 (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
566 gtid, lb, ub, str, chunk_sz)); \
568 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
569 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
570 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
571 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
572 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
573 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
574 (kmp_int *)p_ub, (kmp_int *)&stride); \
576 KMP_DEBUG_ASSERT(stride == str); \
577 *p_ub += (str > 0) ? 1 : -1; \
586 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
587 gtid, *p_lb, *p_ub, status)); \
592 #define KMP_DOACROSS_FINI(status, gtid) \
593 if (!status && __kmp_threads[gtid]->th.th_dispatch->th_doacross_flags) { \
594 __kmpc_doacross_fini(NULL, gtid); \
597 #define KMP_DOACROSS_FINI(status, gtid) /* Nothing */
600 #define LOOP_NEXT(func, fini_code) \
601 int func(long *p_lb, long *p_ub) { \
604 int gtid = __kmp_get_gtid(); \
605 MKLOC(loc, KMP_STR(func)); \
606 KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
608 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
609 fini_code status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
610 (kmp_int *)p_ub, (kmp_int *)&stride); \
612 *p_ub += (stride > 0) ? 1 : -1; \
614 KMP_DOACROSS_FINI(status, gtid) \
618 (KMP_STR(func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
620 gtid, *p_lb, *p_ub, stride, status)); \
624 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
625 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
626 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START),
627 kmp_sch_dynamic_chunked)
628 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
629 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_START),
630 kmp_sch_guided_chunked)
631 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
632 LOOP_RUNTIME_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_START),
634 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
636 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START),
638 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT),
639 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
640 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START),
641 kmp_ord_dynamic_chunked)
642 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT),
643 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
644 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START),
645 kmp_ord_guided_chunked)
646 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT),
647 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
649 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START),
651 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT),
652 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
655 #define LOOP_DOACROSS_START(func, schedule) \
656 bool func(unsigned ncounts, long *counts, long chunk_sz, long *p_lb, \
659 long stride, lb, ub, str; \
660 int gtid = __kmp_entry_gtid(); \
661 struct kmp_dim *dims = \
662 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
663 MKLOC(loc, KMP_STR(func)); \
664 for (unsigned i = 0; i < ncounts; ++i) { \
666 dims[i].up = counts[i] - 1; \
669 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
673 KA_TRACE(20, (KMP_STR(func) ": T#%d, ncounts %u, lb 0x%lx, ub 0x%lx, str " \
676 gtid, ncounts, lb, ub, str, chunk_sz)); \
678 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
679 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
680 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
681 (schedule) != kmp_sch_static); \
682 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
683 (kmp_int *)p_ub, (kmp_int *)&stride); \
685 KMP_DEBUG_ASSERT(stride == str); \
686 *p_ub += (str > 0) ? 1 : -1; \
691 KMP_DOACROSS_FINI(status, gtid); \
696 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
697 gtid, *p_lb, *p_ub, status)); \
702 #define LOOP_DOACROSS_RUNTIME_START(func, schedule) \
703 int func(unsigned ncounts, long *counts, long *p_lb, long *p_ub) { \
705 long stride, lb, ub, str; \
707 int gtid = __kmp_entry_gtid(); \
708 struct kmp_dim *dims = \
709 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
710 MKLOC(loc, KMP_STR(func)); \
711 for (unsigned i = 0; i < ncounts; ++i) { \
713 dims[i].up = counts[i] - 1; \
716 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
722 (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
723 gtid, lb, ub, str, chunk_sz)); \
725 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
726 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
727 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
728 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
729 (kmp_int *)p_ub, (kmp_int *)&stride); \
731 KMP_DEBUG_ASSERT(stride == str); \
732 *p_ub += (str > 0) ? 1 : -1; \
737 KMP_DOACROSS_FINI(status, gtid); \
742 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
743 gtid, *p_lb, *p_ub, status)); \
749 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START),
752 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START),
753 kmp_sch_dynamic_chunked)
755 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START),
756 kmp_sch_guided_chunked)
757 LOOP_DOACROSS_RUNTIME_START(
758 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START),
760 #endif // OMP_45_ENABLED
762 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END)(void) {
763 int gtid = __kmp_get_gtid();
764 KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
766 #if OMPT_SUPPORT && OMPT_OPTIONAL
767 ompt_frame_t *ompt_frame;
768 if (ompt_enabled.enabled) {
769 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
770 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
771 OMPT_STORE_RETURN_ADDRESS(gtid);
774 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
775 #if OMPT_SUPPORT && OMPT_OPTIONAL
776 if (ompt_enabled.enabled) {
777 ompt_frame->enter_frame = ompt_data_none;
781 KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
784 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void) {
785 KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
788 // Unsigned long long loop worksharing constructs
790 // These are new with gcc 4.4
792 #define LOOP_START_ULL(func, schedule) \
793 int func(int up, unsigned long long lb, unsigned long long ub, \
794 unsigned long long str, unsigned long long chunk_sz, \
795 unsigned long long *p_lb, unsigned long long *p_ub) { \
797 long long str2 = up ? ((long long)str) : -((long long)str); \
799 int gtid = __kmp_entry_gtid(); \
800 MKLOC(loc, KMP_STR(func)); \
802 KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
803 "0x%llx, chunk_sz 0x%llx\n", \
804 gtid, up, lb, ub, str, chunk_sz)); \
806 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
807 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
808 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
809 (schedule) != kmp_sch_static); \
811 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
812 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
814 KMP_DEBUG_ASSERT(stride == str2); \
815 *p_ub += (str > 0) ? 1 : -1; \
824 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
825 gtid, *p_lb, *p_ub, status)); \
829 #define LOOP_RUNTIME_START_ULL(func, schedule) \
830 int func(int up, unsigned long long lb, unsigned long long ub, \
831 unsigned long long str, unsigned long long *p_lb, \
832 unsigned long long *p_ub) { \
834 long long str2 = up ? ((long long)str) : -((long long)str); \
835 unsigned long long stride; \
836 unsigned long long chunk_sz = 0; \
837 int gtid = __kmp_entry_gtid(); \
838 MKLOC(loc, KMP_STR(func)); \
840 KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
841 "0x%llx, chunk_sz 0x%llx\n", \
842 gtid, up, lb, ub, str, chunk_sz)); \
844 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
845 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
846 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
849 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
850 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
852 KMP_DEBUG_ASSERT((long long)stride == str2); \
853 *p_ub += (str > 0) ? 1 : -1; \
862 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
863 gtid, *p_lb, *p_ub, status)); \
867 #define LOOP_NEXT_ULL(func, fini_code) \
868 int func(unsigned long long *p_lb, unsigned long long *p_ub) { \
871 int gtid = __kmp_get_gtid(); \
872 MKLOC(loc, KMP_STR(func)); \
873 KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
876 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
877 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
879 *p_ub += (stride > 0) ? 1 : -1; \
885 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
887 gtid, *p_lb, *p_ub, stride, status)); \
891 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START),
893 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
894 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START),
895 kmp_sch_dynamic_chunked)
896 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
897 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START),
898 kmp_sch_guided_chunked)
899 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
900 LOOP_RUNTIME_START_ULL(
901 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
902 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
904 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START),
906 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT),
907 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
909 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START),
910 kmp_ord_dynamic_chunked)
911 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT),
912 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
913 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START),
914 kmp_ord_guided_chunked)
915 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT),
916 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
917 LOOP_RUNTIME_START_ULL(
918 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START),
920 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT),
921 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
924 #define LOOP_DOACROSS_START_ULL(func, schedule) \
925 int func(unsigned ncounts, unsigned long long *counts, \
926 unsigned long long chunk_sz, unsigned long long *p_lb, \
927 unsigned long long *p_ub) { \
929 long long stride, str, lb, ub; \
930 int gtid = __kmp_entry_gtid(); \
931 struct kmp_dim *dims = \
932 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
933 MKLOC(loc, KMP_STR(func)); \
934 for (unsigned i = 0; i < ncounts; ++i) { \
936 dims[i].up = counts[i] - 1; \
939 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
944 KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
945 "0x%llx, chunk_sz 0x%llx\n", \
946 gtid, lb, ub, str, chunk_sz)); \
948 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
949 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
950 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
951 (schedule) != kmp_sch_static); \
953 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
954 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
956 KMP_DEBUG_ASSERT(stride == str); \
957 *p_ub += (str > 0) ? 1 : -1; \
962 KMP_DOACROSS_FINI(status, gtid); \
967 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
968 gtid, *p_lb, *p_ub, status)); \
973 #define LOOP_DOACROSS_RUNTIME_START_ULL(func, schedule) \
974 int func(unsigned ncounts, unsigned long long *counts, \
975 unsigned long long *p_lb, unsigned long long *p_ub) { \
977 unsigned long long stride, str, lb, ub; \
978 unsigned long long chunk_sz = 0; \
979 int gtid = __kmp_entry_gtid(); \
980 struct kmp_dim *dims = \
981 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
982 MKLOC(loc, KMP_STR(func)); \
983 for (unsigned i = 0; i < ncounts; ++i) { \
985 dims[i].up = counts[i] - 1; \
988 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
992 KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
993 "0x%llx, chunk_sz 0x%llx\n", \
994 gtid, lb, ub, str, chunk_sz)); \
996 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
997 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
998 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1001 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
1002 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
1004 KMP_DEBUG_ASSERT(stride == str); \
1005 *p_ub += (str > 0) ? 1 : -1; \
1010 KMP_DOACROSS_FINI(status, gtid); \
1015 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
1016 gtid, *p_lb, *p_ub, status)); \
1021 LOOP_DOACROSS_START_ULL(
1022 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START),
1024 LOOP_DOACROSS_START_ULL(
1025 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START),
1026 kmp_sch_dynamic_chunked)
1027 LOOP_DOACROSS_START_ULL(
1028 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START),
1029 kmp_sch_guided_chunked)
1030 LOOP_DOACROSS_RUNTIME_START_ULL(
1031 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START),
1035 // Combined parallel / loop worksharing constructs
1037 // There are no ull versions (yet).
1039 #define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
1040 void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1041 long ub, long str, long chunk_sz) { \
1042 int gtid = __kmp_entry_gtid(); \
1043 MKLOC(loc, KMP_STR(func)); \
1047 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1048 gtid, lb, ub, str, chunk_sz)); \
1052 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1053 if (num_threads != 0) { \
1054 __kmp_push_num_threads(&loc, gtid, num_threads); \
1056 __kmp_GOMP_fork_call(&loc, gtid, task, \
1057 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1058 9, task, data, num_threads, &loc, (schedule), lb, \
1059 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1060 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid)); \
1062 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
1063 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid)); \
1066 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1067 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1068 (schedule) != kmp_sch_static); \
1072 KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1075 #if OMPT_SUPPORT && OMPT_OPTIONAL
1077 #define OMPT_LOOP_PRE() \
1078 ompt_frame_t *parent_frame; \
1079 if (ompt_enabled.enabled) { \
1080 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL); \
1081 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0); \
1082 OMPT_STORE_RETURN_ADDRESS(gtid); \
1085 #define OMPT_LOOP_POST() \
1086 if (ompt_enabled.enabled) { \
1087 parent_frame->enter_frame = ompt_data_none; \
1092 #define OMPT_LOOP_PRE()
1094 #define OMPT_LOOP_POST()
1098 PARALLEL_LOOP_START(
1099 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
1100 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1101 PARALLEL_LOOP_START(
1102 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
1103 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1104 PARALLEL_LOOP_START(
1105 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
1106 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1107 PARALLEL_LOOP_START(
1108 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
1109 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1111 // Tasking constructs
1113 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data,
1114 void (*copy_func)(void *, void *),
1115 long arg_size, long arg_align,
1116 bool if_cond, unsigned gomp_flags
1122 MKLOC(loc, "GOMP_task");
1123 int gtid = __kmp_entry_gtid();
1124 kmp_int32 flags = 0;
1125 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1127 KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
1129 // The low-order bit is the "untied" flag
1130 if (!(gomp_flags & 1)) {
1131 input_flags->tiedness = 1;
1133 // The second low-order bit is the "final" flag
1134 if (gomp_flags & 2) {
1135 input_flags->final = 1;
1137 input_flags->native = 1;
1138 // __kmp_task_alloc() sets up all other flags
1144 kmp_task_t *task = __kmp_task_alloc(
1145 &loc, gtid, input_flags, sizeof(kmp_task_t),
1146 arg_size ? arg_size + arg_align - 1 : 0, (kmp_routine_entry_t)func);
1149 if (arg_align > 0) {
1150 task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1151 arg_align * arg_align);
1156 (*copy_func)(task->shareds, data);
1158 KMP_MEMCPY(task->shareds, data, arg_size);
1163 kmp_taskdata_t *current_task;
1164 if (ompt_enabled.enabled) {
1165 OMPT_STORE_RETURN_ADDRESS(gtid);
1166 current_task = __kmp_threads[gtid]->th.th_current_task;
1167 current_task->ompt_task_info.frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1173 if (gomp_flags & 8) {
1175 const size_t ndeps = (kmp_intptr_t)depend[0];
1176 const size_t nout = (kmp_intptr_t)depend[1];
1177 kmp_depend_info_t dep_list[ndeps];
1179 for (size_t i = 0U; i < ndeps; i++) {
1180 dep_list[i].base_addr = (kmp_intptr_t)depend[2U + i];
1181 dep_list[i].len = 0U;
1182 dep_list[i].flags.in = 1;
1183 dep_list[i].flags.out = (i < nout);
1185 __kmpc_omp_task_with_deps(&loc, gtid, task, ndeps, dep_list, 0, NULL);
1188 __kmpc_omp_task(&loc, gtid, task);
1192 ompt_thread_info_t oldInfo;
1194 kmp_taskdata_t *taskdata;
1195 if (ompt_enabled.enabled) {
1196 // Store the threads states and restore them after the task
1197 thread = __kmp_threads[gtid];
1198 taskdata = KMP_TASK_TO_TASKDATA(task);
1199 oldInfo = thread->th.ompt_thread_info;
1200 thread->th.ompt_thread_info.wait_id = 0;
1201 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
1202 taskdata->ompt_task_info.frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1203 OMPT_STORE_RETURN_ADDRESS(gtid);
1207 __kmpc_omp_task_begin_if0(&loc, gtid, task);
1209 __kmpc_omp_task_complete_if0(&loc, gtid, task);
1212 if (ompt_enabled.enabled) {
1213 thread->th.ompt_thread_info = oldInfo;
1214 taskdata->ompt_task_info.frame.exit_frame = ompt_data_none;
1219 if (ompt_enabled.enabled) {
1220 current_task->ompt_task_info.frame.enter_frame = ompt_data_none;
1224 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1227 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT)(void) {
1228 MKLOC(loc, "GOMP_taskwait");
1229 int gtid = __kmp_entry_gtid();
1232 if (ompt_enabled.enabled)
1233 OMPT_STORE_RETURN_ADDRESS(gtid);
1236 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1238 __kmpc_omp_taskwait(&loc, gtid);
1240 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1243 // Sections worksharing constructs
1245 // For the sections construct, we initialize a dynamically scheduled loop
1246 // worksharing construct with lb 1 and stride 1, and use the iteration #'s
1247 // that its returns as sections ids.
1249 // There are no special entry points for ordered sections, so we always use
1250 // the dynamically scheduled workshare, even if the sections aren't ordered.
1252 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count) {
1254 kmp_int lb, ub, stride;
1255 int gtid = __kmp_entry_gtid();
1256 MKLOC(loc, "GOMP_sections_start");
1257 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1259 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1261 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1263 KMP_DEBUG_ASSERT(stride == 1);
1264 KMP_DEBUG_ASSERT(lb > 0);
1265 KMP_ASSERT(lb == ub);
1270 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1272 return (unsigned)lb;
1275 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void) {
1277 kmp_int lb, ub, stride;
1278 int gtid = __kmp_get_gtid();
1279 MKLOC(loc, "GOMP_sections_next");
1280 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1283 OMPT_STORE_RETURN_ADDRESS(gtid);
1286 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1288 KMP_DEBUG_ASSERT(stride == 1);
1289 KMP_DEBUG_ASSERT(lb > 0);
1290 KMP_ASSERT(lb == ub);
1296 20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid, (unsigned)lb));
1297 return (unsigned)lb;
1300 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(
1301 void (*task)(void *), void *data, unsigned num_threads, unsigned count) {
1302 int gtid = __kmp_entry_gtid();
1305 ompt_frame_t *parent_frame;
1307 if (ompt_enabled.enabled) {
1308 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
1309 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1310 OMPT_STORE_RETURN_ADDRESS(gtid);
1314 MKLOC(loc, "GOMP_parallel_sections_start");
1315 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1317 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1318 if (num_threads != 0) {
1319 __kmp_push_num_threads(&loc, gtid, num_threads);
1321 __kmp_GOMP_fork_call(&loc, gtid, task,
1322 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1323 task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1324 (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1326 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1330 if (ompt_enabled.enabled) {
1331 parent_frame->enter_frame = ompt_data_none;
1335 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1337 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1340 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END)(void) {
1341 int gtid = __kmp_get_gtid();
1342 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1345 ompt_frame_t *ompt_frame;
1346 if (ompt_enabled.enabled) {
1347 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
1348 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1349 OMPT_STORE_RETURN_ADDRESS(gtid);
1352 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1354 if (ompt_enabled.enabled) {
1355 ompt_frame->enter_frame = ompt_data_none;
1359 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1362 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void) {
1363 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1366 // libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1367 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKYIELD)(void) {
1368 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1372 #if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1374 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *),
1376 unsigned num_threads,
1377 unsigned int flags) {
1378 int gtid = __kmp_entry_gtid();
1379 MKLOC(loc, "GOMP_parallel");
1380 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1383 ompt_task_info_t *parent_task_info, *task_info;
1384 if (ompt_enabled.enabled) {
1385 parent_task_info = __ompt_get_task_info_object(0);
1386 parent_task_info->frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1387 OMPT_STORE_RETURN_ADDRESS(gtid);
1390 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1391 if (num_threads != 0) {
1392 __kmp_push_num_threads(&loc, gtid, num_threads);
1395 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1397 __kmp_GOMP_fork_call(&loc, gtid, task,
1398 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
1401 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1404 if (ompt_enabled.enabled) {
1405 task_info = __ompt_get_task_info_object(0);
1406 task_info->frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1411 if (ompt_enabled.enabled) {
1412 OMPT_STORE_RETURN_ADDRESS(gtid);
1415 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1417 if (ompt_enabled.enabled) {
1418 task_info->frame.exit_frame = ompt_data_none;
1419 parent_task_info->frame.enter_frame = ompt_data_none;
1424 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
1426 unsigned num_threads,
1429 int gtid = __kmp_entry_gtid();
1430 MKLOC(loc, "GOMP_parallel_sections");
1431 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1434 OMPT_STORE_RETURN_ADDRESS(gtid);
1437 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1438 if (num_threads != 0) {
1439 __kmp_push_num_threads(&loc, gtid, num_threads);
1442 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1444 __kmp_GOMP_fork_call(&loc, gtid, task,
1445 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1446 task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1447 (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1449 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1453 OMPT_STORE_RETURN_ADDRESS(gtid);
1456 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1459 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1460 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1463 #define PARALLEL_LOOP(func, schedule, ompt_pre, ompt_post) \
1464 void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1465 long ub, long str, long chunk_sz, unsigned flags) { \
1466 int gtid = __kmp_entry_gtid(); \
1467 MKLOC(loc, KMP_STR(func)); \
1471 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1472 gtid, lb, ub, str, chunk_sz)); \
1475 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1476 if (num_threads != 0) { \
1477 __kmp_push_num_threads(&loc, gtid, num_threads); \
1480 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1482 __kmp_GOMP_fork_call(&loc, gtid, task, \
1483 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1484 9, task, data, num_threads, &loc, (schedule), lb, \
1485 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1487 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
1490 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
1491 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1492 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1493 (schedule) != kmp_sch_static); \
1495 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1498 KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1501 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC),
1502 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1503 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC),
1504 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1505 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED),
1506 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1507 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME),
1508 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1510 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_START)(void) {
1511 int gtid = __kmp_entry_gtid();
1512 MKLOC(loc, "GOMP_taskgroup_start");
1513 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1516 if (ompt_enabled.enabled)
1517 OMPT_STORE_RETURN_ADDRESS(gtid);
1520 __kmpc_taskgroup(&loc, gtid);
1525 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_END)(void) {
1526 int gtid = __kmp_get_gtid();
1527 MKLOC(loc, "GOMP_taskgroup_end");
1528 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1531 if (ompt_enabled.enabled)
1532 OMPT_STORE_RETURN_ADDRESS(gtid);
1535 __kmpc_end_taskgroup(&loc, gtid);
1542 #endif /* KMP_DEBUG */
1544 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
1545 kmp_int32 cncl_kind = 0;
1546 switch (gomp_kind) {
1548 cncl_kind = cancel_parallel;
1551 cncl_kind = cancel_loop;
1554 cncl_kind = cancel_sections;
1557 cncl_kind = cancel_taskgroup;
1563 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which) {
1564 if (__kmp_omp_cancellation) {
1565 KMP_FATAL(NoGompCancellation);
1567 int gtid = __kmp_get_gtid();
1568 MKLOC(loc, "GOMP_cancellation_point");
1569 KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1571 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1573 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1576 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void) {
1577 if (__kmp_omp_cancellation) {
1578 KMP_FATAL(NoGompCancellation);
1580 KMP_FATAL(NoGompCancellation);
1581 int gtid = __kmp_get_gtid();
1582 MKLOC(loc, "GOMP_barrier_cancel");
1583 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1585 return __kmpc_cancel_barrier(&loc, gtid);
1588 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel) {
1589 if (__kmp_omp_cancellation) {
1590 KMP_FATAL(NoGompCancellation);
1595 int gtid = __kmp_get_gtid();
1596 MKLOC(loc, "GOMP_cancel");
1597 KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1599 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1601 if (do_cancel == FALSE) {
1602 return KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1604 return __kmpc_cancel(&loc, gtid, cncl_kind);
1608 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void) {
1609 if (__kmp_omp_cancellation) {
1610 KMP_FATAL(NoGompCancellation);
1612 int gtid = __kmp_get_gtid();
1613 MKLOC(loc, "GOMP_sections_end_cancel");
1614 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1616 return __kmpc_cancel_barrier(&loc, gtid);
1619 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void) {
1620 if (__kmp_omp_cancellation) {
1621 KMP_FATAL(NoGompCancellation);
1623 int gtid = __kmp_get_gtid();
1624 MKLOC(loc, "GOMP_loop_end_cancel");
1625 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1627 return __kmpc_cancel_barrier(&loc, gtid);
1630 // All target functions are empty as of 2014-05-29
1631 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn)(void *),
1632 const void *openmp_target,
1633 size_t mapnum, void **hostaddrs,
1635 unsigned char *kinds) {
1639 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_DATA)(
1640 int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1641 size_t *sizes, unsigned char *kinds) {
1645 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_END_DATA)(void) { return; }
1647 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_UPDATE)(
1648 int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1649 size_t *sizes, unsigned char *kinds) {
1653 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams,
1654 unsigned int thread_limit) {
1657 #endif // OMP_40_ENABLED
1661 // Task duplication function which copies src to dest (both are
1662 // preallocated task structures)
1663 static void __kmp_gomp_task_dup(kmp_task_t *dest, kmp_task_t *src,
1664 kmp_int32 last_private) {
1665 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(src);
1666 if (taskdata->td_copy_func) {
1667 (taskdata->td_copy_func)(dest->shareds, src->shareds);
1675 template <typename T>
1676 void __GOMP_taskloop(void (*func)(void *), void *data,
1677 void (*copy_func)(void *, void *), long arg_size,
1678 long arg_align, unsigned gomp_flags,
1679 unsigned long num_tasks, int priority, T start, T end,
1681 typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
1682 MKLOC(loc, "GOMP_taskloop");
1685 int gtid = __kmp_entry_gtid();
1686 kmp_int32 flags = 0;
1687 int if_val = gomp_flags & (1u << 10);
1688 int nogroup = gomp_flags & (1u << 11);
1689 int up = gomp_flags & (1u << 8);
1690 p_task_dup_t task_dup = NULL;
1691 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1695 buff = __kmp_str_format(
1696 "GOMP_taskloop: T#%%d: func:%%p data:%%p copy_func:%%p "
1697 "arg_size:%%ld arg_align:%%ld gomp_flags:0x%%x num_tasks:%%lu "
1698 "priority:%%d start:%%%s end:%%%s step:%%%s\n",
1699 traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec);
1700 KA_TRACE(20, (buff, gtid, func, data, copy_func, arg_size, arg_align,
1701 gomp_flags, num_tasks, priority, start, end, step));
1702 __kmp_str_free(&buff);
1705 KMP_ASSERT((size_t)arg_size >= 2 * sizeof(T));
1706 KMP_ASSERT(arg_align > 0);
1707 // The low-order bit is the "untied" flag
1708 if (!(gomp_flags & 1)) {
1709 input_flags->tiedness = 1;
1711 // The second low-order bit is the "final" flag
1712 if (gomp_flags & 2) {
1713 input_flags->final = 1;
1715 // Negative step flag
1717 // If step is flagged as negative, but isn't properly sign extended
1718 // Then manually sign extend it. Could be a short, int, char embedded
1719 // in a long. So cannot assume any cast.
1721 for (int i = sizeof(T) * CHAR_BIT - 1; i >= 0L; --i) {
1722 // break at the first 1 bit
1723 if (step & ((T)1 << i))
1725 step |= ((T)1 << i);
1729 input_flags->native = 1;
1730 // Figure out if none/grainsize/num_tasks clause specified
1731 if (num_tasks > 0) {
1732 if (gomp_flags & (1u << 9))
1733 sched = 1; // grainsize specified
1735 sched = 2; // num_tasks specified
1736 // neither grainsize nor num_tasks specified
1741 // __kmp_task_alloc() sets up all other flags
1743 __kmp_task_alloc(&loc, gtid, input_flags, sizeof(kmp_task_t),
1744 arg_size + arg_align - 1, (kmp_routine_entry_t)func);
1745 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
1746 taskdata->td_copy_func = copy_func;
1747 taskdata->td_size_loop_bounds = sizeof(T);
1749 // re-align shareds if needed and setup firstprivate copy constructors
1750 // through the task_dup mechanism
1751 task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1752 arg_align * arg_align);
1754 task_dup = __kmp_gomp_task_dup;
1756 KMP_MEMCPY(task->shareds, data, arg_size);
1758 loop_bounds = (T *)task->shareds;
1759 loop_bounds[0] = start;
1760 loop_bounds[1] = end + (up ? -1 : 1);
1761 __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
1762 (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, nogroup,
1763 sched, (kmp_uint64)num_tasks, (void *)task_dup);
1766 // 4 byte version of GOMP_doacross_post
1767 // This verison needs to create a temporary array which converts 4 byte
1768 // integers into 8 byte integeres
1769 template <typename T, bool need_conversion = (sizeof(long) == 4)>
1770 void __kmp_GOMP_doacross_post(T *count);
1772 template <> void __kmp_GOMP_doacross_post<long, true>(long *count) {
1773 int gtid = __kmp_entry_gtid();
1774 kmp_info_t *th = __kmp_threads[gtid];
1775 MKLOC(loc, "GOMP_doacross_post");
1776 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1778 (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1779 for (kmp_int64 i = 0; i < num_dims; ++i) {
1780 vec[i] = (kmp_int64)count[i];
1782 __kmpc_doacross_post(&loc, gtid, vec);
1783 __kmp_thread_free(th, vec);
1786 // 8 byte versions of GOMP_doacross_post
1787 // This version can just pass in the count array directly instead of creating
1788 // a temporary array
1789 template <> void __kmp_GOMP_doacross_post<long, false>(long *count) {
1790 int gtid = __kmp_entry_gtid();
1791 MKLOC(loc, "GOMP_doacross_post");
1792 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1795 template <typename T> void __kmp_GOMP_doacross_wait(T first, va_list args) {
1796 int gtid = __kmp_entry_gtid();
1797 kmp_info_t *th = __kmp_threads[gtid];
1798 MKLOC(loc, "GOMP_doacross_wait");
1799 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1801 (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1802 vec[0] = (kmp_int64)first;
1803 for (kmp_int64 i = 1; i < num_dims; ++i) {
1804 T item = va_arg(args, T);
1805 vec[i] = (kmp_int64)item;
1807 __kmpc_doacross_wait(&loc, gtid, vec);
1808 __kmp_thread_free(th, vec);
1814 #endif // __cplusplus
1816 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP)(
1817 void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1818 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1819 int priority, long start, long end, long step) {
1820 __GOMP_taskloop<long>(func, data, copy_func, arg_size, arg_align, gomp_flags,
1821 num_tasks, priority, start, end, step);
1824 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP_ULL)(
1825 void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1826 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1827 int priority, unsigned long long start, unsigned long long end,
1828 unsigned long long step) {
1829 __GOMP_taskloop<unsigned long long>(func, data, copy_func, arg_size,
1830 arg_align, gomp_flags, num_tasks,
1831 priority, start, end, step);
1834 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_POST)(long *count) {
1835 __kmp_GOMP_doacross_post(count);
1838 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_WAIT)(long first, ...) {
1840 va_start(args, first);
1841 __kmp_GOMP_doacross_wait<long>(first, args);
1845 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_POST)(
1846 unsigned long long *count) {
1847 int gtid = __kmp_entry_gtid();
1848 MKLOC(loc, "GOMP_doacross_ull_post");
1849 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1852 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT)(
1853 unsigned long long first, ...) {
1855 va_start(args, first);
1856 __kmp_GOMP_doacross_wait<unsigned long long>(first, args);
1860 #endif // OMP_45_ENABLED
1862 /* The following sections of code create aliases for the GOMP_* functions, then
1863 create versioned symbols using the assembler directive .symver. This is only
1864 pertinent for ELF .so library. The KMP_VERSION_SYMBOL macro is defined in
1867 #ifdef KMP_USE_VERSION_SYMBOLS
1868 // GOMP_1.0 versioned symbols
1869 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1870 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1871 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1872 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1873 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1874 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1875 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1876 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1877 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1878 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1879 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1880 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1881 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1882 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1883 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10,
1885 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1886 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1887 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1888 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10,
1890 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1891 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1892 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1893 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1894 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1895 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1896 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1897 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1898 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1899 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10,
1901 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10,
1903 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10,
1905 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10,
1907 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1908 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1909 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1910 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1911 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1912 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1913 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1914 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1915 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1917 // GOMP_2.0 versioned symbols
1918 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1919 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
1920 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1921 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1922 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1923 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1924 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20,
1926 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20,
1928 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20,
1930 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20,
1932 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20,
1934 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20,
1936 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20,
1938 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20,
1940 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1941 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1942 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1943 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1945 // GOMP_3.0 versioned symbols
1946 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1948 // GOMP_4.0 versioned symbols
1950 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1951 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1952 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1953 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1954 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1955 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1956 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1957 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1958 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1959 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1960 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1961 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1962 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1963 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1964 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1965 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1966 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1967 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1970 // GOMP_4.5 versioned symbols
1972 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP, 45, "GOMP_4.5");
1973 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP_ULL, 45, "GOMP_4.5");
1974 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_POST, 45, "GOMP_4.5");
1975 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_WAIT, 45, "GOMP_4.5");
1976 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START, 45,
1978 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START, 45,
1980 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START, 45,
1982 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START, 45,
1984 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_POST, 45, "GOMP_4.5");
1985 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT, 45, "GOMP_4.5");
1986 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START, 45,
1988 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START, 45,
1990 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START, 45,
1992 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, 45,
1996 #endif // KMP_USE_VERSION_SYMBOLS
2000 #endif // __cplusplus