Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 2797

#pragma omp cancel for compilation error

$
0
0

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
		}
	}
}

 


Viewing all articles
Browse latest Browse all 2797


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>