xref: /llvm-project/openmp/runtime/test/ompt/tasks/taskyield.c (revision 2b46d30fc7049fc5cc5b9f98df654509bb4d61a2)
182e94a59SJoachim Protze // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s
282e94a59SJoachim Protze // REQUIRES: ompt
382e94a59SJoachim Protze // Current GOMP interface implements taskyield as stub
482e94a59SJoachim Protze // XFAIL: gcc
582e94a59SJoachim Protze 
682e94a59SJoachim Protze #include "callback.h"
782e94a59SJoachim Protze #include <omp.h>
882e94a59SJoachim Protze #include <unistd.h>
982e94a59SJoachim Protze 
main()1082e94a59SJoachim Protze int main()
1182e94a59SJoachim Protze {
1282e94a59SJoachim Protze   int condition=0, x=0;
1382e94a59SJoachim Protze   #pragma omp parallel num_threads(2)
1482e94a59SJoachim Protze   {
1582e94a59SJoachim Protze     #pragma omp master
1682e94a59SJoachim Protze     {
1782e94a59SJoachim Protze         #pragma omp task shared(condition)
1882e94a59SJoachim Protze         {
1982e94a59SJoachim Protze           OMPT_SIGNAL(condition);
2082e94a59SJoachim Protze           OMPT_WAIT(condition,2);
2182e94a59SJoachim Protze         }
2282e94a59SJoachim Protze         OMPT_WAIT(condition,1);
2382e94a59SJoachim Protze         #pragma omp task shared(x)
2482e94a59SJoachim Protze         {
2582e94a59SJoachim Protze           x++;
2682e94a59SJoachim Protze         }
2782e94a59SJoachim Protze         printf("%" PRIu64 ": before yield\n", ompt_get_thread_data()->value);
2882e94a59SJoachim Protze         #pragma omp taskyield
2982e94a59SJoachim Protze         printf("%" PRIu64 ": after yield\n", ompt_get_thread_data()->value);
3082e94a59SJoachim Protze         OMPT_SIGNAL(condition);
3182e94a59SJoachim Protze     }
3282e94a59SJoachim Protze   }
3382e94a59SJoachim Protze 
3482e94a59SJoachim Protze 
3582e94a59SJoachim Protze   // Check if libomp supports the callbacks for this test.
3682e94a59SJoachim Protze   // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'
3782e94a59SJoachim Protze   // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_schedule'
3882e94a59SJoachim Protze   // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
3982e94a59SJoachim Protze 
4082e94a59SJoachim Protze 
4182e94a59SJoachim Protze   // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
4282e94a59SJoachim Protze 
4382e94a59SJoachim Protze   // make sure initial data pointers are null
4482e94a59SJoachim Protze   // CHECK-NOT: 0: new_task_data initially not null
4582e94a59SJoachim Protze 
4682e94a59SJoachim Protze   // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_implicit_task_begin: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID:[0-9]+]], team_size={{[0-9]+}}, thread_num={{[0-9]+}}
4782e94a59SJoachim Protze 
4882e94a59SJoachim Protze   // CHECK: {{^}}[[MASTER_ID]]: ompt_event_task_create: parent_task_id={{[0-9]+}}, parent_task_frame.exit={{0x[0-f]+}}, parent_task_frame.reenter={{0x[0-f]+}}, new_task_id=[[WORKER_TASK:[0-9]+]], codeptr_ra={{0x[0-f]+}}, task_type=ompt_task_explicit=4, has_dependences=no
4982e94a59SJoachim Protze   // CHECK: {{^}}[[MASTER_ID]]: ompt_event_task_create: parent_task_id={{[0-9]+}}, parent_task_frame.exit={{0x[0-f]+}}, parent_task_frame.reenter={{0x[0-f]+}}, new_task_id=[[MAIN_TASK:[0-9]+]], codeptr_ra={{0x[0-f]+}}, task_type=ompt_task_explicit=4, has_dependences=no
5082e94a59SJoachim Protze 
5182e94a59SJoachim Protze   // CHECK: {{^}}[[MASTER_ID]]: ompt_event_task_schedule: first_task_id=[[IMPLICIT_TASK_ID]], second_task_id=[[MAIN_TASK]], prior_task_status=ompt_task_yield=2
5282e94a59SJoachim Protze   // CHECK: {{^}}[[MASTER_ID]]: ompt_event_task_schedule: first_task_id=[[MAIN_TASK]], second_task_id=[[IMPLICIT_TASK_ID]], prior_task_status=ompt_task_complete=1
5382e94a59SJoachim Protze 
54*2b46d30fSJoachim Protze   // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_task_schedule: first_task_id={{[0-9]+}}, second_task_id=[[WORKER_TASK]], prior_task_status=ompt_task_switch=7
5582e94a59SJoachim Protze   // CHECK: {{^}}[[THREAD_ID]]: ompt_event_task_schedule: first_task_id=[[WORKER_TASK]], second_task_id={{[0-9]+}}, prior_task_status=ompt_task_complete=1
5682e94a59SJoachim Protze 
5782e94a59SJoachim Protze 
5882e94a59SJoachim Protze 
5982e94a59SJoachim Protze 
6082e94a59SJoachim Protze 
6182e94a59SJoachim Protze   return 0;
6282e94a59SJoachim Protze }
63