1 /*
2  * kmp_gsupport.cpp
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 //                     The LLVM Compiler Infrastructure
8 //
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "kmp.h"
15 #include "kmp_atomic.h"
16 
17 #if OMPT_SUPPORT
18 #include "ompt-specific.h"
19 #endif
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif // __cplusplus
24 
25 #define MKLOC(loc, routine)                                                    \
26   static ident_t(loc) = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;"};
27 
28 #include "kmp_ftn_os.h"
29 
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   omp_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 = OMPT_GET_FRAME_ADDRESS(1);
39     OMPT_STORE_RETURN_ADDRESS(gtid);
40   }
41 #endif
42   __kmpc_barrier(&loc, gtid);
43 #if OMPT_SUPPORT && OMPT_OPTIONAL
44   if (ompt_enabled.enabled) {
45     ompt_frame->enter_frame = NULL;
46   }
47 #endif
48 }
49 
50 // Mutual exclusion
51 
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 ".".
55 //
56 // The RTL contains an assembly language definition of .gomp_critical_user_
57 // with another symbol __kmp_unnamed_critical_addr initialized with it's
58 // address.
59 extern kmp_critical_name *__kmp_unnamed_critical_addr;
60 
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);
67 #endif
68   __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
69 }
70 
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);
77 #endif
78   __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
79 }
80 
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);
86 }
87 
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);
93 }
94 
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));
101 
102 #if OMPT_SUPPORT
103   __ompt_thread_assign_wait_id(0);
104 #endif
105 
106   __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
107 }
108 
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);
113 }
114 
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));
119 
120   if (!TCR_4(__kmp_init_parallel))
121     __kmp_parallel_initialize();
122 
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);
127 
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);
132 
133   if (ompt_enabled.enabled) {
134     if (rc) {
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));
141       }
142     } else {
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));
154       }
155     }
156   }
157 #endif
158 
159   return rc;
160 }
161 
162 void *KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_START)(void) {
163   void *retval;
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));
167 
168   if (!TCR_4(__kmp_init_parallel))
169     __kmp_parallel_initialize();
170 
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))
175     return NULL;
176 
177 // Wait for the first thread to set the copyprivate data pointer,
178 // and for all other threads to reach this point.
179 
180 #if OMPT_SUPPORT && OMPT_OPTIONAL
181   omp_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 = OMPT_GET_FRAME_ADDRESS(1);
185     OMPT_STORE_RETURN_ADDRESS(gtid);
186   }
187 #endif
188   __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
189 
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);
196   }
197 #endif
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 = NULL;
202   }
203 #endif
204   return retval;
205 }
206 
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));
210 
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   omp_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 = OMPT_GET_FRAME_ADDRESS(1);
221     OMPT_STORE_RETURN_ADDRESS(gtid);
222   }
223 #endif
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);
228   }
229 #endif
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 = NULL;
234   }
235 #endif
236 }
237 
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);
244 #endif
245   __kmpc_ordered(&loc, gtid);
246 }
247 
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);
254 #endif
255   __kmpc_end_ordered(&loc, gtid);
256 }
257 
258 // Dispatch macro defs
259 //
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).
262 
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
267 #else
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 */
272 
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
276 
277 // The parallel contruct
278 
279 #ifndef KMP_DEBUG
280 static
281 #endif /* KMP_DEBUG */
282     void
283     __kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
284                                  void *data) {
285 #if OMPT_SUPPORT
286   kmp_info_t *thr;
287   omp_frame_t *ompt_frame;
288   omp_state_t enclosing_state;
289 
290   if (ompt_enabled.enabled) {
291     // get pointer to thread data structure
292     thr = __kmp_threads[*gtid];
293 
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 = omp_state_work_parallel;
297 
298     // set task frame
299     __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
300     ompt_frame->exit_frame = OMPT_GET_FRAME_ADDRESS(0);
301   }
302 #endif
303 
304   task(data);
305 
306 #if OMPT_SUPPORT
307   if (ompt_enabled.enabled) {
308     // clear task frame
309     ompt_frame->exit_frame = NULL;
310 
311     // restore enclosing state
312     thr->th.ompt_thread_info.state = enclosing_state;
313   }
314 #endif
315 }
316 
317 #ifndef KMP_DEBUG
318 static
319 #endif /* KMP_DEBUG */
320     void
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,
325                                           long end, long incr,
326                                           long chunk_size) {
327   // Intialize the loop worksharing construct.
328 
329   KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
330                     schedule != kmp_sch_static);
331 
332 #if OMPT_SUPPORT
333   kmp_info_t *thr;
334   omp_frame_t *ompt_frame;
335   omp_state_t enclosing_state;
336 
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 = omp_state_work_parallel;
342 
343     // set task frame
344     __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
345     ompt_frame->exit_frame = OMPT_GET_FRAME_ADDRESS(0);
346   }
347 #endif
348 
349   // Now invoke the microtask.
350   task(data);
351 
352 #if OMPT_SUPPORT
353   if (ompt_enabled.enabled) {
354     // clear task frame
355     ompt_frame->exit_frame = NULL;
356 
357     // reset enclosing state
358     thr->th.ompt_thread_info.state = enclosing_state;
359   }
360 #endif
361 }
362 
363 #ifndef KMP_DEBUG
364 static
365 #endif /* KMP_DEBUG */
366     void
367     __kmp_GOMP_fork_call(ident_t *loc, int gtid, void (*unwrapped_task)(void *),
368                          microtask_t wrapper, int argc, ...) {
369   int rc;
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);
373 
374   va_list ap;
375   va_start(ap, argc);
376 
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
380                        &ap
381 #else
382                        ap
383 #endif
384                        );
385 
386   va_end(ap);
387 
388   if (rc) {
389     __kmp_run_before_invoked_task(gtid, tid, thr, team);
390   }
391 
392 #if OMPT_SUPPORT
393   int ompt_team_size;
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);
397 
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));
404       task_info->thread_num = __kmp_tid_from_gtid(gtid);
405     }
406     thr->th.ompt_thread_info.state = omp_state_work_parallel;
407   }
408 #endif
409 }
410 
411 static void __kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid,
412                                            void (*task)(void *)) {
413 #if OMPT_SUPPORT
414   OMPT_STORE_RETURN_ADDRESS(gtid);
415 #endif
416   __kmp_serialized_parallel(loc, gtid);
417 }
418 
419 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *),
420                                                        void *data,
421                                                        unsigned num_threads) {
422   int gtid = __kmp_entry_gtid();
423 
424 #if OMPT_SUPPORT
425   omp_frame_t *parent_frame, *frame;
426 
427   if (ompt_enabled.enabled) {
428     __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
429     parent_frame->enter_frame = OMPT_GET_FRAME_ADDRESS(1);
430     OMPT_STORE_RETURN_ADDRESS(gtid);
431   }
432 #endif
433 
434   MKLOC(loc, "GOMP_parallel_start");
435   KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
436 
437   if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
438     if (num_threads != 0) {
439       __kmp_push_num_threads(&loc, gtid, num_threads);
440     }
441     __kmp_GOMP_fork_call(&loc, gtid, task,
442                          (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
443                          data);
444   } else {
445     __kmp_GOMP_serialized_parallel(&loc, gtid, task);
446   }
447 
448 #if OMPT_SUPPORT
449   if (ompt_enabled.enabled) {
450     __ompt_get_task_info_internal(0, NULL, NULL, &frame, NULL, NULL);
451     frame->exit_frame = OMPT_GET_FRAME_ADDRESS(1);
452   }
453 #endif
454 }
455 
456 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(void) {
457   int gtid = __kmp_get_gtid();
458   kmp_info_t *thr;
459   int ompt_team_size = __kmp_team_from_gtid(gtid)->t.t_nproc;
460 
461   thr = __kmp_threads[gtid];
462 
463   MKLOC(loc, "GOMP_parallel_end");
464   KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
465 
466   if (!thr->th.th_team->t.t_serialized) {
467     __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
468                                  thr->th.th_team);
469 
470 #if OMPT_SUPPORT
471     if (ompt_enabled.enabled) {
472       // Implicit task is finished here, in the barrier we might schedule
473       // deferred tasks,
474       // these don't see the implicit task on the stack
475       OMPT_CUR_TASK_INFO(thr)->frame.exit_frame = NULL;
476     }
477 #endif
478 
479     __kmp_join_call(&loc, gtid
480 #if OMPT_SUPPORT
481                     ,
482                     fork_context_gnu
483 #endif
484                     );
485   } else {
486     __kmpc_end_serialized_parallel(&loc, gtid);
487   }
488 }
489 
490 // Loop worksharing constructs
491 
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).
496 //
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.
500 //
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.
504 //
505 // The "runtime" versions do not take a chunk_sz parameter.
506 //
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.
513 
514 #if OMPT_SUPPORT
515 #define IF_OMPT_SUPPORT(code) code
516 #else
517 #define IF_OMPT_SUPPORT(code)
518 #endif
519 
520 #define LOOP_START(func, schedule)                                             \
521   int func(long lb, long ub, long str, long chunk_sz, long *p_lb,              \
522            long *p_ub) {                                                       \
523     int status;                                                                \
524     long stride;                                                               \
525     int gtid = __kmp_entry_gtid();                                             \
526     MKLOC(loc, KMP_STR(func));                                                 \
527     KA_TRACE(                                                                  \
528         20,                                                                    \
529         (KMP_STR(                                                              \
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));                                        \
532                                                                                \
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);         \
541       if (status) {                                                            \
542         KMP_DEBUG_ASSERT(stride == str);                                       \
543         *p_ub += (str > 0) ? 1 : -1;                                           \
544       }                                                                        \
545     } else {                                                                   \
546       status = 0;                                                              \
547     }                                                                          \
548                                                                                \
549     KA_TRACE(                                                                  \
550         20,                                                                    \
551         (KMP_STR(                                                              \
552              func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n",    \
553          gtid, *p_lb, *p_ub, status));                                         \
554     return status;                                                             \
555   }
556 
557 #define LOOP_RUNTIME_START(func, schedule)                                     \
558   int func(long lb, long ub, long str, long *p_lb, long *p_ub) {               \
559     int status;                                                                \
560     long stride;                                                               \
561     long chunk_sz = 0;                                                         \
562     int gtid = __kmp_entry_gtid();                                             \
563     MKLOC(loc, KMP_STR(func));                                                 \
564     KA_TRACE(                                                                  \
565         20,                                                                    \
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));                                        \
568                                                                                \
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);         \
576       if (status) {                                                            \
577         KMP_DEBUG_ASSERT(stride == str);                                       \
578         *p_ub += (str > 0) ? 1 : -1;                                           \
579       }                                                                        \
580     } else {                                                                   \
581       status = 0;                                                              \
582     }                                                                          \
583                                                                                \
584     KA_TRACE(                                                                  \
585         20,                                                                    \
586         (KMP_STR(                                                              \
587              func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n",    \
588          gtid, *p_lb, *p_ub, status));                                         \
589     return status;                                                             \
590   }
591 
592 #if OMP_45_ENABLED
593 #define KMP_DOACROSS_FINI(status, gtid)                                        \
594   if (!status && __kmp_threads[gtid]->th.th_dispatch->th_doacross_flags) {     \
595     __kmpc_doacross_fini(NULL, gtid);                                          \
596   }
597 #else
598 #define KMP_DOACROSS_FINI(status, gtid) /* Nothing */
599 #endif
600 
601 #define LOOP_NEXT(func, fini_code)                                             \
602   int func(long *p_lb, long *p_ub) {                                           \
603     int status;                                                                \
604     long stride;                                                               \
605     int gtid = __kmp_get_gtid();                                               \
606     MKLOC(loc, KMP_STR(func));                                                 \
607     KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid));                            \
608                                                                                \
609     IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);)                          \
610     fini_code status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb,    \
611                                          (kmp_int *)p_ub, (kmp_int *)&stride); \
612     if (status) {                                                              \
613       *p_ub += (stride > 0) ? 1 : -1;                                          \
614     }                                                                          \
615     KMP_DOACROSS_FINI(status, gtid)                                            \
616                                                                                \
617     KA_TRACE(                                                                  \
618         20,                                                                    \
619         (KMP_STR(func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
620                        "returning %d\n",                                       \
621          gtid, *p_lb, *p_ub, stride, status));                                 \
622     return status;                                                             \
623   }
624 
625 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
626 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
627 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START),
628            kmp_sch_dynamic_chunked)
629 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
630 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_START),
631            kmp_sch_guided_chunked)
632 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
633 LOOP_RUNTIME_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_START),
634                    kmp_sch_runtime)
635 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
636 
637 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START),
638            kmp_ord_static)
639 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT),
640           { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
641 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START),
642            kmp_ord_dynamic_chunked)
643 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT),
644           { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
645 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START),
646            kmp_ord_guided_chunked)
647 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT),
648           { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
649 LOOP_RUNTIME_START(
650     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START),
651     kmp_ord_runtime)
652 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT),
653           { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
654 
655 #if OMP_45_ENABLED
656 #define LOOP_DOACROSS_START(func, schedule)                                    \
657   bool func(unsigned ncounts, long *counts, long chunk_sz, long *p_lb,         \
658             long *p_ub) {                                                      \
659     int status;                                                                \
660     long stride, lb, ub, str;                                                  \
661     int gtid = __kmp_entry_gtid();                                             \
662     struct kmp_dim *dims =                                                     \
663         (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts);    \
664     MKLOC(loc, KMP_STR(func));                                                 \
665     for (unsigned i = 0; i < ncounts; ++i) {                                   \
666       dims[i].lo = 0;                                                          \
667       dims[i].up = counts[i] - 1;                                              \
668       dims[i].st = 1;                                                          \
669     }                                                                          \
670     __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims);                      \
671     lb = 0;                                                                    \
672     ub = counts[0];                                                            \
673     str = 1;                                                                   \
674     KA_TRACE(20, (KMP_STR(func) ": T#%d, ncounts %u, lb 0x%lx, ub 0x%lx, str " \
675                                 "0x%lx, chunk_sz "                             \
676                                 "0x%lx\n",                                     \
677                   gtid, ncounts, lb, ub, str, chunk_sz));                      \
678                                                                                \
679     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
680       KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb,                            \
681                         (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz,        \
682                         (schedule) != kmp_sch_static);                         \
683       status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb,            \
684                                  (kmp_int *)p_ub, (kmp_int *)&stride);         \
685       if (status) {                                                            \
686         KMP_DEBUG_ASSERT(stride == str);                                       \
687         *p_ub += (str > 0) ? 1 : -1;                                           \
688       }                                                                        \
689     } else {                                                                   \
690       status = 0;                                                              \
691     }                                                                          \
692     KMP_DOACROSS_FINI(status, gtid);                                           \
693                                                                                \
694     KA_TRACE(                                                                  \
695         20,                                                                    \
696         (KMP_STR(                                                              \
697              func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n",    \
698          gtid, *p_lb, *p_ub, status));                                         \
699     __kmp_free(dims);                                                          \
700     return status;                                                             \
701   }
702 
703 #define LOOP_DOACROSS_RUNTIME_START(func, schedule)                            \
704   int func(unsigned ncounts, long *counts, long *p_lb, long *p_ub) {           \
705     int status;                                                                \
706     long stride, lb, ub, str;                                                  \
707     long chunk_sz = 0;                                                         \
708     int gtid = __kmp_entry_gtid();                                             \
709     struct kmp_dim *dims =                                                     \
710         (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts);    \
711     MKLOC(loc, KMP_STR(func));                                                 \
712     for (unsigned i = 0; i < ncounts; ++i) {                                   \
713       dims[i].lo = 0;                                                          \
714       dims[i].up = counts[i] - 1;                                              \
715       dims[i].st = 1;                                                          \
716     }                                                                          \
717     __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims);                      \
718     lb = 0;                                                                    \
719     ub = counts[0];                                                            \
720     str = 1;                                                                   \
721     KA_TRACE(                                                                  \
722         20,                                                                    \
723         (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
724          gtid, lb, ub, str, chunk_sz));                                        \
725                                                                                \
726     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
727       KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb,                            \
728                         (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
729       status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb,            \
730                                  (kmp_int *)p_ub, (kmp_int *)&stride);         \
731       if (status) {                                                            \
732         KMP_DEBUG_ASSERT(stride == str);                                       \
733         *p_ub += (str > 0) ? 1 : -1;                                           \
734       }                                                                        \
735     } else {                                                                   \
736       status = 0;                                                              \
737     }                                                                          \
738     KMP_DOACROSS_FINI(status, gtid);                                           \
739                                                                                \
740     KA_TRACE(                                                                  \
741         20,                                                                    \
742         (KMP_STR(                                                              \
743              func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n",    \
744          gtid, *p_lb, *p_ub, status));                                         \
745     __kmp_free(dims);                                                          \
746     return status;                                                             \
747   }
748 
749 LOOP_DOACROSS_START(
750     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START),
751     kmp_sch_static)
752 LOOP_DOACROSS_START(
753     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START),
754     kmp_sch_dynamic_chunked)
755 LOOP_DOACROSS_START(
756     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START),
757     kmp_sch_guided_chunked)
758 LOOP_DOACROSS_RUNTIME_START(
759     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START),
760     kmp_sch_runtime)
761 #endif // OMP_45_ENABLED
762 
763 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END)(void) {
764   int gtid = __kmp_get_gtid();
765   KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
766 
767 #if OMPT_SUPPORT && OMPT_OPTIONAL
768   omp_frame_t *ompt_frame;
769   if (ompt_enabled.enabled) {
770     __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
771     ompt_frame->enter_frame = OMPT_GET_FRAME_ADDRESS(1);
772     OMPT_STORE_RETURN_ADDRESS(gtid);
773   }
774 #endif
775   __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
776 #if OMPT_SUPPORT && OMPT_OPTIONAL
777   if (ompt_enabled.enabled) {
778     ompt_frame->enter_frame = NULL;
779   }
780 #endif
781 
782   KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
783 }
784 
785 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void) {
786   KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
787 }
788 
789 // Unsigned long long loop worksharing constructs
790 //
791 // These are new with gcc 4.4
792 
793 #define LOOP_START_ULL(func, schedule)                                         \
794   int func(int up, unsigned long long lb, unsigned long long ub,               \
795            unsigned long long str, unsigned long long chunk_sz,                \
796            unsigned long long *p_lb, unsigned long long *p_ub) {               \
797     int status;                                                                \
798     long long str2 = up ? ((long long)str) : -((long long)str);                \
799     long long stride;                                                          \
800     int gtid = __kmp_entry_gtid();                                             \
801     MKLOC(loc, KMP_STR(func));                                                 \
802                                                                                \
803     KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str "    \
804                                 "0x%llx, chunk_sz 0x%llx\n",                   \
805                   gtid, up, lb, ub, str, chunk_sz));                           \
806                                                                                \
807     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
808       KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb,                        \
809                             (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz,  \
810                             (schedule) != kmp_sch_static);                     \
811       status =                                                                 \
812           KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb,          \
813                                 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride);     \
814       if (status) {                                                            \
815         KMP_DEBUG_ASSERT(stride == str2);                                      \
816         *p_ub += (str > 0) ? 1 : -1;                                           \
817       }                                                                        \
818     } else {                                                                   \
819       status = 0;                                                              \
820     }                                                                          \
821                                                                                \
822     KA_TRACE(                                                                  \
823         20,                                                                    \
824         (KMP_STR(                                                              \
825              func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n",  \
826          gtid, *p_lb, *p_ub, status));                                         \
827     return status;                                                             \
828   }
829 
830 #define LOOP_RUNTIME_START_ULL(func, schedule)                                 \
831   int func(int up, unsigned long long lb, unsigned long long ub,               \
832            unsigned long long str, unsigned long long *p_lb,                   \
833            unsigned long long *p_ub) {                                         \
834     int status;                                                                \
835     long long str2 = up ? ((long long)str) : -((long long)str);                \
836     unsigned long long stride;                                                 \
837     unsigned long long chunk_sz = 0;                                           \
838     int gtid = __kmp_entry_gtid();                                             \
839     MKLOC(loc, KMP_STR(func));                                                 \
840                                                                                \
841     KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str "    \
842                                 "0x%llx, chunk_sz 0x%llx\n",                   \
843                   gtid, up, lb, ub, str, chunk_sz));                           \
844                                                                                \
845     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
846       KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb,                        \
847                             (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz,  \
848                             TRUE);                                             \
849       status =                                                                 \
850           KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb,          \
851                                 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride);     \
852       if (status) {                                                            \
853         KMP_DEBUG_ASSERT((long long)stride == str2);                           \
854         *p_ub += (str > 0) ? 1 : -1;                                           \
855       }                                                                        \
856     } else {                                                                   \
857       status = 0;                                                              \
858     }                                                                          \
859                                                                                \
860     KA_TRACE(                                                                  \
861         20,                                                                    \
862         (KMP_STR(                                                              \
863              func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n",  \
864          gtid, *p_lb, *p_ub, status));                                         \
865     return status;                                                             \
866   }
867 
868 #define LOOP_NEXT_ULL(func, fini_code)                                         \
869   int func(unsigned long long *p_lb, unsigned long long *p_ub) {               \
870     int status;                                                                \
871     long long stride;                                                          \
872     int gtid = __kmp_get_gtid();                                               \
873     MKLOC(loc, KMP_STR(func));                                                 \
874     KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid));                            \
875                                                                                \
876     fini_code status =                                                         \
877         KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb,            \
878                               (kmp_uint64 *)p_ub, (kmp_int64 *)&stride);       \
879     if (status) {                                                              \
880       *p_ub += (stride > 0) ? 1 : -1;                                          \
881     }                                                                          \
882                                                                                \
883     KA_TRACE(                                                                  \
884         20,                                                                    \
885         (KMP_STR(                                                              \
886              func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, "  \
887                    "returning %d\n",                                           \
888          gtid, *p_lb, *p_ub, stride, status));                                 \
889     return status;                                                             \
890   }
891 
892 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START),
893                kmp_sch_static)
894 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
895 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START),
896                kmp_sch_dynamic_chunked)
897 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
898 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START),
899                kmp_sch_guided_chunked)
900 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
901 LOOP_RUNTIME_START_ULL(
902     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
903 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
904 
905 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START),
906                kmp_ord_static)
907 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT),
908               { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
909 LOOP_START_ULL(
910     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START),
911     kmp_ord_dynamic_chunked)
912 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT),
913               { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
914 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START),
915                kmp_ord_guided_chunked)
916 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT),
917               { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
918 LOOP_RUNTIME_START_ULL(
919     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START),
920     kmp_ord_runtime)
921 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT),
922               { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
923 
924 #if OMP_45_ENABLED
925 #define LOOP_DOACROSS_START_ULL(func, schedule)                                \
926   int func(unsigned ncounts, unsigned long long *counts,                       \
927            unsigned long long chunk_sz, unsigned long long *p_lb,              \
928            unsigned long long *p_ub) {                                         \
929     int status;                                                                \
930     long long stride, str, lb, ub;                                             \
931     int gtid = __kmp_entry_gtid();                                             \
932     struct kmp_dim *dims =                                                     \
933         (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts);    \
934     MKLOC(loc, KMP_STR(func));                                                 \
935     for (unsigned i = 0; i < ncounts; ++i) {                                   \
936       dims[i].lo = 0;                                                          \
937       dims[i].up = counts[i] - 1;                                              \
938       dims[i].st = 1;                                                          \
939     }                                                                          \
940     __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims);                      \
941     lb = 0;                                                                    \
942     ub = counts[0];                                                            \
943     str = 1;                                                                   \
944                                                                                \
945     KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str "           \
946                                 "0x%llx, chunk_sz 0x%llx\n",                   \
947                   gtid, lb, ub, str, chunk_sz));                               \
948                                                                                \
949     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
950       KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb,                        \
951                             (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz,    \
952                             (schedule) != kmp_sch_static);                     \
953       status =                                                                 \
954           KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb,          \
955                                 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride);     \
956       if (status) {                                                            \
957         KMP_DEBUG_ASSERT(stride == str);                                       \
958         *p_ub += (str > 0) ? 1 : -1;                                           \
959       }                                                                        \
960     } else {                                                                   \
961       status = 0;                                                              \
962     }                                                                          \
963     KMP_DOACROSS_FINI(status, gtid);                                           \
964                                                                                \
965     KA_TRACE(                                                                  \
966         20,                                                                    \
967         (KMP_STR(                                                              \
968              func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n",  \
969          gtid, *p_lb, *p_ub, status));                                         \
970     __kmp_free(dims);                                                          \
971     return status;                                                             \
972   }
973 
974 #define LOOP_DOACROSS_RUNTIME_START_ULL(func, schedule)                        \
975   int func(unsigned ncounts, unsigned long long *counts,                       \
976            unsigned long long *p_lb, unsigned long long *p_ub) {               \
977     int status;                                                                \
978     unsigned long long stride, str, lb, ub;                                    \
979     unsigned long long chunk_sz = 0;                                           \
980     int gtid = __kmp_entry_gtid();                                             \
981     struct kmp_dim *dims =                                                     \
982         (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts);    \
983     MKLOC(loc, KMP_STR(func));                                                 \
984     for (unsigned i = 0; i < ncounts; ++i) {                                   \
985       dims[i].lo = 0;                                                          \
986       dims[i].up = counts[i] - 1;                                              \
987       dims[i].st = 1;                                                          \
988     }                                                                          \
989     __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims);                      \
990     lb = 0;                                                                    \
991     ub = counts[0];                                                            \
992     str = 1;                                                                   \
993     KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str "           \
994                                 "0x%llx, chunk_sz 0x%llx\n",                   \
995                   gtid, lb, ub, str, chunk_sz));                               \
996                                                                                \
997     if ((str > 0) ? (lb < ub) : (lb > ub)) {                                   \
998       KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb,                        \
999                             (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz,    \
1000                             TRUE);                                             \
1001       status =                                                                 \
1002           KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb,          \
1003                                 (kmp_uint64 *)p_ub, (kmp_int64 *)&stride);     \
1004       if (status) {                                                            \
1005         KMP_DEBUG_ASSERT((long long)stride == str);                            \
1006         *p_ub += (str > 0) ? 1 : -1;                                           \
1007       }                                                                        \
1008     } else {                                                                   \
1009       status = 0;                                                              \
1010     }                                                                          \
1011     KMP_DOACROSS_FINI(status, gtid);                                           \
1012                                                                                \
1013     KA_TRACE(                                                                  \
1014         20,                                                                    \
1015         (KMP_STR(                                                              \
1016              func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n",  \
1017          gtid, *p_lb, *p_ub, status));                                         \
1018     __kmp_free(dims);                                                          \
1019     return status;                                                             \
1020   }
1021 
1022 LOOP_DOACROSS_START_ULL(
1023     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START),
1024     kmp_sch_static)
1025 LOOP_DOACROSS_START_ULL(
1026     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START),
1027     kmp_sch_dynamic_chunked)
1028 LOOP_DOACROSS_START_ULL(
1029     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START),
1030     kmp_sch_guided_chunked)
1031 LOOP_DOACROSS_RUNTIME_START_ULL(
1032     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START),
1033     kmp_sch_runtime)
1034 #endif
1035 
1036 // Combined parallel / loop worksharing constructs
1037 //
1038 // There are no ull versions (yet).
1039 
1040 #define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post)               \
1041   void func(void (*task)(void *), void *data, unsigned num_threads, long lb,   \
1042             long ub, long str, long chunk_sz) {                                \
1043     int gtid = __kmp_entry_gtid();                                             \
1044     MKLOC(loc, KMP_STR(func));                                                 \
1045     KA_TRACE(                                                                  \
1046         20,                                                                    \
1047         (KMP_STR(                                                              \
1048              func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n",  \
1049          gtid, lb, ub, str, chunk_sz));                                        \
1050                                                                                \
1051     ompt_pre();                                                                \
1052                                                                                \
1053     if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {                       \
1054       if (num_threads != 0) {                                                  \
1055         __kmp_push_num_threads(&loc, gtid, num_threads);                       \
1056       }                                                                        \
1057       __kmp_GOMP_fork_call(&loc, gtid, task,                                   \
1058                            (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1059                            9, task, data, num_threads, &loc, (schedule), lb,   \
1060                            (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz);    \
1061       IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid));                        \
1062     } else {                                                                   \
1063       __kmp_GOMP_serialized_parallel(&loc, gtid, task);                        \
1064       IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid));                        \
1065     }                                                                          \
1066                                                                                \
1067     KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb,                              \
1068                       (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz,          \
1069                       (schedule) != kmp_sch_static);                           \
1070                                                                                \
1071     ompt_post();                                                               \
1072                                                                                \
1073     KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid));                       \
1074   }
1075 
1076 #if OMPT_SUPPORT && OMPT_OPTIONAL
1077 
1078 #define OMPT_LOOP_PRE()                                                        \
1079   omp_frame_t *parent_frame;                                                   \
1080   if (ompt_enabled.enabled) {                                                  \
1081     __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);   \
1082     parent_frame->enter_frame = OMPT_GET_FRAME_ADDRESS(1);                     \
1083     OMPT_STORE_RETURN_ADDRESS(gtid);                                           \
1084   }
1085 
1086 #define OMPT_LOOP_POST()                                                       \
1087   if (ompt_enabled.enabled) {                                                  \
1088     parent_frame->enter_frame = NULL;                                          \
1089   }
1090 
1091 #else
1092 
1093 #define OMPT_LOOP_PRE()
1094 
1095 #define OMPT_LOOP_POST()
1096 
1097 #endif
1098 
1099 PARALLEL_LOOP_START(
1100     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
1101     kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1102 PARALLEL_LOOP_START(
1103     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
1104     kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1105 PARALLEL_LOOP_START(
1106     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
1107     kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1108 PARALLEL_LOOP_START(
1109     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
1110     kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1111 
1112 // Tasking constructs
1113 
1114 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data,
1115                                              void (*copy_func)(void *, void *),
1116                                              long arg_size, long arg_align,
1117                                              bool if_cond, unsigned gomp_flags
1118 #if OMP_40_ENABLED
1119                                              ,
1120                                              void **depend
1121 #endif
1122                                              ) {
1123   MKLOC(loc, "GOMP_task");
1124   int gtid = __kmp_entry_gtid();
1125   kmp_int32 flags = 0;
1126   kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1127 
1128   KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
1129 
1130   // The low-order bit is the "untied" flag
1131   if (!(gomp_flags & 1)) {
1132     input_flags->tiedness = 1;
1133   }
1134   // The second low-order bit is the "final" flag
1135   if (gomp_flags & 2) {
1136     input_flags->final = 1;
1137   }
1138   input_flags->native = 1;
1139   // __kmp_task_alloc() sets up all other flags
1140 
1141   if (!if_cond) {
1142     arg_size = 0;
1143   }
1144 
1145   kmp_task_t *task = __kmp_task_alloc(
1146       &loc, gtid, input_flags, sizeof(kmp_task_t),
1147       arg_size ? arg_size + arg_align - 1 : 0, (kmp_routine_entry_t)func);
1148 
1149   if (arg_size > 0) {
1150     if (arg_align > 0) {
1151       task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1152                                arg_align * arg_align);
1153     }
1154     // else error??
1155 
1156     if (copy_func) {
1157       (*copy_func)(task->shareds, data);
1158     } else {
1159       KMP_MEMCPY(task->shareds, data, arg_size);
1160     }
1161   }
1162 
1163 #if OMPT_SUPPORT
1164   kmp_taskdata_t *current_task;
1165   if (ompt_enabled.enabled) {
1166     OMPT_STORE_RETURN_ADDRESS(gtid);
1167     current_task = __kmp_threads[gtid]->th.th_current_task;
1168     current_task->ompt_task_info.frame.enter_frame = OMPT_GET_FRAME_ADDRESS(1);
1169   }
1170 #endif
1171 
1172   if (if_cond) {
1173 #if OMP_40_ENABLED
1174     if (gomp_flags & 8) {
1175       KMP_ASSERT(depend);
1176       const size_t ndeps = (kmp_intptr_t)depend[0];
1177       const size_t nout = (kmp_intptr_t)depend[1];
1178       kmp_depend_info_t dep_list[ndeps];
1179 
1180       for (size_t i = 0U; i < ndeps; i++) {
1181         dep_list[i].base_addr = (kmp_intptr_t)depend[2U + i];
1182         dep_list[i].len = 0U;
1183         dep_list[i].flags.in = 1;
1184         dep_list[i].flags.out = (i < nout);
1185       }
1186       __kmpc_omp_task_with_deps(&loc, gtid, task, ndeps, dep_list, 0, NULL);
1187     } else {
1188 #endif
1189       __kmpc_omp_task(&loc, gtid, task);
1190     }
1191   } else {
1192 #if OMPT_SUPPORT
1193     ompt_thread_info_t oldInfo;
1194     kmp_info_t *thread;
1195     kmp_taskdata_t *taskdata;
1196     kmp_taskdata_t *current_task;
1197     if (ompt_enabled.enabled) {
1198       // Store the threads states and restore them after the task
1199       thread = __kmp_threads[gtid];
1200       taskdata = KMP_TASK_TO_TASKDATA(task);
1201       oldInfo = thread->th.ompt_thread_info;
1202       thread->th.ompt_thread_info.wait_id = 0;
1203       thread->th.ompt_thread_info.state = omp_state_work_parallel;
1204       taskdata->ompt_task_info.frame.exit_frame = OMPT_GET_FRAME_ADDRESS(0);
1205       OMPT_STORE_RETURN_ADDRESS(gtid);
1206     }
1207 #endif
1208 
1209     __kmpc_omp_task_begin_if0(&loc, gtid, task);
1210     func(data);
1211     __kmpc_omp_task_complete_if0(&loc, gtid, task);
1212 
1213 #if OMPT_SUPPORT
1214     if (ompt_enabled.enabled) {
1215       thread->th.ompt_thread_info = oldInfo;
1216       taskdata->ompt_task_info.frame.exit_frame = NULL;
1217     }
1218 #endif
1219   }
1220 #if OMPT_SUPPORT
1221   if (ompt_enabled.enabled) {
1222     current_task->ompt_task_info.frame.enter_frame = NULL;
1223   }
1224 #endif
1225 
1226   KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1227 }
1228 
1229 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT)(void) {
1230   MKLOC(loc, "GOMP_taskwait");
1231   int gtid = __kmp_entry_gtid();
1232 
1233 #if OMPT_SUPPORT
1234   if (ompt_enabled.enabled)
1235     OMPT_STORE_RETURN_ADDRESS(gtid);
1236 #endif
1237 
1238   KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1239 
1240   __kmpc_omp_taskwait(&loc, gtid);
1241 
1242   KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1243 }
1244 
1245 // Sections worksharing constructs
1246 //
1247 // For the sections construct, we initialize a dynamically scheduled loop
1248 // worksharing construct with lb 1 and stride 1, and use the iteration #'s
1249 // that its returns as sections ids.
1250 //
1251 // There are no special entry points for ordered sections, so we always use
1252 // the dynamically scheduled workshare, even if the sections aren't ordered.
1253 
1254 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count) {
1255   int status;
1256   kmp_int lb, ub, stride;
1257   int gtid = __kmp_entry_gtid();
1258   MKLOC(loc, "GOMP_sections_start");
1259   KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1260 
1261   KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1262 
1263   status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1264   if (status) {
1265     KMP_DEBUG_ASSERT(stride == 1);
1266     KMP_DEBUG_ASSERT(lb > 0);
1267     KMP_ASSERT(lb == ub);
1268   } else {
1269     lb = 0;
1270   }
1271 
1272   KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1273                 (unsigned)lb));
1274   return (unsigned)lb;
1275 }
1276 
1277 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void) {
1278   int status;
1279   kmp_int lb, ub, stride;
1280   int gtid = __kmp_get_gtid();
1281   MKLOC(loc, "GOMP_sections_next");
1282   KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1283 
1284 #if OMPT_SUPPORT
1285   OMPT_STORE_RETURN_ADDRESS(gtid);
1286 #endif
1287 
1288   status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1289   if (status) {
1290     KMP_DEBUG_ASSERT(stride == 1);
1291     KMP_DEBUG_ASSERT(lb > 0);
1292     KMP_ASSERT(lb == ub);
1293   } else {
1294     lb = 0;
1295   }
1296 
1297   KA_TRACE(
1298       20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid, (unsigned)lb));
1299   return (unsigned)lb;
1300 }
1301 
1302 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(
1303     void (*task)(void *), void *data, unsigned num_threads, unsigned count) {
1304   int gtid = __kmp_entry_gtid();
1305 
1306 #if OMPT_SUPPORT
1307   omp_frame_t *parent_frame;
1308 
1309   if (ompt_enabled.enabled) {
1310     __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
1311     parent_frame->enter_frame = OMPT_GET_FRAME_ADDRESS(1);
1312     OMPT_STORE_RETURN_ADDRESS(gtid);
1313   }
1314 #endif
1315 
1316   MKLOC(loc, "GOMP_parallel_sections_start");
1317   KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1318 
1319   if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1320     if (num_threads != 0) {
1321       __kmp_push_num_threads(&loc, gtid, num_threads);
1322     }
1323     __kmp_GOMP_fork_call(&loc, gtid, task,
1324                          (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1325                          task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1326                          (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1327   } else {
1328     __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1329   }
1330 
1331 #if OMPT_SUPPORT
1332   if (ompt_enabled.enabled) {
1333     parent_frame->enter_frame = NULL;
1334   }
1335 #endif
1336 
1337   KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1338 
1339   KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1340 }
1341 
1342 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END)(void) {
1343   int gtid = __kmp_get_gtid();
1344   KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1345 
1346 #if OMPT_SUPPORT
1347   omp_frame_t *ompt_frame;
1348   if (ompt_enabled.enabled) {
1349     __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
1350     ompt_frame->enter_frame = OMPT_GET_FRAME_ADDRESS(1);
1351     OMPT_STORE_RETURN_ADDRESS(gtid);
1352   }
1353 #endif
1354   __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1355 #if OMPT_SUPPORT
1356   if (ompt_enabled.enabled) {
1357     ompt_frame->enter_frame = NULL;
1358   }
1359 #endif
1360 
1361   KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1362 }
1363 
1364 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void) {
1365   KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1366 }
1367 
1368 // libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1369 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKYIELD)(void) {
1370   KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1371   return;
1372 }
1373 
1374 #if OMP_40_ENABLED // these are new GOMP_4.0 entry points
1375 
1376 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *),
1377                                                  void *data,
1378                                                  unsigned num_threads,
1379                                                  unsigned int flags) {
1380   int gtid = __kmp_entry_gtid();
1381   MKLOC(loc, "GOMP_parallel");
1382   KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1383 
1384 #if OMPT_SUPPORT
1385   ompt_task_info_t *parent_task_info, *task_info;
1386   if (ompt_enabled.enabled) {
1387     parent_task_info = __ompt_get_task_info_object(0);
1388     parent_task_info->frame.enter_frame = OMPT_GET_FRAME_ADDRESS(1);
1389     OMPT_STORE_RETURN_ADDRESS(gtid);
1390   }
1391 #endif
1392   if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1393     if (num_threads != 0) {
1394       __kmp_push_num_threads(&loc, gtid, num_threads);
1395     }
1396     if (flags != 0) {
1397       __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1398     }
1399     __kmp_GOMP_fork_call(&loc, gtid, task,
1400                          (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
1401                          data);
1402   } else {
1403     __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1404   }
1405 #if OMPT_SUPPORT
1406   if (ompt_enabled.enabled) {
1407     task_info = __ompt_get_task_info_object(0);
1408     task_info->frame.exit_frame = OMPT_GET_FRAME_ADDRESS(0);
1409   }
1410 #endif
1411   task(data);
1412 #if OMPT_SUPPORT
1413   if (ompt_enabled.enabled) {
1414     OMPT_STORE_RETURN_ADDRESS(gtid);
1415   }
1416 #endif
1417   KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1418 #if OMPT_SUPPORT
1419   if (ompt_enabled.enabled) {
1420     task_info->frame.exit_frame = NULL;
1421     parent_task_info->frame.enter_frame = NULL;
1422   }
1423 #endif
1424 }
1425 
1426 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
1427                                                           void *data,
1428                                                           unsigned num_threads,
1429                                                           unsigned count,
1430                                                           unsigned flags) {
1431   int gtid = __kmp_entry_gtid();
1432   MKLOC(loc, "GOMP_parallel_sections");
1433   KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1434 
1435 #if OMPT_SUPPORT
1436   OMPT_STORE_RETURN_ADDRESS(gtid);
1437 #endif
1438 
1439   if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {
1440     if (num_threads != 0) {
1441       __kmp_push_num_threads(&loc, gtid, num_threads);
1442     }
1443     if (flags != 0) {
1444       __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);
1445     }
1446     __kmp_GOMP_fork_call(&loc, gtid, task,
1447                          (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1448                          task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1449                          (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1450   } else {
1451     __kmp_GOMP_serialized_parallel(&loc, gtid, task);
1452   }
1453 
1454 #if OMPT_SUPPORT
1455   OMPT_STORE_RETURN_ADDRESS(gtid);
1456 #endif
1457 
1458   KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1459 
1460   task(data);
1461   KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1462   KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1463 }
1464 
1465 #define PARALLEL_LOOP(func, schedule, ompt_pre, ompt_post)                     \
1466   void func(void (*task)(void *), void *data, unsigned num_threads, long lb,   \
1467             long ub, long str, long chunk_sz, unsigned flags) {                \
1468     int gtid = __kmp_entry_gtid();                                             \
1469     MKLOC(loc, KMP_STR(func));                                                 \
1470     KA_TRACE(                                                                  \
1471         20,                                                                    \
1472         (KMP_STR(                                                              \
1473              func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n",  \
1474          gtid, lb, ub, str, chunk_sz));                                        \
1475                                                                                \
1476     ompt_pre();                                                                \
1477     if (__kmpc_ok_to_fork(&loc) && (num_threads != 1)) {                       \
1478       if (num_threads != 0) {                                                  \
1479         __kmp_push_num_threads(&loc, gtid, num_threads);                       \
1480       }                                                                        \
1481       if (flags != 0) {                                                        \
1482         __kmp_push_proc_bind(&loc, gtid, (kmp_proc_bind_t)flags);              \
1483       }                                                                        \
1484       __kmp_GOMP_fork_call(&loc, gtid, task,                                   \
1485                            (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1486                            9, task, data, num_threads, &loc, (schedule), lb,   \
1487                            (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz);    \
1488     } else {                                                                   \
1489       __kmp_GOMP_serialized_parallel(&loc, gtid, task);                        \
1490     }                                                                          \
1491                                                                                \
1492     IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);)                          \
1493     KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb,                              \
1494                       (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz,          \
1495                       (schedule) != kmp_sch_static);                           \
1496     task(data);                                                                \
1497     KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();                         \
1498     ompt_post();                                                               \
1499                                                                                \
1500     KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid));                       \
1501   }
1502 
1503 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC),
1504               kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1505 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC),
1506               kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1507 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED),
1508               kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1509 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME),
1510               kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1511 
1512 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_START)(void) {
1513   int gtid = __kmp_entry_gtid();
1514   MKLOC(loc, "GOMP_taskgroup_start");
1515   KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1516 
1517 #if OMPT_SUPPORT
1518   if (ompt_enabled.enabled)
1519     OMPT_STORE_RETURN_ADDRESS(gtid);
1520 #endif
1521 
1522   __kmpc_taskgroup(&loc, gtid);
1523 
1524   return;
1525 }
1526 
1527 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_END)(void) {
1528   int gtid = __kmp_get_gtid();
1529   MKLOC(loc, "GOMP_taskgroup_end");
1530   KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1531 
1532 #if OMPT_SUPPORT
1533   if (ompt_enabled.enabled)
1534     OMPT_STORE_RETURN_ADDRESS(gtid);
1535 #endif
1536 
1537   __kmpc_end_taskgroup(&loc, gtid);
1538 
1539   return;
1540 }
1541 
1542 #ifndef KMP_DEBUG
1543 static
1544 #endif /* KMP_DEBUG */
1545     kmp_int32
1546     __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
1547   kmp_int32 cncl_kind = 0;
1548   switch (gomp_kind) {
1549   case 1:
1550     cncl_kind = cancel_parallel;
1551     break;
1552   case 2:
1553     cncl_kind = cancel_loop;
1554     break;
1555   case 4:
1556     cncl_kind = cancel_sections;
1557     break;
1558   case 8:
1559     cncl_kind = cancel_taskgroup;
1560     break;
1561   }
1562   return cncl_kind;
1563 }
1564 
1565 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which) {
1566   if (__kmp_omp_cancellation) {
1567     KMP_FATAL(NoGompCancellation);
1568   }
1569   int gtid = __kmp_get_gtid();
1570   MKLOC(loc, "GOMP_cancellation_point");
1571   KA_TRACE(20, ("GOMP_cancellation_point: T#%d\n", gtid));
1572 
1573   kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1574 
1575   return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1576 }
1577 
1578 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void) {
1579   if (__kmp_omp_cancellation) {
1580     KMP_FATAL(NoGompCancellation);
1581   }
1582   KMP_FATAL(NoGompCancellation);
1583   int gtid = __kmp_get_gtid();
1584   MKLOC(loc, "GOMP_barrier_cancel");
1585   KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1586 
1587   return __kmpc_cancel_barrier(&loc, gtid);
1588 }
1589 
1590 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel) {
1591   if (__kmp_omp_cancellation) {
1592     KMP_FATAL(NoGompCancellation);
1593   } else {
1594     return FALSE;
1595   }
1596 
1597   int gtid = __kmp_get_gtid();
1598   MKLOC(loc, "GOMP_cancel");
1599   KA_TRACE(20, ("GOMP_cancel: T#%d\n", gtid));
1600 
1601   kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1602 
1603   if (do_cancel == FALSE) {
1604     return KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(which);
1605   } else {
1606     return __kmpc_cancel(&loc, gtid, cncl_kind);
1607   }
1608 }
1609 
1610 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void) {
1611   if (__kmp_omp_cancellation) {
1612     KMP_FATAL(NoGompCancellation);
1613   }
1614   int gtid = __kmp_get_gtid();
1615   MKLOC(loc, "GOMP_sections_end_cancel");
1616   KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1617 
1618   return __kmpc_cancel_barrier(&loc, gtid);
1619 }
1620 
1621 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void) {
1622   if (__kmp_omp_cancellation) {
1623     KMP_FATAL(NoGompCancellation);
1624   }
1625   int gtid = __kmp_get_gtid();
1626   MKLOC(loc, "GOMP_loop_end_cancel");
1627   KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1628 
1629   return __kmpc_cancel_barrier(&loc, gtid);
1630 }
1631 
1632 // All target functions are empty as of 2014-05-29
1633 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn)(void *),
1634                                                const void *openmp_target,
1635                                                size_t mapnum, void **hostaddrs,
1636                                                size_t *sizes,
1637                                                unsigned char *kinds) {
1638   return;
1639 }
1640 
1641 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_DATA)(
1642     int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1643     size_t *sizes, unsigned char *kinds) {
1644   return;
1645 }
1646 
1647 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_END_DATA)(void) { return; }
1648 
1649 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_UPDATE)(
1650     int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1651     size_t *sizes, unsigned char *kinds) {
1652   return;
1653 }
1654 
1655 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams,
1656                                               unsigned int thread_limit) {
1657   return;
1658 }
1659 #endif // OMP_40_ENABLED
1660 
1661 #if OMP_45_ENABLED
1662 
1663 // Task duplication function which copies src to dest (both are
1664 // preallocated task structures)
1665 static void __kmp_gomp_task_dup(kmp_task_t *dest, kmp_task_t *src,
1666                                 kmp_int32 last_private) {
1667   kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(src);
1668   if (taskdata->td_copy_func) {
1669     (taskdata->td_copy_func)(dest->shareds, src->shareds);
1670   }
1671 }
1672 
1673 #ifdef __cplusplus
1674 } // extern "C"
1675 #endif
1676 
1677 template <typename T>
1678 void __GOMP_taskloop(void (*func)(void *), void *data,
1679                      void (*copy_func)(void *, void *), long arg_size,
1680                      long arg_align, unsigned gomp_flags,
1681                      unsigned long num_tasks, int priority, T start, T end,
1682                      T step) {
1683   typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
1684   MKLOC(loc, "GOMP_taskloop");
1685   int sched;
1686   T *loop_bounds;
1687   int gtid = __kmp_entry_gtid();
1688   kmp_int32 flags = 0;
1689   int if_val = gomp_flags & (1u << 10);
1690   int nogroup = gomp_flags & (1u << 11);
1691   int up = gomp_flags & (1u << 8);
1692   p_task_dup_t task_dup = NULL;
1693   kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1694 #ifdef KMP_DEBUG
1695   {
1696     char *buff;
1697     buff = __kmp_str_format(
1698         "GOMP_taskloop: T#%%d: func:%%p data:%%p copy_func:%%p "
1699         "arg_size:%%ld arg_align:%%ld gomp_flags:0x%%x num_tasks:%%lu "
1700         "priority:%%d start:%%%s end:%%%s step:%%%s\n",
1701         traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec);
1702     KA_TRACE(20, (buff, gtid, func, data, copy_func, arg_size, arg_align,
1703                   gomp_flags, num_tasks, priority, start, end, step));
1704     __kmp_str_free(&buff);
1705   }
1706 #endif
1707   KMP_ASSERT((size_t)arg_size >= 2 * sizeof(T));
1708   KMP_ASSERT(arg_align > 0);
1709   // The low-order bit is the "untied" flag
1710   if (!(gomp_flags & 1)) {
1711     input_flags->tiedness = 1;
1712   }
1713   // The second low-order bit is the "final" flag
1714   if (gomp_flags & 2) {
1715     input_flags->final = 1;
1716   }
1717   // Negative step flag
1718   if (!up) {
1719     // If step is flagged as negative, but isn't properly sign extended
1720     // Then manually sign extend it.  Could be a short, int, char embedded
1721     // in a long.  So cannot assume any cast.
1722     if (step > 0) {
1723       for (int i = sizeof(T) * CHAR_BIT - 1; i >= 0L; --i) {
1724         // break at the first 1 bit
1725         if (step & ((T)1 << i))
1726           break;
1727         step |= ((T)1 << i);
1728       }
1729     }
1730   }
1731   input_flags->native = 1;
1732   // Figure out if none/grainsize/num_tasks clause specified
1733   if (num_tasks > 0) {
1734     if (gomp_flags & (1u << 9))
1735       sched = 1; // grainsize specified
1736     else
1737       sched = 2; // num_tasks specified
1738     // neither grainsize nor num_tasks specified
1739   } else {
1740     sched = 0;
1741   }
1742 
1743   // __kmp_task_alloc() sets up all other flags
1744   kmp_task_t *task =
1745       __kmp_task_alloc(&loc, gtid, input_flags, sizeof(kmp_task_t),
1746                        arg_size + arg_align - 1, (kmp_routine_entry_t)func);
1747   kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
1748   taskdata->td_copy_func = copy_func;
1749   taskdata->td_size_loop_bounds = sizeof(T);
1750 
1751   // re-align shareds if needed and setup firstprivate copy constructors
1752   // through the task_dup mechanism
1753   task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1754                            arg_align * arg_align);
1755   if (copy_func) {
1756     task_dup = __kmp_gomp_task_dup;
1757   }
1758   KMP_MEMCPY(task->shareds, data, arg_size);
1759 
1760   loop_bounds = (T *)task->shareds;
1761   loop_bounds[0] = start;
1762   loop_bounds[1] = end + (up ? -1 : 1);
1763   __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
1764                   (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, nogroup,
1765                   sched, (kmp_uint64)num_tasks, (void *)task_dup);
1766 }
1767 
1768 // 4 byte version of GOMP_doacross_post
1769 // This verison needs to create a temporary array which converts 4 byte
1770 // integers into 8 byte integeres
1771 template <typename T, bool need_conversion = (sizeof(long) == 4)>
1772 void __kmp_GOMP_doacross_post(T *count);
1773 
1774 template <> void __kmp_GOMP_doacross_post<long, true>(long *count) {
1775   int gtid = __kmp_entry_gtid();
1776   kmp_info_t *th = __kmp_threads[gtid];
1777   MKLOC(loc, "GOMP_doacross_post");
1778   kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1779   kmp_int64 *vec =
1780       (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1781   for (kmp_int64 i = 0; i < num_dims; ++i) {
1782     vec[i] = (kmp_int64)count[i];
1783   }
1784   __kmpc_doacross_post(&loc, gtid, vec);
1785   __kmp_thread_free(th, vec);
1786 }
1787 
1788 // 8 byte versions of GOMP_doacross_post
1789 // This version can just pass in the count array directly instead of creating
1790 // a temporary array
1791 template <> void __kmp_GOMP_doacross_post<long, false>(long *count) {
1792   int gtid = __kmp_entry_gtid();
1793   MKLOC(loc, "GOMP_doacross_post");
1794   __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1795 }
1796 
1797 template <typename T> void __kmp_GOMP_doacross_wait(T first, va_list args) {
1798   int gtid = __kmp_entry_gtid();
1799   kmp_info_t *th = __kmp_threads[gtid];
1800   MKLOC(loc, "GOMP_doacross_wait");
1801   kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1802   kmp_int64 *vec =
1803       (kmp_int64 *)__kmp_thread_malloc(th, sizeof(kmp_int64) * num_dims);
1804   vec[0] = (kmp_int64)first;
1805   for (kmp_int64 i = 1; i < num_dims; ++i) {
1806     T item = va_arg(args, T);
1807     vec[i] = (kmp_int64)item;
1808   }
1809   __kmpc_doacross_wait(&loc, gtid, vec);
1810   __kmp_thread_free(th, vec);
1811   return;
1812 }
1813 
1814 #ifdef __cplusplus
1815 extern "C" {
1816 #endif // __cplusplus
1817 
1818 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP)(
1819     void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1820     long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1821     int priority, long start, long end, long step) {
1822   __GOMP_taskloop<long>(func, data, copy_func, arg_size, arg_align, gomp_flags,
1823                         num_tasks, priority, start, end, step);
1824 }
1825 
1826 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP_ULL)(
1827     void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1828     long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1829     int priority, unsigned long long start, unsigned long long end,
1830     unsigned long long step) {
1831   __GOMP_taskloop<unsigned long long>(func, data, copy_func, arg_size,
1832                                       arg_align, gomp_flags, num_tasks,
1833                                       priority, start, end, step);
1834 }
1835 
1836 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_POST)(long *count) {
1837   __kmp_GOMP_doacross_post(count);
1838 }
1839 
1840 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_WAIT)(long first, ...) {
1841   va_list args;
1842   va_start(args, first);
1843   __kmp_GOMP_doacross_wait<long>(first, args);
1844   va_end(args);
1845 }
1846 
1847 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_POST)(
1848     unsigned long long *count) {
1849   int gtid = __kmp_entry_gtid();
1850   MKLOC(loc, "GOMP_doacross_ull_post");
1851   __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1852 }
1853 
1854 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT)(
1855     unsigned long long first, ...) {
1856   va_list args;
1857   va_start(args, first);
1858   __kmp_GOMP_doacross_wait<unsigned long long>(first, args);
1859   va_end(args);
1860 }
1861 
1862 #endif // OMP_45_ENABLED
1863 
1864 /* The following sections of code create aliases for the GOMP_* functions, then
1865    create versioned symbols using the assembler directive .symver. This is only
1866    pertinent for ELF .so library. The KMP_VERSION_SYMBOL macro is defined in
1867    kmp_os.h  */
1868 
1869 #ifdef KMP_USE_VERSION_SYMBOLS
1870 // GOMP_1.0 versioned symbols
1871 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1872 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1873 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1874 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1875 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1876 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1877 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1878 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1879 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1880 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1881 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1882 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1883 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1884 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1885 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10,
1886                    "GOMP_1.0");
1887 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1888 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1889 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1890 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10,
1891                    "GOMP_1.0");
1892 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1893 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1894 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1895 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1896 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1897 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1898 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1899 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1900 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1901 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10,
1902                    "GOMP_1.0");
1903 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10,
1904                    "GOMP_1.0");
1905 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10,
1906                    "GOMP_1.0");
1907 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10,
1908                    "GOMP_1.0");
1909 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1910 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1911 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1912 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1913 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1914 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1915 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1916 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1917 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1918 
1919 // GOMP_2.0 versioned symbols
1920 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1921 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
1922 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1923 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1924 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1925 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1926 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20,
1927                    "GOMP_2.0");
1928 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20,
1929                    "GOMP_2.0");
1930 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20,
1931                    "GOMP_2.0");
1932 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20,
1933                    "GOMP_2.0");
1934 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20,
1935                    "GOMP_2.0");
1936 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20,
1937                    "GOMP_2.0");
1938 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20,
1939                    "GOMP_2.0");
1940 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20,
1941                    "GOMP_2.0");
1942 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1943 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1944 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1945 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1946 
1947 // GOMP_3.0 versioned symbols
1948 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
1949 
1950 // GOMP_4.0 versioned symbols
1951 #if OMP_40_ENABLED
1952 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
1953 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
1954 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
1955 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
1956 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
1957 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
1958 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
1959 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
1960 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
1961 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
1962 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
1963 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
1964 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
1965 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
1966 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
1967 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
1968 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
1969 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
1970 #endif
1971 
1972 // GOMP_4.5 versioned symbols
1973 #if OMP_45_ENABLED
1974 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP, 45, "GOMP_4.5");
1975 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP_ULL, 45, "GOMP_4.5");
1976 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_POST, 45, "GOMP_4.5");
1977 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_WAIT, 45, "GOMP_4.5");
1978 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START, 45,
1979                    "GOMP_4.5");
1980 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START, 45,
1981                    "GOMP_4.5");
1982 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START, 45,
1983                    "GOMP_4.5");
1984 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START, 45,
1985                    "GOMP_4.5");
1986 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_POST, 45, "GOMP_4.5");
1987 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT, 45, "GOMP_4.5");
1988 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START, 45,
1989                    "GOMP_4.5");
1990 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START, 45,
1991                    "GOMP_4.5");
1992 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START, 45,
1993                    "GOMP_4.5");
1994 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, 45,
1995                    "GOMP_4.5");
1996 #endif
1997 
1998 #endif // KMP_USE_VERSION_SYMBOLS
1999 
2000 #ifdef __cplusplus
2001 } // extern "C"
2002 #endif // __cplusplus
2003