1 #ifndef _BSD_SOURCE 2 #define _BSD_SOURCE 3 #endif 4 #ifndef _DEFAULT_SOURCE 5 #define _DEFAULT_SOURCE 6 #endif 7 #include <stdio.h> 8 #ifndef __STDC_FORMAT_MACROS 9 #define __STDC_FORMAT_MACROS 10 #endif 11 #include <inttypes.h> 12 #include <omp.h> 13 #include <omp-tools.h> 14 #include "ompt-signal.h" 15 16 // Used to detect architecture 17 #include "../../src/kmp_platform.h" 18 19 #ifndef _TOOL_PREFIX 20 #define _TOOL_PREFIX "" 21 // If no _TOOL_PREFIX is set, we assume that we run as part of an OMPT test 22 #define _OMPT_TESTS 23 #endif 24 25 static const char *ompt_thread_t_values[] = { 26 "ompt_thread_UNDEFINED", "ompt_thread_initial", "ompt_thread_worker", 27 "ompt_thread_other"}; 28 29 static const char *ompt_task_status_t_values[] = { 30 "ompt_task_UNDEFINED", 31 "ompt_task_complete", // 1 32 "ompt_task_yield", // 2 33 "ompt_task_cancel", // 3 34 "ompt_task_detach", // 4 35 "ompt_task_early_fulfill", // 5 36 "ompt_task_late_fulfill", // 6 37 "ompt_task_switch", // 7 38 "ompt_taskwait_complete" // 8 39 }; 40 static const char* ompt_cancel_flag_t_values[] = { 41 "ompt_cancel_parallel", 42 "ompt_cancel_sections", 43 "ompt_cancel_loop", 44 "ompt_cancel_taskgroup", 45 "ompt_cancel_activated", 46 "ompt_cancel_detected", 47 "ompt_cancel_discarded_task" 48 }; 49 50 static const char *ompt_dependence_type_t_values[] = { 51 "ompt_dependence_type_UNDEFINED", 52 "ompt_dependence_type_in", // 1 53 "ompt_dependence_type_out", // 2 54 "ompt_dependence_type_inout", // 3 55 "ompt_dependence_type_mutexinoutset", // 4 56 "ompt_dependence_type_source", // 5 57 "ompt_dependence_type_sink", // 6 58 "ompt_dependence_type_inoutset" // 7 59 }; 60 61 static void format_task_type(int type, char *buffer) { 62 char *progress = buffer; 63 if (type & ompt_task_initial) 64 progress += sprintf(progress, "ompt_task_initial"); 65 if (type & ompt_task_implicit) 66 progress += sprintf(progress, "ompt_task_implicit"); 67 if (type & ompt_task_explicit) 68 progress += sprintf(progress, "ompt_task_explicit"); 69 if (type & ompt_task_target) 70 progress += sprintf(progress, "ompt_task_target"); 71 if (type & ompt_task_taskwait) 72 progress += sprintf(progress, "ompt_task_taskwait"); 73 if (type & ompt_task_undeferred) 74 progress += sprintf(progress, "|ompt_task_undeferred"); 75 if (type & ompt_task_untied) 76 progress += sprintf(progress, "|ompt_task_untied"); 77 if (type & ompt_task_final) 78 progress += sprintf(progress, "|ompt_task_final"); 79 if (type & ompt_task_mergeable) 80 progress += sprintf(progress, "|ompt_task_mergeable"); 81 if (type & ompt_task_merged) 82 progress += sprintf(progress, "|ompt_task_merged"); 83 } 84 85 static ompt_set_callback_t ompt_set_callback; 86 static ompt_get_callback_t ompt_get_callback; 87 static ompt_get_state_t ompt_get_state; 88 static ompt_get_task_info_t ompt_get_task_info; 89 static ompt_get_task_memory_t ompt_get_task_memory; 90 static ompt_get_thread_data_t ompt_get_thread_data; 91 static ompt_get_parallel_info_t ompt_get_parallel_info; 92 static ompt_get_unique_id_t ompt_get_unique_id; 93 static ompt_finalize_tool_t ompt_finalize_tool; 94 static ompt_get_num_procs_t ompt_get_num_procs; 95 static ompt_get_num_places_t ompt_get_num_places; 96 static ompt_get_place_proc_ids_t ompt_get_place_proc_ids; 97 static ompt_get_place_num_t ompt_get_place_num; 98 static ompt_get_partition_place_nums_t ompt_get_partition_place_nums; 99 static ompt_get_proc_id_t ompt_get_proc_id; 100 static ompt_enumerate_states_t ompt_enumerate_states; 101 static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls; 102 103 static void print_ids(int level) 104 { 105 int task_type, thread_num; 106 ompt_frame_t *frame; 107 ompt_data_t *task_parallel_data; 108 ompt_data_t *task_data; 109 int exists_task = ompt_get_task_info(level, &task_type, &task_data, &frame, 110 &task_parallel_data, &thread_num); 111 char buffer[2048]; 112 format_task_type(task_type, buffer); 113 if (frame) 114 printf("%" PRIu64 ": task level %d: parallel_id=%" PRIu64 115 ", task_id=%" PRIu64 ", exit_frame=%p, reenter_frame=%p, " 116 "task_type=%s=%d, thread_num=%d\n", 117 ompt_get_thread_data()->value, level, 118 exists_task ? task_parallel_data->value : 0, 119 exists_task ? task_data->value : 0, frame->exit_frame.ptr, 120 frame->enter_frame.ptr, buffer, task_type, thread_num); 121 } 122 123 #define get_frame_address(level) __builtin_frame_address(level) 124 125 #define print_frame(level) \ 126 printf("%" PRIu64 ": __builtin_frame_address(%d)=%p\n", \ 127 ompt_get_thread_data()->value, level, get_frame_address(level)) 128 129 // clang (version 5.0 and above) adds an intermediate function call with debug flag (-g) 130 #if defined(TEST_NEED_PRINT_FRAME_FROM_OUTLINED_FN) 131 #if defined(DEBUG) && defined(__clang__) && __clang_major__ >= 5 132 #define print_frame_from_outlined_fn(level) print_frame(level+1) 133 #else 134 #define print_frame_from_outlined_fn(level) print_frame(level) 135 #endif 136 137 #if defined(__clang__) && __clang_major__ >= 5 138 #warning "Clang 5.0 and later add an additional wrapper for outlined functions when compiling with debug information." 139 #warning "Please define -DDEBUG iff you manually pass in -g to make the tests succeed!" 140 #endif 141 #endif 142 143 // This macro helps to define a label at the current position that can be used 144 // to get the current address in the code. 145 // 146 // For print_current_address(): 147 // To reliably determine the offset between the address of the label and the 148 // actual return address, we insert a NOP instruction as a jump target as the 149 // compiler would otherwise insert an instruction that we can't control. The 150 // instruction length is target dependent and is explained below. 151 // 152 // (The empty block between "#pragma omp ..." and the __asm__ statement is a 153 // workaround for a bug in the Intel Compiler.) 154 #define define_ompt_label(id) \ 155 {} \ 156 __asm__("nop"); \ 157 ompt_label_##id: 158 159 // This macro helps to get the address of a label that is inserted by the above 160 // macro define_ompt_label(). The address is obtained with a GNU extension 161 // (&&label) that has been tested with gcc, clang and icc. 162 #define get_ompt_label_address(id) (&& ompt_label_##id) 163 164 // This macro prints the exact address that a previously called runtime function 165 // returns to. 166 #define print_current_address(id) \ 167 define_ompt_label(id) \ 168 print_possible_return_addresses(get_ompt_label_address(id)) 169 170 #if KMP_ARCH_X86 || KMP_ARCH_X86_64 171 // On X86 the NOP instruction is 1 byte long. In addition, the compiler inserts 172 // a MOV instruction for non-void runtime functions which is 3 bytes long. 173 #define print_possible_return_addresses(addr) \ 174 printf("%" PRIu64 ": current_address=%p or %p for non-void functions\n", \ 175 ompt_get_thread_data()->value, ((char *)addr) - 1, ((char *)addr) - 4) 176 #elif KMP_ARCH_PPC64 177 // On Power the NOP instruction is 4 bytes long. In addition, the compiler 178 // inserts a second NOP instruction (another 4 bytes). For non-void runtime 179 // functions Clang inserts a STW instruction (but only if compiling under 180 // -fno-PIC which will be the default with Clang 8.0, another 4 bytes). 181 #define print_possible_return_addresses(addr) \ 182 printf("%" PRIu64 ": current_address=%p or %p\n", ompt_get_thread_data()->value, \ 183 ((char *)addr) - 8, ((char *)addr) - 12) 184 #elif KMP_ARCH_AARCH64 185 // On AArch64 the NOP instruction is 4 bytes long, can be followed by inserted 186 // store instruction (another 4 bytes long). 187 #define print_possible_return_addresses(addr) \ 188 printf("%" PRIu64 ": current_address=%p or %p\n", ompt_get_thread_data()->value, \ 189 ((char *)addr) - 4, ((char *)addr) - 8) 190 #elif KMP_ARCH_RISCV64 191 #if __riscv_compressed 192 // On RV64GC the C.NOP instruction is 2 byte long. In addition, the compiler 193 // inserts a J instruction (targeting the successor basic block), which 194 // accounts for another 4 bytes. Finally, an additional J instruction may 195 // appear (adding 4 more bytes) when the C.NOP is referenced elsewhere (ie. 196 // another branch). 197 #define print_possible_return_addresses(addr) \ 198 printf("%" PRIu64 ": current_address=%p or %p\n", \ 199 ompt_get_thread_data()->value, ((char *)addr) - 6, ((char *)addr) - 10) 200 #else 201 // On RV64G the NOP instruction is 4 byte long. In addition, the compiler 202 // inserts a J instruction (targeting the successor basic block), which 203 // accounts for another 4 bytes. Finally, an additional J instruction may 204 // appear (adding 4 more bytes) when the NOP is referenced elsewhere (ie. 205 // another branch). 206 #define print_possible_return_addresses(addr) \ 207 printf("%" PRIu64 ": current_address=%p or %p\n", \ 208 ompt_get_thread_data()->value, ((char *)addr) - 8, ((char *)addr) - 12) 209 #endif 210 #else 211 #error Unsupported target architecture, cannot determine address offset! 212 #endif 213 214 215 // This macro performs a somewhat similar job to print_current_address(), except 216 // that it discards a certain number of nibbles from the address and only prints 217 // the most significant bits / nibbles. This can be used for cases where the 218 // return address can only be approximated. 219 // 220 // To account for overflows (ie the most significant bits / nibbles have just 221 // changed as we are a few bytes above the relevant power of two) the addresses 222 // of the "current" and of the "previous block" are printed. 223 #define print_fuzzy_address(id) \ 224 define_ompt_label(id) \ 225 print_fuzzy_address_blocks(get_ompt_label_address(id)) 226 227 // If you change this define you need to adapt all capture patterns in the tests 228 // to include or discard the new number of nibbles! 229 #define FUZZY_ADDRESS_DISCARD_NIBBLES 2 230 #define FUZZY_ADDRESS_DISCARD_BYTES (1 << ((FUZZY_ADDRESS_DISCARD_NIBBLES) * 4)) 231 #define print_fuzzy_address_blocks(addr) \ 232 printf("%" PRIu64 ": fuzzy_address=0x%" PRIx64 " or 0x%" PRIx64 \ 233 " or 0x%" PRIx64 " or 0x%" PRIx64 " (%p)\n", \ 234 ompt_get_thread_data()->value, \ 235 ((uint64_t)addr) / FUZZY_ADDRESS_DISCARD_BYTES - 1, \ 236 ((uint64_t)addr) / FUZZY_ADDRESS_DISCARD_BYTES, \ 237 ((uint64_t)addr) / FUZZY_ADDRESS_DISCARD_BYTES + 1, \ 238 ((uint64_t)addr) / FUZZY_ADDRESS_DISCARD_BYTES + 2, addr) 239 240 #define register_ompt_callback_t(name, type) \ 241 do { \ 242 type f_##name = &on_##name; \ 243 if (ompt_set_callback(name, (ompt_callback_t)f_##name) == ompt_set_never) \ 244 printf("0: Could not register callback '" #name "'\n"); \ 245 } while (0) 246 247 #define register_ompt_callback(name) register_ompt_callback_t(name, name##_t) 248 249 #ifndef USE_PRIVATE_TOOL 250 static void 251 on_ompt_callback_mutex_acquire( 252 ompt_mutex_t kind, 253 unsigned int hint, 254 unsigned int impl, 255 ompt_wait_id_t wait_id, 256 const void *codeptr_ra) 257 { 258 switch(kind) 259 { 260 case ompt_mutex_lock: 261 printf("%" PRIu64 ":" _TOOL_PREFIX 262 " ompt_event_wait_lock: wait_id=%" PRIu64 ", hint=%" PRIu32 263 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 264 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 265 break; 266 case ompt_mutex_nest_lock: 267 printf("%" PRIu64 ":" _TOOL_PREFIX 268 " ompt_event_wait_nest_lock: wait_id=%" PRIu64 ", hint=%" PRIu32 269 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 270 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 271 break; 272 case ompt_mutex_critical: 273 printf("%" PRIu64 ":" _TOOL_PREFIX 274 " ompt_event_wait_critical: wait_id=%" PRIu64 ", hint=%" PRIu32 275 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 276 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 277 break; 278 case ompt_mutex_atomic: 279 printf("%" PRIu64 ":" _TOOL_PREFIX 280 " ompt_event_wait_atomic: wait_id=%" PRIu64 ", hint=%" PRIu32 281 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 282 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 283 break; 284 case ompt_mutex_ordered: 285 printf("%" PRIu64 ":" _TOOL_PREFIX 286 " ompt_event_wait_ordered: wait_id=%" PRIu64 ", hint=%" PRIu32 287 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 288 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 289 break; 290 default: 291 break; 292 } 293 } 294 295 static void 296 on_ompt_callback_mutex_acquired( 297 ompt_mutex_t kind, 298 ompt_wait_id_t wait_id, 299 const void *codeptr_ra) 300 { 301 switch(kind) 302 { 303 case ompt_mutex_lock: 304 printf("%" PRIu64 ":" _TOOL_PREFIX 305 " ompt_event_acquired_lock: wait_id=%" PRIu64 ", codeptr_ra=%p \n", 306 ompt_get_thread_data()->value, wait_id, codeptr_ra); 307 break; 308 case ompt_mutex_nest_lock: 309 printf("%" PRIu64 ":" _TOOL_PREFIX 310 " ompt_event_acquired_nest_lock_first: wait_id=%" PRIu64 311 ", codeptr_ra=%p \n", 312 ompt_get_thread_data()->value, wait_id, codeptr_ra); 313 break; 314 case ompt_mutex_critical: 315 printf("%" PRIu64 ":" _TOOL_PREFIX 316 " ompt_event_acquired_critical: wait_id=%" PRIu64 317 ", codeptr_ra=%p \n", 318 ompt_get_thread_data()->value, wait_id, codeptr_ra); 319 break; 320 case ompt_mutex_atomic: 321 printf("%" PRIu64 ":" _TOOL_PREFIX 322 " ompt_event_acquired_atomic: wait_id=%" PRIu64 323 ", codeptr_ra=%p \n", 324 ompt_get_thread_data()->value, wait_id, codeptr_ra); 325 break; 326 case ompt_mutex_ordered: 327 printf("%" PRIu64 ":" _TOOL_PREFIX 328 " ompt_event_acquired_ordered: wait_id=%" PRIu64 329 ", codeptr_ra=%p \n", 330 ompt_get_thread_data()->value, wait_id, codeptr_ra); 331 break; 332 default: 333 break; 334 } 335 } 336 337 static void 338 on_ompt_callback_mutex_released( 339 ompt_mutex_t kind, 340 ompt_wait_id_t wait_id, 341 const void *codeptr_ra) 342 { 343 switch(kind) 344 { 345 case ompt_mutex_lock: 346 printf("%" PRIu64 ":" _TOOL_PREFIX 347 " ompt_event_release_lock: wait_id=%" PRIu64 ", codeptr_ra=%p \n", 348 ompt_get_thread_data()->value, wait_id, codeptr_ra); 349 break; 350 case ompt_mutex_nest_lock: 351 printf("%" PRIu64 ":" _TOOL_PREFIX 352 " ompt_event_release_nest_lock_last: wait_id=%" PRIu64 353 ", codeptr_ra=%p \n", 354 ompt_get_thread_data()->value, wait_id, codeptr_ra); 355 break; 356 case ompt_mutex_critical: 357 printf("%" PRIu64 ":" _TOOL_PREFIX 358 " ompt_event_release_critical: wait_id=%" PRIu64 359 ", codeptr_ra=%p \n", 360 ompt_get_thread_data()->value, wait_id, codeptr_ra); 361 break; 362 case ompt_mutex_atomic: 363 printf("%" PRIu64 ":" _TOOL_PREFIX 364 " ompt_event_release_atomic: wait_id=%" PRIu64 365 ", codeptr_ra=%p \n", 366 ompt_get_thread_data()->value, wait_id, codeptr_ra); 367 break; 368 case ompt_mutex_ordered: 369 printf("%" PRIu64 ":" _TOOL_PREFIX 370 " ompt_event_release_ordered: wait_id=%" PRIu64 371 ", codeptr_ra=%p \n", 372 ompt_get_thread_data()->value, wait_id, codeptr_ra); 373 break; 374 default: 375 break; 376 } 377 } 378 379 static void 380 on_ompt_callback_nest_lock( 381 ompt_scope_endpoint_t endpoint, 382 ompt_wait_id_t wait_id, 383 const void *codeptr_ra) 384 { 385 switch(endpoint) 386 { 387 case ompt_scope_begin: 388 printf("%" PRIu64 ":" _TOOL_PREFIX 389 " ompt_event_acquired_nest_lock_next: wait_id=%" PRIu64 390 ", codeptr_ra=%p \n", 391 ompt_get_thread_data()->value, wait_id, codeptr_ra); 392 break; 393 case ompt_scope_end: 394 printf("%" PRIu64 ":" _TOOL_PREFIX 395 " ompt_event_release_nest_lock_prev: wait_id=%" PRIu64 396 ", codeptr_ra=%p \n", 397 ompt_get_thread_data()->value, wait_id, codeptr_ra); 398 break; 399 case ompt_scope_beginend: 400 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 401 exit(-1); 402 } 403 } 404 405 static void 406 on_ompt_callback_sync_region( 407 ompt_sync_region_t kind, 408 ompt_scope_endpoint_t endpoint, 409 ompt_data_t *parallel_data, 410 ompt_data_t *task_data, 411 const void *codeptr_ra) 412 { 413 switch(endpoint) 414 { 415 case ompt_scope_begin: 416 switch(kind) 417 { 418 case ompt_sync_region_barrier: 419 case ompt_sync_region_barrier_implicit: 420 case ompt_sync_region_barrier_implicit_workshare: 421 case ompt_sync_region_barrier_implicit_parallel: 422 case ompt_sync_region_barrier_teams: 423 case ompt_sync_region_barrier_explicit: 424 case ompt_sync_region_barrier_implementation: 425 printf("%" PRIu64 ":" _TOOL_PREFIX 426 " ompt_event_barrier_begin: parallel_id=%" PRIu64 427 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 428 ompt_get_thread_data()->value, parallel_data->value, 429 task_data->value, codeptr_ra); 430 print_ids(0); 431 break; 432 case ompt_sync_region_taskwait: 433 printf("%" PRIu64 ":" _TOOL_PREFIX 434 " ompt_event_taskwait_begin: parallel_id=%" PRIu64 435 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 436 ompt_get_thread_data()->value, parallel_data->value, 437 task_data->value, codeptr_ra); 438 break; 439 case ompt_sync_region_taskgroup: 440 printf("%" PRIu64 ":" _TOOL_PREFIX 441 " ompt_event_taskgroup_begin: parallel_id=%" PRIu64 442 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 443 ompt_get_thread_data()->value, parallel_data->value, 444 task_data->value, codeptr_ra); 445 break; 446 case ompt_sync_region_reduction: 447 printf("ompt_sync_region_reduction should never be passed to " 448 "on_ompt_callback_sync_region\n"); 449 exit(-1); 450 break; 451 } 452 break; 453 case ompt_scope_end: 454 switch(kind) 455 { 456 case ompt_sync_region_barrier: 457 case ompt_sync_region_barrier_implicit: 458 case ompt_sync_region_barrier_explicit: 459 case ompt_sync_region_barrier_implicit_workshare: 460 case ompt_sync_region_barrier_implicit_parallel: 461 case ompt_sync_region_barrier_teams: 462 case ompt_sync_region_barrier_implementation: 463 printf("%" PRIu64 ":" _TOOL_PREFIX 464 " ompt_event_barrier_end: parallel_id=%" PRIu64 465 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 466 ompt_get_thread_data()->value, 467 (parallel_data) ? parallel_data->value : 0, task_data->value, 468 codeptr_ra); 469 break; 470 case ompt_sync_region_taskwait: 471 printf("%" PRIu64 ":" _TOOL_PREFIX 472 " ompt_event_taskwait_end: parallel_id=%" PRIu64 473 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 474 ompt_get_thread_data()->value, 475 (parallel_data) ? parallel_data->value : 0, task_data->value, 476 codeptr_ra); 477 break; 478 case ompt_sync_region_taskgroup: 479 printf("%" PRIu64 ":" _TOOL_PREFIX 480 " ompt_event_taskgroup_end: parallel_id=%" PRIu64 481 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 482 ompt_get_thread_data()->value, 483 (parallel_data) ? parallel_data->value : 0, task_data->value, 484 codeptr_ra); 485 break; 486 case ompt_sync_region_reduction: 487 printf("ompt_sync_region_reduction should never be passed to " 488 "on_ompt_callback_sync_region\n"); 489 exit(-1); 490 break; 491 } 492 break; 493 case ompt_scope_beginend: 494 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 495 exit(-1); 496 } 497 } 498 499 static void 500 on_ompt_callback_sync_region_wait( 501 ompt_sync_region_t kind, 502 ompt_scope_endpoint_t endpoint, 503 ompt_data_t *parallel_data, 504 ompt_data_t *task_data, 505 const void *codeptr_ra) 506 { 507 switch(endpoint) 508 { 509 case ompt_scope_begin: 510 switch(kind) 511 { 512 case ompt_sync_region_barrier: 513 case ompt_sync_region_barrier_implicit: 514 case ompt_sync_region_barrier_implicit_workshare: 515 case ompt_sync_region_barrier_implicit_parallel: 516 case ompt_sync_region_barrier_teams: 517 case ompt_sync_region_barrier_explicit: 518 case ompt_sync_region_barrier_implementation: 519 printf("%" PRIu64 ":" _TOOL_PREFIX 520 " ompt_event_wait_barrier_begin: parallel_id=%" PRIu64 521 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 522 ompt_get_thread_data()->value, parallel_data->value, 523 task_data->value, codeptr_ra); 524 break; 525 case ompt_sync_region_taskwait: 526 printf("%" PRIu64 ":" _TOOL_PREFIX 527 " ompt_event_wait_taskwait_begin: parallel_id=%" PRIu64 528 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 529 ompt_get_thread_data()->value, parallel_data->value, 530 task_data->value, codeptr_ra); 531 break; 532 case ompt_sync_region_taskgroup: 533 printf("%" PRIu64 ":" _TOOL_PREFIX 534 " ompt_event_wait_taskgroup_begin: parallel_id=%" PRIu64 535 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 536 ompt_get_thread_data()->value, parallel_data->value, 537 task_data->value, codeptr_ra); 538 break; 539 case ompt_sync_region_reduction: 540 printf("ompt_sync_region_reduction should never be passed to " 541 "on_ompt_callback_sync_region_wait\n"); 542 exit(-1); 543 break; 544 } 545 break; 546 case ompt_scope_end: 547 switch(kind) 548 { 549 case ompt_sync_region_barrier: 550 case ompt_sync_region_barrier_implicit: 551 case ompt_sync_region_barrier_implicit_workshare: 552 case ompt_sync_region_barrier_implicit_parallel: 553 case ompt_sync_region_barrier_teams: 554 case ompt_sync_region_barrier_explicit: 555 case ompt_sync_region_barrier_implementation: 556 printf("%" PRIu64 ":" _TOOL_PREFIX 557 " ompt_event_wait_barrier_end: parallel_id=%" PRIu64 558 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 559 ompt_get_thread_data()->value, 560 (parallel_data) ? parallel_data->value : 0, task_data->value, 561 codeptr_ra); 562 break; 563 case ompt_sync_region_taskwait: 564 printf("%" PRIu64 ":" _TOOL_PREFIX 565 " ompt_event_wait_taskwait_end: parallel_id=%" PRIu64 566 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 567 ompt_get_thread_data()->value, 568 (parallel_data) ? parallel_data->value : 0, task_data->value, 569 codeptr_ra); 570 break; 571 case ompt_sync_region_taskgroup: 572 printf("%" PRIu64 ":" _TOOL_PREFIX 573 " ompt_event_wait_taskgroup_end: parallel_id=%" PRIu64 574 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 575 ompt_get_thread_data()->value, 576 (parallel_data) ? parallel_data->value : 0, task_data->value, 577 codeptr_ra); 578 break; 579 case ompt_sync_region_reduction: 580 printf("ompt_sync_region_reduction should never be passed to " 581 "on_ompt_callback_sync_region_wait\n"); 582 exit(-1); 583 break; 584 } 585 break; 586 case ompt_scope_beginend: 587 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 588 exit(-1); 589 } 590 } 591 592 static void on_ompt_callback_reduction(ompt_sync_region_t kind, 593 ompt_scope_endpoint_t endpoint, 594 ompt_data_t *parallel_data, 595 ompt_data_t *task_data, 596 const void *codeptr_ra) { 597 switch (endpoint) { 598 case ompt_scope_begin: 599 printf("%" PRIu64 ":" _TOOL_PREFIX 600 " ompt_event_reduction_begin: parallel_id=%" PRIu64 601 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 602 ompt_get_thread_data()->value, 603 (parallel_data) ? parallel_data->value : 0, task_data->value, 604 codeptr_ra); 605 break; 606 case ompt_scope_end: 607 printf("%" PRIu64 ":" _TOOL_PREFIX 608 " ompt_event_reduction_end: parallel_id=%" PRIu64 609 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 610 ompt_get_thread_data()->value, 611 (parallel_data) ? parallel_data->value : 0, task_data->value, 612 codeptr_ra); 613 break; 614 case ompt_scope_beginend: 615 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 616 exit(-1); 617 } 618 } 619 620 static void 621 on_ompt_callback_flush( 622 ompt_data_t *thread_data, 623 const void *codeptr_ra) 624 { 625 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_flush: codeptr_ra=%p\n", 626 thread_data->value, codeptr_ra); 627 } 628 629 static void 630 on_ompt_callback_cancel( 631 ompt_data_t *task_data, 632 int flags, 633 const void *codeptr_ra) 634 { 635 const char* first_flag_value; 636 const char* second_flag_value; 637 if(flags & ompt_cancel_parallel) 638 first_flag_value = ompt_cancel_flag_t_values[0]; 639 else if(flags & ompt_cancel_sections) 640 first_flag_value = ompt_cancel_flag_t_values[1]; 641 else if(flags & ompt_cancel_loop) 642 first_flag_value = ompt_cancel_flag_t_values[2]; 643 else if(flags & ompt_cancel_taskgroup) 644 first_flag_value = ompt_cancel_flag_t_values[3]; 645 646 if(flags & ompt_cancel_activated) 647 second_flag_value = ompt_cancel_flag_t_values[4]; 648 else if(flags & ompt_cancel_detected) 649 second_flag_value = ompt_cancel_flag_t_values[5]; 650 else if(flags & ompt_cancel_discarded_task) 651 second_flag_value = ompt_cancel_flag_t_values[6]; 652 653 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_cancel: task_data=%" PRIu64 654 ", flags=%s|%s=%" PRIu32 ", codeptr_ra=%p\n", 655 ompt_get_thread_data()->value, task_data->value, first_flag_value, 656 second_flag_value, flags, codeptr_ra); 657 } 658 659 static void 660 on_ompt_callback_implicit_task( 661 ompt_scope_endpoint_t endpoint, 662 ompt_data_t *parallel_data, 663 ompt_data_t *task_data, 664 unsigned int team_size, 665 unsigned int thread_num, 666 int flags) 667 { 668 switch(endpoint) 669 { 670 case ompt_scope_begin: 671 if(task_data->ptr) 672 printf("%s\n", "0: task_data initially not null"); 673 task_data->value = ompt_get_unique_id(); 674 675 //there is no parallel_begin callback for implicit parallel region 676 //thus it is initialized in initial task 677 if(flags & ompt_task_initial) 678 { 679 char buffer[2048]; 680 681 format_task_type(flags, buffer); 682 // Only check initial task not created by teams construct 683 if (team_size == 1 && thread_num == 1 && parallel_data->ptr) 684 printf("%s\n", "0: parallel_data initially not null"); 685 parallel_data->value = ompt_get_unique_id(); 686 printf("%" PRIu64 ":" _TOOL_PREFIX 687 " ompt_event_initial_task_begin: parallel_id=%" PRIu64 688 ", task_id=%" PRIu64 ", actual_parallelism=%" PRIu32 689 ", index=%" PRIu32 ", flags=%" PRIu32 "\n", 690 ompt_get_thread_data()->value, parallel_data->value, 691 task_data->value, team_size, thread_num, flags); 692 } else { 693 printf("%" PRIu64 ":" _TOOL_PREFIX 694 " ompt_event_implicit_task_begin: parallel_id=%" PRIu64 695 ", task_id=%" PRIu64 ", team_size=%" PRIu32 696 ", thread_num=%" PRIu32 "\n", 697 ompt_get_thread_data()->value, parallel_data->value, 698 task_data->value, team_size, thread_num); 699 } 700 701 break; 702 case ompt_scope_end: 703 if(flags & ompt_task_initial){ 704 printf("%" PRIu64 ":" _TOOL_PREFIX 705 " ompt_event_initial_task_end: parallel_id=%" PRIu64 706 ", task_id=%" PRIu64 ", actual_parallelism=%" PRIu32 707 ", index=%" PRIu32 "\n", 708 ompt_get_thread_data()->value, 709 (parallel_data) ? parallel_data->value : 0, task_data->value, 710 team_size, thread_num); 711 } else { 712 printf("%" PRIu64 ":" _TOOL_PREFIX 713 " ompt_event_implicit_task_end: parallel_id=%" PRIu64 714 ", task_id=%" PRIu64 ", team_size=%" PRIu32 715 ", thread_num=%" PRIu32 "\n", 716 ompt_get_thread_data()->value, 717 (parallel_data) ? parallel_data->value : 0, task_data->value, 718 team_size, thread_num); 719 } 720 break; 721 case ompt_scope_beginend: 722 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 723 exit(-1); 724 } 725 } 726 727 static void 728 on_ompt_callback_lock_init( 729 ompt_mutex_t kind, 730 unsigned int hint, 731 unsigned int impl, 732 ompt_wait_id_t wait_id, 733 const void *codeptr_ra) 734 { 735 switch(kind) 736 { 737 case ompt_mutex_lock: 738 printf("%" PRIu64 ":" _TOOL_PREFIX 739 " ompt_event_init_lock: wait_id=%" PRIu64 ", hint=%" PRIu32 740 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 741 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 742 break; 743 case ompt_mutex_nest_lock: 744 printf("%" PRIu64 ":" _TOOL_PREFIX 745 " ompt_event_init_nest_lock: wait_id=%" PRIu64 ", hint=%" PRIu32 746 ", impl=%" PRIu32 ", codeptr_ra=%p \n", 747 ompt_get_thread_data()->value, wait_id, hint, impl, codeptr_ra); 748 break; 749 default: 750 break; 751 } 752 } 753 754 static void 755 on_ompt_callback_lock_destroy( 756 ompt_mutex_t kind, 757 ompt_wait_id_t wait_id, 758 const void *codeptr_ra) 759 { 760 switch(kind) 761 { 762 case ompt_mutex_lock: 763 printf("%" PRIu64 ":" _TOOL_PREFIX 764 " ompt_event_destroy_lock: wait_id=%" PRIu64 ", codeptr_ra=%p \n", 765 ompt_get_thread_data()->value, wait_id, codeptr_ra); 766 break; 767 case ompt_mutex_nest_lock: 768 printf("%" PRIu64 ":" _TOOL_PREFIX 769 " ompt_event_destroy_nest_lock: wait_id=%" PRIu64 770 ", codeptr_ra=%p \n", 771 ompt_get_thread_data()->value, wait_id, codeptr_ra); 772 break; 773 default: 774 break; 775 } 776 } 777 778 static void 779 on_ompt_callback_work( 780 ompt_work_t wstype, 781 ompt_scope_endpoint_t endpoint, 782 ompt_data_t *parallel_data, 783 ompt_data_t *task_data, 784 uint64_t count, 785 const void *codeptr_ra) 786 { 787 switch(endpoint) 788 { 789 case ompt_scope_begin: 790 switch(wstype) 791 { 792 case ompt_work_loop: 793 printf("%" PRIu64 ":" _TOOL_PREFIX 794 " ompt_event_loop_begin: parallel_id=%" PRIu64 795 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 796 "\n", 797 ompt_get_thread_data()->value, parallel_data->value, 798 task_data->value, codeptr_ra, count); 799 break; 800 case ompt_work_sections: 801 printf("%" PRIu64 ":" _TOOL_PREFIX 802 " ompt_event_sections_begin: parallel_id=%" PRIu64 803 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 804 "\n", 805 ompt_get_thread_data()->value, parallel_data->value, 806 task_data->value, codeptr_ra, count); 807 break; 808 case ompt_work_single_executor: 809 printf("%" PRIu64 ":" _TOOL_PREFIX 810 " ompt_event_single_in_block_begin: parallel_id=%" PRIu64 811 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 812 "\n", 813 ompt_get_thread_data()->value, parallel_data->value, 814 task_data->value, codeptr_ra, count); 815 break; 816 case ompt_work_single_other: 817 printf("%" PRIu64 ":" _TOOL_PREFIX 818 " ompt_event_single_others_begin: parallel_id=%" PRIu64 819 ", task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 "\n", 820 ompt_get_thread_data()->value, parallel_data->value, 821 task_data->value, codeptr_ra, count); 822 break; 823 case ompt_work_workshare: 824 //impl 825 break; 826 case ompt_work_distribute: 827 printf("%" PRIu64 ":" _TOOL_PREFIX 828 " ompt_event_distribute_begin: parallel_id=%" PRIu64 829 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 830 "\n", 831 ompt_get_thread_data()->value, parallel_data->value, 832 task_data->value, codeptr_ra, count); 833 break; 834 case ompt_work_taskloop: 835 //impl 836 printf("%" PRIu64 ":" _TOOL_PREFIX 837 " ompt_event_taskloop_begin: parallel_id=%" PRIu64 838 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 839 "\n", 840 ompt_get_thread_data()->value, parallel_data->value, 841 task_data->value, codeptr_ra, count); 842 break; 843 case ompt_work_scope: 844 printf("%" PRIu64 ":" _TOOL_PREFIX 845 " ompt_event_scope_begin: parallel_id=%" PRIu64 846 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 847 "\n", 848 ompt_get_thread_data()->value, parallel_data->value, 849 task_data->value, codeptr_ra, count); 850 break; 851 } 852 break; 853 case ompt_scope_end: 854 switch(wstype) 855 { 856 case ompt_work_loop: 857 printf("%" PRIu64 ":" _TOOL_PREFIX 858 " ompt_event_loop_end: parallel_id=%" PRIu64 859 ", task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 "\n", 860 ompt_get_thread_data()->value, parallel_data->value, 861 task_data->value, codeptr_ra, count); 862 break; 863 case ompt_work_sections: 864 printf("%" PRIu64 ":" _TOOL_PREFIX 865 " ompt_event_sections_end: parallel_id=%" PRIu64 866 ", task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 "\n", 867 ompt_get_thread_data()->value, parallel_data->value, 868 task_data->value, codeptr_ra, count); 869 break; 870 case ompt_work_single_executor: 871 printf("%" PRIu64 ":" _TOOL_PREFIX 872 " ompt_event_single_in_block_end: parallel_id=%" PRIu64 873 ", task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 "\n", 874 ompt_get_thread_data()->value, parallel_data->value, 875 task_data->value, codeptr_ra, count); 876 break; 877 case ompt_work_single_other: 878 printf("%" PRIu64 ":" _TOOL_PREFIX 879 " ompt_event_single_others_end: parallel_id=%" PRIu64 880 ", task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 "\n", 881 ompt_get_thread_data()->value, parallel_data->value, 882 task_data->value, codeptr_ra, count); 883 break; 884 case ompt_work_workshare: 885 //impl 886 break; 887 case ompt_work_distribute: 888 printf("%" PRIu64 ":" _TOOL_PREFIX 889 " ompt_event_distribute_end: parallel_id=%" PRIu64 890 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 891 "\n", 892 ompt_get_thread_data()->value, parallel_data->value, 893 task_data->value, codeptr_ra, count); 894 break; 895 case ompt_work_taskloop: 896 //impl 897 printf("%" PRIu64 ":" _TOOL_PREFIX 898 " ompt_event_taskloop_end: parallel_id=%" PRIu64 899 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 900 "\n", 901 ompt_get_thread_data()->value, parallel_data->value, 902 task_data->value, codeptr_ra, count); 903 break; 904 case ompt_work_scope: 905 printf("%" PRIu64 ":" _TOOL_PREFIX 906 " ompt_event_scope_end: parallel_id=%" PRIu64 907 ", parent_task_id=%" PRIu64 ", codeptr_ra=%p, count=%" PRIu64 908 "\n", 909 ompt_get_thread_data()->value, parallel_data->value, 910 task_data->value, codeptr_ra, count); 911 break; 912 } 913 break; 914 case ompt_scope_beginend: 915 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 916 exit(-1); 917 } 918 } 919 920 static void on_ompt_callback_masked(ompt_scope_endpoint_t endpoint, 921 ompt_data_t *parallel_data, 922 ompt_data_t *task_data, 923 const void *codeptr_ra) { 924 switch(endpoint) 925 { 926 case ompt_scope_begin: 927 printf("%" PRIu64 ":" _TOOL_PREFIX 928 " ompt_event_masked_begin: parallel_id=%" PRIu64 929 ", task_id=%" PRIu64 ", codeptr_ra=%p\n", 930 ompt_get_thread_data()->value, parallel_data->value, 931 task_data->value, codeptr_ra); 932 break; 933 case ompt_scope_end: 934 printf("%" PRIu64 ":" _TOOL_PREFIX 935 " ompt_event_masked_end: parallel_id=%" PRIu64 ", task_id=%" PRIu64 936 ", codeptr_ra=%p\n", 937 ompt_get_thread_data()->value, parallel_data->value, 938 task_data->value, codeptr_ra); 939 break; 940 case ompt_scope_beginend: 941 printf("ompt_scope_beginend should never be passed to %s\n", __func__); 942 exit(-1); 943 } 944 } 945 946 static void on_ompt_callback_parallel_begin( 947 ompt_data_t *encountering_task_data, 948 const ompt_frame_t *encountering_task_frame, ompt_data_t *parallel_data, 949 uint32_t requested_team_size, int flag, const void *codeptr_ra) { 950 if(parallel_data->ptr) 951 printf("0: parallel_data initially not null\n"); 952 parallel_data->value = ompt_get_unique_id(); 953 int invoker = flag & 0xF; 954 const char *event = (flag & ompt_parallel_team) ? "parallel" : "teams"; 955 const char *size = (flag & ompt_parallel_team) ? "team_size" : "num_teams"; 956 printf("%" PRIu64 ":" _TOOL_PREFIX 957 " ompt_event_%s_begin: parent_task_id=%" PRIu64 958 ", parent_task_frame.exit=%p, parent_task_frame.reenter=%p, " 959 "parallel_id=%" PRIu64 ", requested_%s=%" PRIu32 960 ", codeptr_ra=%p, invoker=%d\n", 961 ompt_get_thread_data()->value, event, encountering_task_data->value, 962 encountering_task_frame->exit_frame.ptr, 963 encountering_task_frame->enter_frame.ptr, parallel_data->value, size, 964 requested_team_size, codeptr_ra, invoker); 965 } 966 967 static void on_ompt_callback_parallel_end(ompt_data_t *parallel_data, 968 ompt_data_t *encountering_task_data, 969 int flag, const void *codeptr_ra) { 970 int invoker = flag & 0xF; 971 const char *event = (flag & ompt_parallel_team) ? "parallel" : "teams"; 972 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_%s_end: parallel_id=%" PRIu64 973 ", task_id=%" PRIu64 ", invoker=%d, codeptr_ra=%p\n", 974 ompt_get_thread_data()->value, event, parallel_data->value, 975 encountering_task_data->value, invoker, codeptr_ra); 976 } 977 978 static void 979 on_ompt_callback_task_create( 980 ompt_data_t *encountering_task_data, 981 const ompt_frame_t *encountering_task_frame, 982 ompt_data_t* new_task_data, 983 int type, 984 int has_dependences, 985 const void *codeptr_ra) 986 { 987 if(new_task_data->ptr) 988 printf("0: new_task_data initially not null\n"); 989 new_task_data->value = ompt_get_unique_id(); 990 char buffer[2048]; 991 992 format_task_type(type, buffer); 993 994 printf( 995 "%" PRIu64 ":" _TOOL_PREFIX 996 " ompt_event_task_create: parent_task_id=%" PRIu64 997 ", parent_task_frame.exit=%p, parent_task_frame.reenter=%p, " 998 "new_task_id=%" PRIu64 999 ", codeptr_ra=%p, task_type=%s=%d, has_dependences=%s\n", 1000 ompt_get_thread_data()->value, 1001 encountering_task_data ? encountering_task_data->value : 0, 1002 encountering_task_frame ? encountering_task_frame->exit_frame.ptr : NULL, 1003 encountering_task_frame ? encountering_task_frame->enter_frame.ptr : NULL, 1004 new_task_data->value, codeptr_ra, buffer, type, 1005 has_dependences ? "yes" : "no"); 1006 } 1007 1008 static void 1009 on_ompt_callback_task_schedule( 1010 ompt_data_t *first_task_data, 1011 ompt_task_status_t prior_task_status, 1012 ompt_data_t *second_task_data) 1013 { 1014 printf("%" PRIu64 ":" _TOOL_PREFIX 1015 " ompt_event_task_schedule: first_task_id=%" PRIu64 1016 ", second_task_id=%" PRIu64 ", prior_task_status=%s=%d\n", 1017 ompt_get_thread_data()->value, first_task_data->value, 1018 (second_task_data ? second_task_data->value : -1), 1019 ompt_task_status_t_values[prior_task_status], prior_task_status); 1020 if (prior_task_status == ompt_task_complete || 1021 prior_task_status == ompt_task_late_fulfill || 1022 prior_task_status == ompt_taskwait_complete) { 1023 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_task_end: task_id=%" PRIu64 1024 "\n", ompt_get_thread_data()->value, first_task_data->value); 1025 } 1026 } 1027 1028 static void 1029 on_ompt_callback_dependences( 1030 ompt_data_t *task_data, 1031 const ompt_dependence_t *deps, 1032 int ndeps) 1033 { 1034 char buffer[2048]; 1035 char *progress = buffer; 1036 int i; 1037 for (i = 0; i < ndeps && progress < buffer + 2000; i++) { 1038 if (deps[i].dependence_type == ompt_dependence_type_source || 1039 deps[i].dependence_type == ompt_dependence_type_sink) 1040 progress += 1041 sprintf(progress, "(%" PRIu64 ", %s), ", deps[i].variable.value, 1042 ompt_dependence_type_t_values[deps[i].dependence_type]); 1043 else 1044 progress += 1045 sprintf(progress, "(%p, %s), ", deps[i].variable.ptr, 1046 ompt_dependence_type_t_values[deps[i].dependence_type]); 1047 } 1048 if (ndeps > 0) 1049 progress[-2] = 0; 1050 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_dependences: task_id=%" PRIu64 1051 ", deps=[%s], ndeps=%d\n", 1052 ompt_get_thread_data()->value, task_data->value, buffer, ndeps); 1053 } 1054 1055 static void 1056 on_ompt_callback_task_dependence( 1057 ompt_data_t *first_task_data, 1058 ompt_data_t *second_task_data) 1059 { 1060 printf("%" PRIu64 ":" _TOOL_PREFIX 1061 " ompt_event_task_dependence_pair: first_task_id=%" PRIu64 1062 ", second_task_id=%" PRIu64 "\n", 1063 ompt_get_thread_data()->value, first_task_data->value, 1064 second_task_data->value); 1065 } 1066 1067 static void 1068 on_ompt_callback_thread_begin( 1069 ompt_thread_t thread_type, 1070 ompt_data_t *thread_data) 1071 { 1072 if(thread_data->ptr) 1073 printf("%s\n", "0: thread_data initially not null"); 1074 thread_data->value = ompt_get_unique_id(); 1075 printf("%" PRIu64 ":" _TOOL_PREFIX 1076 " ompt_event_thread_begin: thread_type=%s=%d, thread_id=%" PRIu64 "\n", 1077 ompt_get_thread_data()->value, ompt_thread_t_values[thread_type], 1078 thread_type, thread_data->value); 1079 } 1080 1081 static void 1082 on_ompt_callback_thread_end( 1083 ompt_data_t *thread_data) 1084 { 1085 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_thread_end: thread_id=%" PRIu64 1086 "\n", 1087 ompt_get_thread_data()->value, thread_data->value); 1088 } 1089 1090 static int 1091 on_ompt_callback_control_tool( 1092 uint64_t command, 1093 uint64_t modifier, 1094 void *arg, 1095 const void *codeptr_ra) 1096 { 1097 ompt_frame_t* omptTaskFrame; 1098 ompt_get_task_info(0, NULL, (ompt_data_t**) NULL, &omptTaskFrame, NULL, NULL); 1099 printf("%" PRIu64 ":" _TOOL_PREFIX " ompt_event_control_tool: command=%" PRIu64 1100 ", modifier=%" PRIu64 1101 ", arg=%p, codeptr_ra=%p, current_task_frame.exit=%p, " 1102 "current_task_frame.reenter=%p \n", 1103 ompt_get_thread_data()->value, command, modifier, arg, codeptr_ra, 1104 omptTaskFrame->exit_frame.ptr, omptTaskFrame->enter_frame.ptr); 1105 1106 // the following would interfere with expected output for OMPT tests, so skip 1107 #ifndef _OMPT_TESTS 1108 // print task data 1109 int task_level = 0; 1110 ompt_data_t *task_data; 1111 while (ompt_get_task_info(task_level, NULL, (ompt_data_t **)&task_data, NULL, 1112 NULL, NULL)) { 1113 printf("%" PRIu64 ":" _TOOL_PREFIX " task level %d: task_id=%" PRIu64 "\n", 1114 ompt_get_thread_data()->value, task_level, task_data->value); 1115 task_level++; 1116 } 1117 1118 // print parallel data 1119 int parallel_level = 0; 1120 ompt_data_t *parallel_data; 1121 while (ompt_get_parallel_info(parallel_level, (ompt_data_t **)¶llel_data, 1122 NULL)) { 1123 printf("%" PRIu64 ":" _TOOL_PREFIX " parallel level %d: parallel_id=%" PRIu64 1124 "\n", 1125 ompt_get_thread_data()->value, parallel_level, parallel_data->value); 1126 parallel_level++; 1127 } 1128 #endif 1129 return 0; //success 1130 } 1131 1132 static void on_ompt_callback_error(ompt_severity_t severity, 1133 const char *message, size_t length, 1134 const void *codeptr_ra) { 1135 printf("%" PRIu64 ": ompt_event_runtime_error: severity=%" PRIu32 1136 ", message=%s, length=%" PRIu64 ", codeptr_ra=%p\n", 1137 ompt_get_thread_data()->value, severity, message, (uint64_t)length, 1138 codeptr_ra); 1139 } 1140 1141 int ompt_initialize( 1142 ompt_function_lookup_t lookup, 1143 int initial_device_num, 1144 ompt_data_t *tool_data) 1145 { 1146 ompt_set_callback = (ompt_set_callback_t) lookup("ompt_set_callback"); 1147 ompt_get_callback = (ompt_get_callback_t) lookup("ompt_get_callback"); 1148 ompt_get_state = (ompt_get_state_t) lookup("ompt_get_state"); 1149 ompt_get_task_info = (ompt_get_task_info_t) lookup("ompt_get_task_info"); 1150 ompt_get_task_memory = (ompt_get_task_memory_t)lookup("ompt_get_task_memory"); 1151 ompt_get_thread_data = (ompt_get_thread_data_t) lookup("ompt_get_thread_data"); 1152 ompt_get_parallel_info = (ompt_get_parallel_info_t) lookup("ompt_get_parallel_info"); 1153 ompt_get_unique_id = (ompt_get_unique_id_t) lookup("ompt_get_unique_id"); 1154 ompt_finalize_tool = (ompt_finalize_tool_t)lookup("ompt_finalize_tool"); 1155 1156 ompt_get_unique_id(); 1157 1158 ompt_get_num_procs = (ompt_get_num_procs_t) lookup("ompt_get_num_procs"); 1159 ompt_get_num_places = (ompt_get_num_places_t) lookup("ompt_get_num_places"); 1160 ompt_get_place_proc_ids = (ompt_get_place_proc_ids_t) lookup("ompt_get_place_proc_ids"); 1161 ompt_get_place_num = (ompt_get_place_num_t) lookup("ompt_get_place_num"); 1162 ompt_get_partition_place_nums = (ompt_get_partition_place_nums_t) lookup("ompt_get_partition_place_nums"); 1163 ompt_get_proc_id = (ompt_get_proc_id_t) lookup("ompt_get_proc_id"); 1164 ompt_enumerate_states = (ompt_enumerate_states_t) lookup("ompt_enumerate_states"); 1165 ompt_enumerate_mutex_impls = (ompt_enumerate_mutex_impls_t) lookup("ompt_enumerate_mutex_impls"); 1166 1167 register_ompt_callback(ompt_callback_mutex_acquire); 1168 register_ompt_callback_t(ompt_callback_mutex_acquired, ompt_callback_mutex_t); 1169 register_ompt_callback_t(ompt_callback_mutex_released, ompt_callback_mutex_t); 1170 register_ompt_callback(ompt_callback_nest_lock); 1171 register_ompt_callback(ompt_callback_sync_region); 1172 register_ompt_callback_t(ompt_callback_sync_region_wait, ompt_callback_sync_region_t); 1173 register_ompt_callback_t(ompt_callback_reduction, ompt_callback_sync_region_t); 1174 register_ompt_callback(ompt_callback_control_tool); 1175 register_ompt_callback(ompt_callback_flush); 1176 register_ompt_callback(ompt_callback_cancel); 1177 register_ompt_callback(ompt_callback_implicit_task); 1178 register_ompt_callback_t(ompt_callback_lock_init, ompt_callback_mutex_acquire_t); 1179 register_ompt_callback_t(ompt_callback_lock_destroy, ompt_callback_mutex_t); 1180 register_ompt_callback(ompt_callback_work); 1181 register_ompt_callback(ompt_callback_masked); 1182 register_ompt_callback(ompt_callback_parallel_begin); 1183 register_ompt_callback(ompt_callback_parallel_end); 1184 register_ompt_callback(ompt_callback_task_create); 1185 register_ompt_callback(ompt_callback_task_schedule); 1186 register_ompt_callback(ompt_callback_dependences); 1187 register_ompt_callback(ompt_callback_task_dependence); 1188 register_ompt_callback(ompt_callback_thread_begin); 1189 register_ompt_callback(ompt_callback_thread_end); 1190 register_ompt_callback(ompt_callback_error); 1191 printf("0: NULL_POINTER=%p\n", (void*)NULL); 1192 return 1; //success 1193 } 1194 1195 void ompt_finalize(ompt_data_t *tool_data) 1196 { 1197 printf("0: ompt_event_runtime_shutdown\n"); 1198 } 1199 1200 #ifdef __cplusplus 1201 extern "C" { 1202 #endif 1203 ompt_start_tool_result_t* ompt_start_tool( 1204 unsigned int omp_version, 1205 const char *runtime_version) 1206 { 1207 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,&ompt_finalize, 0}; 1208 return &ompt_start_tool_result; 1209 } 1210 #ifdef __cplusplus 1211 } 1212 #endif 1213 #endif // ifndef USE_PRIVATE_TOOL 1214 #ifdef _OMPT_TESTS 1215 #undef _OMPT_TESTS 1216 #endif 1217