brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · 2b852c6 Raw
132 lines · c
1// clang-format off2// RUN: %libomp-compile-and-run | FileCheck %s3// REQUIRES: ompt4// clang-format on5 6#include "callback.h"7#include <omp.h>8 9__attribute__ ((noinline)) // workaround for bug in icc10void print_task_info_at(int ancestor_level, int id)11{12#pragma omp critical13  {14    int task_type;15char buffer[2048];16ompt_data_t *parallel_data;17ompt_data_t *task_data;18int thread_num;19ompt_get_task_info(ancestor_level, &task_type, &task_data, NULL, &parallel_data,20                   &thread_num);21format_task_type(task_type, buffer);22printf("%" PRIu64 ": ancestor_level=%d id=%d task_type=%s=%d "23       "parallel_id=%" PRIx64 " task_id=%" PRIx64 " thread_num=%d\n",24       ompt_get_thread_data()->value, ancestor_level, id, buffer, task_type,25       parallel_data->value, task_data->value, thread_num);26}27}28;29 30__attribute__ ((noinline)) // workaround for bug in icc31void print_innermost_task_info(int id)32{33  print_task_info_at(0, id);34}35 36int main() {37 38#pragma omp parallel num_threads(2)39  {40    // sync threads before checking the output41#pragma omp barrier42    // region 043    if (omp_get_thread_num() == 1) {44      // executed by worker thread only45      // assert that thread_num is 146      print_innermost_task_info(1);47 48#pragma omp parallel num_threads(1)49      {50        // serialized region 151        // assert that thread_num is 052        print_innermost_task_info(2);53 54#pragma omp parallel num_threads(1)55        {56          // serialized region 257          // assert that thread_num is 058          print_innermost_task_info(3);59 60          // Check the value of thread_num while iterating over the hierarchy61          // of active tasks.62          print_task_info_at(0, 3);63          print_task_info_at(1, 2);64          print_task_info_at(2, 1);65        }66      }67    }68  }69 70  // clang-format off71  // Check if libomp supports the callbacks for this test.72  // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'73  // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'74 75 76  // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]77  // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id=[[PARALLEL_ID_0:[0-9]+]], task_id=[[TASK_ID_0:[0-9]+]], actual_parallelism=1, index=1, flags=178 79  // region 080  // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_0]],81  // CHECK-SAME: parallel_id=[[PARALLEL_ID_1:[0-9]+]]82  // CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_1]], task_id=[[TASK_ID_1:[0-9]+]]83  // CHECK-DAG: {{^}}[[WORKER_ID:[0-9]+]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_1]], task_id=[[TASK_ID_2:[0-9]+]]84  // assert some info about implicit task executed by worker thread85  // thread_num is the most important86  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=187  // CHECK-SAME: parallel_id=[[PARALLEL_ID_1]] task_id=[[TASK_ID_2]]88  // CHECK-SAME: thread_num=189 90  // serialized region 191  // CHECK: {{^}}[[WORKER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_2]],92  // CHECK-SAME: parallel_id=[[PARALLEL_ID_2:[0-9]+]]93  // CHECK-DAG: {{^}}[[WORKER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_2]], task_id=[[TASK_ID_3:[0-9]+]]94  // assert some information about the implicit task of the serialized region 195  // pay attention that thread_num should take value 096  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=297  // CHECK-SAME: parallel_id=[[PARALLEL_ID_2]] task_id=[[TASK_ID_3]]98  // CHECK-SAME: thread_num=099 100  // serialized region 2101  // CHECK: {{^}}[[WORKER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_3]],102  // CHECK-SAME: parallel_id=[[PARALLEL_ID_3:[0-9]+]]103  // CHECK-DAG: {{^}}[[WORKER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_3]], task_id=[[TASK_ID_4:[0-9]+]]104  // assert some information about the implicit task of the serialized region 2105  // pay attention that thread_num should take value 0106  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=3107  // CHECK-SAME: parallel_id=[[PARALLEL_ID_3]] task_id=[[TASK_ID_4]]108  // CHECK-SAME: thread_num=0109 110  // Check the value of thread_num argument while iterating over the hierarchy111  // of active tasks. The expected is that thread_num takes the value checked112  // above in the test case (0, 0, 1 - respectively).113 114  // Thread is the master thread of the region 2, so thread_num should be 0.115  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=3116  // CHECK-SAME: parallel_id=[[PARALLEL_ID_3]] task_id=[[TASK_ID_4]]117  // CHECK-SAME: thread_num=0118 119  // Thread is the master thread of the region 1, so thread_num should be 0.120  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=1 id=2121  // CHECK-SAME: parallel_id=[[PARALLEL_ID_2]] task_id=[[TASK_ID_3]]122  // CHECK-SAME: thread_num=0123 124  // Thread is the worker thread of the region 0, so thread_num should be 1.125  // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=2 id=1126  // CHECK-SAME: parallel_id=[[PARALLEL_ID_1]] task_id=[[TASK_ID_2]]127  // CHECK-SAME: thread_num=1128  // clang-format on129 130  return 0;131}132