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