1// RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s
2// REQUIRES: ompt
3// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7
4#include "callback.h"
5#include <omp.h>
6
7int main()
8{
9 omp_nest_lock_t nest_lock;
10 omp_init_nest_lock(&nest_lock);
11
12 #pragma omp parallel num_threads(2)
13 {
14 #pragma omp master
15 {
16 omp_set_nest_lock(&nest_lock);
17 print_fuzzy_address(1);
18 }
19 #pragma omp barrier
20 omp_test_nest_lock(&nest_lock); //should fail for non-master
21 print_fuzzy_address(2);
22 #pragma omp barrier
23 #pragma omp master
24 {
25 omp_unset_nest_lock(&nest_lock);
26 print_fuzzy_address(3);
27 omp_unset_nest_lock(&nest_lock);
28 print_fuzzy_address(4);
29 }
30 }
31
32 omp_destroy_nest_lock(&nest_lock);
33
34 // Check if libomp supports the callbacks for this test.
35 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire'
36 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired'
37 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released'
38 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_nest_lock'
39
40 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
41
42 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_wait_nest_lock: wait_id=[[WAIT_ID:[0-9]+]], hint=0, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
43 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_nest_lock_first: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}}
44 // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
45 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_test_nest_lock: wait_id=[[WAIT_ID]], hint=0, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
46 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_nest_lock_next: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}}
47 // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
48 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_nest_lock_prev: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
49 // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
50 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_nest_lock_last: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
51 // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
52
53 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_destroy_nest_lock: wait_id=[[WAIT_ID]]
54
55 // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_wait_test_nest_lock: wait_id=[[WAIT_ID]], hint=0, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
56 // CHECK-NOT: {{^}}[[THREAD_ID]]: ompt_event_acquired_test_nest_lock_next: wait_id=[[WAIT_ID]]
57 // CHECK-NEXT: {{^}}[[THREAD_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
58
59 return 0;
60}
61

source code of openmp/runtime/test/ompt/synchronization/test_nest_lock_parallel.c