The following code is accepted – while clang errors with: test.c:18:5: error: exactly one 'ordered' directive must appear in the loop body of an enclosing directive Cf. "Additional restrictions to the block-associated ordered construct are as follows:" ... "During execution of the logical iteration of a loop-associated construct, a thread must not execute more than one block-associated ordered region that binds to the corresponding region of the loop-associated construct." int a[10]; void foo(int n) { #if 0 #pragma omp for ordered schedule(static) #pragma omp unroll partial(2) for(int i = 1; i < n; i++) { #pragma omp ordered a[i] += a[i-1]; } // -> #endif #pragma omp for ordered schedule(static) for(int i = 1; i < n; i += 2) { #pragma omp ordered a[i] += a[i-1]; #pragma omp ordered a[i+1] += a[i]; } }
This is not easy, because it is only invalid if one ordered dominates the other (so we need cfg to find that out) and further more it is an execution time restriction, so it is unclear if we can error, perhaps just warn?
Even the dominating case could be valid. E.g. if the body does #pragma omp ordered foo (); bar (); #pragma omp ordered baz (); where bar () calls exit (0);