41 #include "kmp_atomic.h"
47 #define MKLOC(loc,routine) \
48 static ident_t (loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;" };
54 int gtid = __kmp_entry_gtid();
55 MKLOC(loc,
"GOMP_barrier");
56 KA_TRACE(20, (
"GOMP_barrier: T#%d\n", gtid));
76 extern kmp_critical_name *__kmp_unnamed_critical_addr;
80 GOMP_critical_start(
void)
82 int gtid = __kmp_entry_gtid();
83 MKLOC(loc,
"GOMP_critical_start");
84 KA_TRACE(20, (
"GOMP_critical_start: T#%d\n", gtid));
90 GOMP_critical_end(
void)
92 int gtid = __kmp_get_gtid();
93 MKLOC(loc,
"GOMP_critical_end");
94 KA_TRACE(20, (
"GOMP_critical_end: T#%d\n", gtid));
100 GOMP_critical_name_start(
void **pptr)
102 int gtid = __kmp_entry_gtid();
103 MKLOC(loc,
"GOMP_critical_name_start");
104 KA_TRACE(20, (
"GOMP_critical_name_start: T#%d\n", gtid));
110 GOMP_critical_name_end(
void **pptr)
112 int gtid = __kmp_get_gtid();
113 MKLOC(loc,
"GOMP_critical_name_end");
114 KA_TRACE(20, (
"GOMP_critical_name_end: T#%d\n", gtid));
126 GOMP_atomic_start(
void)
128 int gtid = __kmp_entry_gtid();
129 KA_TRACE(20, (
"GOMP_atomic_start: T#%d\n", gtid));
130 __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
135 GOMP_atomic_end(
void)
137 int gtid = __kmp_get_gtid();
138 KA_TRACE(20, (
"GOMP_atomic_start: T#%d\n", gtid));
139 __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
144 GOMP_single_start(
void)
146 int gtid = __kmp_entry_gtid();
147 MKLOC(loc,
"GOMP_single_start");
148 KA_TRACE(20, (
"GOMP_single_start: T#%d\n", gtid));
150 if (! TCR_4(__kmp_init_parallel))
151 __kmp_parallel_initialize();
158 return __kmp_enter_single(gtid, &loc, FALSE);
163 GOMP_single_copy_start(
void)
166 int gtid = __kmp_entry_gtid();
167 MKLOC(loc,
"GOMP_single_copy_start");
168 KA_TRACE(20, (
"GOMP_single_copy_start: T#%d\n", gtid));
170 if (! TCR_4(__kmp_init_parallel))
171 __kmp_parallel_initialize();
178 if (__kmp_enter_single(gtid, &loc, FALSE))
185 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
191 retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
192 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
198 GOMP_single_copy_end(
void *data)
200 int gtid = __kmp_get_gtid();
201 MKLOC(loc,
"GOMP_single_copy_end");
202 KA_TRACE(20, (
"GOMP_single_copy_end: T#%d\n", gtid));
211 __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
212 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
213 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
218 GOMP_ordered_start(
void)
220 int gtid = __kmp_entry_gtid();
221 MKLOC(loc,
"GOMP_ordered_start");
222 KA_TRACE(20, (
"GOMP_ordered_start: T#%d\n", gtid));
228 GOMP_ordered_end(
void)
230 int gtid = __kmp_get_gtid();
231 MKLOC(loc,
"GOMP_ordered_end");
232 KA_TRACE(20, (
"GOMP_ordered_start: T#%d\n", gtid));
246 # define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
247 # define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
248 # define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
250 # define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
251 # define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
252 # define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
255 # define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
256 # define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
257 # define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
269 __kmp_GOMP_microtask_wrapper(
int *gtid,
int *npr,
void (*task)(
void *),
280 __kmp_GOMP_parallel_microtask_wrapper(
int *gtid,
int *npr,
281 void (*task)(
void *),
void *data,
unsigned num_threads,
ident_t *loc,
282 enum sched_type schedule,
long start,
long end,
long incr,
long chunk_size)
287 KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
301 __kmp_GOMP_fork_call(
ident_t *loc,
int gtid, microtask_t wrapper,
int argc,...)
308 rc = __kmp_fork_call(loc, gtid, FALSE, argc, wrapper, __kmp_invoke_task_func,
309 #
if KMP_ARCH_X86_64 && KMP_OS_LINUX
319 kmp_info_t *thr = __kmp_threads[gtid];
320 __kmp_run_before_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
327 GOMP_parallel_start(
void (*task)(
void *),
void *data,
unsigned num_threads)
329 int gtid = __kmp_entry_gtid();
330 MKLOC(loc,
"GOMP_parallel_start");
331 KA_TRACE(20, (
"GOMP_parallel_start: T#%d\n", gtid));
334 if (num_threads != 0) {
335 __kmp_push_num_threads(&loc, gtid, num_threads);
337 __kmp_GOMP_fork_call(&loc, gtid,
338 (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task, data);
347 GOMP_parallel_end(
void)
349 int gtid = __kmp_get_gtid();
350 MKLOC(loc,
"GOMP_parallel_end");
351 KA_TRACE(20, (
"GOMP_parallel_end: T#%d\n", gtid));
353 if (! __kmp_threads[gtid]->th.th_team->t.t_serialized) {
354 kmp_info_t *thr = __kmp_threads[gtid];
355 __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
357 __kmp_join_call(&loc, gtid);
394 #define LOOP_START(func,schedule) \
395 int func (long lb, long ub, long str, long chunk_sz, long *p_lb, \
400 int gtid = __kmp_entry_gtid(); \
402 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
403 gtid, lb, ub, str, chunk_sz )); \
405 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
406 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
407 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
408 (schedule) != kmp_sch_static); \
409 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
410 (kmp_int *)p_ub, (kmp_int *)&stride); \
412 KMP_DEBUG_ASSERT(stride == str); \
413 *p_ub += (str > 0) ? 1 : -1; \
420 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
421 gtid, *p_lb, *p_ub, status)); \
426 #define LOOP_RUNTIME_START(func,schedule) \
427 int func (long lb, long ub, long str, long *p_lb, long *p_ub) \
432 int gtid = __kmp_entry_gtid(); \
434 KA_TRACE(20, ( #func ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
435 gtid, lb, ub, str, chunk_sz )); \
437 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
438 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
439 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
440 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
441 (kmp_int *)p_ub, (kmp_int *)&stride); \
443 KMP_DEBUG_ASSERT(stride == str); \
444 *p_ub += (str > 0) ? 1 : -1; \
451 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
452 gtid, *p_lb, *p_ub, status)); \
457 #define LOOP_NEXT(func,fini_code) \
458 int func(long *p_lb, long *p_ub) \
462 int gtid = __kmp_get_gtid(); \
464 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
467 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
468 (kmp_int *)p_ub, (kmp_int *)&stride); \
470 *p_ub += (stride > 0) ? 1 : -1; \
473 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
474 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
480 LOOP_NEXT(GOMP_loop_static_next, {})
481 LOOP_START(GOMP_loop_dynamic_start, kmp_sch_dynamic_chunked)
482 LOOP_NEXT(GOMP_loop_dynamic_next, {})
484 LOOP_NEXT(GOMP_loop_guided_next, {})
485 LOOP_RUNTIME_START(GOMP_loop_runtime_start, kmp_sch_runtime)
486 LOOP_NEXT(GOMP_loop_runtime_next, {})
489 LOOP_NEXT(GOMP_loop_ordered_static_next, \
490 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
491 LOOP_START(GOMP_loop_ordered_dynamic_start, kmp_ord_dynamic_chunked)
492 LOOP_NEXT(GOMP_loop_ordered_dynamic_next, \
493 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
494 LOOP_START(GOMP_loop_ordered_guided_start, kmp_ord_guided_chunked)
495 LOOP_NEXT(GOMP_loop_ordered_guided_next, \
496 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
497 LOOP_RUNTIME_START(GOMP_loop_ordered_runtime_start, kmp_ord_runtime)
498 LOOP_NEXT(GOMP_loop_ordered_runtime_next, \
499 { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
505 int gtid = __kmp_get_gtid();
506 KA_TRACE(20, (
"GOMP_loop_end: T#%d\n", gtid))
508 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
510 KA_TRACE(20, ("GOMP_loop_end exit: T
#%d\n", gtid))
515 GOMP_loop_end_nowait(
void)
517 KA_TRACE(20, (
"GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
528 #define LOOP_START_ULL(func,schedule) \
529 int func (int up, unsigned long long lb, unsigned long long ub, \
530 unsigned long long str, unsigned long long chunk_sz, \
531 unsigned long long *p_lb, unsigned long long *p_ub) \
534 long long str2 = up ? ((long long)str) : -((long long)str); \
536 int gtid = __kmp_entry_gtid(); \
539 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
540 gtid, up, lb, ub, str, chunk_sz )); \
542 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
543 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
544 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
545 (schedule) != kmp_sch_static); \
546 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
547 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
549 KMP_DEBUG_ASSERT(stride == str2); \
550 *p_ub += (str > 0) ? 1 : -1; \
557 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
558 gtid, *p_lb, *p_ub, status)); \
563 #define LOOP_RUNTIME_START_ULL(func,schedule) \
564 int func (int up, unsigned long long lb, unsigned long long ub, \
565 unsigned long long str, unsigned long long *p_lb, \
566 unsigned long long *p_ub) \
569 long long str2 = up ? ((long long)str) : -((long long)str); \
570 unsigned long long stride; \
571 unsigned long long chunk_sz = 0; \
572 int gtid = __kmp_entry_gtid(); \
575 KA_TRACE(20, ( #func ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str 0x%llx, chunk_sz 0x%llx\n", \
576 gtid, up, lb, ub, str, chunk_sz )); \
578 if ((str > 0) ? (lb < ub) : (lb > ub)) { \
579 KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
580 (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, TRUE); \
581 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, \
582 (kmp_uint64 *)p_lb, (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
584 KMP_DEBUG_ASSERT(stride == str2); \
585 *p_ub += (str > 0) ? 1 : -1; \
592 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
593 gtid, *p_lb, *p_ub, status)); \
598 #define LOOP_NEXT_ULL(func,fini_code) \
599 int func(unsigned long long *p_lb, unsigned long long *p_ub) \
603 int gtid = __kmp_get_gtid(); \
605 KA_TRACE(20, ( #func ": T#%d\n", gtid)); \
608 status = KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
609 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
611 *p_ub += (stride > 0) ? 1 : -1; \
614 KA_TRACE(20, ( #func " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
615 "returning %d\n", gtid, *p_lb, *p_ub, stride, status)); \
621 LOOP_NEXT_ULL(GOMP_loop_ull_static_next, {})
622 LOOP_START_ULL(GOMP_loop_ull_dynamic_start, kmp_sch_dynamic_chunked)
623 LOOP_NEXT_ULL(GOMP_loop_ull_dynamic_next, {})
625 LOOP_NEXT_ULL(GOMP_loop_ull_guided_next, {})
626 LOOP_RUNTIME_START_ULL(GOMP_loop_ull_runtime_start, kmp_sch_runtime)
627 LOOP_NEXT_ULL(GOMP_loop_ull_runtime_next, {})
629 LOOP_START_ULL(GOMP_loop_ull_ordered_static_start,
kmp_ord_static)
630 LOOP_NEXT_ULL(GOMP_loop_ull_ordered_static_next, \
631 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
632 LOOP_START_ULL(GOMP_loop_ull_ordered_dynamic_start, kmp_ord_dynamic_chunked)
633 LOOP_NEXT_ULL(GOMP_loop_ull_ordered_dynamic_next, \
634 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
635 LOOP_START_ULL(GOMP_loop_ull_ordered_guided_start, kmp_ord_guided_chunked)
636 LOOP_NEXT_ULL(GOMP_loop_ull_ordered_guided_next, \
637 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
638 LOOP_RUNTIME_START_ULL(GOMP_loop_ull_ordered_runtime_start, kmp_ord_runtime)
639 LOOP_NEXT_ULL(GOMP_loop_ull_ordered_runtime_next, \
640 { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
650 #define PARALLEL_LOOP_START(func, schedule) \
651 void func (
void (*task) (
void *),
void *data,
unsigned num_threads, \
652 long lb,
long ub,
long str,
long chunk_sz) \
654 int gtid = __kmp_entry_gtid(); \
657 KA_TRACE(20, ( #func
": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
658 gtid, lb, ub, str, chunk_sz )); \
661 if (num_threads != 0) { \
662 __kmp_push_num_threads(&loc, gtid, num_threads); \
664 __kmp_GOMP_fork_call(&loc, gtid, \
665 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, \
666 task, data, num_threads, &loc, (schedule), lb, \
667 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
670 __kmpc_serialized_parallel(&loc, gtid); \
673 KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
674 (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
677 KA_TRACE(20, ( #func
" exit: T#%d\n", gtid)); \
681 PARALLEL_LOOP_START(GOMP_parallel_loop_static_start,
kmp_sch_static)
682 PARALLEL_LOOP_START(GOMP_parallel_loop_dynamic_start, kmp_sch_dynamic_chunked)
684 PARALLEL_LOOP_START(GOMP_parallel_loop_runtime_start, kmp_sch_runtime)
696 GOMP_task(
void (*func)(
void *),
void *data,
void (*copy_func)(
void *,
void *),
697 long arg_size,
long arg_align,
int if_cond,
unsigned gomp_flags)
699 MKLOC(loc,
"GOMP_task");
700 int gtid = __kmp_entry_gtid();
702 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *) & flags;
704 KA_TRACE(20, (
"GOMP_task: T#%d\n", gtid));
707 if (gomp_flags & 1) {
708 input_flags->tiedness = 1;
710 input_flags->native = 1;
717 kmp_task_t *task = __kmp_task_alloc(&loc, gtid, input_flags,
718 sizeof(kmp_task_t), arg_size ? arg_size + arg_align - 1 : 0,
719 (kmp_routine_entry_t)func);
723 task->shareds = (
void *)((((
size_t)task->shareds)
724 + arg_align - 1) / arg_align * arg_align);
729 (*copy_func)(task->shareds, data);
732 memcpy(task->shareds, data, arg_size);
737 __kmpc_omp_task(&loc, gtid, task);
740 __kmpc_omp_task_begin_if0(&loc, gtid, task);
742 __kmpc_omp_task_complete_if0(&loc, gtid, task);
745 KA_TRACE(20, (
"GOMP_task exit: T#%d\n", gtid));
752 MKLOC(loc,
"GOMP_taskwait");
753 int gtid = __kmp_entry_gtid();
755 KA_TRACE(20, (
"GOMP_taskwait: T#%d\n", gtid));
757 __kmpc_omp_taskwait(&loc, gtid);
759 KA_TRACE(20, (
"GOMP_taskwait exit: T#%d\n", gtid));
781 GOMP_sections_start(
unsigned count)
784 kmp_int lb, ub, stride;
785 int gtid = __kmp_entry_gtid();
786 MKLOC(loc,
"GOMP_sections_start");
787 KA_TRACE(20, (
"GOMP_sections_start: T#%d\n", gtid));
789 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
791 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
793 KMP_DEBUG_ASSERT(stride == 1);
794 KMP_DEBUG_ASSERT(lb > 0);
795 KMP_ASSERT(lb == ub);
801 KA_TRACE(20, (
"GOMP_sections_start exit: T#%d returning %u\n", gtid,
808 GOMP_sections_next(
void)
811 kmp_int lb, ub, stride;
812 int gtid = __kmp_get_gtid();
813 MKLOC(loc,
"GOMP_sections_next");
814 KA_TRACE(20, (
"GOMP_sections_next: T#%d\n", gtid));
816 status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
818 KMP_DEBUG_ASSERT(stride == 1);
819 KMP_DEBUG_ASSERT(lb > 0);
820 KMP_ASSERT(lb == ub);
826 KA_TRACE(20, (
"GOMP_sections_next exit: T#%d returning %u\n", gtid,
833 GOMP_parallel_sections_start(
void (*task) (
void *),
void *data,
834 unsigned num_threads,
unsigned count)
836 int gtid = __kmp_entry_gtid();
838 MKLOC(loc,
"GOMP_parallel_sections_start");
839 KA_TRACE(20, (
"GOMP_parallel_sections_start: T#%d\n", gtid));
842 if (num_threads != 0) {
843 __kmp_push_num_threads(&loc, gtid, num_threads);
845 __kmp_GOMP_fork_call(&loc, gtid,
846 (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9, task, data,
847 num_threads, &loc, kmp_nm_dynamic_chunked, (kmp_int)1,
848 (kmp_int)count, (kmp_int)1, (kmp_int)1);
854 KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
856 KA_TRACE(20, (
"GOMP_parallel_sections_start exit: T#%d\n", gtid));
861 GOMP_sections_end(
void)
863 int gtid = __kmp_get_gtid();
864 KA_TRACE(20, (
"GOMP_sections_end: T#%d\n", gtid))
866 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
868 KA_TRACE(20, ("GOMP_sections_end exit: T
#%d\n", gtid))
873 GOMP_sections_end_nowait(
void)
875 KA_TRACE(20, (
"GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
880 #endif // __cplusplus