LLVM OpenMP* Runtime Library
kmp_gsupport.cpp
1 /*
2  * kmp_gsupport.cpp
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "kmp.h"
14 #include "kmp_atomic.h"
15 
16 #if OMPT_SUPPORT
17 #include "ompt-specific.h"
18 #endif
19 
20 enum {
21  KMP_GOMP_TASK_UNTIED_FLAG = 1,
22  KMP_GOMP_TASK_FINAL_FLAG = 2,
23  KMP_GOMP_TASK_DEPENDS_FLAG = 8
24 };
25 
26 // This class helps convert gomp dependency info into
27 // kmp_depend_info_t structures
28 class kmp_gomp_depends_info_t {
29  void **depend;
30  kmp_int32 num_deps;
31  size_t num_out, num_mutexinout, num_in;
32  size_t offset;
33 
34 public:
35  kmp_gomp_depends_info_t(void **depend) : depend(depend) {
36  size_t ndeps = (kmp_intptr_t)depend[0];
37  size_t num_doable;
38  // GOMP taskdep structure:
39  // if depend[0] != 0:
40  // depend = [ ndeps | nout | &out | ... | &out | &in | ... | &in ]
41  //
42  // if depend[0] == 0:
43  // depend = [ 0 | ndeps | nout | nmtx | nin | &out | ... | &out | &mtx |
44  // ... | &mtx | &in | ... | &in | &depobj | ... | &depobj ]
45  if (ndeps) {
46  num_out = (kmp_intptr_t)depend[1];
47  num_in = ndeps - num_out;
48  num_mutexinout = 0;
49  num_doable = ndeps;
50  offset = 2;
51  } else {
52  ndeps = (kmp_intptr_t)depend[1];
53  num_out = (kmp_intptr_t)depend[2];
54  num_mutexinout = (kmp_intptr_t)depend[3];
55  num_in = (kmp_intptr_t)depend[4];
56  num_doable = num_out + num_mutexinout + num_in;
57  offset = 5;
58  }
59  // TODO: Support gomp depobj
60  if (ndeps != num_doable) {
61  KMP_FATAL(GompFeatureNotSupported, "depobj");
62  }
63  num_deps = static_cast<kmp_int32>(ndeps);
64  }
65  kmp_int32 get_num_deps() const { return num_deps; }
66  kmp_depend_info_t get_kmp_depend(size_t index) const {
67  kmp_depend_info_t retval;
68  memset(&retval, '\0', sizeof(retval));
69  KMP_ASSERT(index < (size_t)num_deps);
70  retval.base_addr = (kmp_intptr_t)depend[offset + index];
71  retval.len = 0;
72  // Because inout and out are logically equivalent,
73  // use inout and in dependency flags. GOMP does not provide a
74  // way to distinguish if user specified out vs. inout.
75  if (index < num_out) {
76  retval.flags.in = 1;
77  retval.flags.out = 1;
78  } else if (index >= num_out && index < (num_out + num_mutexinout)) {
79  retval.flags.mtx = 1;
80  } else {
81  retval.flags.in = 1;
82  }
83  return retval;
84  }
85 };
86 
87 #ifdef __cplusplus
88 extern "C" {
89 #endif // __cplusplus
90 
91 #define MKLOC(loc, routine) \
92  static ident_t loc = {0, KMP_IDENT_KMPC, 0, 0, ";unknown;unknown;0;0;;"};
93 
94 #include "kmp_ftn_os.h"
95 
96 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER)(void) {
97  int gtid = __kmp_entry_gtid();
98  MKLOC(loc, "GOMP_barrier");
99  KA_TRACE(20, ("GOMP_barrier: T#%d\n", gtid));
100 #if OMPT_SUPPORT && OMPT_OPTIONAL
101  ompt_frame_t *ompt_frame;
102  if (ompt_enabled.enabled) {
103  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
104  ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
105  }
106  OMPT_STORE_RETURN_ADDRESS(gtid);
107 #endif
108  __kmpc_barrier(&loc, gtid);
109 #if OMPT_SUPPORT && OMPT_OPTIONAL
110  if (ompt_enabled.enabled) {
111  ompt_frame->enter_frame = ompt_data_none;
112  }
113 #endif
114 }
115 
116 // Mutual exclusion
117 
118 // The symbol that icc/ifort generates for unnamed for unnamed critical sections
119 // - .gomp_critical_user_ - is defined using .comm in any objects reference it.
120 // We can't reference it directly here in C code, as the symbol contains a ".".
121 //
122 // The RTL contains an assembly language definition of .gomp_critical_user_
123 // with another symbol __kmp_unnamed_critical_addr initialized with it's
124 // address.
125 extern kmp_critical_name *__kmp_unnamed_critical_addr;
126 
127 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_START)(void) {
128  int gtid = __kmp_entry_gtid();
129  MKLOC(loc, "GOMP_critical_start");
130  KA_TRACE(20, ("GOMP_critical_start: T#%d\n", gtid));
131 #if OMPT_SUPPORT && OMPT_OPTIONAL
132  OMPT_STORE_RETURN_ADDRESS(gtid);
133 #endif
134  __kmpc_critical(&loc, gtid, __kmp_unnamed_critical_addr);
135 }
136 
137 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_END)(void) {
138  int gtid = __kmp_get_gtid();
139  MKLOC(loc, "GOMP_critical_end");
140  KA_TRACE(20, ("GOMP_critical_end: T#%d\n", gtid));
141 #if OMPT_SUPPORT && OMPT_OPTIONAL
142  OMPT_STORE_RETURN_ADDRESS(gtid);
143 #endif
144  __kmpc_end_critical(&loc, gtid, __kmp_unnamed_critical_addr);
145 }
146 
147 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_START)(void **pptr) {
148  int gtid = __kmp_entry_gtid();
149  MKLOC(loc, "GOMP_critical_name_start");
150  KA_TRACE(20, ("GOMP_critical_name_start: T#%d\n", gtid));
151  __kmpc_critical(&loc, gtid, (kmp_critical_name *)pptr);
152 }
153 
154 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CRITICAL_NAME_END)(void **pptr) {
155  int gtid = __kmp_get_gtid();
156  MKLOC(loc, "GOMP_critical_name_end");
157  KA_TRACE(20, ("GOMP_critical_name_end: T#%d\n", gtid));
158  __kmpc_end_critical(&loc, gtid, (kmp_critical_name *)pptr);
159 }
160 
161 // The Gnu codegen tries to use locked operations to perform atomic updates
162 // inline. If it can't, then it calls GOMP_atomic_start() before performing
163 // the update and GOMP_atomic_end() afterward, regardless of the data type.
164 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_START)(void) {
165  int gtid = __kmp_entry_gtid();
166  KA_TRACE(20, ("GOMP_atomic_start: T#%d\n", gtid));
167 
168 #if OMPT_SUPPORT
169  __ompt_thread_assign_wait_id(0);
170 #endif
171 
172  __kmp_acquire_atomic_lock(&__kmp_atomic_lock, gtid);
173 }
174 
175 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ATOMIC_END)(void) {
176  int gtid = __kmp_get_gtid();
177  KA_TRACE(20, ("GOMP_atomic_end: T#%d\n", gtid));
178  __kmp_release_atomic_lock(&__kmp_atomic_lock, gtid);
179 }
180 
181 int KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_START)(void) {
182  int gtid = __kmp_entry_gtid();
183  MKLOC(loc, "GOMP_single_start");
184  KA_TRACE(20, ("GOMP_single_start: T#%d\n", gtid));
185 
186  if (!TCR_4(__kmp_init_parallel))
187  __kmp_parallel_initialize();
188  __kmp_resume_if_soft_paused();
189 
190  // 3rd parameter == FALSE prevents kmp_enter_single from pushing a
191  // workshare when USE_CHECKS is defined. We need to avoid the push,
192  // as there is no corresponding GOMP_single_end() call.
193  kmp_int32 rc = __kmp_enter_single(gtid, &loc, FALSE);
194 
195 #if OMPT_SUPPORT && OMPT_OPTIONAL
196  kmp_info_t *this_thr = __kmp_threads[gtid];
197  kmp_team_t *team = this_thr->th.th_team;
198  int tid = __kmp_tid_from_gtid(gtid);
199 
200  if (ompt_enabled.enabled) {
201  if (rc) {
202  if (ompt_enabled.ompt_callback_work) {
203  ompt_callbacks.ompt_callback(ompt_callback_work)(
204  ompt_work_single_executor, ompt_scope_begin,
205  &(team->t.ompt_team_info.parallel_data),
206  &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
207  1, OMPT_GET_RETURN_ADDRESS(0));
208  }
209  } else {
210  if (ompt_enabled.ompt_callback_work) {
211  ompt_callbacks.ompt_callback(ompt_callback_work)(
212  ompt_work_single_other, ompt_scope_begin,
213  &(team->t.ompt_team_info.parallel_data),
214  &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
215  1, OMPT_GET_RETURN_ADDRESS(0));
216  ompt_callbacks.ompt_callback(ompt_callback_work)(
217  ompt_work_single_other, ompt_scope_end,
218  &(team->t.ompt_team_info.parallel_data),
219  &(team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_data),
220  1, OMPT_GET_RETURN_ADDRESS(0));
221  }
222  }
223  }
224 #endif
225 
226  return rc;
227 }
228 
229 void *KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_START)(void) {
230  void *retval;
231  int gtid = __kmp_entry_gtid();
232  MKLOC(loc, "GOMP_single_copy_start");
233  KA_TRACE(20, ("GOMP_single_copy_start: T#%d\n", gtid));
234 
235  if (!TCR_4(__kmp_init_parallel))
236  __kmp_parallel_initialize();
237  __kmp_resume_if_soft_paused();
238 
239  // If this is the first thread to enter, return NULL. The generated code will
240  // then call GOMP_single_copy_end() for this thread only, with the
241  // copyprivate data pointer as an argument.
242  if (__kmp_enter_single(gtid, &loc, FALSE))
243  return NULL;
244 
245  // Wait for the first thread to set the copyprivate data pointer,
246  // and for all other threads to reach this point.
247 
248 #if OMPT_SUPPORT && OMPT_OPTIONAL
249  ompt_frame_t *ompt_frame;
250  if (ompt_enabled.enabled) {
251  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
252  ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
253  }
254  OMPT_STORE_RETURN_ADDRESS(gtid);
255 #endif
256  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
257 
258  // Retrieve the value of the copyprivate data point, and wait for all
259  // threads to do likewise, then return.
260  retval = __kmp_team_from_gtid(gtid)->t.t_copypriv_data;
261  {
262 #if OMPT_SUPPORT && OMPT_OPTIONAL
263  OMPT_STORE_RETURN_ADDRESS(gtid);
264 #endif
265  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
266  }
267 #if OMPT_SUPPORT && OMPT_OPTIONAL
268  if (ompt_enabled.enabled) {
269  ompt_frame->enter_frame = ompt_data_none;
270  }
271 #endif
272  return retval;
273 }
274 
275 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SINGLE_COPY_END)(void *data) {
276  int gtid = __kmp_get_gtid();
277  KA_TRACE(20, ("GOMP_single_copy_end: T#%d\n", gtid));
278 
279  // Set the copyprivate data pointer fo the team, then hit the barrier so that
280  // the other threads will continue on and read it. Hit another barrier before
281  // continuing, so that the know that the copyprivate data pointer has been
282  // propagated to all threads before trying to reuse the t_copypriv_data field.
283  __kmp_team_from_gtid(gtid)->t.t_copypriv_data = data;
284 #if OMPT_SUPPORT && OMPT_OPTIONAL
285  ompt_frame_t *ompt_frame;
286  if (ompt_enabled.enabled) {
287  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
288  ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
289  }
290  OMPT_STORE_RETURN_ADDRESS(gtid);
291 #endif
292  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
293  {
294 #if OMPT_SUPPORT && OMPT_OPTIONAL
295  OMPT_STORE_RETURN_ADDRESS(gtid);
296 #endif
297  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
298  }
299 #if OMPT_SUPPORT && OMPT_OPTIONAL
300  if (ompt_enabled.enabled) {
301  ompt_frame->enter_frame = ompt_data_none;
302  }
303 #endif
304 }
305 
306 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_START)(void) {
307  int gtid = __kmp_entry_gtid();
308  MKLOC(loc, "GOMP_ordered_start");
309  KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
310 #if OMPT_SUPPORT && OMPT_OPTIONAL
311  OMPT_STORE_RETURN_ADDRESS(gtid);
312 #endif
313  __kmpc_ordered(&loc, gtid);
314 }
315 
316 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_END)(void) {
317  int gtid = __kmp_get_gtid();
318  MKLOC(loc, "GOMP_ordered_end");
319  KA_TRACE(20, ("GOMP_ordered_start: T#%d\n", gtid));
320 #if OMPT_SUPPORT && OMPT_OPTIONAL
321  OMPT_STORE_RETURN_ADDRESS(gtid);
322 #endif
323  __kmpc_end_ordered(&loc, gtid);
324 }
325 
326 // Dispatch macro defs
327 //
328 // They come in two flavors: 64-bit unsigned, and either 32-bit signed
329 // (IA-32 architecture) or 64-bit signed (Intel(R) 64).
330 
331 #if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
332 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
333 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
334 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4
335 #else
336 #define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_8
337 #define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_8
338 #define KMP_DISPATCH_NEXT __kmpc_dispatch_next_8
339 #endif /* KMP_ARCH_X86 */
340 
341 #define KMP_DISPATCH_INIT_ULL __kmp_aux_dispatch_init_8u
342 #define KMP_DISPATCH_FINI_CHUNK_ULL __kmp_aux_dispatch_fini_chunk_8u
343 #define KMP_DISPATCH_NEXT_ULL __kmpc_dispatch_next_8u
344 
345 // The parallel construct
346 
347 #ifndef KMP_DEBUG
348 static
349 #endif /* KMP_DEBUG */
350  void
351  __kmp_GOMP_microtask_wrapper(int *gtid, int *npr, void (*task)(void *),
352  void *data) {
353 #if OMPT_SUPPORT
354  kmp_info_t *thr;
355  ompt_frame_t *ompt_frame;
356  ompt_state_t enclosing_state;
357 
358  if (ompt_enabled.enabled) {
359  // get pointer to thread data structure
360  thr = __kmp_threads[*gtid];
361 
362  // save enclosing task state; set current state for task
363  enclosing_state = thr->th.ompt_thread_info.state;
364  thr->th.ompt_thread_info.state = ompt_state_work_parallel;
365 
366  // set task frame
367  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
368  ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
369  }
370 #endif
371 
372  task(data);
373 
374 #if OMPT_SUPPORT
375  if (ompt_enabled.enabled) {
376  // clear task frame
377  ompt_frame->exit_frame = ompt_data_none;
378 
379  // restore enclosing state
380  thr->th.ompt_thread_info.state = enclosing_state;
381  }
382 #endif
383 }
384 
385 #ifndef KMP_DEBUG
386 static
387 #endif /* KMP_DEBUG */
388  void
389  __kmp_GOMP_parallel_microtask_wrapper(int *gtid, int *npr,
390  void (*task)(void *), void *data,
391  unsigned num_threads, ident_t *loc,
392  enum sched_type schedule, long start,
393  long end, long incr,
394  long chunk_size) {
395  // Initialize the loop worksharing construct.
396 
397  KMP_DISPATCH_INIT(loc, *gtid, schedule, start, end, incr, chunk_size,
398  schedule != kmp_sch_static);
399 
400 #if OMPT_SUPPORT
401  kmp_info_t *thr;
402  ompt_frame_t *ompt_frame;
403  ompt_state_t enclosing_state;
404 
405  if (ompt_enabled.enabled) {
406  thr = __kmp_threads[*gtid];
407  // save enclosing task state; set current state for task
408  enclosing_state = thr->th.ompt_thread_info.state;
409  thr->th.ompt_thread_info.state = ompt_state_work_parallel;
410 
411  // set task frame
412  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
413  ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
414  }
415 #endif
416 
417  // Now invoke the microtask.
418  task(data);
419 
420 #if OMPT_SUPPORT
421  if (ompt_enabled.enabled) {
422  // clear task frame
423  ompt_frame->exit_frame = ompt_data_none;
424 
425  // reset enclosing state
426  thr->th.ompt_thread_info.state = enclosing_state;
427  }
428 #endif
429 }
430 
431 static void __kmp_GOMP_fork_call(ident_t *loc, int gtid, unsigned num_threads,
432  unsigned flags, void (*unwrapped_task)(void *),
433  microtask_t wrapper, int argc, ...) {
434  int rc;
435  kmp_info_t *thr = __kmp_threads[gtid];
436  kmp_team_t *team = thr->th.th_team;
437  int tid = __kmp_tid_from_gtid(gtid);
438 
439  va_list ap;
440  va_start(ap, argc);
441 
442  if (num_threads != 0)
443  __kmp_push_num_threads(loc, gtid, num_threads);
444  if (flags != 0)
445  __kmp_push_proc_bind(loc, gtid, (kmp_proc_bind_t)flags);
446  rc = __kmp_fork_call(loc, gtid, fork_context_gnu, argc, wrapper,
447  __kmp_invoke_task_func, kmp_va_addr_of(ap));
448 
449  va_end(ap);
450 
451  if (rc) {
452  __kmp_run_before_invoked_task(gtid, tid, thr, team);
453  }
454 
455 #if OMPT_SUPPORT
456  int ompt_team_size;
457  if (ompt_enabled.enabled) {
458  ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
459  ompt_task_info_t *task_info = __ompt_get_task_info_object(0);
460 
461  // implicit task callback
462  if (ompt_enabled.ompt_callback_implicit_task) {
463  ompt_team_size = __kmp_team_from_gtid(gtid)->t.t_nproc;
464  ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
465  ompt_scope_begin, &(team_info->parallel_data),
466  &(task_info->task_data), ompt_team_size, __kmp_tid_from_gtid(gtid),
467  ompt_task_implicit); // TODO: Can this be ompt_task_initial?
468  task_info->thread_num = __kmp_tid_from_gtid(gtid);
469  }
470  thr->th.ompt_thread_info.state = ompt_state_work_parallel;
471  }
472 #endif
473 }
474 
475 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *),
476  void *data,
477  unsigned num_threads) {
478  int gtid = __kmp_entry_gtid();
479 
480 #if OMPT_SUPPORT
481  ompt_frame_t *parent_frame, *frame;
482 
483  if (ompt_enabled.enabled) {
484  __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
485  parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
486  }
487  OMPT_STORE_RETURN_ADDRESS(gtid);
488 #endif
489 
490  MKLOC(loc, "GOMP_parallel_start");
491  KA_TRACE(20, ("GOMP_parallel_start: T#%d\n", gtid));
492  __kmp_GOMP_fork_call(&loc, gtid, num_threads, 0u, task,
493  (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
494  data);
495 #if OMPT_SUPPORT
496  if (ompt_enabled.enabled) {
497  __ompt_get_task_info_internal(0, NULL, NULL, &frame, NULL, NULL);
498  frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
499  }
500 #endif
501 }
502 
503 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(void) {
504  int gtid = __kmp_get_gtid();
505  kmp_info_t *thr;
506 
507  thr = __kmp_threads[gtid];
508 
509  MKLOC(loc, "GOMP_parallel_end");
510  KA_TRACE(20, ("GOMP_parallel_end: T#%d\n", gtid));
511 
512  if (!thr->th.th_team->t.t_serialized) {
513  __kmp_run_after_invoked_task(gtid, __kmp_tid_from_gtid(gtid), thr,
514  thr->th.th_team);
515  }
516 #if OMPT_SUPPORT
517  if (ompt_enabled.enabled) {
518  // Implicit task is finished here, in the barrier we might schedule
519  // deferred tasks,
520  // these don't see the implicit task on the stack
521  OMPT_CUR_TASK_INFO(thr)->frame.exit_frame = ompt_data_none;
522  }
523 #endif
524 
525  __kmp_join_call(&loc, gtid
526 #if OMPT_SUPPORT
527  ,
528  fork_context_gnu
529 #endif
530  );
531 }
532 
533 // Loop worksharing constructs
534 
535 // The Gnu codegen passes in an exclusive upper bound for the overall range,
536 // but the libguide dispatch code expects an inclusive upper bound, hence the
537 // "end - incr" 5th argument to KMP_DISPATCH_INIT (and the " ub - str" 11th
538 // argument to __kmp_GOMP_fork_call).
539 //
540 // Conversely, KMP_DISPATCH_NEXT returns and inclusive upper bound in *p_ub,
541 // but the Gnu codegen expects an exclusive upper bound, so the adjustment
542 // "*p_ub += stride" compensates for the discrepancy.
543 //
544 // Correction: the gnu codegen always adjusts the upper bound by +-1, not the
545 // stride value. We adjust the dispatch parameters accordingly (by +-1), but
546 // we still adjust p_ub by the actual stride value.
547 //
548 // The "runtime" versions do not take a chunk_sz parameter.
549 //
550 // The profile lib cannot support construct checking of unordered loops that
551 // are predetermined by the compiler to be statically scheduled, as the gcc
552 // codegen will not always emit calls to GOMP_loop_static_next() to get the
553 // next iteration. Instead, it emits inline code to call omp_get_thread_num()
554 // num and calculate the iteration space using the result. It doesn't do this
555 // with ordered static loop, so they can be checked.
556 
557 #if OMPT_SUPPORT
558 #define IF_OMPT_SUPPORT(code) code
559 #else
560 #define IF_OMPT_SUPPORT(code)
561 #endif
562 
563 #define LOOP_START(func, schedule) \
564  int func(long lb, long ub, long str, long chunk_sz, long *p_lb, \
565  long *p_ub) { \
566  int status; \
567  long stride; \
568  int gtid = __kmp_entry_gtid(); \
569  MKLOC(loc, KMP_STR(func)); \
570  KA_TRACE( \
571  20, \
572  (KMP_STR( \
573  func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
574  gtid, lb, ub, str, chunk_sz)); \
575  \
576  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
577  { \
578  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
579  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
580  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
581  (schedule) != kmp_sch_static); \
582  } \
583  { \
584  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
585  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
586  (kmp_int *)p_ub, (kmp_int *)&stride); \
587  } \
588  if (status) { \
589  KMP_DEBUG_ASSERT(stride == str); \
590  *p_ub += (str > 0) ? 1 : -1; \
591  } \
592  } else { \
593  status = 0; \
594  } \
595  \
596  KA_TRACE( \
597  20, \
598  (KMP_STR( \
599  func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
600  gtid, *p_lb, *p_ub, status)); \
601  return status; \
602  }
603 
604 #define LOOP_RUNTIME_START(func, schedule) \
605  int func(long lb, long ub, long str, long *p_lb, long *p_ub) { \
606  int status; \
607  long stride; \
608  long chunk_sz = 0; \
609  int gtid = __kmp_entry_gtid(); \
610  MKLOC(loc, KMP_STR(func)); \
611  KA_TRACE( \
612  20, \
613  (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
614  gtid, lb, ub, str, chunk_sz)); \
615  \
616  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
617  { \
618  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
619  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
620  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
621  TRUE); \
622  } \
623  { \
624  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
625  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
626  (kmp_int *)p_ub, (kmp_int *)&stride); \
627  } \
628  if (status) { \
629  KMP_DEBUG_ASSERT(stride == str); \
630  *p_ub += (str > 0) ? 1 : -1; \
631  } \
632  } else { \
633  status = 0; \
634  } \
635  \
636  KA_TRACE( \
637  20, \
638  (KMP_STR( \
639  func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
640  gtid, *p_lb, *p_ub, status)); \
641  return status; \
642  }
643 
644 #define KMP_DOACROSS_FINI(status, gtid) \
645  if (!status && __kmp_threads[gtid]->th.th_dispatch->th_doacross_flags) { \
646  __kmpc_doacross_fini(NULL, gtid); \
647  }
648 
649 #define LOOP_NEXT(func, fini_code) \
650  int func(long *p_lb, long *p_ub) { \
651  int status; \
652  long stride; \
653  int gtid = __kmp_get_gtid(); \
654  MKLOC(loc, KMP_STR(func)); \
655  KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
656  \
657  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
658  fini_code status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
659  (kmp_int *)p_ub, (kmp_int *)&stride); \
660  if (status) { \
661  *p_ub += (stride > 0) ? 1 : -1; \
662  } \
663  KMP_DOACROSS_FINI(status, gtid) \
664  \
665  KA_TRACE( \
666  20, \
667  (KMP_STR(func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, stride 0x%lx, " \
668  "returning %d\n", \
669  gtid, *p_lb, *p_ub, stride, status)); \
670  return status; \
671  }
672 
673 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_START), kmp_sch_static)
674 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT), {})
675 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START),
676  kmp_sch_dynamic_chunked)
677 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_START),
678  kmp_sch_dynamic_chunked)
679 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT), {})
680 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_NEXT), {})
681 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_START),
683 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_START),
685 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT), {})
686 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_NEXT), {})
687 LOOP_RUNTIME_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_START),
688  kmp_sch_runtime)
689 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT), {})
690 LOOP_RUNTIME_START(
691  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START),
692  kmp_sch_runtime)
693 LOOP_RUNTIME_START(
694  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_START),
695  kmp_sch_runtime)
696 LOOP_NEXT(
697  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT), {})
698 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT), {})
699 
700 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START),
702 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT),
703  { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
704 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START),
705  kmp_ord_dynamic_chunked)
706 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT),
707  { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
708 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START),
709  kmp_ord_guided_chunked)
710 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT),
711  { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
712 LOOP_RUNTIME_START(
713  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START),
714  kmp_ord_runtime)
715 LOOP_NEXT(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT),
716  { KMP_DISPATCH_FINI_CHUNK(&loc, gtid); })
717 
718 #define LOOP_DOACROSS_START(func, schedule) \
719  bool func(unsigned ncounts, long *counts, long chunk_sz, long *p_lb, \
720  long *p_ub) { \
721  int status; \
722  long stride, lb, ub, str; \
723  int gtid = __kmp_entry_gtid(); \
724  struct kmp_dim *dims = \
725  (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
726  MKLOC(loc, KMP_STR(func)); \
727  for (unsigned i = 0; i < ncounts; ++i) { \
728  dims[i].lo = 0; \
729  dims[i].up = counts[i] - 1; \
730  dims[i].st = 1; \
731  } \
732  __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
733  lb = 0; \
734  ub = counts[0]; \
735  str = 1; \
736  KA_TRACE(20, (KMP_STR(func) ": T#%d, ncounts %u, lb 0x%lx, ub 0x%lx, str " \
737  "0x%lx, chunk_sz " \
738  "0x%lx\n", \
739  gtid, ncounts, lb, ub, str, chunk_sz)); \
740  \
741  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
742  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
743  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
744  (schedule) != kmp_sch_static); \
745  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
746  (kmp_int *)p_ub, (kmp_int *)&stride); \
747  if (status) { \
748  KMP_DEBUG_ASSERT(stride == str); \
749  *p_ub += (str > 0) ? 1 : -1; \
750  } \
751  } else { \
752  status = 0; \
753  } \
754  KMP_DOACROSS_FINI(status, gtid); \
755  \
756  KA_TRACE( \
757  20, \
758  (KMP_STR( \
759  func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
760  gtid, *p_lb, *p_ub, status)); \
761  __kmp_free(dims); \
762  return status; \
763  }
764 
765 #define LOOP_DOACROSS_RUNTIME_START(func, schedule) \
766  int func(unsigned ncounts, long *counts, long *p_lb, long *p_ub) { \
767  int status; \
768  long stride, lb, ub, str; \
769  long chunk_sz = 0; \
770  int gtid = __kmp_entry_gtid(); \
771  struct kmp_dim *dims = \
772  (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
773  MKLOC(loc, KMP_STR(func)); \
774  for (unsigned i = 0; i < ncounts; ++i) { \
775  dims[i].lo = 0; \
776  dims[i].up = counts[i] - 1; \
777  dims[i].st = 1; \
778  } \
779  __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
780  lb = 0; \
781  ub = counts[0]; \
782  str = 1; \
783  KA_TRACE( \
784  20, \
785  (KMP_STR(func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz %d\n", \
786  gtid, lb, ub, str, chunk_sz)); \
787  \
788  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
789  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
790  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, TRUE); \
791  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, (kmp_int *)p_lb, \
792  (kmp_int *)p_ub, (kmp_int *)&stride); \
793  if (status) { \
794  KMP_DEBUG_ASSERT(stride == str); \
795  *p_ub += (str > 0) ? 1 : -1; \
796  } \
797  } else { \
798  status = 0; \
799  } \
800  KMP_DOACROSS_FINI(status, gtid); \
801  \
802  KA_TRACE( \
803  20, \
804  (KMP_STR( \
805  func) " exit: T#%d, *p_lb 0x%lx, *p_ub 0x%lx, returning %d\n", \
806  gtid, *p_lb, *p_ub, status)); \
807  __kmp_free(dims); \
808  return status; \
809  }
810 
811 LOOP_DOACROSS_START(
812  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START),
814 LOOP_DOACROSS_START(
815  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START),
816  kmp_sch_dynamic_chunked)
817 LOOP_DOACROSS_START(
818  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START),
820 LOOP_DOACROSS_RUNTIME_START(
821  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START),
822  kmp_sch_runtime)
823 
824 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END)(void) {
825  int gtid = __kmp_get_gtid();
826  KA_TRACE(20, ("GOMP_loop_end: T#%d\n", gtid))
827 
828 #if OMPT_SUPPORT && OMPT_OPTIONAL
829  ompt_frame_t *ompt_frame;
830  if (ompt_enabled.enabled) {
831  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
832  ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
833  OMPT_STORE_RETURN_ADDRESS(gtid);
834  }
835 #endif
836  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
837 #if OMPT_SUPPORT && OMPT_OPTIONAL
838  if (ompt_enabled.enabled) {
839  ompt_frame->enter_frame = ompt_data_none;
840  }
841 #endif
842 
843  KA_TRACE(20, ("GOMP_loop_end exit: T#%d\n", gtid))
844 }
845 
846 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_NOWAIT)(void) {
847  KA_TRACE(20, ("GOMP_loop_end_nowait: T#%d\n", __kmp_get_gtid()))
848 }
849 
850 // Unsigned long long loop worksharing constructs
851 //
852 // These are new with gcc 4.4
853 
854 #define LOOP_START_ULL(func, schedule) \
855  int func(int up, unsigned long long lb, unsigned long long ub, \
856  unsigned long long str, unsigned long long chunk_sz, \
857  unsigned long long *p_lb, unsigned long long *p_ub) { \
858  int status; \
859  long long str2 = up ? ((long long)str) : -((long long)str); \
860  long long stride; \
861  int gtid = __kmp_entry_gtid(); \
862  MKLOC(loc, KMP_STR(func)); \
863  \
864  KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
865  "0x%llx, chunk_sz 0x%llx\n", \
866  gtid, up, lb, ub, str, chunk_sz)); \
867  \
868  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
869  KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
870  (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
871  (schedule) != kmp_sch_static); \
872  status = \
873  KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
874  (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
875  if (status) { \
876  KMP_DEBUG_ASSERT(stride == str2); \
877  *p_ub += (str > 0) ? 1 : -1; \
878  } \
879  } else { \
880  status = 0; \
881  } \
882  \
883  KA_TRACE( \
884  20, \
885  (KMP_STR( \
886  func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
887  gtid, *p_lb, *p_ub, status)); \
888  return status; \
889  }
890 
891 #define LOOP_RUNTIME_START_ULL(func, schedule) \
892  int func(int up, unsigned long long lb, unsigned long long ub, \
893  unsigned long long str, unsigned long long *p_lb, \
894  unsigned long long *p_ub) { \
895  int status; \
896  long long str2 = up ? ((long long)str) : -((long long)str); \
897  unsigned long long stride; \
898  unsigned long long chunk_sz = 0; \
899  int gtid = __kmp_entry_gtid(); \
900  MKLOC(loc, KMP_STR(func)); \
901  \
902  KA_TRACE(20, (KMP_STR(func) ": T#%d, up %d, lb 0x%llx, ub 0x%llx, str " \
903  "0x%llx, chunk_sz 0x%llx\n", \
904  gtid, up, lb, ub, str, chunk_sz)); \
905  \
906  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
907  KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
908  (str2 > 0) ? (ub - 1) : (ub + 1), str2, chunk_sz, \
909  TRUE); \
910  status = \
911  KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
912  (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
913  if (status) { \
914  KMP_DEBUG_ASSERT((long long)stride == str2); \
915  *p_ub += (str > 0) ? 1 : -1; \
916  } \
917  } else { \
918  status = 0; \
919  } \
920  \
921  KA_TRACE( \
922  20, \
923  (KMP_STR( \
924  func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
925  gtid, *p_lb, *p_ub, status)); \
926  return status; \
927  }
928 
929 #define LOOP_NEXT_ULL(func, fini_code) \
930  int func(unsigned long long *p_lb, unsigned long long *p_ub) { \
931  int status; \
932  long long stride; \
933  int gtid = __kmp_get_gtid(); \
934  MKLOC(loc, KMP_STR(func)); \
935  KA_TRACE(20, (KMP_STR(func) ": T#%d\n", gtid)); \
936  \
937  fini_code status = \
938  KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
939  (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
940  if (status) { \
941  *p_ub += (stride > 0) ? 1 : -1; \
942  } \
943  \
944  KA_TRACE( \
945  20, \
946  (KMP_STR( \
947  func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, stride 0x%llx, " \
948  "returning %d\n", \
949  gtid, *p_lb, *p_ub, stride, status)); \
950  return status; \
951  }
952 
953 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START),
955 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT), {})
956 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START),
957  kmp_sch_dynamic_chunked)
958 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT), {})
959 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START),
961 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT), {})
962 LOOP_START_ULL(
963  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_START),
964  kmp_sch_dynamic_chunked)
965 LOOP_NEXT_ULL(
966  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_NEXT), {})
967 LOOP_START_ULL(
968  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START),
970 LOOP_NEXT_ULL(
971  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_NEXT), {})
972 LOOP_RUNTIME_START_ULL(
973  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START), kmp_sch_runtime)
974 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT), {})
975 LOOP_RUNTIME_START_ULL(
976  KMP_EXPAND_NAME(
977  KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START),
978  kmp_sch_runtime)
979 LOOP_RUNTIME_START_ULL(
980  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START),
981  kmp_sch_runtime)
982 LOOP_NEXT_ULL(
983  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT),
984  {})
985 LOOP_NEXT_ULL(
986  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT), {})
987 
988 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START),
990 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT),
991  { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
992 LOOP_START_ULL(
993  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START),
994  kmp_ord_dynamic_chunked)
995 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT),
996  { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
997 LOOP_START_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START),
998  kmp_ord_guided_chunked)
999 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT),
1000  { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
1001 LOOP_RUNTIME_START_ULL(
1002  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START),
1003  kmp_ord_runtime)
1004 LOOP_NEXT_ULL(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT),
1005  { KMP_DISPATCH_FINI_CHUNK_ULL(&loc, gtid); })
1006 
1007 #define LOOP_DOACROSS_START_ULL(func, schedule) \
1008  int func(unsigned ncounts, unsigned long long *counts, \
1009  unsigned long long chunk_sz, unsigned long long *p_lb, \
1010  unsigned long long *p_ub) { \
1011  int status; \
1012  long long stride, str, lb, ub; \
1013  int gtid = __kmp_entry_gtid(); \
1014  struct kmp_dim *dims = \
1015  (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
1016  MKLOC(loc, KMP_STR(func)); \
1017  for (unsigned i = 0; i < ncounts; ++i) { \
1018  dims[i].lo = 0; \
1019  dims[i].up = counts[i] - 1; \
1020  dims[i].st = 1; \
1021  } \
1022  __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
1023  lb = 0; \
1024  ub = counts[0]; \
1025  str = 1; \
1026  \
1027  KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
1028  "0x%llx, chunk_sz 0x%llx\n", \
1029  gtid, lb, ub, str, chunk_sz)); \
1030  \
1031  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
1032  KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
1033  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1034  (schedule) != kmp_sch_static); \
1035  status = \
1036  KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
1037  (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
1038  if (status) { \
1039  KMP_DEBUG_ASSERT(stride == str); \
1040  *p_ub += (str > 0) ? 1 : -1; \
1041  } \
1042  } else { \
1043  status = 0; \
1044  } \
1045  KMP_DOACROSS_FINI(status, gtid); \
1046  \
1047  KA_TRACE( \
1048  20, \
1049  (KMP_STR( \
1050  func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
1051  gtid, *p_lb, *p_ub, status)); \
1052  __kmp_free(dims); \
1053  return status; \
1054  }
1055 
1056 #define LOOP_DOACROSS_RUNTIME_START_ULL(func, schedule) \
1057  int func(unsigned ncounts, unsigned long long *counts, \
1058  unsigned long long *p_lb, unsigned long long *p_ub) { \
1059  int status; \
1060  unsigned long long stride, str, lb, ub; \
1061  unsigned long long chunk_sz = 0; \
1062  int gtid = __kmp_entry_gtid(); \
1063  struct kmp_dim *dims = \
1064  (struct kmp_dim *)__kmp_allocate(sizeof(struct kmp_dim) * ncounts); \
1065  MKLOC(loc, KMP_STR(func)); \
1066  for (unsigned i = 0; i < ncounts; ++i) { \
1067  dims[i].lo = 0; \
1068  dims[i].up = counts[i] - 1; \
1069  dims[i].st = 1; \
1070  } \
1071  __kmpc_doacross_init(&loc, gtid, (int)ncounts, dims); \
1072  lb = 0; \
1073  ub = counts[0]; \
1074  str = 1; \
1075  KA_TRACE(20, (KMP_STR(func) ": T#%d, lb 0x%llx, ub 0x%llx, str " \
1076  "0x%llx, chunk_sz 0x%llx\n", \
1077  gtid, lb, ub, str, chunk_sz)); \
1078  \
1079  if ((str > 0) ? (lb < ub) : (lb > ub)) { \
1080  KMP_DISPATCH_INIT_ULL(&loc, gtid, (schedule), lb, \
1081  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1082  TRUE); \
1083  status = \
1084  KMP_DISPATCH_NEXT_ULL(&loc, gtid, NULL, (kmp_uint64 *)p_lb, \
1085  (kmp_uint64 *)p_ub, (kmp_int64 *)&stride); \
1086  if (status) { \
1087  KMP_DEBUG_ASSERT(stride == str); \
1088  *p_ub += (str > 0) ? 1 : -1; \
1089  } \
1090  } else { \
1091  status = 0; \
1092  } \
1093  KMP_DOACROSS_FINI(status, gtid); \
1094  \
1095  KA_TRACE( \
1096  20, \
1097  (KMP_STR( \
1098  func) " exit: T#%d, *p_lb 0x%llx, *p_ub 0x%llx, returning %d\n", \
1099  gtid, *p_lb, *p_ub, status)); \
1100  __kmp_free(dims); \
1101  return status; \
1102  }
1103 
1104 LOOP_DOACROSS_START_ULL(
1105  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START),
1107 LOOP_DOACROSS_START_ULL(
1108  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START),
1109  kmp_sch_dynamic_chunked)
1110 LOOP_DOACROSS_START_ULL(
1111  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START),
1113 LOOP_DOACROSS_RUNTIME_START_ULL(
1114  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START),
1115  kmp_sch_runtime)
1116 
1117 // Combined parallel / loop worksharing constructs
1118 //
1119 // There are no ull versions (yet).
1120 
1121 #define PARALLEL_LOOP_START(func, schedule, ompt_pre, ompt_post) \
1122  void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1123  long ub, long str, long chunk_sz) { \
1124  int gtid = __kmp_entry_gtid(); \
1125  MKLOC(loc, KMP_STR(func)); \
1126  KA_TRACE( \
1127  20, \
1128  (KMP_STR( \
1129  func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1130  gtid, lb, ub, str, chunk_sz)); \
1131  \
1132  ompt_pre(); \
1133  \
1134  __kmp_GOMP_fork_call(&loc, gtid, num_threads, 0u, task, \
1135  (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1136  9, task, data, num_threads, &loc, (schedule), lb, \
1137  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1138  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid)); \
1139  \
1140  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1141  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1142  (schedule) != kmp_sch_static); \
1143  \
1144  ompt_post(); \
1145  \
1146  KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1147  }
1148 
1149 #if OMPT_SUPPORT && OMPT_OPTIONAL
1150 
1151 #define OMPT_LOOP_PRE() \
1152  ompt_frame_t *parent_frame; \
1153  if (ompt_enabled.enabled) { \
1154  __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL); \
1155  parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0); \
1156  OMPT_STORE_RETURN_ADDRESS(gtid); \
1157  }
1158 
1159 #define OMPT_LOOP_POST() \
1160  if (ompt_enabled.enabled) { \
1161  parent_frame->enter_frame = ompt_data_none; \
1162  }
1163 
1164 #else
1165 
1166 #define OMPT_LOOP_PRE()
1167 
1168 #define OMPT_LOOP_POST()
1169 
1170 #endif
1171 
1172 PARALLEL_LOOP_START(
1173  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START),
1174  kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1175 PARALLEL_LOOP_START(
1176  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START),
1177  kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1178 PARALLEL_LOOP_START(
1179  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START),
1180  kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1181 PARALLEL_LOOP_START(
1182  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START),
1183  kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1184 
1185 // Tasking constructs
1186 
1187 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data,
1188  void (*copy_func)(void *, void *),
1189  long arg_size, long arg_align,
1190  bool if_cond, unsigned gomp_flags,
1191  void **depend) {
1192  MKLOC(loc, "GOMP_task");
1193  int gtid = __kmp_entry_gtid();
1194  kmp_int32 flags = 0;
1195  kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1196 
1197  KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
1198 
1199  // The low-order bit is the "untied" flag
1200  if (!(gomp_flags & KMP_GOMP_TASK_UNTIED_FLAG)) {
1201  input_flags->tiedness = 1;
1202  }
1203  // The second low-order bit is the "final" flag
1204  if (gomp_flags & KMP_GOMP_TASK_FINAL_FLAG) {
1205  input_flags->final = 1;
1206  }
1207  input_flags->native = 1;
1208  // __kmp_task_alloc() sets up all other flags
1209 
1210  if (!if_cond) {
1211  arg_size = 0;
1212  }
1213 
1214  kmp_task_t *task = __kmp_task_alloc(
1215  &loc, gtid, input_flags, sizeof(kmp_task_t),
1216  arg_size ? arg_size + arg_align - 1 : 0, (kmp_routine_entry_t)func);
1217 
1218  if (arg_size > 0) {
1219  if (arg_align > 0) {
1220  task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1221  arg_align * arg_align);
1222  }
1223  // else error??
1224 
1225  if (copy_func) {
1226  (*copy_func)(task->shareds, data);
1227  } else {
1228  KMP_MEMCPY(task->shareds, data, arg_size);
1229  }
1230  }
1231 
1232 #if OMPT_SUPPORT
1233  kmp_taskdata_t *current_task;
1234  if (ompt_enabled.enabled) {
1235  current_task = __kmp_threads[gtid]->th.th_current_task;
1236  current_task->ompt_task_info.frame.enter_frame.ptr =
1237  OMPT_GET_FRAME_ADDRESS(0);
1238  }
1239  OMPT_STORE_RETURN_ADDRESS(gtid);
1240 #endif
1241 
1242  if (if_cond) {
1243  if (gomp_flags & KMP_GOMP_TASK_DEPENDS_FLAG) {
1244  KMP_ASSERT(depend);
1245  kmp_gomp_depends_info_t gomp_depends(depend);
1246  kmp_int32 ndeps = gomp_depends.get_num_deps();
1247  kmp_depend_info_t dep_list[ndeps];
1248  for (kmp_int32 i = 0; i < ndeps; i++)
1249  dep_list[i] = gomp_depends.get_kmp_depend(i);
1250  kmp_int32 ndeps_cnv;
1251  __kmp_type_convert(ndeps, &ndeps_cnv);
1252  __kmpc_omp_task_with_deps(&loc, gtid, task, ndeps_cnv, dep_list, 0, NULL);
1253  } else {
1254  __kmpc_omp_task(&loc, gtid, task);
1255  }
1256  } else {
1257 #if OMPT_SUPPORT
1258  ompt_thread_info_t oldInfo;
1259  kmp_info_t *thread;
1260  kmp_taskdata_t *taskdata;
1261  if (ompt_enabled.enabled) {
1262  // Store the threads states and restore them after the task
1263  thread = __kmp_threads[gtid];
1264  taskdata = KMP_TASK_TO_TASKDATA(task);
1265  oldInfo = thread->th.ompt_thread_info;
1266  thread->th.ompt_thread_info.wait_id = 0;
1267  thread->th.ompt_thread_info.state = ompt_state_work_parallel;
1268  taskdata->ompt_task_info.frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1269  }
1270  OMPT_STORE_RETURN_ADDRESS(gtid);
1271 #endif
1272  if (gomp_flags & KMP_GOMP_TASK_DEPENDS_FLAG) {
1273  KMP_ASSERT(depend);
1274  kmp_gomp_depends_info_t gomp_depends(depend);
1275  kmp_int32 ndeps = gomp_depends.get_num_deps();
1276  kmp_depend_info_t dep_list[ndeps];
1277  for (kmp_int32 i = 0; i < ndeps; i++)
1278  dep_list[i] = gomp_depends.get_kmp_depend(i);
1279  __kmpc_omp_wait_deps(&loc, gtid, ndeps, dep_list, 0, NULL);
1280  }
1281 
1282  __kmpc_omp_task_begin_if0(&loc, gtid, task);
1283  func(data);
1284  __kmpc_omp_task_complete_if0(&loc, gtid, task);
1285 
1286 #if OMPT_SUPPORT
1287  if (ompt_enabled.enabled) {
1288  thread->th.ompt_thread_info = oldInfo;
1289  taskdata->ompt_task_info.frame.exit_frame = ompt_data_none;
1290  }
1291 #endif
1292  }
1293 #if OMPT_SUPPORT
1294  if (ompt_enabled.enabled) {
1295  current_task->ompt_task_info.frame.enter_frame = ompt_data_none;
1296  }
1297 #endif
1298 
1299  KA_TRACE(20, ("GOMP_task exit: T#%d\n", gtid));
1300 }
1301 
1302 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT)(void) {
1303  MKLOC(loc, "GOMP_taskwait");
1304  int gtid = __kmp_entry_gtid();
1305 
1306 #if OMPT_SUPPORT
1307  OMPT_STORE_RETURN_ADDRESS(gtid);
1308 #endif
1309 
1310  KA_TRACE(20, ("GOMP_taskwait: T#%d\n", gtid));
1311 
1312  __kmpc_omp_taskwait(&loc, gtid);
1313 
1314  KA_TRACE(20, ("GOMP_taskwait exit: T#%d\n", gtid));
1315 }
1316 
1317 // Sections worksharing constructs
1318 //
1319 // For the sections construct, we initialize a dynamically scheduled loop
1320 // worksharing construct with lb 1 and stride 1, and use the iteration #'s
1321 // that its returns as sections ids.
1322 //
1323 // There are no special entry points for ordered sections, so we always use
1324 // the dynamically scheduled workshare, even if the sections aren't ordered.
1325 
1326 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_START)(unsigned count) {
1327  int status;
1328  kmp_int lb, ub, stride;
1329  int gtid = __kmp_entry_gtid();
1330  MKLOC(loc, "GOMP_sections_start");
1331  KA_TRACE(20, ("GOMP_sections_start: T#%d\n", gtid));
1332 
1333  KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1334 
1335  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1336  if (status) {
1337  KMP_DEBUG_ASSERT(stride == 1);
1338  KMP_DEBUG_ASSERT(lb > 0);
1339  KMP_ASSERT(lb == ub);
1340  } else {
1341  lb = 0;
1342  }
1343 
1344  KA_TRACE(20, ("GOMP_sections_start exit: T#%d returning %u\n", gtid,
1345  (unsigned)lb));
1346  return (unsigned)lb;
1347 }
1348 
1349 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_NEXT)(void) {
1350  int status;
1351  kmp_int lb, ub, stride;
1352  int gtid = __kmp_get_gtid();
1353  MKLOC(loc, "GOMP_sections_next");
1354  KA_TRACE(20, ("GOMP_sections_next: T#%d\n", gtid));
1355 
1356 #if OMPT_SUPPORT
1357  OMPT_STORE_RETURN_ADDRESS(gtid);
1358 #endif
1359 
1360  status = KMP_DISPATCH_NEXT(&loc, gtid, NULL, &lb, &ub, &stride);
1361  if (status) {
1362  KMP_DEBUG_ASSERT(stride == 1);
1363  KMP_DEBUG_ASSERT(lb > 0);
1364  KMP_ASSERT(lb == ub);
1365  } else {
1366  lb = 0;
1367  }
1368 
1369  KA_TRACE(
1370  20, ("GOMP_sections_next exit: T#%d returning %u\n", gtid, (unsigned)lb));
1371  return (unsigned)lb;
1372 }
1373 
1374 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(
1375  void (*task)(void *), void *data, unsigned num_threads, unsigned count) {
1376  int gtid = __kmp_entry_gtid();
1377 
1378 #if OMPT_SUPPORT
1379  ompt_frame_t *parent_frame;
1380 
1381  if (ompt_enabled.enabled) {
1382  __ompt_get_task_info_internal(0, NULL, NULL, &parent_frame, NULL, NULL);
1383  parent_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1384  }
1385  OMPT_STORE_RETURN_ADDRESS(gtid);
1386 #endif
1387 
1388  MKLOC(loc, "GOMP_parallel_sections_start");
1389  KA_TRACE(20, ("GOMP_parallel_sections_start: T#%d\n", gtid));
1390 
1391  __kmp_GOMP_fork_call(&loc, gtid, num_threads, 0u, task,
1392  (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1393  task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1394  (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1395 
1396 #if OMPT_SUPPORT
1397  if (ompt_enabled.enabled) {
1398  parent_frame->enter_frame = ompt_data_none;
1399  }
1400 #endif
1401 
1402  KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1403 
1404  KA_TRACE(20, ("GOMP_parallel_sections_start exit: T#%d\n", gtid));
1405 }
1406 
1407 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END)(void) {
1408  int gtid = __kmp_get_gtid();
1409  KA_TRACE(20, ("GOMP_sections_end: T#%d\n", gtid))
1410 
1411 #if OMPT_SUPPORT
1412  ompt_frame_t *ompt_frame;
1413  if (ompt_enabled.enabled) {
1414  __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
1415  ompt_frame->enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1416  }
1417  OMPT_STORE_RETURN_ADDRESS(gtid);
1418 #endif
1419  __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1420 #if OMPT_SUPPORT
1421  if (ompt_enabled.enabled) {
1422  ompt_frame->enter_frame = ompt_data_none;
1423  }
1424 #endif
1425 
1426  KA_TRACE(20, ("GOMP_sections_end exit: T#%d\n", gtid))
1427 }
1428 
1429 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT)(void) {
1430  KA_TRACE(20, ("GOMP_sections_end_nowait: T#%d\n", __kmp_get_gtid()))
1431 }
1432 
1433 // libgomp has an empty function for GOMP_taskyield as of 2013-10-10
1434 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKYIELD)(void) {
1435  KA_TRACE(20, ("GOMP_taskyield: T#%d\n", __kmp_get_gtid()))
1436  return;
1437 }
1438 
1439 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL)(void (*task)(void *),
1440  void *data,
1441  unsigned num_threads,
1442  unsigned int flags) {
1443  int gtid = __kmp_entry_gtid();
1444  MKLOC(loc, "GOMP_parallel");
1445  KA_TRACE(20, ("GOMP_parallel: T#%d\n", gtid));
1446 
1447 #if OMPT_SUPPORT
1448  ompt_task_info_t *parent_task_info, *task_info;
1449  if (ompt_enabled.enabled) {
1450  parent_task_info = __ompt_get_task_info_object(0);
1451  parent_task_info->frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1452  }
1453  OMPT_STORE_RETURN_ADDRESS(gtid);
1454 #endif
1455  __kmp_GOMP_fork_call(&loc, gtid, num_threads, flags, task,
1456  (microtask_t)__kmp_GOMP_microtask_wrapper, 2, task,
1457  data);
1458 #if OMPT_SUPPORT
1459  if (ompt_enabled.enabled) {
1460  task_info = __ompt_get_task_info_object(0);
1461  task_info->frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1462  }
1463 #endif
1464  task(data);
1465  {
1466 #if OMPT_SUPPORT
1467  OMPT_STORE_RETURN_ADDRESS(gtid);
1468 #endif
1469  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1470  }
1471 #if OMPT_SUPPORT
1472  if (ompt_enabled.enabled) {
1473  task_info->frame.exit_frame = ompt_data_none;
1474  parent_task_info->frame.enter_frame = ompt_data_none;
1475  }
1476 #endif
1477 }
1478 
1479 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_SECTIONS)(void (*task)(void *),
1480  void *data,
1481  unsigned num_threads,
1482  unsigned count,
1483  unsigned flags) {
1484  int gtid = __kmp_entry_gtid();
1485  MKLOC(loc, "GOMP_parallel_sections");
1486  KA_TRACE(20, ("GOMP_parallel_sections: T#%d\n", gtid));
1487 
1488 #if OMPT_SUPPORT
1489  OMPT_STORE_RETURN_ADDRESS(gtid);
1490 #endif
1491 
1492  __kmp_GOMP_fork_call(&loc, gtid, num_threads, flags, task,
1493  (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, 9,
1494  task, data, num_threads, &loc, kmp_nm_dynamic_chunked,
1495  (kmp_int)1, (kmp_int)count, (kmp_int)1, (kmp_int)1);
1496 
1497  {
1498 #if OMPT_SUPPORT
1499  OMPT_STORE_RETURN_ADDRESS(gtid);
1500 #endif
1501 
1502  KMP_DISPATCH_INIT(&loc, gtid, kmp_nm_dynamic_chunked, 1, count, 1, 1, TRUE);
1503  }
1504  task(data);
1505  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)();
1506  KA_TRACE(20, ("GOMP_parallel_sections exit: T#%d\n", gtid));
1507 }
1508 
1509 #define PARALLEL_LOOP(func, schedule, ompt_pre, ompt_post) \
1510  void func(void (*task)(void *), void *data, unsigned num_threads, long lb, \
1511  long ub, long str, long chunk_sz, unsigned flags) { \
1512  int gtid = __kmp_entry_gtid(); \
1513  MKLOC(loc, KMP_STR(func)); \
1514  KA_TRACE( \
1515  20, \
1516  (KMP_STR( \
1517  func) ": T#%d, lb 0x%lx, ub 0x%lx, str 0x%lx, chunk_sz 0x%lx\n", \
1518  gtid, lb, ub, str, chunk_sz)); \
1519  \
1520  ompt_pre(); \
1521  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
1522  __kmp_GOMP_fork_call(&loc, gtid, num_threads, flags, task, \
1523  (microtask_t)__kmp_GOMP_parallel_microtask_wrapper, \
1524  9, task, data, num_threads, &loc, (schedule), lb, \
1525  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz); \
1526  \
1527  { \
1528  IF_OMPT_SUPPORT(OMPT_STORE_RETURN_ADDRESS(gtid);) \
1529  KMP_DISPATCH_INIT(&loc, gtid, (schedule), lb, \
1530  (str > 0) ? (ub - 1) : (ub + 1), str, chunk_sz, \
1531  (schedule) != kmp_sch_static); \
1532  } \
1533  task(data); \
1534  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(); \
1535  ompt_post(); \
1536  \
1537  KA_TRACE(20, (KMP_STR(func) " exit: T#%d\n", gtid)); \
1538  }
1539 
1540 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC),
1541  kmp_sch_static, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1542 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC),
1543  kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1544 PARALLEL_LOOP(
1545  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_GUIDED),
1546  kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1547 PARALLEL_LOOP(
1548  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_DYNAMIC),
1549  kmp_sch_dynamic_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1550 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED),
1551  kmp_sch_guided_chunked, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1552 PARALLEL_LOOP(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME),
1553  kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1554 PARALLEL_LOOP(
1555  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME),
1556  kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1557 PARALLEL_LOOP(
1558  KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME),
1559  kmp_sch_runtime, OMPT_LOOP_PRE, OMPT_LOOP_POST)
1560 
1561 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_START)(void) {
1562  int gtid = __kmp_entry_gtid();
1563  MKLOC(loc, "GOMP_taskgroup_start");
1564  KA_TRACE(20, ("GOMP_taskgroup_start: T#%d\n", gtid));
1565 
1566 #if OMPT_SUPPORT
1567  OMPT_STORE_RETURN_ADDRESS(gtid);
1568 #endif
1569 
1570  __kmpc_taskgroup(&loc, gtid);
1571 
1572  return;
1573 }
1574 
1575 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_END)(void) {
1576  int gtid = __kmp_get_gtid();
1577  MKLOC(loc, "GOMP_taskgroup_end");
1578  KA_TRACE(20, ("GOMP_taskgroup_end: T#%d\n", gtid));
1579 
1580 #if OMPT_SUPPORT
1581  OMPT_STORE_RETURN_ADDRESS(gtid);
1582 #endif
1583 
1584  __kmpc_end_taskgroup(&loc, gtid);
1585 
1586  return;
1587 }
1588 
1589 static kmp_int32 __kmp_gomp_to_omp_cancellation_kind(int gomp_kind) {
1590  kmp_int32 cncl_kind = 0;
1591  switch (gomp_kind) {
1592  case 1:
1593  cncl_kind = cancel_parallel;
1594  break;
1595  case 2:
1596  cncl_kind = cancel_loop;
1597  break;
1598  case 4:
1599  cncl_kind = cancel_sections;
1600  break;
1601  case 8:
1602  cncl_kind = cancel_taskgroup;
1603  break;
1604  }
1605  return cncl_kind;
1606 }
1607 
1608 // Return true if cancellation should take place, false otherwise
1609 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCELLATION_POINT)(int which) {
1610  int gtid = __kmp_get_gtid();
1611  MKLOC(loc, "GOMP_cancellation_point");
1612  KA_TRACE(20, ("GOMP_cancellation_point: T#%d which:%d\n", gtid, which));
1613  kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1614  return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1615 }
1616 
1617 // Return true if cancellation should take place, false otherwise
1618 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_CANCEL)(int which, bool do_cancel) {
1619  int gtid = __kmp_get_gtid();
1620  MKLOC(loc, "GOMP_cancel");
1621  KA_TRACE(20, ("GOMP_cancel: T#%d which:%d do_cancel:%d\n", gtid, which,
1622  (int)do_cancel));
1623  kmp_int32 cncl_kind = __kmp_gomp_to_omp_cancellation_kind(which);
1624 
1625  if (do_cancel == FALSE) {
1626  return __kmpc_cancellationpoint(&loc, gtid, cncl_kind);
1627  } else {
1628  return __kmpc_cancel(&loc, gtid, cncl_kind);
1629  }
1630 }
1631 
1632 // Return true if cancellation should take place, false otherwise
1633 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_BARRIER_CANCEL)(void) {
1634  int gtid = __kmp_get_gtid();
1635  KA_TRACE(20, ("GOMP_barrier_cancel: T#%d\n", gtid));
1636  return __kmp_barrier_gomp_cancel(gtid);
1637 }
1638 
1639 // Return true if cancellation should take place, false otherwise
1640 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL)(void) {
1641  int gtid = __kmp_get_gtid();
1642  KA_TRACE(20, ("GOMP_sections_end_cancel: T#%d\n", gtid));
1643  return __kmp_barrier_gomp_cancel(gtid);
1644 }
1645 
1646 // Return true if cancellation should take place, false otherwise
1647 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_END_CANCEL)(void) {
1648  int gtid = __kmp_get_gtid();
1649  KA_TRACE(20, ("GOMP_loop_end_cancel: T#%d\n", gtid));
1650  return __kmp_barrier_gomp_cancel(gtid);
1651 }
1652 
1653 // All target functions are empty as of 2014-05-29
1654 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET)(int device, void (*fn)(void *),
1655  const void *openmp_target,
1656  size_t mapnum, void **hostaddrs,
1657  size_t *sizes,
1658  unsigned char *kinds) {
1659  return;
1660 }
1661 
1662 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_DATA)(
1663  int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1664  size_t *sizes, unsigned char *kinds) {
1665  return;
1666 }
1667 
1668 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_END_DATA)(void) { return; }
1669 
1670 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TARGET_UPDATE)(
1671  int device, const void *openmp_target, size_t mapnum, void **hostaddrs,
1672  size_t *sizes, unsigned char *kinds) {
1673  return;
1674 }
1675 
1676 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS)(unsigned int num_teams,
1677  unsigned int thread_limit) {
1678  return;
1679 }
1680 
1681 // Task duplication function which copies src to dest (both are
1682 // preallocated task structures)
1683 static void __kmp_gomp_task_dup(kmp_task_t *dest, kmp_task_t *src,
1684  kmp_int32 last_private) {
1685  kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(src);
1686  if (taskdata->td_copy_func) {
1687  (taskdata->td_copy_func)(dest->shareds, src->shareds);
1688  }
1689 }
1690 
1691 #ifdef __cplusplus
1692 } // extern "C"
1693 #endif
1694 
1695 template <typename T>
1696 void __GOMP_taskloop(void (*func)(void *), void *data,
1697  void (*copy_func)(void *, void *), long arg_size,
1698  long arg_align, unsigned gomp_flags,
1699  unsigned long num_tasks, int priority, T start, T end,
1700  T step) {
1701  typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
1702  MKLOC(loc, "GOMP_taskloop");
1703  int sched;
1704  T *loop_bounds;
1705  int gtid = __kmp_entry_gtid();
1706  kmp_int32 flags = 0;
1707  int if_val = gomp_flags & (1u << 10);
1708  int nogroup = gomp_flags & (1u << 11);
1709  int up = gomp_flags & (1u << 8);
1710  p_task_dup_t task_dup = NULL;
1711  kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1712 #ifdef KMP_DEBUG
1713  {
1714  char *buff;
1715  buff = __kmp_str_format(
1716  "GOMP_taskloop: T#%%d: func:%%p data:%%p copy_func:%%p "
1717  "arg_size:%%ld arg_align:%%ld gomp_flags:0x%%x num_tasks:%%lu "
1718  "priority:%%d start:%%%s end:%%%s step:%%%s\n",
1719  traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec);
1720  KA_TRACE(20, (buff, gtid, func, data, copy_func, arg_size, arg_align,
1721  gomp_flags, num_tasks, priority, start, end, step));
1722  __kmp_str_free(&buff);
1723  }
1724 #endif
1725  KMP_ASSERT((size_t)arg_size >= 2 * sizeof(T));
1726  KMP_ASSERT(arg_align > 0);
1727  // The low-order bit is the "untied" flag
1728  if (!(gomp_flags & 1)) {
1729  input_flags->tiedness = 1;
1730  }
1731  // The second low-order bit is the "final" flag
1732  if (gomp_flags & 2) {
1733  input_flags->final = 1;
1734  }
1735  // Negative step flag
1736  if (!up) {
1737  // If step is flagged as negative, but isn't properly sign extended
1738  // Then manually sign extend it. Could be a short, int, char embedded
1739  // in a long. So cannot assume any cast.
1740  if (step > 0) {
1741  for (int i = sizeof(T) * CHAR_BIT - 1; i >= 0L; --i) {
1742  // break at the first 1 bit
1743  if (step & ((T)1 << i))
1744  break;
1745  step |= ((T)1 << i);
1746  }
1747  }
1748  }
1749  input_flags->native = 1;
1750  // Figure out if none/grainsize/num_tasks clause specified
1751  if (num_tasks > 0) {
1752  if (gomp_flags & (1u << 9))
1753  sched = 1; // grainsize specified
1754  else
1755  sched = 2; // num_tasks specified
1756  // neither grainsize nor num_tasks specified
1757  } else {
1758  sched = 0;
1759  }
1760 
1761  // __kmp_task_alloc() sets up all other flags
1762  kmp_task_t *task =
1763  __kmp_task_alloc(&loc, gtid, input_flags, sizeof(kmp_task_t),
1764  arg_size + arg_align - 1, (kmp_routine_entry_t)func);
1765  kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
1766  taskdata->td_copy_func = copy_func;
1767  taskdata->td_size_loop_bounds = sizeof(T);
1768 
1769  // re-align shareds if needed and setup firstprivate copy constructors
1770  // through the task_dup mechanism
1771  task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) /
1772  arg_align * arg_align);
1773  if (copy_func) {
1774  task_dup = __kmp_gomp_task_dup;
1775  }
1776  KMP_MEMCPY(task->shareds, data, arg_size);
1777 
1778  loop_bounds = (T *)task->shareds;
1779  loop_bounds[0] = start;
1780  loop_bounds[1] = end + (up ? -1 : 1);
1781  __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
1782  (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, nogroup,
1783  sched, (kmp_uint64)num_tasks, (void *)task_dup);
1784 }
1785 
1786 // 4 byte version of GOMP_doacross_post
1787 // This verison needs to create a temporary array which converts 4 byte
1788 // integers into 8 byte integers
1789 template <typename T, bool need_conversion = (sizeof(long) == 4)>
1790 void __kmp_GOMP_doacross_post(T *count);
1791 
1792 template <> void __kmp_GOMP_doacross_post<long, true>(long *count) {
1793  int gtid = __kmp_entry_gtid();
1794  kmp_info_t *th = __kmp_threads[gtid];
1795  MKLOC(loc, "GOMP_doacross_post");
1796  kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1797  kmp_int64 *vec = (kmp_int64 *)__kmp_thread_malloc(
1798  th, (size_t)(sizeof(kmp_int64) * num_dims));
1799  for (kmp_int64 i = 0; i < num_dims; ++i) {
1800  vec[i] = (kmp_int64)count[i];
1801  }
1802  __kmpc_doacross_post(&loc, gtid, vec);
1803  __kmp_thread_free(th, vec);
1804 }
1805 
1806 // 8 byte versions of GOMP_doacross_post
1807 // This version can just pass in the count array directly instead of creating
1808 // a temporary array
1809 template <> void __kmp_GOMP_doacross_post<long, false>(long *count) {
1810  int gtid = __kmp_entry_gtid();
1811  MKLOC(loc, "GOMP_doacross_post");
1812  __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1813 }
1814 
1815 template <typename T> void __kmp_GOMP_doacross_wait(T first, va_list args) {
1816  int gtid = __kmp_entry_gtid();
1817  kmp_info_t *th = __kmp_threads[gtid];
1818  MKLOC(loc, "GOMP_doacross_wait");
1819  kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0];
1820  kmp_int64 *vec = (kmp_int64 *)__kmp_thread_malloc(
1821  th, (size_t)(sizeof(kmp_int64) * num_dims));
1822  vec[0] = (kmp_int64)first;
1823  for (kmp_int64 i = 1; i < num_dims; ++i) {
1824  T item = va_arg(args, T);
1825  vec[i] = (kmp_int64)item;
1826  }
1827  __kmpc_doacross_wait(&loc, gtid, vec);
1828  __kmp_thread_free(th, vec);
1829  return;
1830 }
1831 
1832 #ifdef __cplusplus
1833 extern "C" {
1834 #endif // __cplusplus
1835 
1836 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP)(
1837  void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1838  long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1839  int priority, long start, long end, long step) {
1840  __GOMP_taskloop<long>(func, data, copy_func, arg_size, arg_align, gomp_flags,
1841  num_tasks, priority, start, end, step);
1842 }
1843 
1844 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP_ULL)(
1845  void (*func)(void *), void *data, void (*copy_func)(void *, void *),
1846  long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks,
1847  int priority, unsigned long long start, unsigned long long end,
1848  unsigned long long step) {
1849  __GOMP_taskloop<unsigned long long>(func, data, copy_func, arg_size,
1850  arg_align, gomp_flags, num_tasks,
1851  priority, start, end, step);
1852 }
1853 
1854 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_POST)(long *count) {
1855  __kmp_GOMP_doacross_post(count);
1856 }
1857 
1858 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_WAIT)(long first, ...) {
1859  va_list args;
1860  va_start(args, first);
1861  __kmp_GOMP_doacross_wait<long>(first, args);
1862  va_end(args);
1863 }
1864 
1865 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_POST)(
1866  unsigned long long *count) {
1867  int gtid = __kmp_entry_gtid();
1868  MKLOC(loc, "GOMP_doacross_ull_post");
1869  __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count));
1870 }
1871 
1872 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT)(
1873  unsigned long long first, ...) {
1874  va_list args;
1875  va_start(args, first);
1876  __kmp_GOMP_doacross_wait<unsigned long long>(first, args);
1877  va_end(args);
1878 }
1879 
1880 // fn: the function each primary thread of new team will call
1881 // data: argument to fn
1882 // num_teams, thread_limit: max bounds on respective ICV
1883 // flags: unused
1884 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS_REG)(void (*fn)(void *),
1885  void *data,
1886  unsigned num_teams,
1887  unsigned thread_limit,
1888  unsigned flags) {
1889  MKLOC(loc, "GOMP_teams_reg");
1890  int gtid = __kmp_entry_gtid();
1891  KA_TRACE(20, ("GOMP_teams_reg: T#%d num_teams=%u thread_limit=%u flag=%u\n",
1892  gtid, num_teams, thread_limit, flags));
1893  __kmpc_push_num_teams(&loc, gtid, num_teams, thread_limit);
1894  __kmpc_fork_teams(&loc, 2, (microtask_t)__kmp_GOMP_microtask_wrapper, fn,
1895  data);
1896  KA_TRACE(20, ("GOMP_teams_reg exit: T#%d\n", gtid));
1897 }
1898 
1899 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT_DEPEND)(void **depend) {
1900  MKLOC(loc, "GOMP_taskwait_depend");
1901  int gtid = __kmp_entry_gtid();
1902  KA_TRACE(20, ("GOMP_taskwait_depend: T#%d\n", gtid));
1903  kmp_gomp_depends_info_t gomp_depends(depend);
1904  kmp_int32 ndeps = gomp_depends.get_num_deps();
1905  kmp_depend_info_t dep_list[ndeps];
1906  for (kmp_int32 i = 0; i < ndeps; i++)
1907  dep_list[i] = gomp_depends.get_kmp_depend(i);
1908 #if OMPT_SUPPORT
1909  OMPT_STORE_RETURN_ADDRESS(gtid);
1910 #endif
1911  __kmpc_omp_wait_deps(&loc, gtid, ndeps, dep_list, 0, NULL);
1912  KA_TRACE(20, ("GOMP_taskwait_depend exit: T#%d\n", gtid));
1913 }
1914 
1915 /* The following sections of code create aliases for the GOMP_* functions, then
1916  create versioned symbols using the assembler directive .symver. This is only
1917  pertinent for ELF .so library. The KMP_VERSION_SYMBOL macro is defined in
1918  kmp_os.h */
1919 
1920 #ifdef KMP_USE_VERSION_SYMBOLS
1921 // GOMP_1.0 versioned symbols
1922 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0");
1923 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0");
1924 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0");
1925 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0");
1926 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0");
1927 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0");
1928 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0");
1929 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0");
1930 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0");
1931 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0");
1932 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0");
1933 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0");
1934 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0");
1935 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0");
1936 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10,
1937  "GOMP_1.0");
1938 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0");
1939 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0");
1940 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0");
1941 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10,
1942  "GOMP_1.0");
1943 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0");
1944 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0");
1945 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0");
1946 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0");
1947 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0");
1948 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0");
1949 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0");
1950 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0");
1951 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0");
1952 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10,
1953  "GOMP_1.0");
1954 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10,
1955  "GOMP_1.0");
1956 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10,
1957  "GOMP_1.0");
1958 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10,
1959  "GOMP_1.0");
1960 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0");
1961 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0");
1962 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0");
1963 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0");
1964 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0");
1965 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0");
1966 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0");
1967 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0");
1968 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0");
1969 
1970 // GOMP_2.0 versioned symbols
1971 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0");
1972 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0");
1973 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0");
1974 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0");
1975 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0");
1976 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0");
1977 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20,
1978  "GOMP_2.0");
1979 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20,
1980  "GOMP_2.0");
1981 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20,
1982  "GOMP_2.0");
1983 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20,
1984  "GOMP_2.0");
1985 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20,
1986  "GOMP_2.0");
1987 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20,
1988  "GOMP_2.0");
1989 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20,
1990  "GOMP_2.0");
1991 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20,
1992  "GOMP_2.0");
1993 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0");
1994 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0");
1995 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0");
1996 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0");
1997 
1998 // GOMP_3.0 versioned symbols
1999 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0");
2000 
2001 // GOMP_4.0 versioned symbols
2002 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0");
2003 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0");
2004 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0");
2005 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0");
2006 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0");
2007 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0");
2008 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0");
2009 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0");
2010 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0");
2011 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0");
2012 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0");
2013 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0");
2014 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0");
2015 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0");
2016 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0");
2017 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0");
2018 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0");
2019 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0");
2020 
2021 // GOMP_4.5 versioned symbols
2022 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP, 45, "GOMP_4.5");
2023 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP_ULL, 45, "GOMP_4.5");
2024 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_POST, 45, "GOMP_4.5");
2025 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_WAIT, 45, "GOMP_4.5");
2026 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START, 45,
2027  "GOMP_4.5");
2028 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START, 45,
2029  "GOMP_4.5");
2030 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START, 45,
2031  "GOMP_4.5");
2032 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START, 45,
2033  "GOMP_4.5");
2034 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_POST, 45, "GOMP_4.5");
2035 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT, 45, "GOMP_4.5");
2036 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START, 45,
2037  "GOMP_4.5");
2038 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START, 45,
2039  "GOMP_4.5");
2040 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START, 45,
2041  "GOMP_4.5");
2042 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, 45,
2043  "GOMP_4.5");
2044 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_START, 45,
2045  "GOMP_4.5");
2046 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_NEXT, 45,
2047  "GOMP_4.5");
2048 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_START, 45,
2049  "GOMP_4.5");
2050 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_NEXT, 45,
2051  "GOMP_4.5");
2052 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_START, 45,
2053  "GOMP_4.5");
2054 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_NEXT, 45,
2055  "GOMP_4.5");
2056 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START, 45,
2057  "GOMP_4.5");
2058 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_NEXT, 45,
2059  "GOMP_4.5");
2060 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_DYNAMIC, 45,
2061  "GOMP_4.5");
2062 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_GUIDED, 45,
2063  "GOMP_4.5");
2064 
2065 // GOMP_5.0 versioned symbols
2066 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT, 50,
2067  "GOMP_5.0");
2068 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START, 50,
2069  "GOMP_5.0");
2070 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT, 50,
2071  "GOMP_5.0");
2072 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_START, 50,
2073  "GOMP_5.0");
2074 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT,
2075  50, "GOMP_5.0");
2076 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START,
2077  50, "GOMP_5.0");
2078 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT, 50,
2079  "GOMP_5.0");
2080 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START, 50,
2081  "GOMP_5.0");
2082 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME, 50,
2083  "GOMP_5.0");
2084 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME,
2085  50, "GOMP_5.0");
2086 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS_REG, 50, "GOMP_5.0");
2087 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT_DEPEND, 50, "GOMP_5.0");
2088 
2089 #endif // KMP_USE_VERSION_SYMBOLS
2090 
2091 #ifdef __cplusplus
2092 } // extern "C"
2093 #endif // __cplusplus
KMP_EXPORT void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list)
void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int nogroup, int sched, kmp_uint64 grainsize, void *task_dup)
KMP_EXPORT void __kmpc_end_ordered(ident_t *, kmp_int32 global_tid)
void __kmpc_doacross_init(ident_t *loc, int gtid, int num_dims, const struct kmp_dim *dims)
KMP_EXPORT kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list)
KMP_EXPORT void __kmpc_ordered(ident_t *, kmp_int32 global_tid)
sched_type
Definition: kmp.h:351
KMP_EXPORT void __kmpc_critical(ident_t *, kmp_int32 global_tid, kmp_critical_name *)
Definition: kmp.h:229
KMP_EXPORT void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,...)
KMP_EXPORT void __kmpc_barrier(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_end_critical(ident_t *, kmp_int32 global_tid, kmp_critical_name *)
KMP_EXPORT void __kmpc_push_num_teams(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_teams, kmp_int32 num_threads)