Difference between revisions of "Specifying compilers for GEOS-Chem"

From Geos-chem
Jump to: navigation, search
(Using spack)
 
(45 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
'''''[[Configuring your computational environment|Previous]] | [[Specifying software libraries for GEOS-Chem|Next]] | [[Getting Started with GEOS-Chem]]'''''
 
'''''[[Configuring your computational environment|Previous]] | [[Specifying software libraries for GEOS-Chem|Next]] | [[Getting Started with GEOS-Chem]]'''''
 
#[[Minimum system requirements for GEOS-Chem|Minimum system requirements]]
 
#[[Minimum system requirements for GEOS-Chem|Minimum system requirements]]
 +
#[[Installing required software]]
 
#[[Configuring your computational environment]]
 
#[[Configuring your computational environment]]
#*<span style="color:blue">'''Specifying compilers for GEOS-Chem'''</span>
+
#*<span style="color:blue">'''Specifying the compiler'''</span>
 
#*[[Specifying software libraries for GEOS-Chem|Specifying libraries]]
 
#*[[Specifying software libraries for GEOS-Chem|Specifying libraries]]
 
#*[[Specifying settings for OpenMP parallelization|Specifying parallelization settings]]
 
#*[[Specifying settings for OpenMP parallelization|Specifying parallelization settings]]
Line 14: Line 15:
 
#[[Running GEOS-Chem|Running]]
 
#[[Running GEOS-Chem|Running]]
 
#[[GEOS-Chem output files|Output files]]
 
#[[GEOS-Chem output files|Output files]]
#[[Guide_to_visualization_and_analysis_tools_for_GEOS-Chem|Visualizing and processing output]]
+
#[[Python tools for use with GEOS-Chem]]
 
#[[GEOS-Chem_coding_and_debugging|Coding and debugging]]
 
#[[GEOS-Chem_coding_and_debugging|Coding and debugging]]
 
#[[GEOS-Chem_overview#Further_reading|Further reading]]
 
#[[GEOS-Chem_overview#Further_reading|Further reading]]
  
  
== Selecting the compiler ==
+
On this page, we discuss how to specify the compilers that you will use with GEOS-Chem "Classic". 
  
There are typically several ways in which you can select the compiler that you wish to use with GEOS-Chem. Not all of these may be present on your system, so it is always best to ask your IT staff about specifics
+
Please see ''[[Setting Up the GCHP Environment]]'' for detailed instructions about setting up your computational environment for a GCHP simulation.
  
=== Using Lmod modules ===
+
== Selecting the compiler ==
  
Many computational clusters use the Lmod module system to allow you to pick and choose different pre-compiled software programs and librariesLmod makes it easy to switch between different compiler versions, if more than compiler has been installed.  Check with your IT staff if your system uses the Lmod module command.
+
There are typically several ways in which you can select the compiler that you wish to use with GEOS-ChemNot all of these may be present on your system, so it is always best to ask your IT staff about the method that your system uses.
  
If your system uses Lmod, then you can load the compiler with commands such as:
+
=== Using a module manager ===
 +
 
 +
[[Installing_required_software#First.2C_check_if_required_libraries_are_available_as_modules|As discussed earlier]], Many computational clusters use the [https://lmod.readthedocs.io/en/latest/ '''Lmod''' module system] or the [https://modules.readthedocs.io/en/latest/  '''environment-modules''' package] to allow you to pick and choose different pre-compiled software programs and libraries.  If your system uses one of these module managers, then you can specify the compiler you wish to use by means of a command such as:
  
 
  module load intel/19.0
 
  module load intel/19.0
Line 35: Line 38:
 
  module load gcc/9.2.0
 
  module load gcc/9.2.0
  
... etc ...
+
For more information, please see our chapter on ''[[Installing required software]]''.
  
(Actual commands will vary from system to system.)
+
=== Using Spack ===
  
You can typically place these <tt>module load</tt> commands in your <tt>.bashrc</tt> or <tt>.bash_aliases</tt> startup scripts.  Ask your IT staff where they would prefer them to be placed.
+
[[Installing_required_software#Next.2C_check_if_there_is_a_Spack-built_software_stack|As discussed earlier]], if you have a Spack-built software stack on your system, you can use commands such as
  
When a module is "loaded", the following things typically happen:
+
spack load gcc@9.2.0
#The path to the compiler executable is added to your Unix <tt>$PATH</tt> variable.
+
#The path to the compiler library files is added to your <tt>$LD_LIBRARY_PATH</tt> environment variable.
+
#One or more environment variables (e.g. <tt>$INTEL_HOME</tt>, <tt>$GCC_HOME</tt>) are added to your Unix environment.
+
  
=== Using spack ===
+
to specify the compiler that you wish to use. In the above example, we are requesting the GNU Compiler Collection version 9.2.0.
  
TBD
+
Even if you don't have a module manager installed on your system, you can still use Spack-built libraries.  In this case, you might need to manually set some environment variables using the paths to the Spack-built libraries.  For more information, please see the [https://spack.readthedocs.io/en/latest/ Spack documentation].
 +
 
 +
Our [https://www.youtube.com/watch?v=7eMLYKLK9wY&t=1333s '''Spack Tutorial #1'''] video provides a good overview of how to build a compiler using Spack and to make sure that your system can find it.
  
 
=== Direct specification ===
 
=== Direct specification ===
  
TBD
+
If your system uses neither the [[#Using a module manager|a module manager]] nor the [[#Using Spack|Spack package manager]], you can still manually specify the path to the compiler.  Most Unix operating system builds (e.g. CentOS, Ubuntu, etc.) come with a prebuilt version of gcc/gfortran in /usr/bin/gfortran.  So you can add this line to your <tt>~/.bashrc</tt> file:
 +
 
 +
export PATH="/usr/bin/gfortran:$PATH"
 +
 
 +
and then type
 +
 
 +
source ~/.bashrc
 +
 
 +
to accept the changes.
  
 
== Defining the proper environment variables ==
 
== Defining the proper environment variables ==
  
TBD
+
After you have specified a compiler to use with GEOS-Chem, you must set a few [https://www.networkworld.com/article/3215965/all-you-need-to-know-about-unix-environment-variables.html Unix environment variables].  These definitions can be placed in the same startup script (usually <tt>.bashrc</tt> or <tt>.bash-aliases</tt>) as the commands that load the compiler.
 +
 
 +
=== Unix environment variables for compilers ===
 +
 
 +
It is a Unix convention to use the following environment variable names for compilers:
 +
 
 +
{| border=1 cellspacing=0 cellpadding=5
 +
|-valign="top" bgcolor="#CCCCCC"
 +
!width="100px"|Variable
 +
!width="300px"|Description
 +
 
 +
|-valign="top"
 +
|<tt>FC</tt> || Name of the Fortran compiler
 +
 
 +
|-valign="top"
 +
|<tt>CC</tt> || Name of the C compiler
 +
 
 +
|-valign="top"
 +
|<tt>CXX</tt> || Name of the C++ compiler
 +
 
 +
|}
 +
 
 +
In most cases, the Fortran, C, and C++ compilers are installed together as a integrated package.  Often, using the <tt>module load</tt> command will load all three compilers into your Unix environment together.  If you are using GEOS-Chem "Classic" then you really only need the Fortran compiler.  But other software packages on your system will use the C and/or C++ compilers.
 +
 
 +
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:41, 17 December 2019 (UTC)
 +
 
 +
=== Check if compiler environment variables have been automatically set ===
 +
 
 +
On many systems (espcially those using the Lmod module system), <tt>FC</tt>, <tt>CC</tt>, and <tt>CXX</tt> will be set automatically for you when you use the  <tt>module load</tt> command.  The easiest way to check if these variables have been automatically set for you is to print them to the screen.  Type at the Unix prompt:
 +
 
 +
echo $FC
 +
echo $CC
 +
echo $CXX
 +
 
 +
If these variables are all blank, then you must define these manually ([[#Manually defining compiler environment variables|see next section]]). If they are NOT blank, then you are all set!
 +
 
 +
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 21:42, 17 December 2019 (UTC)
 +
 
 +
=== Manually defining compiler environment variables ===
 +
 
 +
If the <tt>FC</tt>, <tt>CC</tt>, and <tt>CXX</tt> environment variables are all undefined, then you will have to manually set them in your startup script as described below:
 +
 
 +
{| border=1 cellspacing=0 cellpadding=5
 +
|-valign="top" bgcolor="#CCCCCC"
 +
!width="125px"|If your<br>shell is
 +
!width="125px"|and your<br>compiler is
 +
!width="300px"|use these definitions
 +
 
 +
|-valign="top"
 +
|<tt>/bin/bash</tt>
 +
|<tt>ifort</tt>
 +
|<tt>export FC=ifort<br>export CC=icc<br>export CXX=icpc</tt>
 +
 
 +
|-valign="top"
 +
|<tt>/bin/bash</tt>
 +
|<tt>gfortran</tt>
 +
|<tt>export FC=gfortran<br>export CC=gcc<br>export CXX=g++</tt>
 +
 +
|}
 +
 
 +
Then make sure to type:
 +
 
 +
source ~/.bashrc  # if you are using bash
 +
 
 +
to apply the changes.
 +
 
 +
== Further reading ==
 +
 
 +
#''[[Guide to compilers for GEOS-Chem]]''
 +
#[[GEOS-Chem basics]]
 +
#[https://www.networkworld.com/article/3215965/all-you-need-to-know-about-unix-environment-variables.html ''All you need to know about Unix environment variables'' (Network World)]
 +
 
 +
 
  
 
----
 
----
 
'''''[[Configuring your computational environment|Previous]] | [[Specifying software libraries for GEOS-Chem|Next]] | [[Getting Started with GEOS-Chem]]'''''
 
'''''[[Configuring your computational environment|Previous]] | [[Specifying software libraries for GEOS-Chem|Next]] | [[Getting Started with GEOS-Chem]]'''''

Latest revision as of 21:27, 8 December 2020

Previous | Next | Getting Started with GEOS-Chem

  1. Minimum system requirements
  2. Installing required software
  3. Configuring your computational environment
  4. Downloading source code
  5. Downloading data directories
  6. Creating run directories
  7. Configuring runs
  8. Compiling
  9. Running
  10. Output files
  11. Python tools for use with GEOS-Chem
  12. Coding and debugging
  13. Further reading


On this page, we discuss how to specify the compilers that you will use with GEOS-Chem "Classic".

Please see Setting Up the GCHP Environment for detailed instructions about setting up your computational environment for a GCHP simulation.

Selecting the compiler

There are typically several ways in which you can select the compiler that you wish to use with GEOS-Chem. Not all of these may be present on your system, so it is always best to ask your IT staff about the method that your system uses.

Using a module manager

As discussed earlier, Many computational clusters use the Lmod module system or the environment-modules package to allow you to pick and choose different pre-compiled software programs and libraries. If your system uses one of these module managers, then you can specify the compiler you wish to use by means of a command such as:

module load intel/19.0

or

module load gcc/9.2.0

For more information, please see our chapter on Installing required software.

Using Spack

As discussed earlier, if you have a Spack-built software stack on your system, you can use commands such as

spack load gcc@9.2.0

to specify the compiler that you wish to use. In the above example, we are requesting the GNU Compiler Collection version 9.2.0.

Even if you don't have a module manager installed on your system, you can still use Spack-built libraries. In this case, you might need to manually set some environment variables using the paths to the Spack-built libraries. For more information, please see the Spack documentation.

Our Spack Tutorial #1 video provides a good overview of how to build a compiler using Spack and to make sure that your system can find it.

Direct specification

If your system uses neither the a module manager nor the Spack package manager, you can still manually specify the path to the compiler. Most Unix operating system builds (e.g. CentOS, Ubuntu, etc.) come with a prebuilt version of gcc/gfortran in /usr/bin/gfortran. So you can add this line to your ~/.bashrc file:

export PATH="/usr/bin/gfortran:$PATH"

and then type

source ~/.bashrc

to accept the changes.

Defining the proper environment variables

After you have specified a compiler to use with GEOS-Chem, you must set a few Unix environment variables. These definitions can be placed in the same startup script (usually .bashrc or .bash-aliases) as the commands that load the compiler.

Unix environment variables for compilers

It is a Unix convention to use the following environment variable names for compilers:

Variable Description
FC Name of the Fortran compiler
CC Name of the C compiler
CXX Name of the C++ compiler

In most cases, the Fortran, C, and C++ compilers are installed together as a integrated package. Often, using the module load command will load all three compilers into your Unix environment together. If you are using GEOS-Chem "Classic" then you really only need the Fortran compiler. But other software packages on your system will use the C and/or C++ compilers.

--Bob Yantosca (talk) 21:41, 17 December 2019 (UTC)

Check if compiler environment variables have been automatically set

On many systems (espcially those using the Lmod module system), FC, CC, and CXX will be set automatically for you when you use the module load command. The easiest way to check if these variables have been automatically set for you is to print them to the screen. Type at the Unix prompt:

echo $FC
echo $CC
echo $CXX

If these variables are all blank, then you must define these manually (see next section). If they are NOT blank, then you are all set!

--Bob Yantosca (talk) 21:42, 17 December 2019 (UTC)

Manually defining compiler environment variables

If the FC, CC, and CXX environment variables are all undefined, then you will have to manually set them in your startup script as described below:

If your
shell is
and your
compiler is
use these definitions
/bin/bash ifort export FC=ifort
export CC=icc
export CXX=icpc
/bin/bash gfortran export FC=gfortran
export CC=gcc
export CXX=g++

Then make sure to type:

source ~/.bashrc   # if you are using bash

to apply the changes.

Further reading

  1. Guide to compilers for GEOS-Chem
  2. GEOS-Chem basics
  3. All you need to know about Unix environment variables (Network World)



Previous | Next | Getting Started with GEOS-Chem