[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / openmp / runtime / test / tasking / omp_taskloop_grainsize.c
blobf1812bd7d0be432c9ad0700c084d4af0f6ff129e
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
7 // UNSUPPORTED: gcc-6
9 /*
10 * Test for taskloop
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
15 #include <stdio.h>
16 #include <omp.h>
17 #include <stdlib.h>
18 #include "omp_testsuite.h"
20 #define CFDMAX_SIZE 1120
22 int test_omp_taskloop_grainsize()
24 int result = 0;
25 int i, grainsize, count, tmp_count, num_off;
26 int *tmp, *tids, *tidsArray;
28 tidsArray = (int *)malloc(sizeof(int) * CFDMAX_SIZE);
29 tids = tidsArray;
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) {
36 tids[i] = -1;
39 #pragma omp parallel shared(tids)
41 #pragma omp master
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) {
49 if (tids[i] == -1) {
50 fprintf(stderr, " Iteration %d not touched!\n", i);
51 result++;
55 for (i = 0; i < CFDMAX_SIZE - 1; ++i) {
56 if (tids[i] != tids[i + 1]) {
57 count++;
61 tmp = (int *)malloc(sizeof(int) * (count + 1));
62 tmp[0] = 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");
68 break;
70 if (tids[i] != tids[i + 1]) {
71 tmp_count++;
72 tmp[tmp_count] = 1;
73 } else {
74 tmp[tmp_count]++;
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) {
85 num_off++;
89 if (num_off > 1) {
90 fprintf(stderr, " The number of bad chunks is %d\n", num_off);
91 result++;
92 } else {
93 fprintf(stderr, " Everything ok\n");
96 free(tmp);
98 free(tidsArray);
99 return (result==0);
102 int main()
104 int i;
105 int num_failed=0;
107 for (i = 0; i < REPETITIONS; i++) {
108 if (!test_omp_taskloop_grainsize()) {
109 num_failed++;
112 return num_failed;