3

Fortran 2008 added a new procedure called COMPILER_OPTIONS() which according to GNU documentation should return a string with the options used for compiling the file. According to Fortran 2003 status wiki, almost all compilers including GNU and PGI seem to support this feature.

I created a simple program COMPILER_OPTIONS.f08 shown below

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

Here are my results from gfortran and pgfortran

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 

Given the above output, I have following questions

  1. What is COMPILER_OPTIONS() procedure expected to return as per Fortran 2008?
  2. What is the status of support across different compilers?

EDIT : Changed flag to -O3 (Optimization Level 3) from -o3 (Output file 3). Thanks to the feedback from Pierre and francescalus.

Oak Bytes
  • 4,649
  • 4
  • 36
  • 53

1 Answers1

4

Fortran 2008 describes the function as (13.8.2.6):

Processor-dependent string describing the options that controlled the program translation phase.

This function returns a "default character scalar with processor-dependent length."

That's an awful lot of freedom for a compiler. There's no indication from the results presented here to suggest any non-compliance.

francescalus
  • 30,576
  • 16
  • 61
  • 96
  • 1
    Agreed, Also, one might ask does the returned string have only the options explicitly specified on the command line or does it include all the other options that are defaults? Intel Fortran now also supports this intrinsic in it's version 18 release. – Steve Lionel Sep 28 '17 at 15:08