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