[llvm-bugs] [Bug 50129] New: omp cancel parallel not working as expected
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Apr 26 16:15:34 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50129
Bug ID: 50129
Summary: omp cancel parallel not working as expected
Product: clang
Version: trunk
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: OpenMP
Assignee: unassignedclangbugs at nondot.org
Reporter: michael.p.rice at intel.com
CC: llvm-bugs at lists.llvm.org
The following test shows 'omp cancel' is not working as expected. Run with:
OMP_CANCELLATION=true ./a.out
It should quickly print:
Cancel happened as you would expect!
Clang will not cancel.
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
// Run with environment variable: OMP_CANCELLATION=true
int main(int argc, char **argv) {
int* array;
int nthreads, i, j;
#pragma omp parallel
#pragma omp single nowait
nthreads = omp_get_num_threads();
array = (int*)malloc(sizeof(int)*nthreads);
for (i = 0; i < nthreads; ++i)
array[i] = 0;
assert(omp_get_cancellation() && "Need to set OMP_CANCELLATION=true");
#pragma omp parallel
{
int tid = omp_get_thread_num();
if (tid == 0) {
// Master signals other threads that cancellation is in order
// This thread will go to end of parallel right here
// not at the cancellation point below
#pragma omp cancel parallel
}
// Have worker threads sleep here for "long enough"
usleep(1000000);
#pragma omp barrier
array[tid] = 1;
}
int errors = 0;
for (i = 0; i < nthreads; ++i) {
if (array[i] != 0) {
printf("Thread %d made it through unexpectedly!\n", i);
errors++;
}
}
if (errors) {
printf("%d errors occurred!\n", errors);
exit(1);
}
printf("Cancel happened as you would expect!\n");
return 0;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210426/f62e47fd/attachment.html>
More information about the llvm-bugs
mailing list