GNU Fortran compiler: Difference between revisions

From Geos-chem
Jump to navigation Jump to search
Line 46: Line 46:


|-valign="top"
|-valign="top"
|<tt>-fautomatic</tt>
|<code>-fautomatic</code>
|This option places local variables (scalars and arrays of all types), except those declared as SAVE, on the run-time stack.  It is as if the variables were declared with the AUTOMATIC attribute.  It does not affect variables that have the SAVE attribute or ALLOCATABLE attribute, or variables that appear in an EQUIVALENCE statement or in a common block.
|This option places local variables (scalars and arrays of all types), except those declared as SAVE, on the run-time stack.  It is as if the variables were declared with the AUTOMATIC attribute.  It does not affect variables that have the SAVE attribute or ALLOCATABLE attribute, or variables that appear in an EQUIVALENCE statement or in a common block.
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<tt>-fconvert=big_endian</tt>
|<code>-fconvert-big-endian</code>
|Specifies that the format will be big endian for integer data and big endian IEEE floating-point for real and complex data.  This only affects file I/O to/from binary files (such as binary punch files) but not ASCII, netCDF, or other file formats.
|Specifies that the format will be big endian for integer data and big endian IEEE floating-point for real and complex data.  This only affects file I/O to/from binary files (such as binary punch files) but not ASCII, netCDF, or other file formats.
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<tt>-fno-align-commons</tt>
|<code>-fno-align-commons</code>
|Prevents the compiler from padding bytes anywhere in common blocks and structures.  Padding can affect numerical precision.
|Prevents the compiler from padding bytes anywhere in common blocks and structures.  Padding can affect numerical precision.
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<tt>-O3</tt>
|<code>-O3</code>
|Optimizes the source code for speed, without taking too many liberties with numerical precision.  For more information, please see the [[#Optimization options|optimization options section above]].
|Optimizes the source code for speed, without taking too many liberties with numerical precision.  For more information, please see the [[#Optimization options|optimization options section above]].
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<tt>-funroll loops</tt>
|<code>-funroll-loops</code>
|Optimizes the source code for speed, without taking too many liberties with numerical precision. For more information, please see the [[#Optimization options|optimization options section above]].
|Typically improves performance on code using iterative DO loops by unrolling them and is probably generally appropriate for Fortran, though it is not turned on at any optimization level. Note that outer loop unrolling isn't done specifically; decisions about whether to unroll a loop are made on the basis of its instruction count.
 
Also, no `loop discovery'1 is done, so only loops written with DO benefit from loop optimizations, including—but not limited to—unrolling. Loops written with IF and GOTO are not currently recognized as such. This option unrolls only iterative DO loops, not DO WHILE loops.  
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<tt>-fp-model source</tt>
|<code>-fp-model source</code>
|Rounds intermediate results to source-defined precision and enables value-safe optimizations.  Basically, this tells the compiler not to take too many liberties with how numerical expressions are evaluated.  For more information about this option, please see our [[#Precision-safe optimization|precision-safe optimization section]] below.  This option can be disabled by compiling GEOS-Chem with the <tt>PRECISE=no</tt> Makefile option.
|Rounds intermediate results to source-defined precision and enables value-safe optimizations.  Basically, this tells the compiler not to take too many liberties with how numerical expressions are evaluated.  For more information about this option, please see our [[#Precision-safe optimization|precision-safe optimization section]] below.  This option can be disabled by compiling GEOS-Chem with the <tt>PRECISE=no</tt> Makefile option.
|Default setting
|Default setting
Line 81: Line 83:


|-valign="top"
|-valign="top"
|<tt>-r8</tt>
|<tt>-fdefault-real-8</tt>
|This option tells the compiler to treat variables that are declared as <tt>REAL</tt> as <tt>REAL*8</tt> (as opposed to <tt>REAL*4</tt>.
|This option tells the compiler to treat variables that are declared as <tt>REAL</tt> as <tt>REAL*8</tt>
 
''NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA.  Current GEOS-Chem programming practice is to use either <tt>REAL*4</tt> or <tt>REAL*8</tt> instead of <tt>REAL</tt>, which avoids confusion.''
|Used as needed
 
|-valign="top"
|<tt>-fdefault-real-8</tt>
|This option tells the compiler to treat variables that are declared as <tt>REAL</tt> as <tt>REAL*8</tt>


''NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA.  Current GEOS-Chem programming practice is to use either <tt>REAL*4</tt> or <tt>REAL*8</tt> instead of <tt>REAL</tt>, which avoids confusion.''
''NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA.  Current GEOS-Chem programming practice is to use either <tt>REAL*4</tt> or <tt>REAL*8</tt> instead of <tt>REAL</tt>, which avoids confusion.''

Revision as of 21:27, 21 September 2016

File:Page is under construction.jpg

Compilation options

Compiler options

Optimization options

Option Description How invoked in GEOS-Chem?

List of commonly-used compilation options

Here are the IFORT compilation options currently used by GEOS-Chem:

Option Description How invoked in GEOS-Chem?
Normal compiler settings
-cpp Turns on the C-preprocessor, to evaluate #if and #define statements in the source code. Default setting
-std=legacy Tells GNU Fortran not to halt compilation when encountering code that does not adhere to the Fortran 95, 2003, or 2008 standards. Gfortran is a much stricter compiler, so turning this option on will tell Gfortran to be more lenient. Default setting
-fautomatic This option places local variables (scalars and arrays of all types), except those declared as SAVE, on the run-time stack. It is as if the variables were declared with the AUTOMATIC attribute. It does not affect variables that have the SAVE attribute or ALLOCATABLE attribute, or variables that appear in an EQUIVALENCE statement or in a common block. Default setting
-fconvert-big-endian Specifies that the format will be big endian for integer data and big endian IEEE floating-point for real and complex data. This only affects file I/O to/from binary files (such as binary punch files) but not ASCII, netCDF, or other file formats. Default setting
-fno-align-commons Prevents the compiler from padding bytes anywhere in common blocks and structures. Padding can affect numerical precision. Default setting
-O3 Optimizes the source code for speed, without taking too many liberties with numerical precision. For more information, please see the optimization options section above. Default setting
-funroll-loops Typically improves performance on code using iterative DO loops by unrolling them and is probably generally appropriate for Fortran, though it is not turned on at any optimization level. Note that outer loop unrolling isn't done specifically; decisions about whether to unroll a loop are made on the basis of its instruction count.

Also, no `loop discovery'1 is done, so only loops written with DO benefit from loop optimizations, including—but not limited to—unrolling. Loops written with IF and GOTO are not currently recognized as such. This option unrolls only iterative DO loops, not DO WHILE loops.

Default setting
-fp-model source Rounds intermediate results to source-defined precision and enables value-safe optimizations. Basically, this tells the compiler not to take too many liberties with how numerical expressions are evaluated. For more information about this option, please see our precision-safe optimization section below. This option can be disabled by compiling GEOS-Chem with the PRECISE=no Makefile option. Default setting
Special compiler settings
-fdefault-real-8 This option tells the compiler to treat variables that are declared as REAL as REAL*8

NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA. Current GEOS-Chem programming practice is to use either REAL*4 or REAL*8 instead of REAL, which avoids confusion.

Used as needed
-fdefault-real-8 This option tells the compiler to treat variables that are declared as REAL as REAL*8

NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA. Current GEOS-Chem programming practice is to use either REAL*4 or REAL*8 instead of REAL, which avoids confusion.

Used as needed
-mcmodel=medium This option is used to tell IFORT to use more than 2GB of static memory. This avoids a specific type of memory error that can occur if you compile GEOS-Chem for use with an extremely high-resolution grid (e.g. 0.25° x 0.3125° nested grid). Default setting
Settings only used for debugging
-debug all Tells the compiler turn on all debug error output. DEBUG=yes
-g Tells the compiler to generate full debugging information in the object file. This will cause a debugger (like Totalview) to display the actual lines of source code, instead of hexadecimal addresses (which is gibberish to anyone except hardware engineers). DEBUG=yes
-O0 Turns off all optimization. Source code instructions (e.g. DO loops, IF blocks) and numerical expressions are evaluated in precisely the order in which they are listed, without being internally rewritten by the optimizer. This is necessary for using a debugger (like Totalview). DEBUG=yes
-fcheck-bounds Check for array-out-of-bounds errors. This is invoked when you compile GEOS-Chem with the BOUNDS=yes Makefile option. NOTE: Only use -CB for debugging, as this option will cause GEOS-Chem to execute more slowly! DEBUG=yes
-fcheck-array-temporaries Checks to see if any array temporaries are created. Depending on how you write your subroutine and function calls, the compiler may need to create a temporary array to hold the values in the array before it passes them to the subroutine. For detailed information, please see our Passing array arguments efficiently in GEOS-Chem wiki page. DEBUG=yes
-Warray-temporaries Prints info about array temporaries. Use in conjunction with -fcheck-array-temporaries DEBUG=yes
-backtrace This option tells the compiler to generate extra information in the object file to provide source file traceback information when a severe error occurs at run time. When the severe error occurs, source file, routine name, and line number correlation information is displayed along with call stack hexadecimal addresses (program counter trace). This option increases the size of the executable program, but has no impact on run-time execution speeds. It functions independently of the debug option. TRACEBACK=yes
-fpe0 This option will cause GEOS-Chem to halt if any type of floating-point error is encountered. This can happen if an equation results in a denormal value, e.g. NaN, or +/-Infinity. Common causes of floating-point errors are divisions where the denominator becomes zero.
NOTE: The default compiler setting is -fpe3, which will convert many of these denormal values to zeros and then continue execution.
FPE=yes
-ftrapuv This option will assign a large numeric value to all local automatic variables. This makes it easier to identify numerical errors caused by improper initialization. FPE=yes

--Bob Y. 11:21, 3 October 2013 (EDT)

Typical settings for a GEOS-Chem simulation

The normal GEOS-Chem build uses the following IFORT compiler flags:

-cpp -w -O2 -auto -noalign -convert big_endian -vec-report0 -fp-model source -openmp

whereas a debugging run (meant to execute in a debugger such as TotalView) will typically use these flags:

-cpp -w -O0 -auto -noalign -convert big_endian -g -DDEBUG -check arg_temp_created -debug all -fp-model source -fpe0 -ftrapuv -check bounds

NOTE: In order to avoid running out of memory if you compiling GEOS-Chem at extremely high resolution (e.g. the 0.25° x 0.3125° nested grids), we recommend adding the following flags:

-mcmodel=medium -shared-intel

These are automatically set when you compile with the NETCDF=yes or HDF=yes compiler options (in GEOS-Chem v9-01-03 and higher).

--Bob Y. 17:34, 29 February 2012 (EST)