- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IVF will not accept having a RETURN or EXITstatement inside a parallel DO OMP loop (it's not legal). I want to do the following:
!$OMP DO
... threads do some work in parallel
... if one thread detects an error condition (say, my algorithm does not converge fast enough), a signal should be sent to all threads to stop their calculations, and all should exit the loop.
!$OMP END DO
How can I achieve this?
Thanks!!
Olivier
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oliver,
use a shared variable
logical :: ExitLoop
...
ExitLoop = .false.
!$OMP DO
...
IF(SomeLogicalErrorExpression) then
ExitLoop = .true.
exit
ENDIF
...
!$OMP END DO
Caution, to not use
ExitLoop = SomeLogicalErrorExpression
as this will/may unset one threads exit condition.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - jimdempseyatthecove
Oliver,
use a shared variable
logical :: ExitLoop
...
ExitLoop = .false.
!$OMP DO
...
IF(SomeLogicalErrorExpression) then
ExitLoop = .true.
exit
ENDIF
...
!$OMP END DO
Caution, to not use
ExitLoop = SomeLogicalErrorExpression
as this will/may unset one threads exit condition.
Jim Dempsey
Jim,
You cannot have an EXIT statement inside a parallelized DO loop...
I am looking for a wayof signaling the threads to stop the (possibly) length calculations they're doing when one of them has encountered a condition that renders any further work useless.
Thanks,
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry about that, then plan B
[cpp] logical :: DoExit integer :: i print *, 'Begin' DoExit = .false. !$omp parallel do do i=1,1000 if(DoExit) cycle print *, i if(iand(i, 15) .eq. 0) DoExit = .true. end do !$omp end parallel do print *, 'End' ------------------------ Begin 1 2 3 4 5 6 7 8 9 501 10 502 11 503 12 504 13 505 14 506 15 507 16 508 End [/cpp]
I can see why GOTO out of the loop should be inhibited. EXIT should not be a problem excepting for potential BARRIER problems. The code above using CYCLE would have the same symptoms should barrier follow the CYCLE.
The BARRIER could be corrected (in implementation) where the EXIT implicitly decrements the number of threads in the team (seperated from the variable held for omp_get_num_threads()). Then the barrier can wait for the remaining number of threads.
Jim Dempsey

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