| 1 | // RUN: %libomp-compile-and-run | FileCheck %s |
| 2 | // REQUIRES: ompt |
| 3 | |
| 4 | #include "callback.h" |
| 5 | #include <omp.h> |
| 6 | |
| 7 | |
| 8 | __attribute__ ((noinline)) // workaround for bug in icc |
| 9 | void print_task_info_at(int ancestor_level, int id) |
| 10 | { |
| 11 | #pragma omp critical |
| 12 | { |
| 13 | int task_type; |
| 14 | char buffer[2048]; |
| 15 | ompt_data_t *parallel_data; |
| 16 | ompt_data_t *task_data; |
| 17 | int thread_num; |
| 18 | ompt_get_task_info(ancestor_level, &task_type, &task_data, NULL, |
| 19 | ¶llel_data, &thread_num); |
| 20 | format_task_type(task_type, buffer); |
| 21 | printf("%" PRIu64 ": ancestor_level=%d id=%d task_type=%s=%d " |
| 22 | "parallel_id=%" PRIu64 " task_id=%" PRIu64 |
| 23 | " thread_num=%d\n" , |
| 24 | ompt_get_thread_data()->value, ancestor_level, id, buffer, |
| 25 | task_type, parallel_data->value, task_data->value, thread_num); |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | |
| 32 | #pragma omp parallel num_threads(2) |
| 33 | { |
| 34 | |
| 35 | if (omp_get_thread_num() == 1) { |
| 36 | // To assert that task is executed by the worker thread, |
| 37 | // if(0) is used in order to ensure that the task is immediately |
| 38 | // executed after its creation. |
| 39 | #pragma omp task if(0) |
| 40 | { |
| 41 | // thread_num should be equal to 1 for both explicit and implicit task |
| 42 | print_task_info_at(ancestor_level: 0, id: 1); |
| 43 | print_task_info_at(ancestor_level: 1, id: 0); |
| 44 | }; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Check if libomp supports the callbacks for this test. |
| 49 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_event_parallel_begin' |
| 50 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' |
| 51 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' |
| 52 | |
| 53 | // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] |
| 54 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin |
| 55 | |
| 56 | // parallel region used only to determine worker thread id |
| 57 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin |
| 58 | // CHECK: {{^}}[[WID:[0-9]+]]: ompt_event_implicit_task{{.*}}thread_num=1 |
| 59 | |
| 60 | // thread_num must be equal to 1 for both explicit and the implicit tasks |
| 61 | // CHECK: {{^}}[[WID]]: ancestor_level=0 id=1 task_type=ompt_task_explicit |
| 62 | // CHECK-SAME: thread_num=1 |
| 63 | // CHECK: {{^}}[[WID]]: ancestor_level=1 id=0 task_type=ompt_task_implicit |
| 64 | // CHECK-SAME: thread_num=1 |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |