Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset cancellation status for 'parallel', 'sections' and 'for' constr…
…acts. Without this fix cancellation status for parallel, sections and for persists across construct boundaries. Differential Revision: https://reviews.llvm.org/D31419 llvm-svn: 299434
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 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,61 @@ | ||
// RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run | ||
// Regression test for a bug in cancellation to cover effect of `#pragma omp cancel` | ||
// in a loop construct, on sections construct. | ||
// Pass condition: Cancellation status from `for` does not persist | ||
// to `sections`. | ||
|
||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
int result[2] = {0, 0}; | ||
|
||
void cq416850_for_sections() { | ||
|
||
unsigned i; | ||
// 1) loop | ||
#pragma omp for | ||
for (i = 0; i < 1; i++) { | ||
result[0] = 1; | ||
#pragma omp cancel for | ||
result[0] = 2; | ||
} | ||
|
||
// printf("thread %d: result[0] = %d, result[1] = %d \n", omp_get_thread_num(), result[0], result[1]); | ||
|
||
|
||
// 2) sections | ||
#pragma omp sections | ||
{ | ||
#pragma omp section | ||
{ | ||
result[1] = 1; | ||
#pragma omp cancellation point sections | ||
result[1] = 2; | ||
} | ||
} | ||
} | ||
|
||
int main(void) { | ||
if(!omp_get_cancellation()) { | ||
printf("Cancellation not enabled!\n"); | ||
return 2; | ||
} | ||
|
||
#pragma omp parallel num_threads(4) | ||
{ | ||
cq416850_for_sections(); | ||
} | ||
|
||
if (result[0] != 1 || result[1] != 2) { | ||
printf("Incorrect values. " | ||
"result[0] = %d (expected 1), " | ||
"result[1] = %d (expected 2).\n", | ||
result[0], result[1]); | ||
printf("FAILED\n"); | ||
return 1; | ||
} | ||
|
||
printf("PASSED\n"); | ||
return 0; | ||
} | ||
|