1614c7ef8SJonathan Peyton // RUN: %libomp-compile-and-run 2614c7ef8SJonathan Peyton #include <stdio.h> 3614c7ef8SJonathan Peyton #include <math.h> 4614c7ef8SJonathan Peyton #include "omp_testsuite.h" 5614c7ef8SJonathan Peyton #include "omp_my_sleep.h" 6614c7ef8SJonathan Peyton test_omp_task_final()7614c7ef8SJonathan Peytonint test_omp_task_final() 8614c7ef8SJonathan Peyton { 9614c7ef8SJonathan Peyton int tids[NUM_TASKS]; 10614c7ef8SJonathan Peyton int includedtids[NUM_TASKS]; 11614c7ef8SJonathan Peyton int i; 12*71797c04SJonathan Peyton int error = 0; 13614c7ef8SJonathan Peyton #pragma omp parallel 14614c7ef8SJonathan Peyton { 15614c7ef8SJonathan Peyton #pragma omp single 16614c7ef8SJonathan Peyton { 17614c7ef8SJonathan Peyton for (i = 0; i < NUM_TASKS; i++) { 18614c7ef8SJonathan Peyton /* First we have to store the value of the loop index in a new variable 19614c7ef8SJonathan Peyton * which will be private for each task because otherwise it will be overwritten 20614c7ef8SJonathan Peyton * if the execution of the task takes longer than the time which is needed to 21614c7ef8SJonathan Peyton * enter the next step of the loop! 22614c7ef8SJonathan Peyton */ 23614c7ef8SJonathan Peyton int myi; 24614c7ef8SJonathan Peyton myi = i; 25614c7ef8SJonathan Peyton 26614c7ef8SJonathan Peyton #pragma omp task final(i>=10) 27614c7ef8SJonathan Peyton { 28614c7ef8SJonathan Peyton tids[myi] = omp_get_thread_num(); 29614c7ef8SJonathan Peyton /* we generate included tasks for final tasks */ 30614c7ef8SJonathan Peyton if(myi >= 10) { 31614c7ef8SJonathan Peyton int included = myi; 32614c7ef8SJonathan Peyton #pragma omp task 33614c7ef8SJonathan Peyton { 34614c7ef8SJonathan Peyton my_sleep (SLEEPTIME); 35614c7ef8SJonathan Peyton includedtids[included] = omp_get_thread_num(); 36614c7ef8SJonathan Peyton } /* end of omp included task of the final task */ 37614c7ef8SJonathan Peyton my_sleep (SLEEPTIME); 38614c7ef8SJonathan Peyton } /* end of if it is a final task*/ 39614c7ef8SJonathan Peyton } /* end of omp task */ 40614c7ef8SJonathan Peyton } /* end of for */ 41614c7ef8SJonathan Peyton } /* end of single */ 42614c7ef8SJonathan Peyton } /*end of parallel */ 43614c7ef8SJonathan Peyton 44614c7ef8SJonathan Peyton /* Now we ckeck if more than one thread executed the final task and its included task. */ 45614c7ef8SJonathan Peyton for (i = 10; i < NUM_TASKS; i++) { 46614c7ef8SJonathan Peyton if (tids[i] != includedtids[i]) { 47614c7ef8SJonathan Peyton error++; 48614c7ef8SJonathan Peyton } 49614c7ef8SJonathan Peyton } 50614c7ef8SJonathan Peyton return (error==0); 51614c7ef8SJonathan Peyton } /* end of check_paralel_for_private */ 52614c7ef8SJonathan Peyton main()53614c7ef8SJonathan Peytonint main() 54614c7ef8SJonathan Peyton { 55614c7ef8SJonathan Peyton int i; 56614c7ef8SJonathan Peyton int num_failed=0; 57614c7ef8SJonathan Peyton 58614c7ef8SJonathan Peyton for(i = 0; i < REPETITIONS; i++) { 59614c7ef8SJonathan Peyton if(!test_omp_task_final()) { 60614c7ef8SJonathan Peyton num_failed++; 61614c7ef8SJonathan Peyton } 62614c7ef8SJonathan Peyton } 63614c7ef8SJonathan Peyton return num_failed; 64614c7ef8SJonathan Peyton } 65614c7ef8SJonathan Peyton 66