1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ifxでのコンパイルの注意点

Last updated at Posted at 2025-04-08

Fortran使いの皆様こんにちは。最近、Intel One API 2025からifortがなくなり、ifxを使う必要が出てきました。

一つセグメンテーションフォルトが起きる事例がありましたので、その回避策とともに紹介します。

integer, optional, intent(in)    :: rec

というoptional引数がある時、

if (present(rec) .and. (rec > 0)) then
    irec = rec - 1
else
   irec = 0
end if

は落ちます。これは、rec > 0を評価しようとして、recが定義されていないからのようです。ifortだと、左を評価してから右を評価してるっぽくて、特に問題はなかったようですが...

    if (present(rec)) then
      if (rec > 0) then
       irec = rec - 1
      end if
    else
       irec = 0
    end if

のようにすると回避できます。

2025/4/9追記

最小構成を作って

module testsub
    contains
subroutine test(k,rec)
    implicit none
    integer,intent(in)::k
    integer,intent(in),optional::rec
    integer::irec

    if (present(rec) .and. (rec > 0)) then
        irec = rec - 1
    else
       irec = 0
    end if

end subroutine test
end module testsub

program main
    use testsub
    implicit none
    integer::k

    k = 3
    call test(k)
end program


色々試していますが、ifortやifxではなく、むしろgfortranで落ちているかもしれません。
gfortran 11だと上のコードがセグフォになることを確認しました。もう少し再現環境について調べます。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?