首页 文章

COMPILER_OPTIONS()应该在Fortran中返回什么?

提问于
浏览
3

Fortran 2008添加了一个名为COMPILER_OPTIONS()的新过程,根据GNU documentation,该过程应该返回一个字符串,其中包含用于编译文件的选项 . 根据Fortran 2003 status wiki,几乎所有编译器(包括GNU和PGI)似乎都支持此功能 .

我创建了一个简单的程序 COMPILER_OPTIONS.f08 如下所示

use iso_fortran_env
   print '(4a)', 'This file was compiled by using the options ', compiler_options()
end

以下是 gfortranpgfortran 的结果

Gfortran 5.4 with no compile time options

$ gfortran COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options -mtune=generic -march=x86-64

Gfortran 5.4 with -O3 passed at compile time

$ gfortran -O3 COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options -mtune=generic -march=x86-64 -O3

PGI 17.4 with no option passed at compile time

$ pgfortran COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options COMPILER_OPTIONS.f08

PGI 17.4 with -O3 passed at compile time

$ pgfortran -O3 COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options COMPILER_OPTIONS.f08 -O3 -Mvect=sse -Mcache_align -Mpre

鉴于以上输出,我有以下问题

  • 根据Fortran 2008,预期返回的COMPILER_OPTIONS()过程是什么?

  • 不同编译器的支持状态如何?

EDIT :从-o3(输出文件3)将标志更改为-O3(优化级别3) . 感谢Pierre和francescalus的反馈 .

1 回答

  • 4

    Fortran 2008将函数描述为(13.8.2.6):

    依赖于处理器的字符串,描述控制程序转换阶段的选项 .

    此函数返回“具有处理器相关长度的默认字符标量” .

    这对编译器来说是一个非常大的自由 . 此处提供的结果没有任何迹象表明存在任何不合规情况 .

相关问题