Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1689 Discussions

Error Message: "Jump out of OpenMP structured block not allowed"

SergeyKostrov
Valued Contributor II
857 Views

Hi everybody,

Is it possible to jump out of OpenMP structured block? Here is an example:

...
#pragma omp parallel for
for( int i = 0; i < 512; i++ )
{
...
if( i == 255 )
break;
...
}
...

Best regards,
Sergey

0 Kudos
7 Replies
Vladimir_P_Intel2
857 Views
It is not allowed by OpenMP specification. Cancelation is not in specification yet.

I guees you can try tasks from OpenMP 3.0

--Vladimir
SergeyKostrov
Valued Contributor II
857 Views
...
The only options is to have an empty if statement, when your abort condition becomes to true so that the loop does not do anything and executes as fast as possible to its natual end.
...
Until we have added user cancellation to the OpenMP specification (we are making progress here), there is no other option.
...


Thank you, Michael. A solution based on'If-Else' will work.

Best regards,
Sergey

jimdempseyatthecove
Black Belt
857 Views
I think you can set the loop control variable toa termination value.

for(int i=0; i < endVal; ++i)
{
...
if(bailOut)
{
i=endVal;
continue;
}
...
}

Although the running thread may have a different start val from 0 and/or may have a different endVal from endVal, no thread will (in this case) have an endVal larger than original endVal.

(This is valid for C/C++ and not valid for FORTRAN as it loops differently)

Jim Dempsey
SergeyKostrov
Valued Contributor II
857 Views
...
(This is valid for C/C++ and not valid for FORTRAN as it loops differently)

Jim Dempsey


I'm researching thisfor a C/C++ application only. Thanks, Jim.

TimP
Black Belt
857 Views
I suppose you make bailOut a shared variable (does it need to be set in a critical?), so each thread should receive the flag as it reaches that point. If your OpenMP doesn't complain about this, the compiler should avoid any optimizations based on i not being touched by your loop body. However, OpenMP implementations are notoriously poor at flagging violations which will produce unexpected results.
Michael_K_Intel2
Employee
857 Views
Hi all,

Modifying the loop counter is also prohibited by teh OpenMP specification. It works in most implementations, but it makes the program non-conforming and might break the code with different compiler releases.

Cheers,
-michael
SergeyKostrov
Valued Contributor II
857 Views
...It works in most implementations, but it makes the program non-conforming and might break the code

[SergeyK] That's my primary concern...

with different compiler releases...

Cheers,
-michael


Thanks to everybody!

Best regards,
Sergey

Reply