1

So am writing a bit of parallel code in Fortran, but I need to use the critical block to prevent a race condition. Here's a bare-bones version of my code (it's an optimizer):

do i=2,8,2
    do j=1,9-i
        Ftemp=1.0e20  !A large number
        !$OMP parallel do default(shared) private(...variables...)
        do k=1,N
            ###Some code that calculates variable Fobj###

            !$OMP Critical
            !$OMP Flush(Ftemp,S,Fv)     !Variables I want optimized
            if (Fobj.lt.Ftemp) then
                S=Stemp
                Fv=Ft
                Ftemp=Fobj
            end if
            !OMP Flush(Ftemp,S,Fv)
            !OMP end Critical

        end do                   !Line 122
        !$OMP end parallel do    !Line 123
     end do
 end do

So without openmp, the code works fine. It also runs without the critical commands (Flush commands are fine). The error I get is "unexpected END statement" on Line 122 and "Unexpected !$OMP end parallel do statement" on line 123. I have no idea why this won't work as the critical block is fully contained inside the parallel loop and there are no exit/goto statements that will leave or enter either... some gotos jump around the main part of the loop, but never leaving it or entering/bypassing the critical block.

4
  • 2
    What's the point of the 2 flush directives, since critical implies a full flush upon entry and exit of the region? I doubt this has anything to do with your problem, however, if only for the clarity of the code, the 2 flush directives should be removed. Commented Dec 8, 2015 at 20:46
  • Which compiler do you use? Are you sure you copied the code exactly? Commented Dec 8, 2015 at 22:16
  • 4
    Your closing directive !OMP end Critical is missing a $ right after the !. Commented Dec 8, 2015 at 22:25
  • 2
    As @HristoIliev's comment makes clear this seems to be the result of a simple typo. Voting to close. Commented Dec 10, 2015 at 11:40

1 Answer 1

1

As Hristo Iliev points out in the comment: Your closing directive !OMP end Critical is missing a $ right after the !.

It is treated just as a comment and ignored.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.