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