Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test taskyield directive. First generate a set of tasks and pause it immediately. Then we resume half of them and check whether they are scheduled by different threads</ompts:testdescription> |
| 3 | <ompts:ompversion>3.0</ompts:ompversion> |
| 4 | <ompts:directive>omp taskyield</ompts:directive> |
| 5 | <ompts:dependences>omp taskwait</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | #include <math.h> |
| 9 | #include "omp_testsuite.h" |
| 10 | #include "omp_my_sleep.h" |
| 11 | |
| 12 | int <ompts:testcode:functionname>omp_taskyield</ompts:testcode:functionname>(FILE * logFile){ |
| 13 | |
| 14 | <ompts:orphan:vars> |
| 15 | int i; |
| 16 | int count = 0; |
| 17 | int start_tid[NUM_TASKS]; |
| 18 | int current_tid[NUM_TASKS]; |
| 19 | </ompts:orphan:vars> |
| 20 | for (i=0; i< NUM_TASKS; i++){ |
| 21 | start_tid[i]=0; |
| 22 | current_tid[i]=0; |
| 23 | } |
| 24 | |
| 25 | #pragma omp parallel |
| 26 | { |
| 27 | #pragma omp single |
| 28 | { |
| 29 | for (i = 0; i < NUM_TASKS; i++) { |
| 30 | <ompts:orphan> |
| 31 | int myi = i; |
| 32 | <ompts:check>#pragma omp task untied</ompts:check> |
| 33 | { |
| 34 | my_sleep(SLEEPTIME); |
| 35 | start_tid[myi] = omp_get_thread_num(); |
| 36 | |
| 37 | #pragma omp taskyield |
| 38 | |
| 39 | if((start_tid[myi] %2) ==0){ |
| 40 | my_sleep(SLEEPTIME); |
| 41 | current_tid[myi] = omp_get_thread_num(); |
| 42 | } /*end of if*/ |
| 43 | } /* end of omp task */ |
| 44 | </ompts:orphan> |
| 45 | } /* end of for */ |
| 46 | } /* end of single */ |
| 47 | } /* end of parallel */ |
| 48 | |
| 49 | for (i=0;i<NUM_TASKS; i++) |
| 50 | { |
| 51 | //printf("start_tid[%d]=%d, current_tid[%d]=%d\n",i, start_tid[i], i , current_tid[i]); |
| 52 | if (current_tid[i] == start_tid[i]) |
| 53 | count++; |
| 54 | } |
| 55 | return (count<NUM_TASKS); |
| 56 | } |
| 57 | </ompts:testcode> |
| 58 | |
| 59 | </ompts:test> |