この問題を抱えたのはあなたが最初ではありません。標準のこの欠陥は Fortran 2015 で修正される予定です。 「プロシージャ内のステートメントの出現に関する制限はerror stop
pure
削除する必要があります」 .
Fortran 2008 標準にはerror stop
、いくつかの新しい並列計算機能のコンテキストにステートメントが含まれていました。エラーを通知し、実行可能な限りすぐにすべてのプロセスを停止します。現在、どちらのstop
ステートメントerror stop
もpure
プロシージャでは許可されていません。これは明らかにスレッドセーフではないためです。実際には、内部エラーが発生した場合、これは不必要に制限的になります。
コンパイラによっては、実装を辛抱強く待つ必要がある場合があります。Intelがifortコンパイラに実装していることを知っています。( "F2015: PURE/ELEMENTAL 手順での STOP および ERROR STOP の制限解除" )
別
別のアプローチについては、この質問を見ることができますが、do concurrent
あなたの場合、pure
.
(正解終わり)
汚れた手がオプションである場合...
それまでの間、あなたは次のような残忍なことをすることができます
pure subroutine internal_error(error_msg)
! Try hard to produce a runtime error, regardless of compiler flags.
! This is useful in pure subprograms where you want to produce an error,
! preferably with a traceback.
!
! Though far from pretty, this solution contains all the ugliness in this
! single subprogram.
!
! TODO: replace with ERROR STOP when supported by compiler
implicit none
character(*), intent(in) :: error_msg
integer, dimension(:), allocatable :: molested
allocate(molested(2))
allocate(molested(2))
molested(3) = molested(4)
molested(1) = -10
molested(2) = sqrt(real(molested(1)))
deallocate(molested)
deallocate(molested)
molested(3) = molested(-10)
end subroutine internal_error
誰かが尋ねたとしても、あなたはこれを私から得たのではありません。