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

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

SergeyKostrov
Valued Contributor II
2,051 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_1234567890
2,051 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
0 Kudos
SergeyKostrov
Valued Contributor II
2,051 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

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,051 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
0 Kudos
SergeyKostrov
Valued Contributor II
2,051 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.

0 Kudos
TimP
Honored Contributor III
2,051 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.
0 Kudos
Michael_K_Intel2
Employee
2,051 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
0 Kudos
SergeyKostrov
Valued Contributor II
2,051 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

0 Kudos
Reply