Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trip count calculation for parallel loops in runtime
The trip count calculation was incorrect for loops with large bounds. For example, for(int i=-2,000,000,000; i < 2,000,000,000; i+=50000000), the trip count calculation had overflow (trying to calculate 2,000,000,000 + 2,000,000,000 with signed integers) and wasn't giving the right value. This patch fixes this error in the runtime by using unsigned integers instead. There is still a bug in the clang compiler component because it warns that there is overflow in the test case file when there isn't. This error isn't there for the Intel Compiler. So for now, the test case is designated as XFAIL. Differential Revision: http://reviews.llvm.org/D19078 llvm-svn: 266677
- Loading branch information
Showing
3 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// RUN: %libomp-compile -DMY_SCHEDULE=static && %libomp-run | ||
// RUN: %libomp-compile -DMY_SCHEDULE=dynamic && %libomp-run | ||
// RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run | ||
// XFAIL: * | ||
/* | ||
* Test that large bounds are handled properly and calculations of | ||
* loop iterations don't accidently overflow | ||
*/ | ||
#include <stdio.h> | ||
#include <omp.h> | ||
#include <stdlib.h> | ||
#include <limits.h> | ||
#include "omp_testsuite.h" | ||
|
||
#define INCR 50000000 | ||
#define MY_MAX 2000000000 | ||
#define MY_MIN -2000000000 | ||
#ifndef MY_SCHEDULE | ||
# define MY_SCHEDULE static | ||
#endif | ||
|
||
int a, b, a_known_value, b_known_value; | ||
|
||
int test_omp_for_bigbounds() | ||
{ | ||
a = 0; | ||
b = 0; | ||
#pragma omp parallel | ||
{ | ||
int i; | ||
#pragma omp for schedule(MY_SCHEDULE) | ||
for (i = INT_MIN; i < MY_MAX; i+=INCR) { | ||
#pragma omp atomic | ||
a++; | ||
} | ||
#pragma omp for schedule(MY_SCHEDULE) | ||
for (i = INT_MAX; i >= MY_MIN; i-=INCR) { | ||
#pragma omp atomic | ||
b++; | ||
} | ||
} | ||
printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value, b, b_known_value); | ||
return (a == a_known_value && b == b_known_value); | ||
} | ||
|
||
int main() | ||
{ | ||
int i; | ||
int num_failed=0; | ||
|
||
a_known_value = 0; | ||
for (i = INT_MIN; i < MY_MAX; i+=INCR) { | ||
a_known_value++; | ||
} | ||
|
||
b_known_value = 0; | ||
for (i = INT_MAX; i >= MY_MIN; i-=INCR) { | ||
b_known_value++; | ||
} | ||
|
||
for(i = 0; i < REPETITIONS; i++) { | ||
if(!test_omp_for_bigbounds()) { | ||
num_failed++; | ||
} | ||
} | ||
return num_failed; | ||
} |