How to parallelize DO loop with EXIT statement?

General OpenMP discussion

How to parallelize DO loop with EXIT statement?

Postby pir0texnik » Thu Mar 27, 2008 5:15 am

I have a code:
Code: Select all
Loop_pq: do m=0,M_max,1
      if ( zabs(ye_circ_out-Y_old)<errrel )  exit Loop_pq
end do  Loop_pq

but I cannot compile it because of

Code: Select all
1>Compiling with Intel(R) Fortran Compiler 10.1.019 [IA-32]...
1>Error: A RETURN, EXIT or CYCLE statement is not legal in a DO loop associated with a parallel directive.

If I simplify this loop by deleting it name I get another error
Code: Select all
1>fortcom: Fatal: There has been an internal compiler error (C0000005).

I use the MSVS2005 environment, the code is compiled with the command line
Code: Select all
/nologo /O3 /Og /QaxT /QxT /Qparallel /Qpar_threshold:2 /Qopenmp /module:"Release\\" /object:"Release\\" /libs:dll /threads /c /Qfpp

How to solve this problem? Thank you!!

Re: How to parallelize DO loop with EXIT statement?

Postby ejd » Thu Mar 27, 2008 9:57 am

When trying to parallelize a DO loop, you can not use RETURN, EXIT, or CYCLE. The problem is, that you have multiple threads running at the same time and there is no easy way to coordinate these actions. In your example using EXIT, one thread would try and exit the loop, but the rest of the threads would still be executing the chunk of iterations they were "assigned". The error message that the Intel compiler is putting out is correct. The internal compiler error is a problem with the Intel compiler, but when fixed, it should put out the same message that you received the first time (when you compiled using labels).

Unfortunately, I don't have a good solution for your problem. Once the threads start work on a workshare DO, they are assigned chunks of work and they are going to complete that work. About all you can do is short-circuit the work by having another variable around and check to see if you need to do the work. If you don't, then you can skip to the next iteration, but there is no way to stop all the iterations from being done.

Sorry. Maybe someone else has an answer for you - though so far this has been a pretty quiet bunch.
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 2 guests