LLVM OpenMP 19.0.0git
omp_taskyield.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <math.h>
4#include "omp_testsuite.h"
5#include "omp_my_sleep.h"
6
8{
9 int i;
10 int count = 0;
11 int start_tid[NUM_TASKS];
12 int current_tid[NUM_TASKS];
13
14 for (i=0; i< NUM_TASKS; i++) {
15 start_tid[i]=0;
16 current_tid[i]=0;
17 }
18
19 #pragma omp parallel
20 {
21 #pragma omp single
22 {
23 for (i = 0; i < NUM_TASKS; i++) {
24 int myi = i;
25 #pragma omp task untied
26 {
28 start_tid[myi] = omp_get_thread_num();
29 #pragma omp taskyield
30 if((start_tid[myi] %2) ==0){
32 current_tid[myi] = omp_get_thread_num();
33 } /*end of if*/
34 } /* end of omp task */
35 } /* end of for */
36 } /* end of single */
37 } /* end of parallel */
38 for (i=0;i<NUM_TASKS; i++) {
39 //printf("start_tid[%d]=%d, current_tid[%d]=%d\n",
40 //i, start_tid[i], i , current_tid[i]);
41 if (current_tid[i] == start_tid[i])
42 count++;
43 }
44 return (count<NUM_TASKS);
45}
46
47int main()
48{
49 int i;
50 int num_failed=0;
51
52 if (omp_get_max_threads() < 2)
54
55 for(i = 0; i < REPETITIONS; i++) {
56 if(!test_omp_taskyield()) {
57 num_failed++;
58 }
59 }
60 return num_failed;
61}
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t count
#define i
Definition: kmp_stub.cpp:87
#define omp_set_num_threads
Definition: kmp_stub.cpp:34
static void my_sleep(double sleeptime)
Utility function to have a sleep function with better resolution and which only stops one thread.
Definition: omp_my_sleep.h:24
int test_omp_taskyield()
Definition: omp_taskyield.c:7
int main()
Definition: omp_taskyield.c:47
#define SLEEPTIME
Definition: omp_testsuite.h:16
#define NUM_TASKS
Definition: omp_testsuite.h:20
#define REPETITIONS
Definition: omp_testsuite.h:13
int omp_get_max_threads()