62 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include <math.h>4#include "omp_testsuite.h"5#include "omp_my_sleep.h"6 7int test_omp_taskyield()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 parallel20 {21 #pragma omp single22 {23 for (i = 0; i < NUM_TASKS; i++) {24 int myi = i;25 #pragma omp task untied26 {27 my_sleep(SLEEPTIME);28 start_tid[myi] = omp_get_thread_num();29 #pragma omp taskyield30 if((start_tid[myi] %2) ==0){31 my_sleep(SLEEPTIME);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)53 omp_set_num_threads(8);54 55 for(i = 0; i < REPETITIONS; i++) {56 if(!test_omp_taskyield()) {57 num_failed++;58 }59 }60 return num_failed;61}62