1 // RUN: %libomp-compile-and-run 2 // RUN: %libomp-compile && env KMP_TASKLOOP_MIN_TASKS=1 %libomp-run 3 // REQUIRES: openmp-4.5 4 5 // These compilers don't support the taskloop construct 6 // UNSUPPORTED: gcc-4, gcc-5, icc-16 7 8 /* 9 * Test for taskloop 10 * Method: caculate how many times the iteration space is dispatched 11 * and judge if each dispatch has the requested grainsize 12 * It is possible for two adjacent chunks are executed by the same thread 13 */ 14 #include <stdio.h> 15 #include <omp.h> 16 #include <stdlib.h> 17 #include "omp_testsuite.h" 18 19 #define CFDMAX_SIZE 1120 20 21 int test_omp_taskloop_num_tasks() 22 { 23 int i; 24 int *tids; 25 int *tidsArray; 26 int count; 27 int result = 0; 28 int num_tasks; 29 30 for (num_tasks = 1; num_tasks < 120; ++num_tasks) { 31 count = 0; 32 tidsArray = (int *)malloc(sizeof(int) * CFDMAX_SIZE); 33 tids = tidsArray; 34 35 #pragma omp parallel shared(tids) 36 { 37 int i; 38 #pragma omp master 39 #pragma omp taskloop num_tasks(num_tasks) 40 for (i = 0; i < CFDMAX_SIZE; i++) { 41 tids[i] = omp_get_thread_num(); 42 } 43 } 44 45 for (i = 0; i < CFDMAX_SIZE - 1; ++i) { 46 if (tids[i] != tids[i + 1]) { 47 count++; 48 } 49 } 50 51 if (count > num_tasks) { 52 fprintf(stderr, "counted too many tasks: (wanted %d, got %d)\n", 53 num_tasks, count); 54 result++; 55 } 56 } 57 58 return (result==0); 59 } 60 61 int main() 62 { 63 int i; 64 int num_failed=0; 65 66 for (i = 0; i < REPETITIONS; i++) { 67 if (!test_omp_taskloop_num_tasks()) { 68 num_failed++; 69 } 70 } 71 return num_failed; 72 } 73