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), 682 kmp_sch_guided_chunked) 683 LOOP_START(KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_START), 684 kmp_sch_guided_chunked) 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), 701 kmp_ord_static) 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), 813 kmp_sch_static) 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), 819 kmp_sch_guided_chunked) 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), 954 kmp_sch_static) 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), 960 kmp_sch_guided_chunked) 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), 969 kmp_sch_guided_chunked) 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), 989 kmp_ord_static) 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), 1106 kmp_sch_static) 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), 1112 kmp_sch_guided_chunked) 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 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_REGISTER)( 1692 uintptr_t *); 1693 1694 #ifdef __cplusplus 1695 } // extern "C" 1696 #endif 1697 1698 template <typename T> 1699 void __GOMP_taskloop(void (*func)(void *), void *data, 1700 void (*copy_func)(void *, void *), long arg_size, 1701 long arg_align, unsigned gomp_flags, 1702 unsigned long num_tasks, int priority, T start, T end, 1703 T step) { 1704 typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32); 1705 MKLOC(loc, "GOMP_taskloop"); 1706 int sched; 1707 T *loop_bounds; 1708 int gtid = __kmp_entry_gtid(); 1709 kmp_int32 flags = 0; 1710 int if_val = gomp_flags & (1u << 10); 1711 int nogroup = gomp_flags & (1u << 11); 1712 int up = gomp_flags & (1u << 8); 1713 int reductions = gomp_flags & (1u << 12); 1714 p_task_dup_t task_dup = NULL; 1715 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags; 1716 #ifdef KMP_DEBUG 1717 { 1718 char *buff; 1719 buff = __kmp_str_format( 1720 "GOMP_taskloop: T#%%d: func:%%p data:%%p copy_func:%%p " 1721 "arg_size:%%ld arg_align:%%ld gomp_flags:0x%%x num_tasks:%%lu " 1722 "priority:%%d start:%%%s end:%%%s step:%%%s\n", 1723 traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec); 1724 KA_TRACE(20, (buff, gtid, func, data, copy_func, arg_size, arg_align, 1725 gomp_flags, num_tasks, priority, start, end, step)); 1726 __kmp_str_free(&buff); 1727 } 1728 #endif 1729 KMP_ASSERT((size_t)arg_size >= 2 * sizeof(T)); 1730 KMP_ASSERT(arg_align > 0); 1731 // The low-order bit is the "untied" flag 1732 if (!(gomp_flags & 1)) { 1733 input_flags->tiedness = 1; 1734 } 1735 // The second low-order bit is the "final" flag 1736 if (gomp_flags & 2) { 1737 input_flags->final = 1; 1738 } 1739 // Negative step flag 1740 if (!up) { 1741 // If step is flagged as negative, but isn't properly sign extended 1742 // Then manually sign extend it. Could be a short, int, char embedded 1743 // in a long. So cannot assume any cast. 1744 if (step > 0) { 1745 for (int i = sizeof(T) * CHAR_BIT - 1; i >= 0L; --i) { 1746 // break at the first 1 bit 1747 if (step & ((T)1 << i)) 1748 break; 1749 step |= ((T)1 << i); 1750 } 1751 } 1752 } 1753 input_flags->native = 1; 1754 // Figure out if none/grainsize/num_tasks clause specified 1755 if (num_tasks > 0) { 1756 if (gomp_flags & (1u << 9)) 1757 sched = 1; // grainsize specified 1758 else 1759 sched = 2; // num_tasks specified 1760 // neither grainsize nor num_tasks specified 1761 } else { 1762 sched = 0; 1763 } 1764 1765 // __kmp_task_alloc() sets up all other flags 1766 kmp_task_t *task = 1767 __kmp_task_alloc(&loc, gtid, input_flags, sizeof(kmp_task_t), 1768 arg_size + arg_align - 1, (kmp_routine_entry_t)func); 1769 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task); 1770 taskdata->td_copy_func = copy_func; 1771 taskdata->td_size_loop_bounds = sizeof(T); 1772 1773 // re-align shareds if needed and setup firstprivate copy constructors 1774 // through the task_dup mechanism 1775 task->shareds = (void *)((((size_t)task->shareds) + arg_align - 1) / 1776 arg_align * arg_align); 1777 if (copy_func) { 1778 task_dup = __kmp_gomp_task_dup; 1779 } 1780 KMP_MEMCPY(task->shareds, data, arg_size); 1781 1782 loop_bounds = (T *)task->shareds; 1783 loop_bounds[0] = start; 1784 loop_bounds[1] = end + (up ? -1 : 1); 1785 1786 if (!nogroup) { 1787 #if OMPT_SUPPORT && OMPT_OPTIONAL 1788 OMPT_STORE_RETURN_ADDRESS(gtid); 1789 #endif 1790 __kmpc_taskgroup(&loc, gtid); 1791 if (reductions) { 1792 // The data pointer points to lb, ub, then reduction data 1793 struct data_t { 1794 T a, b; 1795 uintptr_t *d; 1796 }; 1797 uintptr_t *d = ((data_t *)data)->d; 1798 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_REGISTER)(d); 1799 } 1800 } 1801 __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]), 1802 (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, 1, sched, 1803 (kmp_uint64)num_tasks, (void *)task_dup); 1804 if (!nogroup) { 1805 #if OMPT_SUPPORT && OMPT_OPTIONAL 1806 OMPT_STORE_RETURN_ADDRESS(gtid); 1807 #endif 1808 __kmpc_end_taskgroup(&loc, gtid); 1809 } 1810 } 1811 1812 // 4 byte version of GOMP_doacross_post 1813 // This verison needs to create a temporary array which converts 4 byte 1814 // integers into 8 byte integers 1815 template <typename T, bool need_conversion = (sizeof(long) == 4)> 1816 void __kmp_GOMP_doacross_post(T *count); 1817 1818 template <> void __kmp_GOMP_doacross_post<long, true>(long *count) { 1819 int gtid = __kmp_entry_gtid(); 1820 kmp_info_t *th = __kmp_threads[gtid]; 1821 MKLOC(loc, "GOMP_doacross_post"); 1822 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0]; 1823 kmp_int64 *vec = (kmp_int64 *)__kmp_thread_malloc( 1824 th, (size_t)(sizeof(kmp_int64) * num_dims)); 1825 for (kmp_int64 i = 0; i < num_dims; ++i) { 1826 vec[i] = (kmp_int64)count[i]; 1827 } 1828 __kmpc_doacross_post(&loc, gtid, vec); 1829 __kmp_thread_free(th, vec); 1830 } 1831 1832 // 8 byte versions of GOMP_doacross_post 1833 // This version can just pass in the count array directly instead of creating 1834 // a temporary array 1835 template <> void __kmp_GOMP_doacross_post<long, false>(long *count) { 1836 int gtid = __kmp_entry_gtid(); 1837 MKLOC(loc, "GOMP_doacross_post"); 1838 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count)); 1839 } 1840 1841 template <typename T> void __kmp_GOMP_doacross_wait(T first, va_list args) { 1842 int gtid = __kmp_entry_gtid(); 1843 kmp_info_t *th = __kmp_threads[gtid]; 1844 MKLOC(loc, "GOMP_doacross_wait"); 1845 kmp_int64 num_dims = th->th.th_dispatch->th_doacross_info[0]; 1846 kmp_int64 *vec = (kmp_int64 *)__kmp_thread_malloc( 1847 th, (size_t)(sizeof(kmp_int64) * num_dims)); 1848 vec[0] = (kmp_int64)first; 1849 for (kmp_int64 i = 1; i < num_dims; ++i) { 1850 T item = va_arg(args, T); 1851 vec[i] = (kmp_int64)item; 1852 } 1853 __kmpc_doacross_wait(&loc, gtid, vec); 1854 __kmp_thread_free(th, vec); 1855 return; 1856 } 1857 1858 #ifdef __cplusplus 1859 extern "C" { 1860 #endif // __cplusplus 1861 1862 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP)( 1863 void (*func)(void *), void *data, void (*copy_func)(void *, void *), 1864 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks, 1865 int priority, long start, long end, long step) { 1866 __GOMP_taskloop<long>(func, data, copy_func, arg_size, arg_align, gomp_flags, 1867 num_tasks, priority, start, end, step); 1868 } 1869 1870 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKLOOP_ULL)( 1871 void (*func)(void *), void *data, void (*copy_func)(void *, void *), 1872 long arg_size, long arg_align, unsigned gomp_flags, unsigned long num_tasks, 1873 int priority, unsigned long long start, unsigned long long end, 1874 unsigned long long step) { 1875 __GOMP_taskloop<unsigned long long>(func, data, copy_func, arg_size, 1876 arg_align, gomp_flags, num_tasks, 1877 priority, start, end, step); 1878 } 1879 1880 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_POST)(long *count) { 1881 __kmp_GOMP_doacross_post(count); 1882 } 1883 1884 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_WAIT)(long first, ...) { 1885 va_list args; 1886 va_start(args, first); 1887 __kmp_GOMP_doacross_wait<long>(first, args); 1888 va_end(args); 1889 } 1890 1891 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_POST)( 1892 unsigned long long *count) { 1893 int gtid = __kmp_entry_gtid(); 1894 MKLOC(loc, "GOMP_doacross_ull_post"); 1895 __kmpc_doacross_post(&loc, gtid, RCAST(kmp_int64 *, count)); 1896 } 1897 1898 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT)( 1899 unsigned long long first, ...) { 1900 va_list args; 1901 va_start(args, first); 1902 __kmp_GOMP_doacross_wait<unsigned long long>(first, args); 1903 va_end(args); 1904 } 1905 1906 // fn: the function each primary thread of new team will call 1907 // data: argument to fn 1908 // num_teams, thread_limit: max bounds on respective ICV 1909 // flags: unused 1910 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TEAMS_REG)(void (*fn)(void *), 1911 void *data, 1912 unsigned num_teams, 1913 unsigned thread_limit, 1914 unsigned flags) { 1915 MKLOC(loc, "GOMP_teams_reg"); 1916 int gtid = __kmp_entry_gtid(); 1917 KA_TRACE(20, ("GOMP_teams_reg: T#%d num_teams=%u thread_limit=%u flag=%u\n", 1918 gtid, num_teams, thread_limit, flags)); 1919 __kmpc_push_num_teams(&loc, gtid, num_teams, thread_limit); 1920 __kmpc_fork_teams(&loc, 2, (microtask_t)__kmp_GOMP_microtask_wrapper, fn, 1921 data); 1922 KA_TRACE(20, ("GOMP_teams_reg exit: T#%d\n", gtid)); 1923 } 1924 1925 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKWAIT_DEPEND)(void **depend) { 1926 MKLOC(loc, "GOMP_taskwait_depend"); 1927 int gtid = __kmp_entry_gtid(); 1928 KA_TRACE(20, ("GOMP_taskwait_depend: T#%d\n", gtid)); 1929 kmp_gomp_depends_info_t gomp_depends(depend); 1930 kmp_int32 ndeps = gomp_depends.get_num_deps(); 1931 kmp_depend_info_t dep_list[ndeps]; 1932 for (kmp_int32 i = 0; i < ndeps; i++) 1933 dep_list[i] = gomp_depends.get_kmp_depend(i); 1934 #if OMPT_SUPPORT 1935 OMPT_STORE_RETURN_ADDRESS(gtid); 1936 #endif 1937 __kmpc_omp_wait_deps(&loc, gtid, ndeps, dep_list, 0, NULL); 1938 KA_TRACE(20, ("GOMP_taskwait_depend exit: T#%d\n", gtid)); 1939 } 1940 1941 static inline void 1942 __kmp_GOMP_taskgroup_reduction_register(uintptr_t *data, kmp_taskgroup_t *tg, 1943 int nthreads, 1944 uintptr_t *allocated = nullptr) { 1945 KMP_ASSERT(data); 1946 KMP_ASSERT(nthreads > 0); 1947 // Have private copy pointers point to previously allocated 1948 // reduction data or allocate new data here 1949 if (allocated) { 1950 data[2] = allocated[2]; 1951 data[6] = allocated[6]; 1952 } else { 1953 data[2] = (uintptr_t)__kmp_allocate(nthreads * data[1]); 1954 data[6] = data[2] + (nthreads * data[1]); 1955 } 1956 if (tg) 1957 tg->gomp_data = data; 1958 } 1959 1960 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_REGISTER)( 1961 uintptr_t *data) { 1962 int gtid = __kmp_entry_gtid(); 1963 KA_TRACE(20, ("GOMP_taskgroup_reduction_register: T#%d\n", gtid)); 1964 kmp_info_t *thread = __kmp_threads[gtid]; 1965 kmp_taskgroup_t *tg = thread->th.th_current_task->td_taskgroup; 1966 int nthreads = thread->th.th_team_nproc; 1967 __kmp_GOMP_taskgroup_reduction_register(data, tg, nthreads); 1968 } 1969 1970 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_UNREGISTER)( 1971 uintptr_t *data) { 1972 KA_TRACE(20, 1973 ("GOMP_taskgroup_reduction_unregister: T#%d\n", __kmp_get_gtid())); 1974 KMP_ASSERT(data && data[2]); 1975 __kmp_free((void *)data[2]); 1976 } 1977 1978 // Search through reduction data and set ptrs[] elements 1979 // to proper privatized copy address 1980 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASK_REDUCTION_REMAP)(size_t cnt, 1981 size_t cntorig, 1982 void **ptrs) { 1983 int gtid = __kmp_entry_gtid(); 1984 KA_TRACE(20, ("GOMP_task_reduction_remap: T#%d\n", gtid)); 1985 kmp_info_t *thread = __kmp_threads[gtid]; 1986 kmp_int32 tid = __kmp_get_tid(); 1987 for (size_t i = 0; i < cnt; ++i) { 1988 uintptr_t address = (uintptr_t)ptrs[i]; 1989 void *propagated_address = NULL; 1990 void *mapped_address = NULL; 1991 // Check taskgroups reduce data 1992 kmp_taskgroup_t *tg = thread->th.th_current_task->td_taskgroup; 1993 while (tg) { 1994 uintptr_t *gomp_data = tg->gomp_data; 1995 if (!gomp_data) { 1996 tg = tg->parent; 1997 continue; 1998 } 1999 // Check the shared addresses list 2000 size_t num_vars = (size_t)gomp_data[0]; 2001 uintptr_t per_thread_size = gomp_data[1]; 2002 uintptr_t reduce_data = gomp_data[2]; 2003 uintptr_t end_reduce_data = gomp_data[6]; 2004 for (size_t j = 0; j < num_vars; ++j) { 2005 uintptr_t *entry = gomp_data + 7 + 3 * j; 2006 if (entry[0] == address) { 2007 uintptr_t offset = entry[1]; 2008 mapped_address = 2009 (void *)(reduce_data + tid * per_thread_size + offset); 2010 if (i < cntorig) 2011 propagated_address = (void *)entry[0]; 2012 break; 2013 } 2014 } 2015 if (mapped_address) 2016 break; 2017 // Check if address is within privatized copies range 2018 if (!mapped_address && address >= reduce_data && 2019 address < end_reduce_data) { 2020 uintptr_t offset = (address - reduce_data) % per_thread_size; 2021 mapped_address = (void *)(reduce_data + tid * per_thread_size + offset); 2022 if (i < cntorig) { 2023 for (size_t j = 0; j < num_vars; ++j) { 2024 uintptr_t *entry = gomp_data + 7 + 3 * j; 2025 if (entry[1] == offset) { 2026 propagated_address = (void *)entry[0]; 2027 break; 2028 } 2029 } 2030 } 2031 } 2032 if (mapped_address) 2033 break; 2034 tg = tg->parent; 2035 } 2036 KMP_ASSERT(mapped_address); 2037 ptrs[i] = mapped_address; 2038 if (i < cntorig) { 2039 KMP_ASSERT(propagated_address); 2040 ptrs[cnt + i] = propagated_address; 2041 } 2042 } 2043 } 2044 2045 static void __kmp_GOMP_init_reductions(int gtid, uintptr_t *data, int is_ws) { 2046 kmp_info_t *thr = __kmp_threads[gtid]; 2047 kmp_team_t *team = thr->th.th_team; 2048 // First start a taskgroup 2049 __kmpc_taskgroup(NULL, gtid); 2050 // Then setup reduction data 2051 void *reduce_data = KMP_ATOMIC_LD_RLX(&team->t.t_tg_reduce_data[is_ws]); 2052 if (reduce_data == NULL && 2053 __kmp_atomic_compare_store(&team->t.t_tg_reduce_data[is_ws], reduce_data, 2054 (void *)1)) { 2055 // Single thread enters this block to initialize common reduction data 2056 KMP_DEBUG_ASSERT(reduce_data == NULL); 2057 __kmp_GOMP_taskgroup_reduction_register(data, NULL, thr->th.th_team_nproc); 2058 KMP_ATOMIC_ST_REL(&team->t.t_tg_fini_counter[is_ws], 0); 2059 KMP_ATOMIC_ST_REL(&team->t.t_tg_reduce_data[is_ws], (void *)data); 2060 } else { 2061 // Wait for task reduction initialization 2062 while ((reduce_data = KMP_ATOMIC_LD_ACQ( 2063 &team->t.t_tg_reduce_data[is_ws])) == (void *)1) { 2064 KMP_CPU_PAUSE(); 2065 } 2066 KMP_DEBUG_ASSERT(reduce_data > (void *)1); // should be valid pointer here 2067 } 2068 // For worksharing constructs, each thread has its own reduction structure. 2069 // Have each reduction structure point to same privatized copies of vars. 2070 // For parallel, each thread points to same reduction structure and privatized 2071 // copies of vars 2072 if (is_ws) { 2073 __kmp_GOMP_taskgroup_reduction_register( 2074 data, NULL, thr->th.th_team_nproc, 2075 (uintptr_t *)KMP_ATOMIC_LD_ACQ(&team->t.t_tg_reduce_data[is_ws])); 2076 } 2077 kmp_taskgroup_t *tg = thr->th.th_current_task->td_taskgroup; 2078 tg->gomp_data = data; 2079 } 2080 2081 static unsigned 2082 __kmp_GOMP_par_reductions_microtask_wrapper(int *gtid, int *npr, 2083 void (*task)(void *), void *data) { 2084 kmp_info_t *thr = __kmp_threads[*gtid]; 2085 kmp_team_t *team = thr->th.th_team; 2086 uintptr_t *reduce_data = *(uintptr_t **)data; 2087 __kmp_GOMP_init_reductions(*gtid, reduce_data, 0); 2088 2089 #if OMPT_SUPPORT 2090 ompt_frame_t *ompt_frame; 2091 ompt_state_t enclosing_state; 2092 2093 if (ompt_enabled.enabled) { 2094 // save enclosing task state; set current state for task 2095 enclosing_state = thr->th.ompt_thread_info.state; 2096 thr->th.ompt_thread_info.state = ompt_state_work_parallel; 2097 2098 // set task frame 2099 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL); 2100 ompt_frame->exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0); 2101 } 2102 #endif 2103 2104 task(data); 2105 2106 #if OMPT_SUPPORT 2107 if (ompt_enabled.enabled) { 2108 // clear task frame 2109 ompt_frame->exit_frame = ompt_data_none; 2110 2111 // restore enclosing state 2112 thr->th.ompt_thread_info.state = enclosing_state; 2113 } 2114 #endif 2115 __kmpc_end_taskgroup(NULL, *gtid); 2116 // if last thread out, then reset the team's reduce data 2117 // the GOMP_taskgroup_reduction_unregister() function will deallocate 2118 // private copies after reduction calculations take place. 2119 int count = KMP_ATOMIC_INC(&team->t.t_tg_fini_counter[0]); 2120 if (count == thr->th.th_team_nproc - 1) { 2121 KMP_ATOMIC_ST_REL(&team->t.t_tg_reduce_data[0], NULL); 2122 KMP_ATOMIC_ST_REL(&team->t.t_tg_fini_counter[0], 0); 2123 } 2124 return (unsigned)thr->th.th_team_nproc; 2125 } 2126 2127 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_REDUCTIONS)( 2128 void (*task)(void *), void *data, unsigned num_threads, 2129 unsigned int flags) { 2130 MKLOC(loc, "GOMP_parallel_reductions"); 2131 int gtid = __kmp_entry_gtid(); 2132 KA_TRACE(20, ("GOMP_parallel_reductions: T#%d\n", gtid)); 2133 __kmp_GOMP_fork_call(&loc, gtid, num_threads, flags, task, 2134 (microtask_t)__kmp_GOMP_par_reductions_microtask_wrapper, 2135 2, task, data); 2136 unsigned retval = 2137 __kmp_GOMP_par_reductions_microtask_wrapper(>id, NULL, task, data); 2138 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_PARALLEL_END)(); 2139 KA_TRACE(20, ("GOMP_parallel_reductions exit: T#%d\n", gtid)); 2140 return retval; 2141 } 2142 2143 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_START)( 2144 long start, long end, long incr, long sched, long chunk_size, long *istart, 2145 long *iend, uintptr_t *reductions, void **mem) { 2146 int status = 0; 2147 int gtid = __kmp_entry_gtid(); 2148 KA_TRACE(20, ("GOMP_loop_start: T#%d, reductions: %p\n", gtid, reductions)); 2149 if (reductions) 2150 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2151 if (mem) 2152 KMP_FATAL(GompFeatureNotSupported, "scan"); 2153 if (istart == NULL) 2154 return true; 2155 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2156 long monotonic = sched & MONOTONIC_FLAG; 2157 sched &= ~MONOTONIC_FLAG; 2158 if (sched == 0) { 2159 if (monotonic) 2160 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_RUNTIME_START)( 2161 start, end, incr, istart, iend); 2162 else 2163 status = KMP_EXPAND_NAME( 2164 KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START)( 2165 start, end, incr, istart, iend); 2166 } else if (sched == 1) { 2167 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_STATIC_START)( 2168 start, end, incr, chunk_size, istart, iend); 2169 } else if (sched == 2) { 2170 if (monotonic) 2171 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START)( 2172 start, end, incr, chunk_size, istart, iend); 2173 else 2174 status = 2175 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_START)( 2176 start, end, incr, chunk_size, istart, iend); 2177 } else if (sched == 3) { 2178 if (monotonic) 2179 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_GUIDED_START)( 2180 start, end, incr, chunk_size, istart, iend); 2181 else 2182 status = 2183 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_START)( 2184 start, end, incr, chunk_size, istart, iend); 2185 } else if (sched == 4) { 2186 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_START)( 2187 start, end, incr, istart, iend); 2188 } else { 2189 KMP_ASSERT(0); 2190 } 2191 return status; 2192 } 2193 2194 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_START)( 2195 bool up, unsigned long long start, unsigned long long end, 2196 unsigned long long incr, long sched, unsigned long long chunk_size, 2197 unsigned long long *istart, unsigned long long *iend, uintptr_t *reductions, 2198 void **mem) { 2199 int status = 0; 2200 int gtid = __kmp_entry_gtid(); 2201 KA_TRACE(20, 2202 ("GOMP_loop_ull_start: T#%d, reductions: %p\n", gtid, reductions)); 2203 if (reductions) 2204 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2205 if (mem) 2206 KMP_FATAL(GompFeatureNotSupported, "scan"); 2207 if (istart == NULL) 2208 return true; 2209 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2210 long monotonic = sched & MONOTONIC_FLAG; 2211 sched &= ~MONOTONIC_FLAG; 2212 if (sched == 0) { 2213 if (monotonic) 2214 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START)( 2215 up, start, end, incr, istart, iend); 2216 else 2217 status = KMP_EXPAND_NAME( 2218 KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START)( 2219 up, start, end, incr, istart, iend); 2220 } else if (sched == 1) { 2221 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START)( 2222 up, start, end, incr, chunk_size, istart, iend); 2223 } else if (sched == 2) { 2224 if (monotonic) 2225 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START)( 2226 up, start, end, incr, chunk_size, istart, iend); 2227 else 2228 status = KMP_EXPAND_NAME( 2229 KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_START)( 2230 up, start, end, incr, chunk_size, istart, iend); 2231 } else if (sched == 3) { 2232 if (monotonic) 2233 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START)( 2234 up, start, end, incr, chunk_size, istart, iend); 2235 else 2236 status = 2237 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START)( 2238 up, start, end, incr, chunk_size, istart, iend); 2239 } else if (sched == 4) { 2240 status = 2241 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START)( 2242 up, start, end, incr, istart, iend); 2243 } else { 2244 KMP_ASSERT(0); 2245 } 2246 return status; 2247 } 2248 2249 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_START)( 2250 unsigned ncounts, long *counts, long sched, long chunk_size, long *istart, 2251 long *iend, uintptr_t *reductions, void **mem) { 2252 int status = 0; 2253 int gtid = __kmp_entry_gtid(); 2254 KA_TRACE(20, ("GOMP_loop_doacross_start: T#%d, reductions: %p\n", gtid, 2255 reductions)); 2256 if (reductions) 2257 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2258 if (mem) 2259 KMP_FATAL(GompFeatureNotSupported, "scan"); 2260 if (istart == NULL) 2261 return true; 2262 // Ignore any monotonic flag 2263 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2264 sched &= ~MONOTONIC_FLAG; 2265 if (sched == 0) { 2266 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START)( 2267 ncounts, counts, istart, iend); 2268 } else if (sched == 1) { 2269 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START)( 2270 ncounts, counts, chunk_size, istart, iend); 2271 } else if (sched == 2) { 2272 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START)( 2273 ncounts, counts, chunk_size, istart, iend); 2274 } else if (sched == 3) { 2275 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START)( 2276 ncounts, counts, chunk_size, istart, iend); 2277 } else { 2278 KMP_ASSERT(0); 2279 } 2280 return status; 2281 } 2282 2283 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_START)( 2284 unsigned ncounts, unsigned long long *counts, long sched, 2285 unsigned long long chunk_size, unsigned long long *istart, 2286 unsigned long long *iend, uintptr_t *reductions, void **mem) { 2287 int status = 0; 2288 int gtid = __kmp_entry_gtid(); 2289 KA_TRACE(20, ("GOMP_loop_ull_doacross_start: T#%d, reductions: %p\n", gtid, 2290 reductions)); 2291 if (reductions) 2292 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2293 if (mem) 2294 KMP_FATAL(GompFeatureNotSupported, "scan"); 2295 if (istart == NULL) 2296 return true; 2297 // Ignore any monotonic flag 2298 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2299 sched &= ~MONOTONIC_FLAG; 2300 if (sched == 0) { 2301 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START)( 2302 ncounts, counts, istart, iend); 2303 } else if (sched == 1) { 2304 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START)( 2305 ncounts, counts, chunk_size, istart, iend); 2306 } else if (sched == 2) { 2307 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START)( 2308 ncounts, counts, chunk_size, istart, iend); 2309 } else if (sched == 3) { 2310 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START)( 2311 ncounts, counts, chunk_size, istart, iend); 2312 } else { 2313 KMP_ASSERT(0); 2314 } 2315 return status; 2316 } 2317 2318 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_START)( 2319 long start, long end, long incr, long sched, long chunk_size, long *istart, 2320 long *iend, uintptr_t *reductions, void **mem) { 2321 int status = 0; 2322 int gtid = __kmp_entry_gtid(); 2323 KA_TRACE(20, ("GOMP_loop_ordered_start: T#%d, reductions: %p\n", gtid, 2324 reductions)); 2325 if (reductions) 2326 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2327 if (mem) 2328 KMP_FATAL(GompFeatureNotSupported, "scan"); 2329 if (istart == NULL) 2330 return true; 2331 // Ignore any monotonic flag 2332 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2333 sched &= ~MONOTONIC_FLAG; 2334 if (sched == 0) { 2335 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START)( 2336 start, end, incr, istart, iend); 2337 } else if (sched == 1) { 2338 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START)( 2339 start, end, incr, chunk_size, istart, iend); 2340 } else if (sched == 2) { 2341 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START)( 2342 start, end, incr, chunk_size, istart, iend); 2343 } else if (sched == 3) { 2344 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START)( 2345 start, end, incr, chunk_size, istart, iend); 2346 } else { 2347 KMP_ASSERT(0); 2348 } 2349 return status; 2350 } 2351 2352 bool KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_START)( 2353 bool up, unsigned long long start, unsigned long long end, 2354 unsigned long long incr, long sched, unsigned long long chunk_size, 2355 unsigned long long *istart, unsigned long long *iend, uintptr_t *reductions, 2356 void **mem) { 2357 int status = 0; 2358 int gtid = __kmp_entry_gtid(); 2359 KA_TRACE(20, ("GOMP_loop_ull_ordered_start: T#%d, reductions: %p\n", gtid, 2360 reductions)); 2361 if (reductions) 2362 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2363 if (mem) 2364 KMP_FATAL(GompFeatureNotSupported, "scan"); 2365 if (istart == NULL) 2366 return true; 2367 // Ignore any monotonic flag 2368 const long MONOTONIC_FLAG = (long)(kmp_sched_monotonic); 2369 sched &= ~MONOTONIC_FLAG; 2370 if (sched == 0) { 2371 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START)( 2372 up, start, end, incr, istart, iend); 2373 } else if (sched == 1) { 2374 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START)( 2375 up, start, end, incr, chunk_size, istart, iend); 2376 } else if (sched == 2) { 2377 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START)( 2378 up, start, end, incr, chunk_size, istart, iend); 2379 } else if (sched == 3) { 2380 status = KMP_EXPAND_NAME(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START)( 2381 up, start, end, incr, chunk_size, istart, iend); 2382 } else { 2383 KMP_ASSERT(0); 2384 } 2385 return status; 2386 } 2387 2388 unsigned KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS2_START)( 2389 unsigned count, uintptr_t *reductions, void **mem) { 2390 int gtid = __kmp_entry_gtid(); 2391 KA_TRACE(20, 2392 ("GOMP_sections2_start: T#%d, reductions: %p\n", gtid, reductions)); 2393 if (reductions) 2394 __kmp_GOMP_init_reductions(gtid, reductions, 1); 2395 if (mem) 2396 KMP_FATAL(GompFeatureNotSupported, "scan"); 2397 return KMP_EXPAND_NAME(KMP_API_NAME_GOMP_SECTIONS_START)(count); 2398 } 2399 2400 void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER)( 2401 bool cancelled) { 2402 int gtid = __kmp_get_gtid(); 2403 MKLOC(loc, "GOMP_workshare_task_reduction_unregister"); 2404 KA_TRACE(20, ("GOMP_workshare_task_reduction_unregister: T#%d\n", gtid)); 2405 kmp_info_t *thr = __kmp_threads[gtid]; 2406 kmp_team_t *team = thr->th.th_team; 2407 __kmpc_end_taskgroup(NULL, gtid); 2408 // If last thread out of workshare, then reset the team's reduce data 2409 // the GOMP_taskgroup_reduction_unregister() function will deallocate 2410 // private copies after reduction calculations take place. 2411 int count = KMP_ATOMIC_INC(&team->t.t_tg_fini_counter[1]); 2412 if (count == thr->th.th_team_nproc - 1) { 2413 KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_UNREGISTER) 2414 ((uintptr_t *)KMP_ATOMIC_LD_RLX(&team->t.t_tg_reduce_data[1])); 2415 KMP_ATOMIC_ST_REL(&team->t.t_tg_reduce_data[1], NULL); 2416 KMP_ATOMIC_ST_REL(&team->t.t_tg_fini_counter[1], 0); 2417 } 2418 if (!cancelled) { 2419 __kmpc_barrier(&loc, gtid); 2420 } 2421 } 2422 2423 /* The following sections of code create aliases for the GOMP_* functions, then 2424 create versioned symbols using the assembler directive .symver. This is only 2425 pertinent for ELF .so library. The KMP_VERSION_SYMBOL macro is defined in 2426 kmp_os.h */ 2427 2428 #ifdef KMP_USE_VERSION_SYMBOLS 2429 // GOMP_1.0 versioned symbols 2430 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_END, 10, "GOMP_1.0"); 2431 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ATOMIC_START, 10, "GOMP_1.0"); 2432 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER, 10, "GOMP_1.0"); 2433 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_END, 10, "GOMP_1.0"); 2434 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_END, 10, "GOMP_1.0"); 2435 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_NAME_START, 10, "GOMP_1.0"); 2436 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CRITICAL_START, 10, "GOMP_1.0"); 2437 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_NEXT, 10, "GOMP_1.0"); 2438 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DYNAMIC_START, 10, "GOMP_1.0"); 2439 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END, 10, "GOMP_1.0"); 2440 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_NOWAIT, 10, "GOMP_1.0"); 2441 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_NEXT, 10, "GOMP_1.0"); 2442 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_GUIDED_START, 10, "GOMP_1.0"); 2443 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_NEXT, 10, "GOMP_1.0"); 2444 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_DYNAMIC_START, 10, 2445 "GOMP_1.0"); 2446 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_NEXT, 10, "GOMP_1.0"); 2447 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_GUIDED_START, 10, "GOMP_1.0"); 2448 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_NEXT, 10, "GOMP_1.0"); 2449 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_RUNTIME_START, 10, 2450 "GOMP_1.0"); 2451 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_NEXT, 10, "GOMP_1.0"); 2452 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_STATIC_START, 10, "GOMP_1.0"); 2453 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_NEXT, 10, "GOMP_1.0"); 2454 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_RUNTIME_START, 10, "GOMP_1.0"); 2455 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_NEXT, 10, "GOMP_1.0"); 2456 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_STATIC_START, 10, "GOMP_1.0"); 2457 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_END, 10, "GOMP_1.0"); 2458 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_ORDERED_START, 10, "GOMP_1.0"); 2459 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_END, 10, "GOMP_1.0"); 2460 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC_START, 10, 2461 "GOMP_1.0"); 2462 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED_START, 10, 2463 "GOMP_1.0"); 2464 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME_START, 10, 2465 "GOMP_1.0"); 2466 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC_START, 10, 2467 "GOMP_1.0"); 2468 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START, 10, "GOMP_1.0"); 2469 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_START, 10, "GOMP_1.0"); 2470 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END, 10, "GOMP_1.0"); 2471 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_NOWAIT, 10, "GOMP_1.0"); 2472 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_NEXT, 10, "GOMP_1.0"); 2473 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_START, 10, "GOMP_1.0"); 2474 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_END, 10, "GOMP_1.0"); 2475 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_COPY_START, 10, "GOMP_1.0"); 2476 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SINGLE_START, 10, "GOMP_1.0"); 2477 2478 // GOMP_2.0 versioned symbols 2479 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK, 20, "GOMP_2.0"); 2480 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT, 20, "GOMP_2.0"); 2481 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_NEXT, 20, "GOMP_2.0"); 2482 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DYNAMIC_START, 20, "GOMP_2.0"); 2483 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_NEXT, 20, "GOMP_2.0"); 2484 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_GUIDED_START, 20, "GOMP_2.0"); 2485 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_NEXT, 20, 2486 "GOMP_2.0"); 2487 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_DYNAMIC_START, 20, 2488 "GOMP_2.0"); 2489 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_NEXT, 20, 2490 "GOMP_2.0"); 2491 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_GUIDED_START, 20, 2492 "GOMP_2.0"); 2493 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT, 20, 2494 "GOMP_2.0"); 2495 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_START, 20, 2496 "GOMP_2.0"); 2497 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_NEXT, 20, 2498 "GOMP_2.0"); 2499 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_STATIC_START, 20, 2500 "GOMP_2.0"); 2501 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_NEXT, 20, "GOMP_2.0"); 2502 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_RUNTIME_START, 20, "GOMP_2.0"); 2503 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_NEXT, 20, "GOMP_2.0"); 2504 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_STATIC_START, 20, "GOMP_2.0"); 2505 2506 // GOMP_3.0 versioned symbols 2507 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKYIELD, 30, "GOMP_3.0"); 2508 2509 // GOMP_4.0 versioned symbols 2510 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL, 40, "GOMP_4.0"); 2511 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_SECTIONS, 40, "GOMP_4.0"); 2512 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_DYNAMIC, 40, "GOMP_4.0"); 2513 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_GUIDED, 40, "GOMP_4.0"); 2514 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_RUNTIME, 40, "GOMP_4.0"); 2515 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_STATIC, 40, "GOMP_4.0"); 2516 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_START, 40, "GOMP_4.0"); 2517 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_END, 40, "GOMP_4.0"); 2518 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_BARRIER_CANCEL, 40, "GOMP_4.0"); 2519 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCEL, 40, "GOMP_4.0"); 2520 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_CANCELLATION_POINT, 40, "GOMP_4.0"); 2521 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_END_CANCEL, 40, "GOMP_4.0"); 2522 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS_END_CANCEL, 40, "GOMP_4.0"); 2523 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET, 40, "GOMP_4.0"); 2524 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_DATA, 40, "GOMP_4.0"); 2525 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_END_DATA, 40, "GOMP_4.0"); 2526 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TARGET_UPDATE, 40, "GOMP_4.0"); 2527 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS, 40, "GOMP_4.0"); 2528 2529 // GOMP_4.5 versioned symbols 2530 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP, 45, "GOMP_4.5"); 2531 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKLOOP_ULL, 45, "GOMP_4.5"); 2532 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_POST, 45, "GOMP_4.5"); 2533 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_WAIT, 45, "GOMP_4.5"); 2534 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_STATIC_START, 45, 2535 "GOMP_4.5"); 2536 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_DYNAMIC_START, 45, 2537 "GOMP_4.5"); 2538 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_GUIDED_START, 45, 2539 "GOMP_4.5"); 2540 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_RUNTIME_START, 45, 2541 "GOMP_4.5"); 2542 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_POST, 45, "GOMP_4.5"); 2543 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_DOACROSS_ULL_WAIT, 45, "GOMP_4.5"); 2544 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_STATIC_START, 45, 2545 "GOMP_4.5"); 2546 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_DYNAMIC_START, 45, 2547 "GOMP_4.5"); 2548 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_GUIDED_START, 45, 2549 "GOMP_4.5"); 2550 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_RUNTIME_START, 45, 2551 "GOMP_4.5"); 2552 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_START, 45, 2553 "GOMP_4.5"); 2554 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_DYNAMIC_NEXT, 45, 2555 "GOMP_4.5"); 2556 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_START, 45, 2557 "GOMP_4.5"); 2558 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_GUIDED_NEXT, 45, 2559 "GOMP_4.5"); 2560 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_START, 45, 2561 "GOMP_4.5"); 2562 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_DYNAMIC_NEXT, 45, 2563 "GOMP_4.5"); 2564 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_START, 45, 2565 "GOMP_4.5"); 2566 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_GUIDED_NEXT, 45, 2567 "GOMP_4.5"); 2568 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_DYNAMIC, 45, 2569 "GOMP_4.5"); 2570 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_GUIDED, 45, 2571 "GOMP_4.5"); 2572 2573 // GOMP_5.0 versioned symbols 2574 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_NEXT, 50, 2575 "GOMP_5.0"); 2576 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_MAYBE_NONMONOTONIC_RUNTIME_START, 50, 2577 "GOMP_5.0"); 2578 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_NEXT, 50, 2579 "GOMP_5.0"); 2580 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_NONMONOTONIC_RUNTIME_START, 50, 2581 "GOMP_5.0"); 2582 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_NEXT, 2583 50, "GOMP_5.0"); 2584 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_MAYBE_NONMONOTONIC_RUNTIME_START, 2585 50, "GOMP_5.0"); 2586 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_NEXT, 50, 2587 "GOMP_5.0"); 2588 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_NONMONOTONIC_RUNTIME_START, 50, 2589 "GOMP_5.0"); 2590 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME, 50, 2591 "GOMP_5.0"); 2592 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_LOOP_MAYBE_NONMONOTONIC_RUNTIME, 2593 50, "GOMP_5.0"); 2594 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TEAMS_REG, 50, "GOMP_5.0"); 2595 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKWAIT_DEPEND, 50, "GOMP_5.0"); 2596 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_REGISTER, 50, 2597 "GOMP_5.0"); 2598 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_UNREGISTER, 50, 2599 "GOMP_5.0"); 2600 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_TASK_REDUCTION_REMAP, 50, "GOMP_5.0"); 2601 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_PARALLEL_REDUCTIONS, 50, "GOMP_5.0"); 2602 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_START, 50, "GOMP_5.0"); 2603 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_START, 50, "GOMP_5.0"); 2604 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_DOACROSS_START, 50, "GOMP_5.0"); 2605 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_DOACROSS_START, 50, "GOMP_5.0"); 2606 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ORDERED_START, 50, "GOMP_5.0"); 2607 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_START, 50, "GOMP_5.0"); 2608 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_SECTIONS2_START, 50, "GOMP_5.0"); 2609 KMP_VERSION_SYMBOL(KMP_API_NAME_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER, 50, 2610 "GOMP_5.0"); 2611 #endif // KMP_USE_VERSION_SYMBOLS 2612 2613 #ifdef __cplusplus 2614 } // extern "C" 2615 #endif // __cplusplus 2616