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