| 1 |
// RUN: %libomp-compile -DMY_SCHEDULE=static && %libomp-run |
| 2 |
// RUN: %libomp-compile -DMY_SCHEDULE=dynamic && %libomp-run |
| 3 |
// RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run |
| 4 |
|
| 5 |
// Only works with Intel Compiler since at least version 15.0 and clang since |
| 6 |
// version 11. |
| 7 |
|
| 8 |
// XFAIL: gcc, clang-3, clang-4, clang-5, clang-6, clang-7, clang-8, clang-9, clang-10 |
| 9 |
|
| 10 |
// icc 21 seems to have an issue with the loop boundaries and runs very long |
| 11 |
// UNSUPPORTED: icc-21 |
| 12 |
|
| 13 |
/* |
| 14 |
* Test that large bounds are handled properly and calculations of |
| 15 |
* loop iterations don't accidentally overflow |
| 16 |
*/ |
| 17 |
#include <stdio.h> |
| 18 |
#include <omp.h> |
| 19 |
#include <stdlib.h> |
| 20 |
#include <limits.h> |
| 21 |
#include "omp_testsuite.h" |
| 22 |
|
| 23 |
#define INCR 50000000 |
| 24 |
#define MY_MAX 2000000000 |
| 25 |
#define MY_MIN -2000000000 |
| 26 |
#ifndef MY_SCHEDULE |
| 27 |
# define MY_SCHEDULE static |
| 28 |
#endif |
| 29 |
|
| 30 |
int a, b, a_known_value, b_known_value; |
| 31 |
|
| 32 |
int test_omp_for_bigbounds() |
| 33 |
{ |
| 34 |
a = 0; |
| 35 |
b = 0; |
| 36 |
#pragma omp parallel |
| 37 |
{ |
| 38 |
int i; |
| 39 |
#pragma omp for schedule(MY_SCHEDULE) reduction(+:a) |
| 40 |
for (i = INT_MIN; i < MY_MAX; i+=INCR) { |
| 41 |
a++; |
| 42 |
} |
| 43 |
#pragma omp for schedule(MY_SCHEDULE) reduction(+:b) |
| 44 |
for (i = INT_MAX; i >= MY_MIN; i-=INCR) { |
| 45 |
b++; |
| 46 |
} |
| 47 |
} |
| 48 |
printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value, b, b_known_value); |
| 49 |
return (a == a_known_value && b == b_known_value); |
| 50 |
} |
| 51 |
|
| 52 |
int main() |
| 53 |
{ |
| 54 |
int i; |
| 55 |
int num_failed=0; |
| 56 |
|
| 57 |
a_known_value = 0; |
| 58 |
for (i = INT_MIN; i < MY_MAX; i+=INCR) { |
| 59 |
a_known_value++; |
| 60 |
} |
| 61 |
|
| 62 |
b_known_value = 0; |
| 63 |
for (i = INT_MAX; i >= MY_MIN; i-=INCR) { |
| 64 |
b_known_value++; |
| 65 |
} |
| 66 |
|
| 67 |
for(i = 0; i < REPETITIONS; i++) { |
| 68 |
if(!test_omp_for_bigbounds()) { |
| 69 |
num_failed++; |
| 70 |
} |
| 71 |
} |
| 72 |
return num_failed; |
| 73 |
} |