シーケンシャル コードは次のとおりです。
do i = 1, n
do j = i+1, n
if ("some_condition(i,j)") then
result = "here's result"
return
end if
end do
end do
次以外に、外側のループの反復を同時に実行するためのよりクリーンな方法はありますか?
!$OMP PARALLEL private(i,j)
!$OMP DO
do i = 1, n
!$OMP FLUSH(found)
if (found) goto 10
do j = i+1, n
if ("some_condition(i,j)") then
!$OMP CRITICAL
!$OMP FLUSH(found)
if (.not.found) then
found = .true.
result = "here's result"
end if
!$OMP FLUSH(found)
!$OMP END CRITICAL
goto 10
end if
end do
10 continue
end do
!$OMP END DO NOWAIT
!$OMP END PARALLEL
-loopでの反復の順序は、いくつかi
が見つかる限り、任意である可能性があります ( を満たす限り、実行ごとに変更されても問題ありません)。 result
"some_condition"