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