I was looking at a program using the FORTRAN version of OPENMP. There I encountered a rather strange construct. For making a "do" loop parallel the following construct was used
count = 0
!$OMP PARALLEL
do
if (count > N ) exit
!$OMP CRITICAL
count = count + 1
!$OMP END CRITICAL
call WORK ! do some work here
end do
!$OMP END PARALLEL
I am not really sure, whether the above code is really making the do loop parallel. I know that the standard method of doing this is to use the following work sharing construct.
!$OMP PARALLEL
!$OMP DO
do count = 1,N
call WORK ! do some work here
end do
!$OMP ENDDO
!$OMP END PARALLEL
I have tested both possibilities, by implementing the standard work-sharing construct, and observed some speedup, when using it. I can imagine that the $OMP CRITICAL construct might be acting as a bottle neck and causing some slowing down. I think that using the non standard method for work sharing, might be beneficial if threads were executing at different speed. However, I am not really sure how accurate my thoughts are.
Thank you in advance
Alex