How to break out of a nested parallel (OpenMP) Fortran loop idiomatically?
- by J.F. Sebastian
Here's sequential code:
do i = 1, n
do j = i+1, n
if ("some_condition") then
result = "here's result"
return
end if
end do
end do
Is there a cleaner way to execute iterations of the outer loop concurrently other than:
!$OMP PARALLEL private(i,j)
!$OMP DO
do i = 1, n
if (found) goto 10
do j = i+1, n
if (found) goto 10
if ("some_condition") then
!$OMP CRITICAL
!$OMP FLUSH
if (.not.found) then
found = .true.
result = "here's result"
end if
!$OMP FLUSH
!$OMP END CRITICAL
goto 10
end if
end do
10 continue
end do
!$OMP END DO NOWAIT
!$OMP END PARALLEL