1 // RUN: %libomp-cxx-compile-and-run | %sort-threads | FileCheck %s 2 // REQUIRES: ompt 3 4 #include <iostream> 5 #include <thread> 6 #if !defined(__NetBSD__) 7 #include <alloca.h> 8 #else 9 #include <cstdlib> 10 #endif 11 12 #include "callback.h" 13 #include "omp.h" 14 15 int condition = 0; 16 17 void f() { 18 // Call OpenMP API function to force initialization of OMPT. 19 // (omp_get_thread_num() does not work because it just returns 0 if the 20 // runtime isn't initialized yet...) 21 omp_get_num_threads(); 22 23 // Call alloca() to force availability of frame pointer 24 void *p = alloca(0); 25 26 OMPT_SIGNAL(condition); 27 // Wait for both initial threads to arrive that will eventually become the 28 // master threads in the following parallel region. 29 OMPT_WAIT(condition, 2); 30 31 #pragma omp parallel num_threads(2) 32 { 33 // Wait for all threads to arrive so that no worker thread can be reused... 34 OMPT_SIGNAL(condition); 35 OMPT_WAIT(condition, 6); 36 } 37 } 38 39 int main() { 40 std::thread t1(f); 41 std::thread t2(f); 42 t1.join(); 43 t2.join(); 44 } 45 46 // Check if libomp supports the callbacks for this test. 47 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' 48 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_schedule' 49 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin' 50 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end' 51 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' 52 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_begin' 53 54 // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 55 56 // first master thread 57 // CHECK: {{^}}[[MASTER_ID_1:[0-9]+]]: ompt_event_thread_begin: 58 // CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID_1]] 59 60 // CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_task_create: parent_task_id=0 61 // CHECK-SAME: parent_task_frame.exit=[[NULL]] 62 // CHECK-SAME: parent_task_frame.reenter=[[NULL]] 63 // CHECK-SAME: new_task_id=[[PARENT_TASK_ID_1:[0-9]+]] 64 // CHECK-SAME: codeptr_ra=[[NULL]], task_type=ompt_task_initial=1 65 // CHECK-SAME: has_dependences=no 66 67 // CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_parallel_begin: 68 // CHECK-SAME: parent_task_id=[[PARENT_TASK_ID_1]] 69 // CHECK-SAME: parent_task_frame.exit=[[NULL]] 70 // CHECK-SAME: parent_task_frame.reenter={{0x[0-f]+}} 71 // CHECK-SAME: parallel_id=[[PARALLEL_ID_1:[0-9]+]], requested_team_size=2 72 // CHECK-SAME: codeptr_ra=0x{{[0-f]+}}, invoker={{.*}} 73 74 // CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_parallel_end: 75 // CHECK-SAME: parallel_id=[[PARALLEL_ID_1]], task_id=[[PARENT_TASK_ID_1]] 76 // CHECK-SAME: invoker={{[0-9]+}} 77 78 // CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_thread_end: 79 // CHECK-SAME: thread_id=[[MASTER_ID_1]] 80 81 // second master thread 82 // CHECK: {{^}}[[MASTER_ID_2:[0-9]+]]: ompt_event_thread_begin: 83 // CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID_2]] 84 85 // CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_task_create: parent_task_id=0 86 // CHECK-SAME: parent_task_frame.exit=[[NULL]] 87 // CHECK-SAME: parent_task_frame.reenter=[[NULL]] 88 // CHECK-SAME: new_task_id=[[PARENT_TASK_ID_2:[0-9]+]] 89 // CHECK-SAME: codeptr_ra=[[NULL]], task_type=ompt_task_initial=1 90 // CHECK-SAME: has_dependences=no 91 92 // CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_parallel_begin: 93 // CHECK-SAME: parent_task_id=[[PARENT_TASK_ID_2]] 94 // CHECK-SAME: parent_task_frame.exit=[[NULL]] 95 // CHECK-SAME: parent_task_frame.reenter={{0x[0-f]+}} 96 // CHECK-SAME: parallel_id=[[PARALLEL_ID_2:[0-9]+]] 97 // CHECK-SAME: requested_team_size=2, codeptr_ra=0x{{[0-f]+}} 98 // CHECK-SAME: invoker={{.*}} 99 100 // CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_parallel_end: 101 // CHECK-SAME: parallel_id=[[PARALLEL_ID_2]], task_id=[[PARENT_TASK_ID_2]] 102 // CHECK-SAME: invoker={{[0-9]+}} 103 104 // CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_thread_end: 105 // CHECK-SAME: thread_id=[[MASTER_ID_2]] 106 107 // first worker thread 108 // CHECK: {{^}}[[THREAD_ID_1:[0-9]+]]: ompt_event_thread_begin: 109 // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[THREAD_ID_1]] 110 111 // CHECK: {{^}}[[THREAD_ID_1]]: ompt_event_thread_end: 112 // CHECK-SAME: thread_id=[[THREAD_ID_1]] 113 114 // second worker thread 115 // CHECK: {{^}}[[THREAD_ID_2:[0-9]+]]: ompt_event_thread_begin: 116 // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[THREAD_ID_2]] 117 118 // CHECK: {{^}}[[THREAD_ID_2]]: ompt_event_thread_end: 119 // CHECK-SAME: thread_id=[[THREAD_ID_2]] 120