The following code fails to compile with
error : cancel for must be closely nested in a for region.
I am at a loss here, as this code seems to follow the example in OpenMP 4.0 examples PDF
void causes_an_exception()
{
throw std::logic_error("exception");
}
void example()
{
std::exception *ex = NULL;
bool cancelled = false, failed = false;
int N = 100000;
#pragma omp parallel for
for (int i = 0; i < N; i++) {
// no 'if' that prevents compiler optimizations
try {
causes_an_exception();
}
catch (std::exception *e) {
// still must remember exception for later handling
#pragma omp atomic write
ex = e;
// cancel worksharing construct
#pragma omp cancel for
}
}
}