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