- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is not allowed by OpenMP specification. Cancelation is not in specification yet.
I guees you can try tasks from OpenMP 3.0
--Vladimir
I guees you can try tasks from OpenMP 3.0
--Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Michael Klemm (Intel)
...
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.
...
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting jimdempseyatthecove
...
(This is valid for C/C++ and not valid for FORTRAN as it loops differently)
Jim Dempsey
(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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Michael Klemm (Intel)
...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
[SergeyK] That's my primary concern...
with different compiler releases...
Cheers,
-michael
Thanks to everybody!
Best regards,
Sergey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page