1 // RUN: %libomp-compile-and-run
2 // RUN: %libomp-compile && env KMP_TASKLOOP_MIN_TASKS=1 %libomp-run
4 // These compilers don't support the taskloop construct
5 // UNSUPPORTED: gcc-4, gcc-5, icc-16
6 // GCC 6 has support for taskloops, but at least 6.3.0 is crashing on this test
11 * Method: calculate how many times the iteration space is dispatched
12 * and judge if each dispatch has the requested grainsize
13 * It is possible for two adjacent chunks are executed by the same thread
18 #include "omp_testsuite.h"
20 #define CFDMAX_SIZE 1120
22 int test_omp_taskloop_grainsize()
25 int i
, grainsize
, count
, tmp_count
, num_off
;
26 int *tmp
, *tids
, *tidsArray
;
28 tidsArray
= (int *)malloc(sizeof(int) * CFDMAX_SIZE
);
31 for (grainsize
= 1; grainsize
< 48; ++grainsize
) {
32 fprintf(stderr
, "Grainsize %d\n", grainsize
);
33 count
= tmp_count
= num_off
= 0;
35 for (i
= 0; i
< CFDMAX_SIZE
; ++i
) {
39 #pragma omp parallel shared(tids)
42 #pragma omp taskloop grainsize(grainsize)
43 for (i
= 0; i
< CFDMAX_SIZE
; i
++) {
44 tids
[i
] = omp_get_thread_num();
48 for (i
= 0; i
< CFDMAX_SIZE
; ++i
) {
50 fprintf(stderr
, " Iteration %d not touched!\n", i
);
55 for (i
= 0; i
< CFDMAX_SIZE
- 1; ++i
) {
56 if (tids
[i
] != tids
[i
+ 1]) {
61 tmp
= (int *)malloc(sizeof(int) * (count
+ 1));
64 for (i
= 0; i
< CFDMAX_SIZE
- 1; ++i
) {
65 if (tmp_count
> count
) {
66 printf("--------------------\nTestinternal Error: List too "
67 "small!!!\n--------------------\n");
70 if (tids
[i
] != tids
[i
+ 1]) {
78 // is grainsize statement working?
79 int num_tasks
= CFDMAX_SIZE
/ grainsize
;
80 int multiple1
= CFDMAX_SIZE
/ num_tasks
;
81 int multiple2
= CFDMAX_SIZE
/ num_tasks
+ 1;
82 for (i
= 0; i
< count
; i
++) {
83 // it is possible for 2 adjacent chunks assigned to a same thread
84 if (tmp
[i
] % multiple1
!= 0 && tmp
[i
] % multiple2
!= 0) {
90 fprintf(stderr
, " The number of bad chunks is %d\n", num_off
);
93 fprintf(stderr
, " Everything ok\n");
107 for (i
= 0; i
< REPETITIONS
; i
++) {
108 if (!test_omp_taskloop_grainsize()) {