Let's start by saying that I regard this as a misdesign in OpenMP. However, both gcc and Sun/Oracle disagree with Intel ifort. NAG regards it as a user error. However, my reading is that it is legal, and I quote the specification later. No, I didn't write it, but it was written as a horrible example following a debate about what OpenMP actually permits.
i = 42
!$OMP PARALLEL SHARED(i) NUM_THREADS(5)
x(i) = 0
!$OMP END SINGLE
!$OMP END CRITICAL
!$OMP END PARALLEL
gfortran and Sun print 201, 5 times. Intel prints 42, 5 times.
Let's use OpenMP 3.1, as I have it to hand.
188.8.131.52 page 85, lines 21-22 "Variables with predetermined data-sharing attributes may not be listed in data-sharing attribute clauses, except for the cases listed below."
184.108.40.206 page 86, lines 3-5 "Variables used as loop iteration variables in sequential loops in a parallel or task construct may be listed in data-sharing clauses on the construct itself, and on enclosed constructs, subject to other restrictions."
A.9 page 182 Example A.9.2f.
Comments (other than "Ugh"!) gratefully accepted!