GNU Fortran compiler: Difference between revisions

From Geos-chem
Jump to navigation Jump to search
No edit summary
 
(219 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Image:Page is under construction.jpg]]
__FORCETOC__
'''''[[Supported compilers for GEOS-Chem|Previous]] | [[Intel Fortran Compiler|Next]] | [[Guide to compilers for GEOS-Chem]]'''''
 
#[[Supported compilers for GEOS-Chem]]
#<span style="color:blue">'''The GNU Fortran compiler (gfortran)'''</span>
#[[Intel Fortran Compiler|The Intel Fortran compiler (ifort, ifx)]]
#[[Fortran language resources]]
 
 
On this page, we discuss compiling GEOS-Chem with the GNU Fortran compiler (aka <tt>gfortran</tt>). 
 
'''''The GNU Fortran compiler is our recommended open-source compiler for GEOS-Chem.'''''
 
== Featured tutorial videos ==
 
The following tutorial at our GEOS-Chem YouTube channel ([http://youtube.geos-chem.org '''youtube.geos-chem.org''']) demonstrates how to build GNU Fortran with Spack:
 
{| border="1" cellspacing=0 cellpadding=5
|-valign="top" align="center"
|[[Image:Spack_1_thumbnail.png]]<br>[https://www.youtube.com/watch?v=7eMLYKLK9wY '''<big>Click HERE to view!</big>'''!]
|}
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:20, 16 January 2020 (UTC)
 
== Overview ==
 
We have added several modifications to facilitate compiling GEOS-Chem with the GNU Fortran (aka <tt>gfortran</tt> compiler).    In the process, we have also corrected some coding issues that were flagged by GNU Fortran.  These changes will be added to the v11-01 public release code.
 
=== GNU Fortran versions tested with GEOS-Chem ===
 
The [https://geoschem.github.io/support-team GEOS-Chem Support Team] has experimented using different versions of GNU Fortran to build GEOS-Chem.  Here is the compatibility matrix of GEOS-Chem versions vs. supported GNU Fortran compiler versions.
 
{| border=1 cellspacing=0 cellpadding=5
 
|- bgcolor="#CCCCCC" valign="top"
!width="150px" rowspan="2"|GEOS-Chem version
!colspan="9"|GNU Fortran version
|- bgcolor="#CCFFFF" valign="top"
!width="50px"|4.8.2
!width="50px"|5.2.0
!width="50px"|6.2.0
!width="50px"|7.*.*
!width="50px"|8.*.*
!width="50px"|9.*.*
!width="50px"|10.*.*
!width="50px"|11.*.*
!width="50px"|12.*.*
 
|-valign="top"
|13.0.* and later
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
 
|-valign="top"
|12.9.*
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.8.*
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.7.*
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.6.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.5.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.4.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.3.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.2.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|12.1.*
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="00FF00"|
|bgcolor="FF0000"|
 
|-valign="top"
|[[GEOS-Chem v11-01|v11-01]]
|bgcolor="00FF00"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
 
|-valign="top"
|[[GEOS-Chem v10-01|v10-01]] and prior
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
|bgcolor="FF0000"|
 
|}
 
We invite you to test with other versions of GNU Fortran.  Please send your results to the [https://geoschem.github.io support-team.html GEOS-Chem Support Team].
 
== Environment settings for GNU Fortran ==
 
Here is some information about how you can customize your Linux environment to use the GNU Fortran compiler.  This information was recently migrated to our [https://geos-chem.readthedocs.io geos-chem.readthedocs.io] manual.
 
* [https://geos-chem.readthedocs.io/en/latest/getting-started/login-env-files-gnu.html Create an environment file for GNU compilers]
* [https://geos-chem.readthedocs.io/en/latest/getting-started/login-env-compilers.html Set environment variables for compilers]
* [https://geos-chem.readthedocs.io/en/latest/getting-started/login-env-parallel.html Set environment variables for parallelization]


== Compilation options ==
== Compilation options ==
Line 21: Line 223:
=== List of commonly-used compilation options ===
=== List of commonly-used compilation options ===


Here are the GNU Fortran compilation options currently used by GEOS-Chem:
Here are the GNU Fortran compilation options currently used by GEOS-Chem.  For a complete list of options, please see the [https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gfortran/ GNU Fortran (v4.8.2) manual].


{| border=1 cellspacing=0 cellpadding=5  
{| border=1 cellspacing=0 cellpadding=5  
Line 35: Line 237:


|-valign="top"
|-valign="top"
|<code>-cpp</code>
|<tt>-cpp</tt>
|Turns on the C-preprocessor, to evaluate <code>#if</code> and <code>#define</code> statements in the source code.
|Turns on the C-preprocessor, to evaluate <tt>#if</tt> and <tt>#define</tt> statements in the source code.
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<code>-fautomatic</code>
|<tt>-fautomatic</tt>
|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"
|<code>-fconvert-big-endian</code>
|<tt>-fconvert-big-endian</tt>
|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"
|<code>-fno-align-commons</code>
|<tt>-fno-align-commons</tt>
|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"
|<code>-fopenmp</code>
|<tt>-fopenmp</tt>
|Enables OpenMP parallelization commands.
|Enables OpenMP parallelization commands.
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<code>-funroll-loops</code>
|<tt>-funroll-loops</tt>
|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.
|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.


Line 67: Line 269:


|-valign="top"
|-valign="top"
|<code>-O3</code>
|<tt>-march=native</tt>
|This selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine. Using <tt>-march=native</tt> enables all instruction subsets supported by the local machine (hence the result might not run on different machines).  We use this option for compiling GEOS-Chem because it is the most portable.
 
*NOTE: You should not use this option if you are compiling on a node with Intel CPUs.  This will result in compile-time error.
|<tt>M_ARCH=native</tt>
 
|-valign="top"
|<tt>-O3</tt>
|Performs nearly all supported optimizations that do not involve a space-speed tradeoff, plus a few more optimizations for function inlining and vectorization.  For more information, please see the [https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options ''Optimize Options'' section of the GNU Compiler Collection manual].
|Performs nearly all supported optimizations that do not involve a space-speed tradeoff, plus a few more optimizations for function inlining and vectorization.  For more information, please see the [https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options ''Optimize Options'' section of the GNU Compiler Collection manual].
|Default setting
|Default setting


|-valign="top"
|-valign="top"
|<code>-std=legacy</code>
|<tt>-std=legacy</tt>
|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.   
|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
|Default setting


|-valign="top"
|-valign="top"
|<code>-w</code>
|<tt>-w</tt>
|Turns off most informational warnings.
|Turns off most informational warnings.
|Default setting
|-valign="top"
|<tt>-fbacktrace</tt>
|When a serious runtime error is encountered or a deadly signal is emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals that have the action "dump core"), this option will tell the Fortran runtime library to output a backtrace of the error.  (The complementary option <tt>-fno-backtrace</tt> disables the backtrace generation._ This option only has influence for compilation of the Fortran main program.
|Default setting
|Default setting


Line 87: Line 301:


|-valign="top"
|-valign="top"
|<code>-fdefault-real-8</code>
|<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>
|This option tells the compiler to treat elevate <tt>REAL</tt> variables to <tt>REAL*8</tt>.  As a side-effect, it will also elevate <tt>REAL*8</tt> (or <tt>DOUBLE PRECISION</tt>) variables to <tt>REAL*16</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.''
|Used as needed
|Used as needed


|-valign="top"
|-valign="top"
|<code>-freal-4-real-8</code>
|<tt>-fdefault-double-8</tt>
|This option tells the compiler to treat variables that are declared as <tt>REAL</tt> as <tt>REAL*8</tt>
|Using <tt>-fdefault-real-8 -fdefault-double-8</tt> together will elevate <tt>REAL</tt> variables to <tt>REAL*8</tt>, but will leave <tt>REAL*4</tt> variables unchanged.  It will also leave <tt>REAL*8</tt> or <tt>DOUBLE PRECISION</tt> variables unchanged.


''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.''
|Used as needed
|Used as needed


|-valign="top"
|-valign="top"
|<code>-mcmodel=medium</code>
|<tt>-mcmodel=medium</tt>
|This option is used to tell Gfortran to use more than 2GB of static memory.  This avoids a [[#Relocation truncated to fit error|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&deg; x 0.3125&deg; nested grid).
|This option is used to tell Gfortran to use more than 2GB of static memory.  This avoids a [[#Relocation truncated to fit error|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&deg; x 0.3125&deg; nested grid).
|Default setting
|Default setting
Line 111: Line 325:


|-valign="top"
|-valign="top"
|<code>-fbacktrace</code>
|<tt>-fcheck-array-temporaries</tt>
|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.
|<code>TRACEBACK=yes</code>
 
|-valign="top"
|<code>-fcheck-array-temporaries</code>
|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.
|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.
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<tt>-fcheck-bounds</tt>
|<tt>-fcheck-bounds</tt>
|Check for [[Common GEOS-Chem error messages#Array-out-of-bounds_error|array-out-of-bounds errors]].  This is invoked when you compile GEOS-Chem with the <code>BOUNDS=yes</code> Makefile option.  ''NOTE: Only use this option <code>-fcheck-bounds</code> for debugging, as this option will cause GEOS-Chem to execute more slowly!''
|Check for [[Common GEOS-Chem error messages#Array-out-of-bounds_error|array-out-of-bounds errors]].  This is invoked when you compile GEOS-Chem with the <tt>BOUNDS=yes</tt> Makefile option.  ''NOTE: Only use this option <tt>-fcheck-bounds</tt> for debugging, as this option will cause GEOS-Chem to execute more slowly!''
|<code>BOUNDS=yes</code>
|<tt>BOUNDS=y</tt>


|-valign="top"
|-valign="top"
|<code>-ffpe-trap=invalid,zero,overflow</code>
|<tt>-ffpe-trap=invalid,zero,overflow</tt>
|This option will cause GEOS-Chem to halt when floating-point errors are encountered.  This can happen if an equation results in a denormal value, e.g. <code>NaN</code>, or <code>+/-Infinity</code>.  Common causes of floating-point errors are divisions where the denominator becomes zero.
|This option will cause GEOS-Chem to halt when floating-point errors are encountered.  This can happen if an equation results in a denormal value, e.g. <tt>NaN</tt>, or <tt>+/-Infinity</tt>.  Common causes of floating-point errors are divisions where the denominator becomes zero.
|<code>FPE=yes</code>
|<tt>FPEX=y</tt> or<br><tt>FPE=y</tt>


|-valign="top"
|-valign="top"
|<code>-finit-real-snan</code>
|<tt>-finit-real-snan</tt>
|This option will set local automatic variables to a signaling NaN.  This will make it easier for the compiler to detect undefined variables.
|This option will set local automatic variables to a signaling NaN.  This will make it easier for the compiler to detect undefined variables.
|<code>FPE=yes</code>
|<tt>FPEX=y</tt> or<br><tt>FPE=y</tt>


|-valign="top"
|-valign="top"
|<code>-g</code>
|<tt>-g</tt>
|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).
|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).
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>
 
|-valign="top"
|<tt>-gdwarf-2</tt>
|Tells the compiler to generate full debugging information using the DWARF-2 library standard.
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<code>-O0</code>
|<tt>-gdwarf-2</tt>
|Tells the compiler to strictly adhere to the DWARF-2 debugging library standard.
|<tt>DEBUG=y</tt>
 
|-valign="top"
|<tt>-O0</tt>
|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).
|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).
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<code>-Wall</code>
|<tt>-Wall</tt>
|Enables some common compiler warnings that you probably would not enable out unless you were debugging.
|Enables some common compiler warnings that you probably would not enable out unless you were debugging.
|<tt>DEBUG=yes</tt>
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<code>-Warray-temporaries</code>
|<tt>-Warray-temporaries</tt>
|Warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid
|Warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid
such temporaries. Used in conjunction with <code>-fcheck-array-temporaries</code>.
such temporaries. Used in conjunction with <tt>-fcheck-array-temporaries</tt>.
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<code>-Wconversion</code>
|<tt>-Wconversion</tt>
|Warn about implicit conversions that are likely to change the value of the expression after conversion. Implied by <code>-Wall</code>.
|Warn about implicit conversions that are likely to change the value of the expression after conversion. Implied by <tt>-Wall</tt>.
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>


|-valign="top"
|-valign="top"
|<code>-Wextra</code>
|<tt>-Wextra</tt>
|<code>-Wextra</code> Enables some warning options for usages of language features which may be problematic. This currently includes <code>-Wcompare-reals</code> and <code>-Wunused-parameter</code>.
|<tt>-Wextra</tt> Enables some warning options for usages of language features which may be problematic. This currently includes <tt>-Wcompare-reals</tt> and <tt>-Wunused-parameter</tt>.
|<code>DEBUG=yes</code>
|<tt>DEBUG=y</tt>


|}
|}


--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:55, 21 September 2016 (UTC)
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 20:18, 9 December 2016 (UTC)


=== Typical settings for a GEOS-Chem simulation ===  
=== Typical settings for a GEOS-Chem simulation ===  
Line 174: Line 393:
The normal GEOS-Chem build uses the following Gfortran compiler flags:
The normal GEOS-Chem build uses the following Gfortran compiler flags:


  -cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check  
  -cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check
  -fopenmp -mcmodel=medium -O3 -funroll-loops
  -march=native -fopenmp -mcmodel=medium -O3 -funroll-loops


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


  -cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check  
  -cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check -march=native
  -fopenmp -mcmodel=medium -g -O0 -Wall -Wextra -Warray-temporaries -Wconversion  
  -fopenmp -mcmodel=medium -g gdwarf-2 -gstrict-dwarf -O0 -Wall -Wextra -Warray-temporaries -Wconversion  
  -fcheck-array-temporaries -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow, -finit-real=snan
  -fcheck-array-temporaries -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow, -finit-real=snan


Line 186: Line 405:


== Modifications made to GEOS-Chem for GNU Fortran ==
== Modifications made to GEOS-Chem for GNU Fortran ==
The following tables list the modifications that had to be made in order to compile GEOS-Chem with GNU Fortran.  These fixes were standardized into GEOS-Chem between [[GEOS-Chem v11-01|v11-01]] and the [[GEOS-Chem 12#12.0.0|12.0.0 (aka v11-02-final)]] versions.
=== Module in GeosCore ===
{| border=1 cellspacing=0 cellpadding=5
|- bgcolor="#CCCCCC"
!width="200px"|Module
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="600px"|Code added (in <span style="color:green">GREEN</span>)
|-valign="top"
|
carbon_mod.F
|
GLOB_DARO2(I,J,L,<span style="color:red">:</span>,JHC-5) = DELHC(<span style="color:red">:</span>)
. . .
GLOB_DARO2(I,J,L,<span style="color:red">:</span>,4) = DELHC(<span style="color:red">:</span>)
|
GLOB_DARO2(I,J,L,<span style="color:green">1:2</span>,JHC-5) = DELHC(<span style="color:green">1:2</span>)
. . .
GLOB_DARO2(I,J,L,<span style="color:green">1:2</span>,4) = DELHC(<span style="color:green">1:2</span>)
<span style="color:green"># Now only copy the 1st 2 elements of DELHC
# into GLOB_DARO2, which avoids an array-size mismatch</span>
|-valign="top"
|
convection_mod.F
|
IF ( AER <span style="color:red">== .TRUE.</span> ) THEN
|
IF ( AER ) THEN
|-valign="top"
|
diag3.F
|
(Input_Opt%LSKYRAD(2)<span style="color:red">.EQ.</span>TRUE.))
. . .
(Input_Opt%LSKYRAD(1)<span style="color:red">.EQ.</span>TRUE.))
|
(Input_Opt%LSKYRAD(2)<span style="color:green">.EQV.</span>TRUE.))
. . .
(Input_Opt%LSKYRAD(1)<span style="color:green">.EQV.</span>TRUE.))
|-valign="top"
|
diag_mod.F
|
<span style="color:red">INTEGER, ALLOCATABLE :: AD71_COUNT
INTEGER, ALLOCATABLE :: AD71_HRCT
INTEGER, ALLOCATABLE :: AD71_LHR
INTEGER, ALLOCATABLE :: AD71_LDAY</span>
|
<span style="color:green">INTEGER              :: AD71_COUNT
INTEGER              :: AD71_HRCT
INTEGER              :: AD71_LHR
INTEGER              :: AD71_LDAY
# Scalar variables cannot be declared ALLOCATABLE.</span>
|-valign="top"
|
diag48_mod.F
|
(Input_Opt%LSKYRAD(2)<span style="color:red">.EQ.</span>TRUE.))
. . .
(Input_Opt%LSKYRAD(1)<span style="color:red">.EQ.</span>TRUE.))
|
(Input_Opt%LSKYRAD(2)<span style="color:green">.EQV.</span>TRUE.))
. . .
(Input_Opt%LSKYRAD(1)<span style="color:green">.EQV.</span>TRUE.))
|-valign="top"
|
emissions_mod.F90
|
CALL EMISSCARBON( ... etc ... )
IF ( RC /= GC_SUCCESS ) RETURN
|
<span style="color:green">IF ( Input_Opt%ITS_A_FULLCHEM_SIM  .or. &
      Input_Opt%ITS_AN_AEROSOL_SIM ) THEN</span>
    CALL EMISSCARBON( ... etc ... )
    IF ( RC /= GC_SUCCESS ) RETURN
<span style="color:green">ENDIF
# Need to prevent EMISSCARBON from being called
# for simulations without carbon aerosols</span>
|-valign="top"
|
flexchem_mod.F90
|
  write(*,'(i,a3,a85)') D,' | ',EQN_NAMES(D)
|
  WRITE( 6, '(i<span style="color:green">8,a3,a85)' ) D,' | ',EQN_NAMES(D)
|-valign="top"
|
geosfp_read_mod.F90
|
<span style="color:red">INTEGER</span>, SAVE      :: first = .TRUE.
|
<span style="color:green">LOGICAL</span>, SAVE      :: first = .TRUE.
|-valign="top"
|
hcoi_gc_diagn_mod.F90
|
IF ( YesOrNo <span style="color:red">==</span> .FALSE. ) THEN
|
IF ( YesOrNo <span style="color:green">.eqv.</span> FALSE ) THEN
|-valign="top"
|
hcoi_gc_diagn_mod.F90
|
<span style="color:red">IF ( ( ExtState%DustDead .OR.
        ExtState%DustGinoux )  .AND. &</span>
|
<span style="color:green">Is_DustDead  = ( ExtState%DustDead  )
Is_DustGinoux = ( ExtState%DustGinoux )
. . .
IF ( ( Is_DustDead .OR. Is_DustGinoux )  .AND. &</span>
 
|-valign="top"
|
hcoi_gc_main_mod.F90
|
IF ( Input_Opt%LUCX <span style="color:red">/=</span> LTMP ) THEN  
. . .
IF ( Input_Opt%LSCHEM <span style="color:red">/=</span> LTMP ) THEN
. . .
IF ( Input_Opt%LCHEM <span style="color:red">/=</span>. LTMP .and.
|
IF ( Input_Opt%LUCX <span style="color:green">.neqv.</span> LTMP ) THEN
. . .
IF ( Input_Opt%LSCHEM <span style="color:green">.neqv.</span> LTMP ) THEN
. . .
IF ( Input_Opt%LCHEM <span style="color:green">.neqv./</span> LTMP .and.             
|-valign="top"
|
input_mod.F
|
READ( SUBSTRS(1:N), '(i)') CFCYEAR
. . .
write(MSG,'(I,a,L)') '<>', Input_Opt%TS_DYN, ...
. . .
Input_Opt%ND63_TRACERS(1:ND63) = TRACERS(1:N_ND63)
. . .
IF ( LCH4BUD <span style="color:red">.EQ. .TRUE.</span> ) THEN
|
READ( SUBSTRS(1:N), '(i<span style="color:green">4</span>)') CFCYEAR
. . .
write(MSG,'(I<span style="color:green">8</span>,a,L)') '<>', Input_Opt%TS_DYN, ...
. . .
Input_Opt%ND63_TRACERS(1:<span style="color:green">N_</span>ND63) = TRACERS(1:N_ND63)
. . .
IF ( LCH4BUD ) THEN
|-valign="top"
|
isoropiaII_mod.F
|
<span style="color:red">#IF</span> !defined ( USE_REAL_8 )
      HNO3_sav(I,J,L) = SNGL(HNO3_UGM3)
<span style="color:red">#ELIF</span>
      HNO3_sav(I,J,L) = HNO3_UGM3
<span style="color:red">#ENDIF</span>
|
<span style="color:green">#if</span> !defined( USE_REAL_8 )
      HNO3_sav(I,J,L) = SNGL(HNO3_UGM3)
<span style="color:green">#else</span>
      HNO3_sav(I,J,L) = HNO3_UGM3
<span style="color:green">#endif</span> 
|-valign="top"
|
ocean_mercury_mod.F
|
IF ( <span style="color:red">ND03</span> .and. NN == ID_Hg_tot )
|
IF ( <span style="color:green">( ND03 > 0 )</span> .and. <span style="color:green">(</span> NN == ID_Hg_tot <span style="color:green">)</span> )
<span style="color:green"># Use parentheses to cast to LOGICAL type
|-valign="top"
|
merra2_read_mod.F90
|
<span style="color:red">INTEGER</span>, SAVE      :: first = .TRUE.
|
<span style="color:green">LOGICAL</span>, SAVE      :: first = .TRUE.
|-valign="top"
|
ndxx_setup.F
|
<span style="color:red">INTEGER</span> :: IT_IS_A_CH3I_SIM
<span style="color:red">INTEGER</span> :: IT_IS_A_FULLCHEM_SIM
<span style="color:red">INTEGER</span> :: IT_IS_A_MERCURY_SIM
<span style="color:red">INTEGER</span> :: IT_IS_A_TAGO3_SIM
<span style="color:red">INTEGER</span> :: IT_IS_A_H2HD_SIM
|
<span style="color:green">LOGICAL</span> :: IT_IS_A_CH3I_SIM
<span style="color:green">LOGICAL</span> :: IT_IS_A_FULLCHEM_SIM
<span style="color:green">LOGICAL</span> :: IT_IS_A_MERCURY_SIM
<span style="color:green">LOGICAL</span> :: IT_IS_A_TAGO3_SIM
<span style="color:green">LOGICAL</span> :: IT_IS_A_H2HD_SIM
|-valign="top"
|
ndxx_setup.F
|
<span style="color:red">IF ( ALLOCATED( AD71_COUNT  ) ) DEALLOCATE( AD71_COUNT  )
IF ( ALLOCATED( AD71_HRCT  ) ) DEALLOCATE( AD71_HRCT  )
IF ( ALLOCATED( AD71_LDAY  ) ) DEALLOCATE( AD71_LDAY  )
IF ( ALLOCATED( AD71_LHR    ) ) DEALLOCATE( AD71_LHR    )</span>
|
|-valign="top"
|
seasalt_mod.F
|
<span style="color:red"> IF (DMID(ID) .ge. R0*2e+0_fp .and. ...
&          THEN</span>
|
<span style="color:green"> IF ( DMID(ID) .ge. R0*2e+0_fp  .and.
&    DMID(ID) .le. R1*2e+0_fp ) THEN
# Break IF statement into 2 lines</span>
|-valign="top"
|
seasalt_mod.F
|
IF ( LMPOA <span style="color:red">> 0</span> ) THEN
|
IF ( LMPOA ) THEN
|-valign="top"
|
strat_chem_mod.F90
|
<span style="color:red">'A3O2',    'ACET', etc.</span>
|
<span style="color:green">'A3O2    ', 'ACET    ', etc.
# All strings in array constructors must
# have the same number of spaces</span>
|-valign="top"
|
strat_chem_mod.F90
|
<span style="color:red">TYPE(BrPointers)      :: BrPtrDay(6)
TYPE(BrPointers)      :: BrPtrNight(6)</span>
|
<span style="color:green">TYPE(BrPointers), POINTER :: BrPtrDay(:)
TYPE(BrPointers), POINTER :: BrPtrNight(:) </span>
. . .
<span style="color:green"><nowiki>!</nowiki> BrPtrDay and BrPtrNight have to be allocated dynamically
<nowiki>!</nowiki> because they are pointers (bmy, 10/3/16)
ALLOCATE( BrPtrDay  ( 6 ), STAT=errCode )
ALLOCATE( BrPtrNight( 6 ), STAT=errCode )</span>
. . .
<span style="color:green">IF ( ASSOCIATED( BrPtrDay  ) ) DEALLOCATE( BrPtrDay  )
IF ( ASSOCIATED( BrPtrNight ) ) DEALLOCATE( BrPtrNight )
# Dynamically allocate the BrPtrDay and BrPtrNight arrays
# so as to not have to declare them SAVEd.</span>
|-valign="top"
|
ucx_mod.F90
|
<span style="color:red">JDIF_OUT = SIND(JMAX_OUT)-SIND(JMIN_OUT)</span>
. . .
<span style="color:red">JDIF_TMP = SIND(JMAX_TMP)-SIND(JMIN_TMP)</span>
|
<span style="color:green">USE PhysConstants,      ONLY : PI_180</span>
. . .
  <span style="color:green">JDIF_OUT = SIN( JMAX_OUT * PI_180 )
&        - SIN( JMIN_OUT * PI_180 )</span>
. . .
  <span style="color:green">  JDIF_TMP = SIN( JMAX_TMP * PI_180 )
&            - SIN( JMIN_TMP * PI_180 )
# Remove unsupported SIND function</span>
|}
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 19:45, 28 September 2016 (UTC)
=== Modules in GeosUtil ===
{| border=1 cellspacing=0 cellpadding=5
|- bgcolor="#CCCCCC"
!width="200px"|Module
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="600px"|Code added (in <span style="color:green">GREEN</span>)
|-valign="top"
|
error_mod.F
|
#if defined( LINUX_IFORT )
|
#if defined( LINUX_IFORT ) <span style="color:green">|| defined( LINUX_GFORTRAN )</span>
|-valign="top"
|
geos_timers_mod.F
|
IF ( (SavedTimers(TimerLoc)%ENABLED) <span style="color:red">.eq. .true.</span>)
|
IF ( SavedTimers(TimerLoc)%ENABLED )
|-valign="top"
|
henry_coeffs_mod.F
|
'H2O2',  ! Jacob et al. 2000
'CH3I',  ! Moore et al. 1995
<span style="color:red">'DMS'</span>,    ! De Bruyn et al. 1995
'ACET' )/ ! Benkelberg et al 1995
|
'H2O2',  ! Jacob et al. 2000
'CH3I',  ! Moore et al. 1995
<span style="color:green">'DMS ',</span>  ! De Bruyn et al. 1995
'ACET' )/ ! Benkelberg et al 1995
<span style="color:green"># All strings in an array constructor
# must have the same number of spaces</span>
|}
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 19:13, 28 September 2016 (UTC)
=== Modules in Headers ===
{| border=1 cellspacing=0 cellpadding=5
|- bgcolor="#CCCCCC"
!width="200px"|Module
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="600px"|Code added (in <span style="color:green">GREEN</span>)
|-valign="top"
|
input_opt_mod.F90
|
<span style="color:red">INTEGER</span>                    :: LND51_HDF
. . .
<span style="color:red">INTEGER</span>                    :: LND51b_HDF
. . .
<span style="color:red">INTEGER</span>                    :: LWINDO_SE
. . .
<span style="color:red">INTEGER</span>                    :: LWINDO_CU
|
<span style="color:green">LOGICAL</span>                    :: LND51_HDF
. . .
<span style="color:green">LOGICAL</span>                    :: LND51b_HDF
. . .
<span style="color:green">LOGICAL</span>                    :: LWINDO_SE
. . .
<span style="color:green">LOGICAL</span>                    :: LWINDO_CU
|}
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 19:49, 28 September 2016 (UTC)


=== Modules in HEMCO/Core ===
=== Modules in HEMCO/Core ===
Line 191: Line 783:
{| border=1 cellspacing=0 cellpadding=5  
{| border=1 cellspacing=0 cellpadding=5  
|- bgcolor="#CCCCCC"
|- bgcolor="#CCCCCC"
!width="125px"|Module
!width="200px"|Module
!width="500px"|Code removed
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="500px"|Code added
!width="600px"|Code added (in <span style="color:green">GREEN</span>)


|-valign="top"
|-valign="top"
Line 202: Line 794:
|
|
  IF ( UseConc <span style="color:green">.neqv.</span> Dct%Dta%IsConc ) THEN
  IF ( UseConc <span style="color:green">.neqv.</span> Dct%Dta%IsConc ) THEN
 
  <span style="color:green"># Use .eqv. and .neqv. instead of == or /=
  <span style="color:green"># Use .eqv. and .neqv. instead of == or /=
  # when comparing LOGICAL variables directly.</span>
  # when comparing LOGICAL variables directly.</span>
|-valign="top"
|
hco_datacont_mod.F90
|
  TYPE(ListCont), POINTER :: TmpLct <span style="color:red">=> NULL()</span>
|
  TYPE(ListCont), POINTER :: TmpLct
  . . .
  <span style="color:green">TmpLct => NULL()</span>


|-valign="top"
|-valign="top"
Line 238: Line 840:
  # to avoid using OPTIONAL arguments in a MODULE INTERFACE</span>
  # to avoid using OPTIONAL arguments in a MODULE INTERFACE</span>


|-valign="top"
|
hco_interp_mod.F90
|
<span style="color:red">WHERE ( REGFRACS > MAXFRACS )
    MAXFRACS = REGR_4D
    INDECES  = IVAL
END WHERE</span>
|
<span style="color:green">DO T  = 1, NTIME
DO L  = 1 ,NLEV
DO J  = 1, HcoState%NY
DO I2 = 1, HcoState%NX
    IF ( REGFRACS(I2,J,L,T) > MAXFRACS(I2,J,L,T) ) THEN
      MAXFRACS(I2,J,L,T) = REGR_4D(I2,J,L,T)
      INDECES (I2,J,L,T) = IVAL
    ENDIF
ENDDO
ENDDO
ENDDO
ENDDO</span>
 
|-valign="top"
|-valign="top"
|
|
  hco_unit_mod.F90
  hco_unit_mod.F90
|
|
  '1',            &
  <span style="color:red">'1',            &
  'count',        &
  'count',        &
  'unitless',      &
  'unitless',      &</span>
  etc.
  etc.
|
|
  '1          ',  &
  <span style="color:green">'1          ',  &
  'count      ',  &
  'count      ',  &
  'unitless  ',  &
  'unitless  ',  &</span>
  etc.
  etc.
    
    
  All strings in array constructors
  <span style="color:green"># All strings in array constructors must have the
  now have same the # of spaces
  # same # of spaces or else Gfortran chokes</span>
 
|-valign="top"
|
   
   
|}
|}
Line 266: Line 887:
{| border=1 cellspacing=0 cellpadding=5  
{| border=1 cellspacing=0 cellpadding=5  
|- bgcolor="#CCCCCC"
|- bgcolor="#CCCCCC"
!width="125px"|Module
!width="200px"|Module
!width="500px"|Code removed
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="500px"|Code added
!width="600px"|Code added (in <span style="color:green">GREEN</span>)


|-valign="top"
|-valign="top"
Line 294: Line 915:
  ELSEIF ( IsGFED4 ) THEN
  ELSEIF ( IsGFED4 ) THEN
     ... etc ...
     ... etc ...
   ENDIF
    
ENDIF
   
   
   <span style="color:red"><nowiki>!</nowiki> Make sure HUMTROP does not exceed one
   <span style="color:red"><nowiki>!</nowiki> Make sure HUMTROP does not exceed one
Line 354: Line 976:
   
   
  <span style="color:green"># Don't refer to SS_DEN before it is allocated</span>
  <span style="color:green"># Don't refer to SS_DEN before it is allocated</span>
|}
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:07, 26 September 2016 (UTC)
=== Modules in NcdfUtil ===
{| border=1 cellspacing=0 cellpadding=5
|- bgcolor="#CCCCCC"
!width="200px"|Module
!width="450px"|Code removed (in <span style="color:red">RED</span>)
!width="600px"|Code added (in <span style="color:green">GREEN</span>)


|-valign="top"
|-valign="top"
|
|
   
  ncdf_mod.F90
|
|
  <span style="color:red">PRIVATE :: NC_VAR_WRITE_INT
  PRIVATE :: NC_VAR_WRITE_R4
  PRIVATE :: NC_VAR_WRITE_R8
|
|
  <span style="color:green">PRIVATE :: NC_VAR_WRITE_INT_1D
  PRIVATE :: NC_VAR_WRITE_INT_2D
  PRIVATE :: NC_VAR_WRITE_INT_3D
  PRIVATE :: NC_VAR_WRITE_INT_4D
  PRIVATE :: NC_VAR_WRITE_R4_1D
  PRIVATE :: NC_VAR_WRITE_R4_2D
  PRIVATE :: NC_VAR_WRITE_R4_3D
  PRIVATE :: NC_VAR_WRITE_R4_4D
  PRIVATE :: NC_VAR_WRITE_R8_1D
  PRIVATE :: NC_VAR_WRITE_R8_2D
  PRIVATE :: NC_VAR_WRITE_R8_3D
  PRIVATE :: NC_VAR_WRITE_R8_4D
 
  <span style="color:green">#Added separate, overloaded routine
  # for each combination of array size and INT, REAL*4, REAL*8. 
  # This avoids using OPTIONAL arguments in overloaded routines,
  #which Gfortran hates.</span>


|-valign="top"
|-valign="top"
|
|
ncdf_mod.F90
|
  </span>INTERFACE NC_VAR_WRITE
    <span style="color:red">MODULE PROCEDURE NC_VAR_WRITE_INT
    MODULE PROCEDURE NC_VAR_WRITE_R4
    MODULE PROCEDURE NC_VAR_WRITE_R8</span>
  END INTERFACE NC_VAR_WRITE
|
  </span>INTERFACE NC_VAR_WRITE
    <span style="color:green">MODULE PROCEDURE NC_VAR_WRITE_INT_1D
    MODULE PROCEDURE NC_VAR_WRITE_INT_2D
    MODULE PROCEDURE NC_VAR_WRITE_INT_3D
    MODULE PROCEDURE NC_VAR_WRITE_INT_4D
    MODULE PROCEDURE NC_VAR_WRITE_R4_1D
    MODULE PROCEDURE NC_VAR_WRITE_R4_2D
    MODULE PROCEDURE NC_VAR_WRITE_R4_3D
    MODULE PROCEDURE NC_VAR_WRITE_R4_4D
    MODULE PROCEDURE NC_VAR_WRITE_R8_1D
    MODULE PROCEDURE NC_VAR_WRITE_R8_2D
    MODULE PROCEDURE NC_VAR_WRITE_R8_3D
    MODULE PROCEDURE NC_VAR_WRITE_R8_4D</span>
  END INTERFACE NC_VAR_WRITE
   
   
|-valign="top"
|
|
ncdf_mod.F90
|
READ( tUnit(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) tYr
READ( tUnit(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) tMt
READ( tUnit(L1:L2), <span style="color:red">'(i)</span>', IOSTAT=STAT ) tDy
READ( tUnit(L1:L2), <span style="color:red">'(i)</span>', IOSTAT=STAT ) tHr
READ( tUnit(L1:L2), <span style="color:red">'(i)</span>', IOSTAT=STAT ) tMn
READ( tUnit(L1:L2), <span style="color:red">'(i)</span>', IOSTAT=STAT ) tSc
|
READ( tUnit(L1:L2), <span style="color:green">'(i4)'</span>, IOSTAT=STAT ) tYr
READ( tUnit(L1:L2), <span style="color:green">'(i2)</span>', IOSTAT=STAT ) tMt
READ( tUnit(L1:L2), <span style="color:green">'(i2)</span>', IOSTAT=STAT ) tDy
READ( tUnit(L1:L2), <span style="color:green">'(i2)</span>', IOSTAT=STAT ) tHr
READ( tUnit(L1:L2), <span style="color:green">'(i2)</span>', IOSTAT=STAT ) tMn
READ( tUnit(L1:L2), <span style="color:green">'(i2)</span>', IOSTAT=STAT ) tSc
   
   
<span style="color:green"># Gfortran cannot have a generic integer
#width in a FORMAT statement.</span>
|-valign="top"
|
|
ncdf_mod.F90
|
READ( TIMEUNIT(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) YYYY
READ( TIMEUNIT(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) MM
READ( TIMEUNIT(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) DD
READ( TIMEUNIT(L1:L2), <span style="color:red">'(i)'</span>, IOSTAT=STAT ) HH
|
READ( TIMEUNIT(L1:L2), <span style="color:green">'(i4)'</span>, IOSTAT=STAT ) YYYY
READ( TIMEUNIT(L1:L2), <span style="color:green">'(i2)'</span>, IOSTAT=STAT ) MM
READ( TIMEUNIT(L1:L2), <span style="color:green">'(i2)'</span>, IOSTAT=STAT ) DD
READ( TIMEUNIT(L1:L2), <span style="color:green">'(i2)'</span>, IOSTAT=STAT ) HH
<span style="color:green"># Gfortran cannot have a generic integer
#width in a FORMAT statement.</span>
|}
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 15:14, 29 September 2016 (UTC)
=== Fixes for technical issues in the specialty simulation modules ===
In addition to the modifications listed in the tables above, we fixed a few technical issues were in the various GEOS-Chem specialty simulation modules.  These issues were discovered by running complete set of [[GEOS-Chem Unit Tester|GEOS-Chem unit tests]] using the GNU Fortran compiler.
*[[Mercury#Avoid_floating-point_exception_in_OCEAN_MERCURY_READ|Avoid floating-point exception in OCEAN_MERCURY_READ]]
*[[POPs_simulation#Avoid_floating-point_exception_in_routine_CHEM_POPGP|Avoid floating-point error in routine CHEM_POPGP]]
*[[Aerosol-only_simulation#Fixed_undefined_molecular_weight_of_HNO3_in_routine_SEASALT_CHEM|Fixed undefined molecular weight of HNO3 in routine SEASALT_CHEM]]
*[[Mercury#Now_call_DO_RED_INPLUME_after_the_HEMCO_configuration_file_is_read|Now call subrouine DO_RED_INPLUME after the HEMCO configuration file is read]]
*[[Tagged_CO_simulation#OH_is_now_converted_to_the_proper_units_after_being_read_from_HEMCO|Now convert OH to the proper units in the tagged CO simulation]]
*[[Aerosol_emissions#Bug_fix:_Allocate_the_OCCONV_array_for_marine_POA_simulations|Allocate the OCCONV array for marine POA simulations]]
*[[Coupling_GEOS-Chem_with_RRTMG#Replace_nonstandard_DLOG_function_with_LOG|Replace nonstandard DLOG function with LOG in RRTMG routine]]
--[[User:Lizzie Lundgren|Lizzie Lundgren]] ([[User talk:Lizzie Lundgren|talk]]) 21:24, 1 November 2016 (UTC)
== Validation ==
In general, the results of GEOS-Chem simulations using GNU Fortran essentially identical results those using the [[Intel Fortran Compiler]].  See below for more information.
Also, please see [[Timing tests with GEOS-Chem v11-01|our ''Timing tests with GEOS-Chem v11-01'' wiki page]] to view results from several GEOS-Chem timing tests using GNU Fortran.
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 17:28, 22 December 2016 (UTC)
=== Results from the v11-02a 1-month benchmark comparing ifort and gfortran ===
In order to evaluate the performance of GEOS-Chem using the '''the free and open source GNU Fortran compiler''', we performed two 1-month benchmark simulations for v11-02a.
{| border=1 cellspacing=0 cellpadding=5
|-bgcolor="#CCCCCC"
!width="100px"|Benchmark
!width="700px"|Description


|-valign="top"
|-valign="top"
|
|v11-02a ||Uses the [[Intel Fortran Compiler]] (<tt>ifort 11.1.069</tt>) to compile GEOS-Chem
 
|-valign="top"
|v11-02a.GF || Uses the GNU Fortran Compiler (<tt>gfortran 6.2.0</tt>) to compile GEOS-Chem.
 
|}
 
Both benchmarks yielded essentially identical results in the output (within the expected bounds of numerical noise).  This is demonstrated by looking at the [[Mean_OH_concentration|mean OH concentration]] and methyl chloroform lifetimes from both benchmarks:
 
MEAN OH CONCENTRATION [1e5 molec/cm3/s]
---------------------------------------
v11-02a        : 12.3128108012973      # with ifort 11.1.069
v11-02a.GF      : 12.312863157030780    # with gfortran 6.2.0
% Difference    : 0.000425213497755144
MCF LIFETIME w/r/t TROP OH [years]
----------------------------------
v11-02a        : 5.1159                # with ifort 11.1.069
v11-02a.GF      : 5.1159                # with gfortran 6.2.0
% Difference    : 0
 
Here are the job statistics from both benchmarks:
 
Machine information (identical for benchmarks w/ ifort and gfortran)
---------------------------------------------------------------------
Machine used    : holyjacob01.rc.fas.harvard.edu
CPU Type        : Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50 GHz
Timing results  : v11-02a benchmark    v11-02a benchmark
                : w/ ifort 11.1.069    w/ gfortran 6.2.0
-------------------------------------------------------------
Number of CPUs  :  24                  24
Memory used    :  5.2038 GB            4.5237 GB
Wall Time      :  04:22:54            05:07:26
CPU / Wall Time :  22.5986              17.3599
% of ideal      :  94.12 %              72.33 %
 
We also obtained the wall time spent in each operation of GEOS-Chem.  (This is automatically printed out to the log file when you compile GEOS-Chem with the <tt>TIMERS=1</tt> option.)
 
                                  v11-02a with    v11-02a with
                                  ifort 11.1.069  gfortran 6.2.0
   
   
|
  Timer name                      hh:mm:ss.SSS    hh:mm:ss.SSS
--------------------------------------------------------------------
  GEOS-Chem                    :  04:22:43.009    05:07:21.500
  Initialization                :  00:00:04.054    <span style="color:green">00:00:03.875</span>
  Timesteps                    :  04:22:35.931    05:07:17.375
  HEMCO                        :  00:58:35.751    <span style="color:green">00:51:43.250</span>
  All chemistry                :  01:27:06.851    01:30:07.750
  => Strat chem                :  00:00:33.615    <span style="color:red">00:00:47.250</span>
  => Gas-phase chem            :  01:10:22.802    <span style="color:green">01:06:20.000</span>
  => All aerosol chem          :  00:13:26.291    <span style="color:red">00:20:09.000</span>
  Transport                    :  00:22:17.939    <span style="color:red">00:41:05.000</span>
  Convection                    :  00:48:47.117    <span style="color:red">01:03:08.500</span>
  Dry deposition                :  00:00:55.591    <span style="color:red">00:01:09.625</span>
  Wet deposition                :  00:29:24.046    <span style="color:red">00:39:15.750</span>
  Diagnostics                  :  00:04:56.912    <span style="color:red">00:10:05.125</span>
  Reading met fields            :  00:00:17.359    <span style="color:green">00:00:15.000</span>
  Reading restart file          :  00:00:00.304    00:00:00.500
  Writing restart file          :  00:00:21.253    <span style="color:green">00:00:04.625</span>
 
As you can see, several of the operations (listed in <span style="color:red">RED</span>) are significantly slower with <tt>gfortran 6.2.0</tt> than with <tt>ifort 11.1.069</tt>.  A few operations (listed in <span style="color:green">GREEN</span>) were a little faster in <tt>gfortran 6.2.0</tt>.  We will continue to look for ways to speed up GEOS-Chem when using the GNU Fortran compiler.  This may involve optimizing parallel DO loops or fine-tuning the optimization options.
 
'''Summary:''' The benchmark using GNU Fortran yielded essentially identical results to the benchmark using Intel Fortran.  This is very encouraging, as it will allow GEOS-Chem development to take place on computational platforms that do not have proprietary compilers (such as Intel Fortran or PGI Fortran), which can be prohibitively expensive to purchase.
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 20:04, 20 April 2017 (UTC)
 
== Known issues ==
 
=== GNU Fortran seg fault error may be caused by uninitialized variables ===
 
When using GNU Fortran with debug options (activated when you configure with <tt>-DCMAKE_BUILD_TYPE=Debug</tt>),  <tt>FPE=y</tt>), be aware that this will cause uninitialized variables to be set to a signaling <tt>NaN</tt> value (i.e. IEEE Not-a-Number).  Therefore, an uninitialized value (especially an array) could potentially cause an error that is reported as a segmentation fault.
 
For example, in module <tt>GeosCore/pjc_pfix_window_mod.F</tt> and <tt>GeosCore/tpcore_fvdas_window_mod.F90</tt> we had to zero out several array variables that were uninitialized (in [[GEOS-Chem#v11-02c|GEOS-Chem v11-02c]].  These uninitialized arrays were causing the nested-grid simulations to halt with segmentation fault errors.
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:38, 11 July 2017 (UTC)
 
=== Now us ASIN instead of obsolete function ASIND ===
 
In HEMCO module <tt>HEMCO/Extensions/hcox_paranox_mod.F90</tt>, we had to replace the non-standard function <code>ASIND</code> (which returns the arcsine of an argument in degrees) with the <code>ASIN</code> function (which returns the arcsin in radians).  The proper unit conversion was then applied.
 
The code in <span style="color:red">RED</span> was deleted:
 
VARS(4) = <span style="color:red">ASIND( SC5(I,J) )</span>
VARS(5) = <span style="color:red">ASIND( ExtState%SUNCOS%Arr%Val(I,J) )</span>
 
And the code in <span style="color:green">GREEN</span> was added:
 
VARS(4) = <span style="color:green">ASIN( SC5(I,J)                    ) / HcoState%Phys%PI_180</span>
VARS(5) = <span style="color:green">ASIN( ExtState%SUNCOS%Arr%Val(I,J) ) / HcoState%Phys%PI_180
 
This modification does not cause any numerical differences in the output.  All difference tests returned identical results.
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:00, 30 September 2016 (UTC)
 
=== Now use SIN instead of obsolete function SIND ===
 
In the UCX chemistry module <tt>GeosCore/ucx_mod.F</tt>, we had to replace the non-standard function <code>SIND</code> (which returns the sine of an argument in degrees) with the <code>SIN</code> function (which returns the sine in radians).  The argument was converted from degrees to radians before being passed to <code>SIN</code>.
 
The code in <span style="color:red">RED</span> was deleted:
 
<span style="color:red">JDIF_OUT = SIND(JMAX_OUT)-SIND(JMIN_OUT)</span>
. . .
<span style="color:red">JDIF_TMP = SIND(JMAX_TMP)-SIND(JMIN_TMP)</span>
 
And the code in <span style="color:green">GREEN</span> was added:
 
<span style="color:green">USE PhysConstants,      ONLY : PI_180</span>
. . .
  <span style="color:green">JDIF_OUT = SIN( JMAX_OUT * PI_180 )
&        - SIN( JMIN_OUT * PI_180 )</span>
. . .
  <span style="color:green">  JDIF_TMP = SIN( JMAX_TMP * PI_180 )
&            - SIN( JMIN_TMP * PI_180 )
   
   
|
This change causes very small numerical differences, at the level of numerical noise, only in the "Standard" and "UCX" chemical mechanisms.  We attribute these differences to conversion between degrees and radians, probably with a different value of PI in each case.
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:14, 30 September 2016 (UTC)
 
=== GNU Fortran 4.8 and higher is not compatible with Totalview ===


GNU Fortran 4.8 and higher versions save debugging information to disk using the DWARF library, version 4, by default.  This makes code compiled with GNU Fortran incompatible with the Totalview debugger, version 8.8.0.1, which can only accept DWARF v2 or DWARF v3 input.  The GEOS-Chem Support Team noticed this on our local computer cluster.  We are still looking into a workaround for this.


|
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:39, 30 September 2016 (UTC)

Latest revision as of 19:21, 21 May 2024

Previous | Next | Guide to compilers for GEOS-Chem

  1. Supported compilers for GEOS-Chem
  2. The GNU Fortran compiler (gfortran)
  3. The Intel Fortran compiler (ifort, ifx)
  4. Fortran language resources


On this page, we discuss compiling GEOS-Chem with the GNU Fortran compiler (aka gfortran).

The GNU Fortran compiler is our recommended open-source compiler for GEOS-Chem.

Featured tutorial videos

The following tutorial at our GEOS-Chem YouTube channel (youtube.geos-chem.org) demonstrates how to build GNU Fortran with Spack:

Spack 1 thumbnail.png
Click HERE to view!!

--Bob Yantosca (talk) 21:20, 16 January 2020 (UTC)

Overview

We have added several modifications to facilitate compiling GEOS-Chem with the GNU Fortran (aka gfortran compiler). In the process, we have also corrected some coding issues that were flagged by GNU Fortran. These changes will be added to the v11-01 public release code.

GNU Fortran versions tested with GEOS-Chem

The GEOS-Chem Support Team has experimented using different versions of GNU Fortran to build GEOS-Chem. Here is the compatibility matrix of GEOS-Chem versions vs. supported GNU Fortran compiler versions.

GEOS-Chem version GNU Fortran version
4.8.2 5.2.0 6.2.0 7.*.* 8.*.* 9.*.* 10.*.* 11.*.* 12.*.*
13.0.* and later
12.9.*
12.8.*
12.7.*
12.6.*
12.5.*
12.4.*
12.3.*
12.2.*
12.1.*
v11-01
v10-01 and prior

We invite you to test with other versions of GNU Fortran. Please send your results to the support-team.html GEOS-Chem Support Team.

Environment settings for GNU Fortran

Here is some information about how you can customize your Linux environment to use the GNU Fortran compiler. This information was recently migrated to our geos-chem.readthedocs.io manual.

Compilation options

The sections below contain useful information about the GNU Fortran compiler options that are used for GEOS-Chem.

Optimization options

Please see the Optimize Options section of the GNU Compiler Collection manual for detailed information about GNU Fortran's optimization settings.

The default GNU Fortran optimization settings for GEOS-Chem are: -O3 -funroll-loops.

--Bob Yantosca (talk) 22:01, 21 September 2016 (UTC)

Debugging options

Please see the Debugging Options section of the GNU Compiler Collection manual for detailed information about GNU Fortran's debugging settings.

--Bob Yantosca (talk) 20:16, 22 September 2016 (UTC)

List of commonly-used compilation options

Here are the GNU Fortran compilation options currently used by GEOS-Chem. For a complete list of options, please see the GNU Fortran (v4.8.2) manual.

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
-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
-fopenmp Enables OpenMP parallelization commands. 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' 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
-march=native This selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine. Using -march=native enables all instruction subsets supported by the local machine (hence the result might not run on different machines). We use this option for compiling GEOS-Chem because it is the most portable.
  • NOTE: You should not use this option if you are compiling on a node with Intel CPUs. This will result in compile-time error.
M_ARCH=native
-O3 Performs nearly all supported optimizations that do not involve a space-speed tradeoff, plus a few more optimizations for function inlining and vectorization. For more information, please see the Optimize Options section of the GNU Compiler Collection manual. 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
-w Turns off most informational warnings. Default setting
-fbacktrace When a serious runtime error is encountered or a deadly signal is emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals that have the action "dump core"), this option will tell the Fortran runtime library to output a backtrace of the error. (The complementary option -fno-backtrace disables the backtrace generation._ This option only has influence for compilation of the Fortran main program. Default setting
Special compiler settings
-fdefault-real-8 This option tells the compiler to treat elevate REAL variables to REAL*8. As a side-effect, it will also elevate REAL*8 (or DOUBLE PRECISION) variables to REAL*16.

NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA.

Used as needed
-fdefault-double-8 Using -fdefault-real-8 -fdefault-double-8 together will elevate REAL variables to REAL*8, but will leave REAL*4 variables unchanged. It will also leave REAL*8 or DOUBLE PRECISION variables unchanged.

NOTE: This option is not used globally, but is only applied to certain indidvidual files (mostly from third-party codes like ISORROPIA.

Used as needed
-mcmodel=medium This option is used to tell Gfortran 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
-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=y
-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 this option -fcheck-bounds for debugging, as this option will cause GEOS-Chem to execute more slowly! BOUNDS=y
-ffpe-trap=invalid,zero,overflow This option will cause GEOS-Chem to halt when floating-point errors are 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. FPEX=y or
FPE=y
-finit-real-snan This option will set local automatic variables to a signaling NaN. This will make it easier for the compiler to detect undefined variables. FPEX=y or
FPE=y
-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=y
-gdwarf-2 Tells the compiler to generate full debugging information using the DWARF-2 library standard. DEBUG=y
-gdwarf-2 Tells the compiler to strictly adhere to the DWARF-2 debugging library standard. DEBUG=y
-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=y
-Wall Enables some common compiler warnings that you probably would not enable out unless you were debugging. DEBUG=y
-Warray-temporaries Warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid

such temporaries. Used in conjunction with -fcheck-array-temporaries.

DEBUG=y
-Wconversion Warn about implicit conversions that are likely to change the value of the expression after conversion. Implied by -Wall. DEBUG=y
-Wextra -Wextra Enables some warning options for usages of language features which may be problematic. This currently includes -Wcompare-reals and -Wunused-parameter. DEBUG=y

--Bob Yantosca (talk) 20:18, 9 December 2016 (UTC)

Typical settings for a GEOS-Chem simulation

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

-cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check
-march=native -fopenmp -mcmodel=medium -O3 -funroll-loops

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

-cpp -w -std=legacy -fautomatic -fno-align-commons -fconvert=big-endian -fno-range-check -march=native
-fopenmp -mcmodel=medium -g gdwarf-2 -gstrict-dwarf -O0 -Wall -Wextra -Warray-temporaries -Wconversion 
-fcheck-array-temporaries -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow, -finit-real=snan

--Bob Yantosca (talk) 20:15, 22 September 2016 (UTC)

Modifications made to GEOS-Chem for GNU Fortran

The following tables list the modifications that had to be made in order to compile GEOS-Chem with GNU Fortran. These fixes were standardized into GEOS-Chem between v11-01 and the 12.0.0 (aka v11-02-final) versions.

Module in GeosCore

Module Code removed (in RED) Code added (in GREEN)
carbon_mod.F
GLOB_DARO2(I,J,L,:,JHC-5) = DELHC(:)
. . .
GLOB_DARO2(I,J,L,:,4) = DELHC(:)
GLOB_DARO2(I,J,L,1:2,JHC-5) = DELHC(1:2)
. . .
GLOB_DARO2(I,J,L,1:2,4) = DELHC(1:2)

# Now only copy the 1st 2 elements of DELHC 
# into GLOB_DARO2, which avoids an array-size mismatch
convection_mod.F
IF ( AER == .TRUE. ) THEN
IF ( AER ) THEN
diag3.F
(Input_Opt%LSKYRAD(2).EQ.TRUE.))
. . .
(Input_Opt%LSKYRAD(1).EQ.TRUE.))
(Input_Opt%LSKYRAD(2).EQV.TRUE.))
. . .
(Input_Opt%LSKYRAD(1).EQV.TRUE.))
diag_mod.F
INTEGER, ALLOCATABLE :: AD71_COUNT
INTEGER, ALLOCATABLE :: AD71_HRCT
INTEGER, ALLOCATABLE :: AD71_LHR
INTEGER, ALLOCATABLE :: AD71_LDAY
INTEGER              :: AD71_COUNT
INTEGER              :: AD71_HRCT
INTEGER              :: AD71_LHR
INTEGER              :: AD71_LDAY

# Scalar variables cannot be declared ALLOCATABLE.
diag48_mod.F
(Input_Opt%LSKYRAD(2).EQ.TRUE.))
. . .
(Input_Opt%LSKYRAD(1).EQ.TRUE.))
(Input_Opt%LSKYRAD(2).EQV.TRUE.))
. . .
(Input_Opt%LSKYRAD(1).EQV.TRUE.))
emissions_mod.F90
CALL EMISSCARBON( ... etc ... )
IF ( RC /= GC_SUCCESS ) RETURN 
IF ( Input_Opt%ITS_A_FULLCHEM_SIM   .or. &
     Input_Opt%ITS_AN_AEROSOL_SIM ) THEN
   CALL EMISSCARBON( ... etc ... )
   IF ( RC /= GC_SUCCESS ) RETURN 
ENDIF 

# Need to prevent EMISSCARBON from being called
# for simulations without carbon aerosols
flexchem_mod.F90
 write(*,'(i,a3,a85)') D,' | ',EQN_NAMES(D)
 WRITE( 6, '(i8,a3,a85)' ) D,' | ',EQN_NAMES(D)
geosfp_read_mod.F90
INTEGER, SAVE      :: first = .TRUE.
LOGICAL, SAVE      :: first = .TRUE.
hcoi_gc_diagn_mod.F90
IF ( YesOrNo == .FALSE. ) THEN
IF ( YesOrNo .eqv. FALSE ) THEN 
hcoi_gc_diagn_mod.F90
IF ( ( ExtState%DustDead .OR. 
       ExtState%DustGinoux )   .AND. &
Is_DustDead   = ( ExtState%DustDead   )
Is_DustGinoux = ( ExtState%DustGinoux )
. . .
IF ( ( Is_DustDead .OR. Is_DustGinoux )  .AND. &
 
hcoi_gc_main_mod.F90
IF ( Input_Opt%LUCX /= LTMP ) THEN	   
. . .
IF ( Input_Opt%LSCHEM /= LTMP ) THEN
. . .
IF ( Input_Opt%LCHEM /=. LTMP .and. 
IF ( Input_Opt%LUCX .neqv. LTMP ) THEN
. . .
IF ( Input_Opt%LSCHEM .neqv. LTMP ) THEN
. . .
IF ( Input_Opt%LCHEM .neqv./ LTMP .and.              
input_mod.F
READ( SUBSTRS(1:N), '(i)') CFCYEAR
. . .
write(MSG,'(I,a,L)') '<>', Input_Opt%TS_DYN, ...
. . .
Input_Opt%ND63_TRACERS(1:ND63) = TRACERS(1:N_ND63)
. . .
IF ( LCH4BUD .EQ. .TRUE. ) THEN
READ( SUBSTRS(1:N), '(i4)') CFCYEAR
. . .
write(MSG,'(I8,a,L)') '<>', Input_Opt%TS_DYN, ...
. . .
Input_Opt%ND63_TRACERS(1:N_ND63) = TRACERS(1:N_ND63)
. . .
IF ( LCH4BUD ) THEN
isoropiaII_mod.F
#IF !defined ( USE_REAL_8 )
      HNO3_sav(I,J,L) = SNGL(HNO3_UGM3) 
#ELIF
      HNO3_sav(I,J,L) = HNO3_UGM3
#ENDIF
#if !defined( USE_REAL_8 )
      HNO3_sav(I,J,L) = SNGL(HNO3_UGM3)
#else
      HNO3_sav(I,J,L) = HNO3_UGM3
#endif   
ocean_mercury_mod.F
IF ( ND03 .and. NN == ID_Hg_tot )
IF ( ( ND03 > 0 ) .and. ( NN == ID_Hg_tot ) )

# Use parentheses to cast to LOGICAL type
merra2_read_mod.F90
INTEGER, SAVE      :: first = .TRUE.
LOGICAL, SAVE      :: first = .TRUE.
ndxx_setup.F
INTEGER :: IT_IS_A_CH3I_SIM
INTEGER :: IT_IS_A_FULLCHEM_SIM
INTEGER :: IT_IS_A_MERCURY_SIM
INTEGER :: IT_IS_A_TAGO3_SIM
INTEGER :: IT_IS_A_H2HD_SIM
LOGICAL :: IT_IS_A_CH3I_SIM
LOGICAL :: IT_IS_A_FULLCHEM_SIM
LOGICAL :: IT_IS_A_MERCURY_SIM
LOGICAL :: IT_IS_A_TAGO3_SIM
LOGICAL :: IT_IS_A_H2HD_SIM
ndxx_setup.F
IF ( ALLOCATED( AD71_COUNT  ) ) DEALLOCATE( AD71_COUNT  )
IF ( ALLOCATED( AD71_HRCT   ) ) DEALLOCATE( AD71_HRCT   )
IF ( ALLOCATED( AD71_LDAY   ) ) DEALLOCATE( AD71_LDAY   )
IF ( ALLOCATED( AD71_LHR    ) ) DEALLOCATE( AD71_LHR    )
seasalt_mod.F
 IF (DMID(ID) .ge. R0*2e+0_fp .and. ... 
&          THEN
 IF ( DMID(ID) .ge. R0*2e+0_fp   .and.
&     DMID(ID) .le. R1*2e+0_fp ) THEN

# Break IF statement into 2 lines
seasalt_mod.F
IF ( LMPOA > 0 ) THEN
IF ( LMPOA ) THEN
strat_chem_mod.F90
'A3O2',    'ACET', etc.
'A3O2    ', 'ACET    ', etc.

# All strings in array constructors must
# have the same number of spaces
strat_chem_mod.F90
TYPE(BrPointers)      :: BrPtrDay(6) 
TYPE(BrPointers)      :: BrPtrNight(6) 
TYPE(BrPointers), POINTER :: BrPtrDay(:) 
TYPE(BrPointers), POINTER :: BrPtrNight(:) 
. . .
! BrPtrDay and BrPtrNight have to be allocated dynamically
! because they are pointers (bmy, 10/3/16)
ALLOCATE( BrPtrDay  ( 6 ), STAT=errCode )
ALLOCATE( BrPtrNight( 6 ), STAT=errCode )
. . .
IF ( ASSOCIATED( BrPtrDay   ) ) DEALLOCATE( BrPtrDay   )
IF ( ASSOCIATED( BrPtrNight ) ) DEALLOCATE( BrPtrNight )

# Dynamically allocate the BrPtrDay and BrPtrNight arrays
# so as to not have to declare them SAVEd.
ucx_mod.F90
JDIF_OUT = SIND(JMAX_OUT)-SIND(JMIN_OUT)
. . .
JDIF_TMP = SIND(JMAX_TMP)-SIND(JMIN_TMP)
USE PhysConstants,      ONLY : PI_180
. . .
 JDIF_OUT = SIN( JMAX_OUT * PI_180 )
&         - SIN( JMIN_OUT * PI_180 )
. . .
    JDIF_TMP = SIN( JMAX_TMP * PI_180 )
&            - SIN( JMIN_TMP * PI_180 )

# Remove unsupported SIND function

--Bob Yantosca (talk) 19:45, 28 September 2016 (UTC)

Modules in GeosUtil

Module Code removed (in RED) Code added (in GREEN)
error_mod.F
#if defined( LINUX_IFORT ) 
#if defined( LINUX_IFORT ) || defined( LINUX_GFORTRAN )
geos_timers_mod.F
IF ( (SavedTimers(TimerLoc)%ENABLED) .eq. .true.)
IF ( SavedTimers(TimerLoc)%ENABLED )
henry_coeffs_mod.F
'H2O2',   ! Jacob et al. 2000 
'CH3I',   ! Moore et al. 1995
'DMS',    ! De Bruyn et al. 1995
'ACET' )/ ! Benkelberg et al 1995
'H2O2',   ! Jacob et al. 2000 
'CH3I',   ! Moore et al. 1995
'DMS ',   ! De Bruyn et al. 1995
'ACET' )/ ! Benkelberg et al 1995

# All strings in an array constructor
# must have the same number of spaces

--Bob Yantosca (talk) 19:13, 28 September 2016 (UTC)

Modules in Headers

Module Code removed (in RED) Code added (in GREEN)
input_opt_mod.F90
INTEGER                    :: LND51_HDF
. . .
INTEGER                    :: LND51b_HDF
. . .
INTEGER                    :: LWINDO_SE
. . .
INTEGER                    :: LWINDO_CU
LOGICAL                     :: LND51_HDF
. . .
LOGICAL                     :: LND51b_HDF
. . .
LOGICAL                     :: LWINDO_SE
. . .
LOGICAL                     :: LWINDO_CU

--Bob Yantosca (talk) 19:49, 28 September 2016 (UTC)

Modules in HEMCO/Core

Module Code removed (in RED) Code added (in GREEN)
hco_calc_mod.F90
IF ( UseConc /= Dct%Dta%IsConc ) THEN
IF ( UseConc .neqv. Dct%Dta%IsConc ) THEN

# Use .eqv. and .neqv. instead of == or /=
# when comparing LOGICAL variables directly.
hco_datacont_mod.F90
 TYPE(ListCont), POINTER :: TmpLct => NULL()
 TYPE(ListCont), POINTER :: TmpLct
 . . .
 TmpLct => NULL()
hco_diagn_mod.F90
INTERFACE Diagn_Update
   MODULE PROCEDURE Diagn_UpdateSP
   MODULE PROCEDURE Diagn_UpdateDP
END INTERFACE

# Removed DiagnUpdateSP and DiagnUpdateDP
# which used OPTIONAL arguments
PRIVATE :: Diagn_UpdateSp0d
PRIVATE :: Diagn_UpdateSp0d
PRIVATE :: Diagn_UpdateSp2d
PRIVATE :: Diagn_UpdateSp3d
PRIVATE :: Diagn_UpdateDp0d
PRIVATE :: Diagn_UpdateDp2d
PRIVATE :: Diagn_UpdateDp3d
...
INTERFACE Diagn_Update
   MODULE PROCEDURE Diagn_UpdateSp0d
   MODULE PROCEDURE Diagn_UpdateSp2d
   MODULE PROCEDURE Diagn_UpdateSp3d
   MODULE PROCEDURE Diagn_UpdateDp0d
   MODULE PROCEDURE Diagn_UpdateDp2d
   MODULE PROCEDURE Diagn_UpdateDp3d
END INTERFACE

# Added new routines DiagnUpdateSp* and DiagUpdateDp*
# to avoid using OPTIONAL arguments in a MODULE INTERFACE
hco_interp_mod.F90
WHERE ( REGFRACS > MAXFRACS ) 
   MAXFRACS = REGR_4D
   INDECES  = IVAL
END WHERE
DO T  = 1, NTIME
DO L  = 1 ,NLEV
DO J  = 1, HcoState%NY
DO I2 = 1, HcoState%NX
   IF ( REGFRACS(I2,J,L,T) > MAXFRACS(I2,J,L,T) ) THEN
      MAXFRACS(I2,J,L,T) = REGR_4D(I2,J,L,T)
      INDECES (I2,J,L,T) = IVAL
   ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
  
hco_unit_mod.F90
'1',             &
'count',         &
'unitless',      &
etc.
'1          ',   &
'count      ',   &
'unitless   ',   &
etc.
 
# All strings in array constructors must have the
# same # of spaces or else Gfortran chokes

--Bob Yantosca (talk) 18:21, 26 September 2016 (UTC)

Modules in HEMCO/Extensions

Module Code removed (in RED) Code added (in GREEN)
hcox_gfed_mod.F90
REAL(sp), POINTER   :: TmpPtr(:,:)  => NULL()
REAL(sp), POINTER   :: TmpPtr(:,:)
...
TmpPtr => NULL()

# Setting a pointer to NULL where it is declared
# turns the pointer into a SAVEd variable.
hcox_gfed_mod.F90
! Get pointers to GFED3 data
IF ( IsGFED3 ) THEN
   .... etc ...

! Get pointers to GFED4 data
ELSEIF ( IsGFED4 ) THEN
    ... etc ...
 
ENDIF

 ! Make sure HUMTROP does not exceed one
 WHERE ( HUMTROP > 1.0_sp ) 
    HUMTROP = 1.0_sp
 END WHERE
! Get pointers to GFED3 data
IF ( IsGFED3 ) THEN
   .... etc ...
	 
   ! Make sure HUMTROP does not exceed one
   WHERE ( HUMTROP > 1.0_sp ) 
      HUMTROP = 1.0_sp
   END WHERE

! Get pointers to GFED4 data
ELSEIF ( IsGFED4 ) THEN
   ... etc ...
ENDIF

# HUMTROP is only defined for GFED3, so the
# WHERE statement should go in the IfGFED3 block.
hcox_paranox_mod.F90
VARS(4) = ASIND( SC5(I,J) )
VARS(5) = ASIND( ExtState%SUNCOS%Arr%Val(I,J) )
VARS(4) = ASIN( SC5(I,J)                     ) / HcoState%Phys%PI_180
VARS(5) = ASIN( ExtState%SUNCOS%Arr%Val(I,J) ) / HcoState%Phys%PI_180

# ASIND is not supported in Gfortran.  Use ASIN instead to compute
# the arcsin and convert from degrees to radians manually.
hcox_seasalt_mod.F90
ALLOCATE ( NR  ( NSALT ), STAT=AS )
IF ( AS/=0 ) THEN
  CALL HCO_ERROR( 'Cannot allocate NR', RC )
  RETURN
ENDIF
SS_DEN = 2200.d0

ALLOCATE ( SS_DEN  ( NSALT ), STAT=AS ) 
ALLOCATE ( NR  ( NSALT ), STAT=AS )
IF ( AS/=0 ) THEN
  CALL HCO_ERROR( 'Cannot allocate NR', RC )
  RETURN
ENDIF
NR = 0

ALLOCATE ( SS_DEN  ( NSALT ), STAT=AS ) 

# Don't refer to SS_DEN before it is allocated

--Bob Yantosca (talk) 21:07, 26 September 2016 (UTC)

Modules in NcdfUtil

Module Code removed (in RED) Code added (in GREEN)
ncdf_mod.F90
 PRIVATE :: NC_VAR_WRITE_INT
 PRIVATE :: NC_VAR_WRITE_R4
 PRIVATE :: NC_VAR_WRITE_R8
 PRIVATE :: NC_VAR_WRITE_INT_1D
 PRIVATE :: NC_VAR_WRITE_INT_2D
 PRIVATE :: NC_VAR_WRITE_INT_3D
 PRIVATE :: NC_VAR_WRITE_INT_4D
 PRIVATE :: NC_VAR_WRITE_R4_1D
 PRIVATE :: NC_VAR_WRITE_R4_2D
 PRIVATE :: NC_VAR_WRITE_R4_3D
 PRIVATE :: NC_VAR_WRITE_R4_4D
 PRIVATE :: NC_VAR_WRITE_R8_1D
 PRIVATE :: NC_VAR_WRITE_R8_2D
 PRIVATE :: NC_VAR_WRITE_R8_3D
 PRIVATE :: NC_VAR_WRITE_R8_4D
 
 #Added separate, overloaded routine 
 # for each combination of array size and INT, REAL*4, REAL*8.  
 # This avoids using OPTIONAL arguments in overloaded routines, 
 #which Gfortran hates.
ncdf_mod.F90
 INTERFACE NC_VAR_WRITE
    MODULE PROCEDURE NC_VAR_WRITE_INT
    MODULE PROCEDURE NC_VAR_WRITE_R4
    MODULE PROCEDURE NC_VAR_WRITE_R8
 END INTERFACE NC_VAR_WRITE
 INTERFACE NC_VAR_WRITE
    MODULE PROCEDURE NC_VAR_WRITE_INT_1D
    MODULE PROCEDURE NC_VAR_WRITE_INT_2D
    MODULE PROCEDURE NC_VAR_WRITE_INT_3D
    MODULE PROCEDURE NC_VAR_WRITE_INT_4D
    MODULE PROCEDURE NC_VAR_WRITE_R4_1D
    MODULE PROCEDURE NC_VAR_WRITE_R4_2D
    MODULE PROCEDURE NC_VAR_WRITE_R4_3D
    MODULE PROCEDURE NC_VAR_WRITE_R4_4D
    MODULE PROCEDURE NC_VAR_WRITE_R8_1D
    MODULE PROCEDURE NC_VAR_WRITE_R8_2D
    MODULE PROCEDURE NC_VAR_WRITE_R8_3D
    MODULE PROCEDURE NC_VAR_WRITE_R8_4D
 END INTERFACE NC_VAR_WRITE

ncdf_mod.F90
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tYr 
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tMt
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tDy
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tHr
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tMn
READ( tUnit(L1:L2), '(i)', IOSTAT=STAT ) tSc
READ( tUnit(L1:L2), '(i4)', IOSTAT=STAT ) tYr 
READ( tUnit(L1:L2), '(i2)', IOSTAT=STAT ) tMt
READ( tUnit(L1:L2), '(i2)', IOSTAT=STAT ) tDy
READ( tUnit(L1:L2), '(i2)', IOSTAT=STAT ) tHr
READ( tUnit(L1:L2), '(i2)', IOSTAT=STAT ) tMn 
READ( tUnit(L1:L2), '(i2)', IOSTAT=STAT ) tSc

# Gfortran cannot have a generic integer 
#width in a FORMAT statement.
ncdf_mod.F90
READ( TIMEUNIT(L1:L2), '(i)', IOSTAT=STAT ) YYYY
READ( TIMEUNIT(L1:L2), '(i)', IOSTAT=STAT ) MM
READ( TIMEUNIT(L1:L2), '(i)', IOSTAT=STAT ) DD
READ( TIMEUNIT(L1:L2), '(i)', IOSTAT=STAT ) HH
READ( TIMEUNIT(L1:L2), '(i4)', IOSTAT=STAT ) YYYY
READ( TIMEUNIT(L1:L2), '(i2)', IOSTAT=STAT ) MM
READ( TIMEUNIT(L1:L2), '(i2)', IOSTAT=STAT ) DD
READ( TIMEUNIT(L1:L2), '(i2)', IOSTAT=STAT ) HH

# Gfortran cannot have a generic integer 
#width in a FORMAT statement.

--Bob Yantosca (talk) 15:14, 29 September 2016 (UTC)

Fixes for technical issues in the specialty simulation modules

In addition to the modifications listed in the tables above, we fixed a few technical issues were in the various GEOS-Chem specialty simulation modules. These issues were discovered by running complete set of GEOS-Chem unit tests using the GNU Fortran compiler.

--Lizzie Lundgren (talk) 21:24, 1 November 2016 (UTC)

Validation

In general, the results of GEOS-Chem simulations using GNU Fortran essentially identical results those using the Intel Fortran Compiler. See below for more information.

Also, please see our Timing tests with GEOS-Chem v11-01 wiki page to view results from several GEOS-Chem timing tests using GNU Fortran.

--Bob Yantosca (talk) 17:28, 22 December 2016 (UTC)

Results from the v11-02a 1-month benchmark comparing ifort and gfortran

In order to evaluate the performance of GEOS-Chem using the the free and open source GNU Fortran compiler, we performed two 1-month benchmark simulations for v11-02a.

Benchmark Description
v11-02a Uses the Intel Fortran Compiler (ifort 11.1.069) to compile GEOS-Chem
v11-02a.GF Uses the GNU Fortran Compiler (gfortran 6.2.0) to compile GEOS-Chem.

Both benchmarks yielded essentially identical results in the output (within the expected bounds of numerical noise). This is demonstrated by looking at the mean OH concentration and methyl chloroform lifetimes from both benchmarks:

MEAN OH CONCENTRATION [1e5 molec/cm3/s]
---------------------------------------
v11-02a         : 12.3128108012973      # with ifort 11.1.069
v11-02a.GF      : 12.312863157030780    # with gfortran 6.2.0
% Difference    : 0.000425213497755144

MCF LIFETIME w/r/t TROP OH [years]
----------------------------------
v11-02a         : 5.1159                # with ifort 11.1.069
v11-02a.GF      : 5.1159                # with gfortran 6.2.0
% Difference    : 0

Here are the job statistics from both benchmarks:

Machine information (identical for benchmarks w/ ifort and gfortran)
---------------------------------------------------------------------
Machine used    : holyjacob01.rc.fas.harvard.edu
CPU Type        : Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50 GHz

Timing results  : v11-02a benchmark    v11-02a benchmark
                : w/ ifort 11.1.069    w/ gfortran 6.2.0
-------------------------------------------------------------
Number of CPUs  :  24                   24
Memory used     :  5.2038 GB            4.5237 GB
Wall Time       :  04:22:54             05:07:26
CPU / Wall Time :  22.5986              17.3599
% of ideal      :  94.12 %              72.33 %

We also obtained the wall time spent in each operation of GEOS-Chem. (This is automatically printed out to the log file when you compile GEOS-Chem with the TIMERS=1 option.)

                                  v11-02a with     v11-02a with
                                  ifort 11.1.069   gfortran 6.2.0

 Timer name                       hh:mm:ss.SSS     hh:mm:ss.SSS
-------------------------------------------------------------------- 
 GEOS-Chem                     :  04:22:43.009     05:07:21.500
 Initialization                :  00:00:04.054     00:00:03.875
 Timesteps                     :  04:22:35.931     05:07:17.375
 HEMCO                         :  00:58:35.751     00:51:43.250
 All chemistry                 :  01:27:06.851     01:30:07.750
 => Strat chem                 :  00:00:33.615     00:00:47.250
 => Gas-phase chem             :  01:10:22.802     01:06:20.000
 => All aerosol chem           :  00:13:26.291     00:20:09.000
 Transport                     :  00:22:17.939     00:41:05.000
 Convection                    :  00:48:47.117     01:03:08.500
 Dry deposition                :  00:00:55.591     00:01:09.625
 Wet deposition                :  00:29:24.046     00:39:15.750
 Diagnostics                   :  00:04:56.912     00:10:05.125
 Reading met fields            :  00:00:17.359     00:00:15.000
 Reading restart file          :  00:00:00.304     00:00:00.500
 Writing restart file          :  00:00:21.253     00:00:04.625

As you can see, several of the operations (listed in RED) are significantly slower with gfortran 6.2.0 than with ifort 11.1.069. A few operations (listed in GREEN) were a little faster in gfortran 6.2.0. We will continue to look for ways to speed up GEOS-Chem when using the GNU Fortran compiler. This may involve optimizing parallel DO loops or fine-tuning the optimization options.

Summary: The benchmark using GNU Fortran yielded essentially identical results to the benchmark using Intel Fortran. This is very encouraging, as it will allow GEOS-Chem development to take place on computational platforms that do not have proprietary compilers (such as Intel Fortran or PGI Fortran), which can be prohibitively expensive to purchase.

--Bob Yantosca (talk) 20:04, 20 April 2017 (UTC)

Known issues

GNU Fortran seg fault error may be caused by uninitialized variables

When using GNU Fortran with debug options (activated when you configure with -DCMAKE_BUILD_TYPE=Debug), FPE=y), be aware that this will cause uninitialized variables to be set to a signaling NaN value (i.e. IEEE Not-a-Number). Therefore, an uninitialized value (especially an array) could potentially cause an error that is reported as a segmentation fault.

For example, in module GeosCore/pjc_pfix_window_mod.F and GeosCore/tpcore_fvdas_window_mod.F90 we had to zero out several array variables that were uninitialized (in GEOS-Chem v11-02c. These uninitialized arrays were causing the nested-grid simulations to halt with segmentation fault errors.

--Bob Yantosca (talk) 21:38, 11 July 2017 (UTC)

Now us ASIN instead of obsolete function ASIND

In HEMCO module HEMCO/Extensions/hcox_paranox_mod.F90, we had to replace the non-standard function ASIND (which returns the arcsine of an argument in degrees) with the ASIN function (which returns the arcsin in radians). The proper unit conversion was then applied.

The code in RED was deleted:

VARS(4) = ASIND( SC5(I,J) )
VARS(5) = ASIND( ExtState%SUNCOS%Arr%Val(I,J) )

And the code in GREEN was added:

VARS(4) = ASIN( SC5(I,J)                     ) / HcoState%Phys%PI_180
VARS(5) = ASIN( ExtState%SUNCOS%Arr%Val(I,J) ) / HcoState%Phys%PI_180

This modification does not cause any numerical differences in the output. All difference tests returned identical results.

--Bob Yantosca (talk) 21:00, 30 September 2016 (UTC)

Now use SIN instead of obsolete function SIND

In the UCX chemistry module GeosCore/ucx_mod.F, we had to replace the non-standard function SIND (which returns the sine of an argument in degrees) with the SIN function (which returns the sine in radians). The argument was converted from degrees to radians before being passed to SIN.

The code in RED was deleted:

JDIF_OUT = SIND(JMAX_OUT)-SIND(JMIN_OUT)
. . .
JDIF_TMP = SIND(JMAX_TMP)-SIND(JMIN_TMP)

And the code in GREEN was added:

USE PhysConstants,      ONLY : PI_180
. . .
 JDIF_OUT = SIN( JMAX_OUT * PI_180 )
&         - SIN( JMIN_OUT * PI_180 )
. . .
    JDIF_TMP = SIN( JMAX_TMP * PI_180 )
&            - SIN( JMIN_TMP * PI_180 )

This change causes very small numerical differences, at the level of numerical noise, only in the "Standard" and "UCX" chemical mechanisms. We attribute these differences to conversion between degrees and radians, probably with a different value of PI in each case.

--Bob Yantosca (talk) 21:14, 30 September 2016 (UTC)

GNU Fortran 4.8 and higher is not compatible with Totalview

GNU Fortran 4.8 and higher versions save debugging information to disk using the DWARF library, version 4, by default. This makes code compiled with GNU Fortran incompatible with the Totalview debugger, version 8.8.0.1, which can only accept DWARF v2 or DWARF v3 input. The GEOS-Chem Support Team noticed this on our local computer cluster. We are still looking into a workaround for this.

--Bob Yantosca (talk) 21:39, 30 September 2016 (UTC)