When I use cancel directive (since OpenMP 4.0) to break parallel loop within parallel for construct, GCC 5.1 warns "'#pragma omp cancel for' inside 'nowait' for construct" for the following snippet.
const int N = 10000;
int main()
{
#pragma omp parallel for
for (int i = 0; i < N; i++) {
#pragma omp cancel for // <-- here
}
}
http://coliru.stacked-crooked.com/a/de5c52da5a16c154
For workaround, when I split to parallel + for constructs, GCC accepts the code silently.
int main()
{
#pragma omp parallel
#pragma omp for
for (int i = 0; i < N; i++) {
#pragma omp cancel for
}
}
But I don't know why GCC warns the former case, nevertheless the construct has no 'nowait' clause.
OpenMP 4.0 API spec also says that parallel for is equal to parallel + for constructs.
2.10.1 Parallel Loop Construct
Description
The semantics are identical to explicitly specifying a
paralleldirective immediately followed by afordirective.
Is GCC's behavior correct? or something wrong?
parallel forandparallelfollowed by aforare similar, acancelconstruct allows only one clause...methinks the compiler reads the clause followed by acanceland checks what was the enclosing construct, in your first example it is aparallel forand not afor, hence the compiler throws that error. Just my 2 cents. - Sayan