5 //===----------------------------------------------------------------------===//
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
14 #include "kmp_atomic.h"
17 #include "ompt-specific.h"
24 #define MKLOC(loc, routine) \
25 static ident_t(loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;"};
27 #include "kmp_ftn_os.h"
29 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER)(void) {
30 int gtid = __kmp_entry_gtid();
31 MKLOC(loc, "GOMP_barrier");
32 KA_TRACE(20, ("GOMP_barrier: T#%d\n", gtid));
33 #if OMPT_SUPPORT && OMPT_OPTIONAL
34 ompt_frame_t *ompt_frame;
35 if (ompt_enabled.enabled) {
36 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
37 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
38 OMPT_STORE_RETURN_ADDRESS(gtid);
41 __kmpc_barrier(&loc, gtid);
42 #if OMPT_SUPPORT && OMPT_OPTIONAL
43 if (ompt_enabled.enabled) {
44 ompt_frame->enter_frame = ompt_data_none;
51 // The symbol that icc/ifort generates for unnamed for unnamed critical sections
52 // - .gomp_critical_user_ - is defined using .comm in any objects reference it.
53 // We can't reference it directly here in C code, as the symbol contains a ".".
55 // The RTL contains an assembly language definition of .gomp_critical_user_
56 // with another symbol __kmp_unnamed_critical_addr initialized with it's
58 extern kmp_critical_name *__kmp_unnamed_critical_addr;
60 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_START)(void) {
61 int gtid = __kmp_entry_gtid();
62 MKLOC(loc, "GOMP_critical_start");
63 KA_TRACE(20, ("GOMP_critical_start: T#%d\n", gtid));
64 #if OMPT_SUPPORT && OMPT_OPTIONAL
65 OMPT_STORE_RETURN_ADDRESS(gtid);
67 __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
70 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_END)(void) {
71 int gtid = __kmp_get_gtid();
72 MKLOC(loc, "GOMP_critical_end");
73 KA_TRACE(20, ("GOMP_critical_end: T#%d\n", gtid));
74 #if OMPT_SUPPORT && OMPT_OPTIONAL
75 OMPT_STORE_RETURN_ADDRESS(gtid);
77 __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
80 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_START)(void **pptr) {
81 int gtid = __kmp_entry_gtid();
82 MKLOC(loc, "GOMP_critical_name_start");
83 KA_TRACE(20, ("GOMP_critical_name_start: T#%d\n", gtid));
84 __kmpc_critical(&loc, gtid, (kmp_critical_name *)pptr);
87 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_END)(void **pptr) {
88 int gtid = __kmp_get_gtid();
89 MKLOC(loc, "GOMP_critical_name_end");
90 KA_TRACE(20, ("GOMP_critical_name_end: T#%d\n", gtid));
91 __kmpc_end_critical(&loc, gtid, (kmp_critical_name *)pptr);
94 // The Gnu codegen tries to use locked operations to perform atomic updates
95 // inline. If it can't, then it calls GOMP_atomic_start() before performing
96 // the update and GOMP_atomic_end() afterward, regardless of the data type.
97 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_START)(void) {
98 int gtid = __kmp_entry_gtid();
99 KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
102 __ompt_thread_assign_wait_id(0);
105 __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
108 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_END)(void) {
109 int gtid = __kmp_get_gtid();
110 KA_TRACE(20, ("GOMP_atomic_end: T#%d\n", gtid));
111 __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
114 int KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_START)(void) {
115 int gtid = __kmp_entry_gtid();
116 MKLOC(loc, "GOMP_single_start");
117 KA_TRACE(20, ("GOMP_single_start: T#%d\n", gtid));
119 if (!TCR_4(__kmp_init_parallel))
120 __kmp_parallel_initialize();
121 __kmp_resume_if_soft_paused();
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();
170 __kmp_resume_if_soft_paused();
172 // If this is the first thread to enter, return NULL. The generated code will
173 // then call GOMP_single_copy_end() for this thread only, with the
174 // copyprivate data pointer as an argument.
175 if (__kmp_enter_single(gtid, &loc, FALSE))
178 // Wait for the first thread to set the copyprivate data pointer,
179 // and for all other threads to reach this point.
181 #if OMPT_SUPPORT && OMPT_OPTIONAL
182 ompt_frame_t *ompt_frame;
183 if (ompt_enabled.enabled) {
184 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
185 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
186 OMPT_STORE_RETURN_ADDRESS(gtid);
189 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
191 // Retrieve the value of the copyprivate data point, and wait for all
192 // threads to do likewise, then return.
193 retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
194 #if OMPT_SUPPORT && OMPT_OPTIONAL
195 if (ompt_enabled.enabled) {
196 OMPT_STORE_RETURN_ADDRESS(gtid);
199 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
200 #if OMPT_SUPPORT && OMPT_OPTIONAL
201 if (ompt_enabled.enabled) {
202 ompt_frame->enter_frame = ompt_data_none;
208 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_END)(void *data) {
209 int gtid = __kmp_get_gtid();
210 KA_TRACE(20, ("GOMP_single_copy_end: T#%d\n", gtid));
212 // Set the copyprivate data pointer fo the team, then hit the barrier so that
213 // the other threads will continue on and read it. Hit another barrier before
214 // continuing, so that the know that the copyprivate data pointer has been
215 // propagated to all threads before trying to reuse the t_copypriv_data field.
216 __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
217 #if OMPT_SUPPORT && OMPT_OPTIONAL
218 ompt_frame_t *ompt_frame;
219 if (ompt_enabled.enabled) {
220 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
221 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
222 OMPT_STORE_RETURN_ADDRESS(gtid);
225 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
226 #if OMPT_SUPPORT && OMPT_OPTIONAL
227 if (ompt_enabled.enabled) {
228 OMPT_STORE_RETURN_ADDRESS(gtid);
231 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
232 #if OMPT_SUPPORT && OMPT_OPTIONAL
233 if (ompt_enabled.enabled) {
234 ompt_frame->enter_frame = ompt_data_none;
239 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_START)(void) {
240 int gtid = __kmp_entry_gtid();
241 MKLOC(loc, "GOMP_ordered_start");
242 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
243 #if OMPT_SUPPORT && OMPT_OPTIONAL
244 OMPT_STORE_RETURN_ADDRESS(gtid);
246 __kmpc_ordered(&loc, gtid);
249 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_END)(void) {
250 int gtid = __kmp_get_gtid();
251 MKLOC(loc, "GOMP_ordered_end");
252 KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
253 #if OMPT_SUPPORT && OMPT_OPTIONAL
254 OMPT_STORE_RETURN_ADDRESS(gtid);
256 __kmpc_end_ordered(&loc, gtid);
259 // Dispatch macro defs
261 // They come in two flavors: 64-bit unsigned, and either 32-bit signed
262 // (IA-32 architecture) or 64-bit signed (Intel(R) 64).
264 #if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
265 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
266 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
267 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
269 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
270 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
271 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
272 #endif /* KMP_ARCH_X86 */
274 #define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
275 #define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
276 #define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
278 // The parallel contruct
282 #endif /* KMP_DEBUG */
284 __kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
288 ompt_frame_t *ompt_frame;
289 ompt_state_t enclosing_state;
291 if (ompt_enabled.enabled) {
292 // get pointer to thread data structure
293 thr = __kmp_threads[*gtid];
295 // save enclosing task state; set current state for task
296 enclosing_state = thr->th.ompt_thread_info.state;
297 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
300 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
301 ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
308 if (ompt_enabled.enabled) {
310 ompt_frame->exit_frame = ompt_data_none;
312 // restore enclosing state
313 thr->th.ompt_thread_info.state = enclosing_state;
320 #endif /* KMP_DEBUG */
322 __kmp_GOMP_parallel_microtask_wrapper(int *gtid, int *npr,
323 void (*task)(void *), void *data,
324 unsigned num_threads, ident_t *loc,
325 enum sched_type schedule, long start,
328 // Intialize the loop worksharing construct.
330 KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
331 schedule != kmp_sch_static);
335 ompt_frame_t *ompt_frame;
336 ompt_state_t enclosing_state;
338 if (ompt_enabled.enabled) {
339 thr = __kmp_threads[*gtid];
340 // save enclosing task state; set current state for task
341 enclosing_state = thr->th.ompt_thread_info.state;
342 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
345 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
346 ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
350 // Now invoke the microtask.
354 if (ompt_enabled.enabled) {
356 ompt_frame->exit_frame = ompt_data_none;
358 // reset enclosing state
359 thr->th.ompt_thread_info.state = enclosing_state;
366 #endif /* KMP_DEBUG */
368 __kmp_GOMP_fork_call(ident_t *loc, int gtid, void (*unwrapped_task)(void *),
369 microtask_t wrapper, int argc, ...) {
371 kmp_info_t *thr = __kmp_threads[gtid];
372 kmp_team_t *team = thr->th.th_team;
373 int tid = __kmp_tid_from_gtid(gtid);
378 rc = __kmp_fork_call(loc, gtid, fork_context_gnu, argc, wrapper,
379 __kmp_invoke_task_func,
380 #if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
390 __kmp_run_before_invoked_task(gtid, tid, thr, team);
395 if (ompt_enabled.enabled) {
396 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
397 ompt_task_info_t *task_info = __ompt_get_task_info_object(0);
399 // implicit task callback
400 if (ompt_enabled.ompt_callback_implicit_task) {
401 ompt_team_size = __kmp_team_from_gtid(gtid)->t.t_nproc;
402 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
403 ompt_scope_begin, &(team_info->parallel_data),
404 &(task_info->task_data), ompt_team_size, __kmp_tid_from_gtid(gtid), ompt_task_implicit); // TODO: Can this be ompt_task_initial?
405 task_info->thread_num = __kmp_tid_from_gtid(gtid);
407 thr->th.ompt_thread_info.state = ompt_state_work_parallel;
412 static void __kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid,
413 void (*task)(void *)) {
415 OMPT_STORE_RETURN_ADDRESS(gtid);
417 __kmp_serialized_parallel(loc, gtid);
420 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *),
422 unsigned num_threads) {
423 int gtid = __kmp_entry_gtid();
426 ompt_frame_t *parent_frame, *frame;
428 if (ompt_enabled.enabled) {
429 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
430 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
431 OMPT_STORE_RETURN_ADDRESS(gtid);
435 MKLOC(loc, "GOMP_parallel_start");
436 KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
438 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
439 if (num_threads != 0) {
440 __kmp_push_num_threads(&loc, gtid, num_threads);
442 __kmp_GOMP_fork_call(&loc, gtid, task,
443 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
446 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
450 if (ompt_enabled.enabled) {
451 __ompt_get_task_info_internal(0, NULL, NULL, &frame, NULL, NULL);
452 frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
457 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(void) {
458 int gtid = __kmp_get_gtid();
461 thr = __kmp_threads[gtid];
463 MKLOC(loc, "GOMP_parallel_end");
464 KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
466 if (!thr->th.th_team->t.t_serialized) {
467 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
471 if (ompt_enabled.enabled) {
472 // Implicit task is finished here, in the barrier we might schedule
474 // these don't see the implicit task on the stack
475 OMPT_CUR_TASK_INFO(thr)->frame.exit_frame = ompt_data_none;
479 __kmp_join_call(&loc, gtid
486 __kmpc_end_serialized_parallel(&loc, gtid);
490 // Loop worksharing constructs
492 // The Gnu codegen passes in an exclusive upper bound for the overall range,
493 // but the libguide dispatch code expects an inclusive upper bound, hence the
494 // "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
495 // argument to __kmp_GOMP_fork_call).
497 // Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
498 // but the Gnu codegen expects an excluside upper bound, so the adjustment
499 // "*p_ub += stride" compenstates for the discrepancy.
501 // Correction: the gnu codegen always adjusts the upper bound by +-1, not the
502 // stride value. We adjust the dispatch parameters accordingly (by +-1), but
503 // we still adjust p_ub by the actual stride value.
505 // The "runtime" versions do not take a chunk_sz parameter.
507 // The profile lib cannot support construct checking of unordered loops that
508 // are predetermined by the compiler to be statically scheduled, as the gcc
509 // codegen will not always emit calls to GOMP_loop_static_next() to get the
510 // next iteration. Instead, it emits inline code to call omp_get_thread_num()
511 // num and calculate the iteration space using the result. It doesn't do this
512 // with ordered static loop, so they can be checked.
515 #define IF_OMPT_SUPPORT(code) code
517 #define IF_OMPT_SUPPORT(code)
520 #define LOOP_START(func, schedule) \
521 int func(long lb, long ub, long str, long chunk_sz, long *p_lb, \
525 int gtid = __kmp_entry_gtid(); \
526 MKLOC(loc, KMP_STR(func)); \
530 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
531 gtid, lb, ub, str, chunk_sz)); \
533 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
534 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
535 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
536 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
537 (schedule) != kmp_sch_static); \
538 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
539 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
540 (kmp_int *)p_ub, (kmp_int *)&stride); \
542 KMP_DEBUG_ASSERT(stride == str); \
543 *p_ub += (str > 0) ? 1 : -1; \
552 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
553 gtid, *p_lb, *p_ub, status)); \
557 #define LOOP_RUNTIME_START(func, schedule) \
558 int func(long lb, long ub, long str, long *p_lb, long *p_ub) { \
562 int gtid = __kmp_entry_gtid(); \
563 MKLOC(loc, KMP_STR(func)); \
566 (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
567 gtid, lb, ub, str, chunk_sz)); \
569 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
570 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
571 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
572 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
573 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
574 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
575 (kmp_int *)p_ub, (kmp_int *)&stride); \
577 KMP_DEBUG_ASSERT(stride == str); \
578 *p_ub += (str > 0) ? 1 : -1; \
587 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
588 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 LOOP_NEXT(func, fini_code) \
598 int func(long *p_lb, long *p_ub) { \
601 int gtid = __kmp_get_gtid(); \
602 MKLOC(loc, KMP_STR(func)); \
603 KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
605 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
606 fini_code status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
607 (kmp_int *)p_ub, (kmp_int *)&stride); \
609 *p_ub += (stride > 0) ? 1 : -1; \
611 KMP_DOACROSS_FINI(status, gtid) \
615 (KMP_STR(func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
617 gtid, *p_lb, *p_ub, stride, status)); \
621 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
622 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
623 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START),
624 kmp_sch_dynamic_chunked)
625 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
626 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_START),
627 kmp_sch_guided_chunked)
628 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
629 LOOP_RUNTIME_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_START),
631 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
633 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START),
635 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT),
636 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
637 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START),
638 kmp_ord_dynamic_chunked)
639 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT),
640 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
641 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START),
642 kmp_ord_guided_chunked)
643 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT),
644 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
646 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START),
648 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT),
649 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
651 #define LOOP_DOACROSS_START(func, schedule) \
652 bool func(unsigned ncounts, long *counts, long chunk_sz, long *p_lb, \
655 long stride, lb, ub, str; \
656 int gtid = __kmp_entry_gtid(); \
657 struct kmp_dim *dims = \
658 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
659 MKLOC(loc, KMP_STR(func)); \
660 for (unsigned i = 0; i < ncounts; ++i) { \
662 dims[i].up = counts[i] - 1; \
665 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
669 KA_TRACE(20, (KMP_STR(func) ": T#%d, ncounts %u, lb 0x%lx, ub 0x%lx, str " \
672 gtid, ncounts, lb, ub, str, chunk_sz)); \
674 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
675 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
676 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
677 (schedule) != kmp_sch_static); \
678 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
679 (kmp_int *)p_ub, (kmp_int *)&stride); \
681 KMP_DEBUG_ASSERT(stride == str); \
682 *p_ub += (str > 0) ? 1 : -1; \
687 KMP_DOACROSS_FINI(status, gtid); \
692 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
693 gtid, *p_lb, *p_ub, status)); \
698 #define LOOP_DOACROSS_RUNTIME_START(func, schedule) \
699 int func(unsigned ncounts, long *counts, long *p_lb, long *p_ub) { \
701 long stride, lb, ub, str; \
703 int gtid = __kmp_entry_gtid(); \
704 struct kmp_dim *dims = \
705 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
706 MKLOC(loc, KMP_STR(func)); \
707 for (unsigned i = 0; i < ncounts; ++i) { \
709 dims[i].up = counts[i] - 1; \
712 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
718 (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
719 gtid, lb, ub, str, chunk_sz)); \
721 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
722 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
723 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
724 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
725 (kmp_int *)p_ub, (kmp_int *)&stride); \
727 KMP_DEBUG_ASSERT(stride == str); \
728 *p_ub += (str > 0) ? 1 : -1; \
733 KMP_DOACROSS_FINI(status, gtid); \
738 func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
739 gtid, *p_lb, *p_ub, status)); \
745 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START),
748 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START),
749 kmp_sch_dynamic_chunked)
751 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START),
752 kmp_sch_guided_chunked)
753 LOOP_DOACROSS_RUNTIME_START(
754 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START),
757 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END)(void) {
758 int gtid = __kmp_get_gtid();
759 KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
761 #if OMPT_SUPPORT && OMPT_OPTIONAL
762 ompt_frame_t *ompt_frame;
763 if (ompt_enabled.enabled) {
764 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
765 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
766 OMPT_STORE_RETURN_ADDRESS(gtid);
769 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
770 #if OMPT_SUPPORT && OMPT_OPTIONAL
771 if (ompt_enabled.enabled) {
772 ompt_frame->enter_frame = ompt_data_none;
776 KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
779 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void) {
780 KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
783 // Unsigned long long loop worksharing constructs
785 // These are new with gcc 4.4
787 #define LOOP_START_ULL(func, schedule) \
788 int func(int up, unsigned long long lb, unsigned long long ub, \
789 unsigned long long str, unsigned long long chunk_sz, \
790 unsigned long long *p_lb, unsigned long long *p_ub) { \
792 long long str2 = up ? ((long long)str) : -((long long)str); \
794 int gtid = __kmp_entry_gtid(); \
795 MKLOC(loc, KMP_STR(func)); \
797 KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
798 "0x%llx, chunk_sz 0x%llx\n", \
799 gtid, up, lb, ub, str, chunk_sz)); \
801 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
802 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
803 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
804 (schedule) != kmp_sch_static); \
806 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
807 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
809 KMP_DEBUG_ASSERT(stride == str2); \
810 *p_ub += (str > 0) ? 1 : -1; \
819 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
820 gtid, *p_lb, *p_ub, status)); \
824 #define LOOP_RUNTIME_START_ULL(func, schedule) \
825 int func(int up, unsigned long long lb, unsigned long long ub, \
826 unsigned long long str, unsigned long long *p_lb, \
827 unsigned long long *p_ub) { \
829 long long str2 = up ? ((long long)str) : -((long long)str); \
830 unsigned long long stride; \
831 unsigned long long chunk_sz = 0; \
832 int gtid = __kmp_entry_gtid(); \
833 MKLOC(loc, KMP_STR(func)); \
835 KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
836 "0x%llx, chunk_sz 0x%llx\n", \
837 gtid, up, lb, ub, str, chunk_sz)); \
839 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
840 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
841 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
844 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
845 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
847 KMP_DEBUG_ASSERT((long long)stride == str2); \
848 *p_ub += (str > 0) ? 1 : -1; \
857 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
858 gtid, *p_lb, *p_ub, status)); \
862 #define LOOP_NEXT_ULL(func, fini_code) \
863 int func(unsigned long long *p_lb, unsigned long long *p_ub) { \
866 int gtid = __kmp_get_gtid(); \
867 MKLOC(loc, KMP_STR(func)); \
868 KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
871 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
872 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
874 *p_ub += (stride > 0) ? 1 : -1; \
880 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
882 gtid, *p_lb, *p_ub, stride, status)); \
886 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START),
888 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
889 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START),
890 kmp_sch_dynamic_chunked)
891 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
892 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START),
893 kmp_sch_guided_chunked)
894 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
895 LOOP_RUNTIME_START_ULL(
896 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
897 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
899 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START),
901 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT),
902 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
904 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START),
905 kmp_ord_dynamic_chunked)
906 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT),
907 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
908 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START),
909 kmp_ord_guided_chunked)
910 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT),
911 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
912 LOOP_RUNTIME_START_ULL(
913 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START),
915 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT),
916 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
918 #define LOOP_DOACROSS_START_ULL(func, schedule) \
919 int func(unsigned ncounts, unsigned long long *counts, \
920 unsigned long long chunk_sz, unsigned long long *p_lb, \
921 unsigned long long *p_ub) { \
923 long long stride, str, lb, ub; \
924 int gtid = __kmp_entry_gtid(); \
925 struct kmp_dim *dims = \
926 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
927 MKLOC(loc, KMP_STR(func)); \
928 for (unsigned i = 0; i < ncounts; ++i) { \
930 dims[i].up = counts[i] - 1; \
933 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
938 KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
939 "0x%llx, chunk_sz 0x%llx\n", \
940 gtid, lb, ub, str, chunk_sz)); \
942 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
943 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
944 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
945 (schedule) != kmp_sch_static); \
947 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
948 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
950 KMP_DEBUG_ASSERT(stride == str); \
951 *p_ub += (str > 0) ? 1 : -1; \
956 KMP_DOACROSS_FINI(status, gtid); \
961 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
962 gtid, *p_lb, *p_ub, status)); \
967 #define LOOP_DOACROSS_RUNTIME_START_ULL(func, schedule) \
968 int func(unsigned ncounts, unsigned long long *counts, \
969 unsigned long long *p_lb, unsigned long long *p_ub) { \
971 unsigned long long stride, str, lb, ub; \
972 unsigned long long chunk_sz = 0; \
973 int gtid = __kmp_entry_gtid(); \
974 struct kmp_dim *dims = \
975 (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
976 MKLOC(loc, KMP_STR(func)); \
977 for (unsigned i = 0; i < ncounts; ++i) { \
979 dims[i].up = counts[i] - 1; \
982 __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
986 KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
987 "0x%llx, chunk_sz 0x%llx\n", \
988 gtid, lb, ub, str, chunk_sz)); \
990 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
991 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
992 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
995 KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
996 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
998 KMP_DEBUG_ASSERT(stride == str); \
999 *p_ub += (str > 0) ? 1 : -1; \
1004 KMP_DOACROSS_FINI(status, gtid); \
1009 func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
1010 gtid, *p_lb, *p_ub, status)); \
1015 LOOP_DOACROSS_START_ULL(
1016 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START),
1018 LOOP_DOACROSS_START_ULL(
1019 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START),
1020 kmp_sch_dynamic_chunked)
1021 LOOP_DOACROSS_START_ULL(
1022 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START),
1023 kmp_sch_guided_chunked)
1024 LOOP_DOACROSS_RUNTIME_START_ULL(
1025 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START),
1028 // Combined parallel / loop worksharing constructs
1030 // There are no ull versions (yet).
1032 #define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
1033 void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1034 long ub, long str, long chunk_sz) { \
1035 int gtid = __kmp_entry_gtid(); \
1036 MKLOC(loc, KMP_STR(func)); \
1040 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1041 gtid, lb, ub, str, chunk_sz)); \
1045 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1046 if (num_threads != 0) { \
1047 __kmp_push_num_threads(&loc, gtid, num_threads); \
1049 __kmp_GOMP_fork_call(&loc, gtid, task, \
1050 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1051 9, task, data, num_threads, &loc, (schedule), lb, \
1052 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1053 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid)); \
1055 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
1056 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid)); \
1059 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1060 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1061 (schedule) != kmp_sch_static); \
1065 KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1068 #if OMPT_SUPPORT && OMPT_OPTIONAL
1070 #define OMPT_LOOP_PRE() \
1071 ompt_frame_t *parent_frame; \
1072 if (ompt_enabled.enabled) { \
1073 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL); \
1074 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0); \
1075 OMPT_STORE_RETURN_ADDRESS(gtid); \
1078 #define OMPT_LOOP_POST() \
1079 if (ompt_enabled.enabled) { \
1080 parent_frame->enter_frame = ompt_data_none; \
1085 #define OMPT_LOOP_PRE()
1087 #define OMPT_LOOP_POST()
1091 PARALLEL_LOOP_START(
1092 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
1093 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1094 PARALLEL_LOOP_START(
1095 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
1096 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1097 PARALLEL_LOOP_START(
1098 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
1099 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1100 PARALLEL_LOOP_START(
1101 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
1102 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1104 // Tasking constructs
1106 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data,
1107 void (*copy_func)(void *, void *),
1108 long arg_size, long arg_align,
1109 bool if_cond, unsigned gomp_flags,
1111 MKLOC(loc, "GOMP_task");
1112 int gtid = __kmp_entry_gtid();
1113 kmp_int32 flags = 0;
1114 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1116 KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
1118 // The low-order bit is the "untied" flag
1119 if (!(gomp_flags & 1)) {
1120 input_flags->tiedness = 1;
1122 // The second low-order bit is the "final" flag
1123 if (gomp_flags & 2) {
1124 input_flags->final = 1;
1126 input_flags->native = 1;
1127 // __kmp_task_alloc() sets up all other flags
1133 kmp_task_t *task = __kmp_task_alloc(
1134 &loc, gtid, input_flags, sizeof(kmp_task_t),
1135 arg_size ? arg_size + arg_align - 1 : 0, (kmp_routine_entry_t)func);
1138 if (arg_align > 0) {
1139 task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1140 arg_align * arg_align);
1145 (*copy_func)(task->shareds, data);
1147 KMP_MEMCPY(task->shareds, data, arg_size);
1152 kmp_taskdata_t *current_task;
1153 if (ompt_enabled.enabled) {
1154 OMPT_STORE_RETURN_ADDRESS(gtid);
1155 current_task = __kmp_threads[gtid]->th.th_current_task;
1156 current_task->ompt_task_info.frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1161 if (gomp_flags & 8) {
1163 const size_t ndeps = (kmp_intptr_t)depend[0];
1164 const size_t nout = (kmp_intptr_t)depend[1];
1165 kmp_depend_info_t dep_list[ndeps];
1167 for (size_t i = 0U; i < ndeps; i++) {
1168 dep_list[i].base_addr = (kmp_intptr_t)depend[2U + i];
1169 dep_list[i].len = 0U;
1170 dep_list[i].flags.in = 1;
1171 dep_list[i].flags.out = (i < nout);
1173 __kmpc_omp_task_with_deps(&loc, gtid, task, ndeps, dep_list, 0, NULL);
1175 __kmpc_omp_task(&loc, gtid, task);
1179 ompt_thread_info_t oldInfo;
1181 kmp_taskdata_t *taskdata;
1182 if (ompt_enabled.enabled) {
1183 // Store the threads states and restore them after the task
1184 thread = __kmp_threads[gtid];
1185 taskdata = KMP_TASK_TO_TASKDATA(task);
1186 oldInfo = thread->th.ompt_thread_info;
1187 thread->th.ompt_thread_info.wait_id = 0;
1188 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
1189 taskdata->ompt_task_info.frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1190 OMPT_STORE_RETURN_ADDRESS(gtid);
1194 __kmpc_omp_task_begin_if0(&loc, gtid, task);
1196 __kmpc_omp_task_complete_if0(&loc, gtid, task);
1199 if (ompt_enabled.enabled) {
1200 thread->th.ompt_thread_info = oldInfo;
1201 taskdata->ompt_task_info.frame.exit_frame = ompt_data_none;
1206 if (ompt_enabled.enabled) {
1207 current_task->ompt_task_info.frame.enter_frame = ompt_data_none;
1211 KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1214 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT)(void) {
1215 MKLOC(loc, "GOMP_taskwait");
1216 int gtid = __kmp_entry_gtid();
1219 if (ompt_enabled.enabled)
1220 OMPT_STORE_RETURN_ADDRESS(gtid);
1223 KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1225 __kmpc_omp_taskwait(&loc, gtid);
1227 KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1230 // Sections worksharing constructs
1232 // For the sections construct, we initialize a dynamically scheduled loop
1233 // worksharing construct with lb 1 and stride 1, and use the iteration #'s
1234 // that its returns as sections ids.
1236 // There are no special entry points for ordered sections, so we always use
1237 // the dynamically scheduled workshare, even if the sections aren't ordered.
1239 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count) {
1241 kmp_int lb, ub, stride;
1242 int gtid = __kmp_entry_gtid();
1243 MKLOC(loc, "GOMP_sections_start");
1244 KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1246 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1248 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1250 KMP_DEBUG_ASSERT(stride == 1);
1251 KMP_DEBUG_ASSERT(lb > 0);
1252 KMP_ASSERT(lb == ub);
1257 KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1259 return (unsigned)lb;
1262 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void) {
1264 kmp_int lb, ub, stride;
1265 int gtid = __kmp_get_gtid();
1266 MKLOC(loc, "GOMP_sections_next");
1267 KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1270 OMPT_STORE_RETURN_ADDRESS(gtid);
1273 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1275 KMP_DEBUG_ASSERT(stride == 1);
1276 KMP_DEBUG_ASSERT(lb > 0);
1277 KMP_ASSERT(lb == ub);
1283 20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid, (unsigned)lb));
1284 return (unsigned)lb;
1287 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(
1288 void (*task)(void *), void *data, unsigned num_threads, unsigned count) {
1289 int gtid = __kmp_entry_gtid();
1292 ompt_frame_t *parent_frame;
1294 if (ompt_enabled.enabled) {
1295 __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
1296 parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1297 OMPT_STORE_RETURN_ADDRESS(gtid);
1301 MKLOC(loc, "GOMP_parallel_sections_start");
1302 KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1304 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1305 if (num_threads != 0) {
1306 __kmp_push_num_threads(&loc, gtid, num_threads);
1308 __kmp_GOMP_fork_call(&loc, gtid, task,
1309 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1310 task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1311 (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1313 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1317 if (ompt_enabled.enabled) {
1318 parent_frame->enter_frame = ompt_data_none;
1322 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1324 KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1327 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END)(void) {
1328 int gtid = __kmp_get_gtid();
1329 KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1332 ompt_frame_t *ompt_frame;
1333 if (ompt_enabled.enabled) {
1334 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
1335 ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1336 OMPT_STORE_RETURN_ADDRESS(gtid);
1339 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1341 if (ompt_enabled.enabled) {
1342 ompt_frame->enter_frame = ompt_data_none;
1346 KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1349 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void) {
1350 KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1353 // libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1354 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKYIELD)(void) {
1355 KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1359 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *),
1361 unsigned num_threads,
1362 unsigned int flags) {
1363 int gtid = __kmp_entry_gtid();
1364 MKLOC(loc, "GOMP_parallel");
1365 KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1368 ompt_task_info_t *parent_task_info, *task_info;
1369 if (ompt_enabled.enabled) {
1370 parent_task_info = __ompt_get_task_info_object(0);
1371 parent_task_info->frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1372 OMPT_STORE_RETURN_ADDRESS(gtid);
1375 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1376 if (num_threads != 0) {
1377 __kmp_push_num_threads(&loc, gtid, num_threads);
1380 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1382 __kmp_GOMP_fork_call(&loc, gtid, task,
1383 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
1386 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1389 if (ompt_enabled.enabled) {
1390 task_info = __ompt_get_task_info_object(0);
1391 task_info->frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1396 if (ompt_enabled.enabled) {
1397 OMPT_STORE_RETURN_ADDRESS(gtid);
1400 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1402 if (ompt_enabled.enabled) {
1403 task_info->frame.exit_frame = ompt_data_none;
1404 parent_task_info->frame.enter_frame = ompt_data_none;
1409 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
1411 unsigned num_threads,
1414 int gtid = __kmp_entry_gtid();
1415 MKLOC(loc, "GOMP_parallel_sections");
1416 KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1419 OMPT_STORE_RETURN_ADDRESS(gtid);
1422 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1423 if (num_threads != 0) {
1424 __kmp_push_num_threads(&loc, gtid, num_threads);
1427 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1429 __kmp_GOMP_fork_call(&loc, gtid, task,
1430 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1431 task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1432 (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1434 __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1438 OMPT_STORE_RETURN_ADDRESS(gtid);
1441 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1444 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1445 KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1448 #define PARALLEL_LOOP(func, schedule, ompt_pre, ompt_post) \
1449 void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1450 long ub, long str, long chunk_sz, unsigned flags) { \
1451 int gtid = __kmp_entry_gtid(); \
1452 MKLOC(loc, KMP_STR(func)); \
1456 func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1457 gtid, lb, ub, str, chunk_sz)); \
1460 if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) { \
1461 if (num_threads != 0) { \
1462 __kmp_push_num_threads(&loc, gtid, num_threads); \
1465 __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags); \
1467 __kmp_GOMP_fork_call(&loc, gtid, task, \
1468 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1469 9, task, data, num_threads, &loc, (schedule), lb, \
1470 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1472 __kmp_GOMP_serialized_parallel(&loc, gtid, task); \
1475 IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
1476 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1477 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1478 (schedule) != kmp_sch_static); \
1480 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1483 KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1486 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC),
1487 kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1488 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC),
1489 kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1490 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED),
1491 kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1492 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME),
1493 kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1495 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_START)(void) {
1496 int gtid = __kmp_entry_gtid();
1497 MKLOC(loc, "GOMP_taskgroup_start");
1498 KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1501 if (ompt_enabled.enabled)
1502 OMPT_STORE_RETURN_ADDRESS(gtid);
1505 __kmpc_taskgroup(&loc, gtid);
1510 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_END)(void) {
1511 int gtid = __kmp_get_gtid();
1512 MKLOC(loc, "GOMP_taskgroup_end");
1513 KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1516 if (ompt_enabled.enabled)
1517 OMPT_STORE_RETURN_ADDRESS(gtid);
1520 __kmpc_end_taskgroup(&loc, gtid);
1525 static kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
1526 kmp_int32 cncl_kind = 0;
1527 switch (gomp_kind) {
1529 cncl_kind = cancel_parallel;
1532 cncl_kind = cancel_loop;
1535 cncl_kind = cancel_sections;
1538 cncl_kind = cancel_taskgroup;
1544 // Return true if cancellation should take place, false otherwise
1545 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which) {
1546 int gtid = __kmp_get_gtid();
1547 MKLOC(loc, "GOMP_cancellation_point");
1548 KA_TRACE(20, ("GOMP_cancellation_point: T#%d which:%d\n", gtid, which));
1549 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1550 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1553 // Return true if cancellation should take place, false otherwise
1554 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel) {
1555 int gtid = __kmp_get_gtid();
1556 MKLOC(loc, "GOMP_cancel");
1557 KA_TRACE(20, ("GOMP_cancel: T#%d which:%d do_cancel:%d\n", gtid, which,
1559 kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1561 if (do_cancel == FALSE) {
1562 return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1564 return __kmpc_cancel(&loc, gtid, cncl_kind);
1568 // Return true if cancellation should take place, false otherwise
1569 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void) {
1570 int gtid = __kmp_get_gtid();
1571 KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1572 return __kmp_barrier_gomp_cancel(gtid);
1575 // Return true if cancellation should take place, false otherwise
1576 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void) {
1577 int gtid = __kmp_get_gtid();
1578 KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1579 return __kmp_barrier_gomp_cancel(gtid);
1582 // Return true if cancellation should take place, false otherwise
1583 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void) {
1584 int gtid = __kmp_get_gtid();
1585 KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1586 return __kmp_barrier_gomp_cancel(gtid);
1589 // All target functions are empty as of 2014-05-29
1590 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn)(void *),
1591 const void *openmp_target,
1592 size_t mapnum, void **hostaddrs,
1594 unsigned char *kinds) {
1598 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_DATA)(
1599 int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1600 size_t *sizes, unsigned char *kinds) {
1604 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_END_DATA)(void) { return; }
1606 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_UPDATE)(
1607 int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1608 size_t *sizes, unsigned char *kinds) {
1612 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams,
1613 unsigned int thread_limit) {
1617 // Task duplication function which copies src to dest (both are
1618 // preallocated task structures)
1619 static void __kmp_gomp_task_dup(kmp_task_t *dest, kmp_task_t *src,
1620 kmp_int32 last_private) {
1621 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(src);
1622 if (taskdata->td_copy_func) {
1623 (taskdata->td_copy_func)(dest->shareds, src->shareds);
1631 template <typename T>
1632 void __GOMP_taskloop(void (*func)(void *), void *data,
1633 void (*copy_func)(void *, void *), long arg_size,
1634 long arg_align, unsigned gomp_flags,
1635 unsigned long num_tasks, int priority, T start, T end,
1637 typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
1638 MKLOC(loc, "GOMP_taskloop");
1641 int gtid = __kmp_entry_gtid();
1642 kmp_int32 flags = 0;
1643 int if_val = gomp_flags & (1u << 10);
1644 int nogroup = gomp_flags & (1u << 11);
1645 int up = gomp_flags & (1u << 8);
1646 p_task_dup_t task_dup = NULL;
1647 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1651 buff = __kmp_str_format(
1652 "GOMP_taskloop: T#%%d: func:%%p data:%%p copy_func:%%p "
1653 "arg_size:%%ld arg_align:%%ld gomp_flags:0x%%x num_tasks:%%lu "
1654 "priority:%%d start:%%%s end:%%%s step:%%%s\n",
1655 traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec);
1656 KA_TRACE(20, (buff, gtid, func, data, copy_func, arg_size, arg_align,
1657 gomp_flags, num_tasks, priority, start, end, step));
1658 __kmp_str_free(&buff);
1661 KMP_ASSERT((size_t)arg_size >= 2 * sizeof(T));
1662 KMP_ASSERT(arg_align > 0);
1663 // The low-order bit is the "untied" flag
1664 if (!(gomp_flags & 1)) {
1665 input_flags->tiedness = 1;
1667 // The second low-order bit is the "final" flag
1668 if (gomp_flags & 2) {
1669 input_flags->final = 1;
1671 // Negative step flag
1673 // If step is flagged as negative, but isn't properly sign extended
1674 // Then manually sign extend it. Could be a short, int, char embedded
1675 // in a long. So cannot assume any cast.
1677 for (int i = sizeof(T) * CHAR_BIT - 1; i >= 0L; --i) {
1678 // break at the first 1 bit
1679 if (step & ((T)1 << i))
1681 step |= ((T)1 << i);
1685 input_flags->native = 1;
1686 // Figure out if none/grainsize/num_tasks clause specified
1687 if (num_tasks > 0) {
1688 if (gomp_flags & (1u << 9))
1689 sched = 1; // grainsize specified
1691 sched = 2; // num_tasks specified
1692 // neither grainsize nor num_tasks specified
1697 // __kmp_task_alloc() sets up all other flags
1699 __kmp_task_alloc(&loc, gtid, input_flags, sizeof(kmp_task_t),
1700 arg_size + arg_align - 1, (kmp_routine_entry_t)func);
1701 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
1702 taskdata->td_copy_func = copy_func;
1703 taskdata->td_size_loop_bounds = sizeof(T);
1705 // re-align shareds if needed and setup firstprivate copy constructors
1706 // through the task_dup mechanism
1707 task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1708 arg_align * arg_align);
1710 task_dup = __kmp_gomp_task_dup;
1712 KMP_MEMCPY(task->shareds, data, arg_size);
1714 loop_bounds = (T *)task->shareds;
1715 loop_bounds[0] = start;
1716 loop_bounds[1] = end + (up ? -1 : 1);
1717 __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
1718 (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, nogroup,
1719 sched, (kmp_uint64)num_tasks, (void *)task_dup);
1722 // 4 byte version of GOMP_doacross_post
1723 // This verison needs to create a temporary array which converts 4 byte
1724 // integers into 8 byte integeres
1725 template <typename T, bool need_conversion = (sizeof(long) == 4)>
1726 void __kmp_GOMP_doacross_post(T *count);
1728 template <> void __kmp_GOMP_doacross_post<long, true>(long *count) {
1729 int gtid = __kmp_entry_gtid();
1730 kmp_info_t *th = __kmp_threads[gtid];
1731 MKLOC(loc, "GOMP_doacross_post");
1732 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1734 (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1735 for (kmp_int64 i = 0; i < num_dims; ++i) {
1736 vec[i] = (kmp_int64)count[i];
1738 __kmpc_doacross_post(&loc, gtid, vec);
1739 __kmp_thread_free(th, vec);
1742 // 8 byte versions of GOMP_doacross_post
1743 // This version can just pass in the count array directly instead of creating
1744 // a temporary array
1745 template <> void __kmp_GOMP_doacross_post<long, false>(long *count) {
1746 int gtid = __kmp_entry_gtid();
1747 MKLOC(loc, "GOMP_doacross_post");
1748 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1751 template <typename T> void __kmp_GOMP_doacross_wait(T first, va_list args) {
1752 int gtid = __kmp_entry_gtid();
1753 kmp_info_t *th = __kmp_threads[gtid];
1754 MKLOC(loc, "GOMP_doacross_wait");
1755 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1757 (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1758 vec[0] = (kmp_int64)first;
1759 for (kmp_int64 i = 1; i < num_dims; ++i) {
1760 T item = va_arg(args, T);
1761 vec[i] = (kmp_int64)item;
1763 __kmpc_doacross_wait(&loc, gtid, vec);
1764 __kmp_thread_free(th, vec);
1770 #endif // __cplusplus
1772 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP)(
1773 void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1774 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1775 int priority, long start, long end, long step) {
1776 __GOMP_taskloop<long>(func, data, copy_func, arg_size, arg_align, gomp_flags,
1777 num_tasks, priority, start, end, step);
1780 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP_ULL)(
1781 void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1782 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1783 int priority, unsigned long long start, unsigned long long end,
1784 unsigned long long step) {
1785 __GOMP_taskloop<unsigned long long>(func, data, copy_func, arg_size,
1786 arg_align, gomp_flags, num_tasks,
1787 priority, start, end, step);
1790 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_POST)(long *count) {
1791 __kmp_GOMP_doacross_post(count);
1794 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_WAIT)(long first, ...) {
1796 va_start(args, first);
1797 __kmp_GOMP_doacross_wait<long>(first, args);
1801 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_POST)(
1802 unsigned long long *count) {
1803 int gtid = __kmp_entry_gtid();
1804 MKLOC(loc, "GOMP_doacross_ull_post");
1805 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1808 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT)(
1809 unsigned long long first, ...) {
1811 va_start(args, first);
1812 __kmp_GOMP_doacross_wait<unsigned long long>(first, args);
1816 /* The following sections of code create aliases for the GOMP_* functions, then
1817 create versioned symbols using the assembler directive .symver. This is only
1818 pertinent for ELF .so library. The KMP_VERSION_SYMBOL macro is defined in
1821 #ifdef KMP_USE_VERSION_SYMBOLS
1822 // GOMP_1.0 versioned symbols
1823 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1824 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1825 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1826 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1827 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1828 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1829 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1830 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1831 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1832 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1833 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1834 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1835 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1836 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1837 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10,
1839 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1840 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1841 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1842 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10,
1844 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1845 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1846 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1847 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1848 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1849 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1850 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1851 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1852 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1853 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10,
1855 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10,
1857 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10,
1859 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10,
1861 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1862 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1863 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1864 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1865 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1866 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1867 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1868 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1869 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1871 // GOMP_2.0 versioned symbols
1872 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1873 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
1874 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1875 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1876 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1877 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1878 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20,
1880 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20,
1882 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20,
1884 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20,
1886 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20,
1888 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20,
1890 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20,
1892 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20,
1894 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1895 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1896 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1897 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1899 // GOMP_3.0 versioned symbols
1900 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1902 // GOMP_4.0 versioned symbols
1903 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1904 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1905 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1906 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1907 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1908 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1909 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1910 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1911 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1912 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1913 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1914 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1915 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1916 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1917 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1918 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1919 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1920 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1922 // GOMP_4.5 versioned symbols
1923 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP, 45, "GOMP_4.5");
1924 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP_ULL, 45, "GOMP_4.5");
1925 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_POST, 45, "GOMP_4.5");
1926 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_WAIT, 45, "GOMP_4.5");
1927 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START, 45,
1929 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START, 45,
1931 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START, 45,
1933 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START, 45,
1935 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_POST, 45, "GOMP_4.5");
1936 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT, 45, "GOMP_4.5");
1937 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START, 45,
1939 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START, 45,
1941 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START, 45,
1943 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, 45,
1946 #endif // KMP_USE_VERSION_SYMBOLS
1950 #endif // __cplusplus