Difference between revisions of "Compiling GCHP"

From Geos-chem
Jump to: navigation, search
(Run Directory Makefile)
(38 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''''[[Setting Up the GCHP Environment|Previous]] | [[GCHP_Basic_Example_Run|Next]] | [[Getting_Started_With_GCHP|User Manual Home]] | [[GEOS-Chem_HP|GCHP Home]]'''''
+
'''''[[Downloading_GCHP|Previous]] | [[Obtaining_a_GCHP_Run_Directory|Next]] | [[Getting Started with GCHP]] | [[GCHP Main Page]]'''''
 
#[[GCHP_Hardware_and_Software_Requirements|Hardware and Software Requirements]]
 
#[[GCHP_Hardware_and_Software_Requirements|Hardware and Software Requirements]]
 +
#[[Setting_Up_the_GCHP_Environment|Setting Up the GCHP Environment]]
 
#[[Downloading_GCHP|Downloading Source Code and Data Directories]]
 
#[[Downloading_GCHP|Downloading Source Code and Data Directories]]
 +
#<span style="color:blue">'''Compiling'''</span>
 
#[[Obtaining_a_GCHP_Run_Directory|Obtaining a Run Directory]]
 
#[[Obtaining_a_GCHP_Run_Directory|Obtaining a Run Directory]]
#[[Setting_Up_the_GCHP_Environment|Setting Up the GCHP Environment]]
 
#<span style="color:blue">'''Compiling'''</span>
 
 
#[[Running_GCHP:_Basics|Running GCHP: Basics]]
 
#[[Running_GCHP:_Basics|Running GCHP: Basics]]
 
#[[Running_GCHP:_Configuration|Running GCHP: Configuration]]
 
#[[Running_GCHP:_Configuration|Running GCHP: Configuration]]
Line 12: Line 12:
 
<br>
 
<br>
  
== Overview ==
+
Compiling GCHP is the same procedure as compiling GEOS-Chem Classic. Please see [http://wiki.seas.harvard.edu/geos-chem/index.php/Compiling_with_CMake Compiling with CMake] for instructions.
 
+
This section provides instructions on how to clean and compile GCHP. There are several options for cleaning and compiling which allow clean and compilation of subsets of modules, thereby minimizing recompilation to only modules you have modified. This is a very big time-saver so please pay attention to the build options. You can always see all of your options, along with tips on which option you should use based on your changes, by typing <tt>make</tt> or <tt>make help</tt> at the command line within your run directory.
+
 
+
First time compilation can take 30 minutes or more because it requires building large modules from scratch, including [https://www.earthsystemcog.org/projects/esmf/ ESMF], [https://geos5.org/wiki/index.php?title=MAPL_software MAPL], [https://www.gfdl.noaa.gov/fv3/ FV3 dycore advection], and GEOS-Chem. MAPL, which is short for Modeling, Analysis and Prediction Layer, is built on ESMF, aka the Earth System Modeling Framework. Both systems are highly flexible but highly complex, with significant compilation times. Fortunately, MAPL and ESMF do not need to be recompiled unless parts of their code have been modified which is usually not necessary. Subsequent compile times will therefore be significantly shorter, on the same order of magnitude as compiling GEOS-Chem Classic.
+
 
+
If you run into problems compiling GCHP and cannot figure out why, please create an issue on the GCHP issue tracker located at [https://github.com/geoschem/gchp/issues https://github.com/geoschem/gchp/issues].
+
 
+
== Run Directory Makefile ==
+
 
+
The GCHP run directory <tt>Makefile</tt> contains several options for cleaning and compiling source code, as well as utility options you might find useful. Options are printed out by typing the following at the command line:
+
 
+
make help
+
 
+
It is important that you do this and browse the options available. Several options are particularly useful for cleaning up files in your run directory and displaying the status of your source code. Knowing which build options to use based on what you changed in the model or your libraries is important for saving yourself time.
+
 
+
=== Initial Compile ===
+
 
+
To compile GCHP from scratch, including ESMF, MAPL, FV3 advection, and GEOS-Chem core files, navigate to your run directory. Then type the followng:
+
 
+
make clean_all
+
make build_all
+
 
+
When you first download source code the directories will already be clean, so doing <tt>make clean_all</tt> technically is not necessary. However, it is recommended to be in the habit of including clean for fresh builds. It will be necessary if you change compiler or other libraries.
+
 
+
All build information is sent to both the terminal window and to a log file called <tt>compile.log</tt>. Git information for source code at compile time are recorded in a separate file called <tt>lastbuild</tt> for future reference, similar to GEOS-Chem Classic.
+
 
+
Upon successful compilation, the following empty files are created in your GCHP source code directories:
+
* <tt>GCHP/ESMF/esmf.install</tt>
+
* <tt>GCHP/Shared/mapl.install</tt>
+
* <tt>GCHP/FVdycoreCubed_GridComp/fvdycore.install</tt>
+
 
+
These files indicate successful compilation per module. If you are ever uncertain on whether your ESMF, MAPL, and FV3 dycore were previously built, check if these files exist.
+
 
+
=== Recompile ===
+
 
+
For subsequent GCHP compilations you have several options. You can remind yourself of all options by typing <tt>make</tt> or <tt>make help</tt> at the command prompt. Here is a summary of the compile options.
+
 
+
make build_all  # Compile all source code (slow)
+
make build_mapl # Compile MAPL, FV3, and GEOS-chem core (skip ESMF)
+
make build_core # Compile GEOS-Chem core only (fast)
+
 
+
Same as above but compile GEOS-Chem with debug flags turned on (note that this will slow down the model)
+
make build_core_debug
+
 
+
None of these compile options clean the source code. To save time, we recommend not cleaning source code as you are developing GEOS-Chem. However, if you change libraries are upgrade versions you should always do a fresh build from scratch.
+
 
+
A typical workflow would be:
+
#Create a run directory
+
#Compile from scratch (make clean_all; make build_all)
+
#Edit GEOS-Chem code in GeosCore
+
#Recompile with debug flags on (make build_core_debug)
+
#Do a short test run to see if any of the debug flags trigger a problem
+
#Repeat as needed
+
#Recompile with debug flags off (make build_core) for longer runs after debugging
+
 
+
If at any time your forget what the make options are, simply type:
+
 
+
make help
+
 
+
Note that if you change your underlying libraries (configured in your environment file) you MUST do a full source code clean before rebuilding. Otherwise you will likely encounter a segmentation fault when running the model. For this reason it is recommended that you create a new run directory for each new environment you want to run in, e.g. if you want to test with both Intel and GNU fortran compilers.
+
 
+
== Compilation Tips ==
+
 
+
If a GCHP executable exists in the GEOS-Chem bin/ folder to be copied to your run directory, then you should see the following message at the end of compilation:
+
 
+
###################################
+
### GCHP compiled successfully! ###
+
###################################
+
 
+
If you did a clean compile of your code and you see this message then you know that GCHP compiled without error. Compiler output, including warnings and error messages, will be stored in a log file called <tt>compile.log</tt>. If you inspect your log file or watch the compile output real-time, you will notice that there are many warnings and error messages. Many of these errors are due to leftover components in MAPL which are no longer used but which still try to compile. As long as the compilation continues, these errors can almost always be ignored and they will have no effect on the operation of GCHP.
+
 
+
If you are recompiling your source code and see this message then your compilation may or may not have been successful. Why? Because compilation may fail but the previous executable may still be available to be copied, which is the criteria for this message.
+
 
+
The general rule-of-thumb is if you clean compile or if you build using 'make build_gc' and therefore skip building MAPL, then you can trust the 'GCHP compiled successfully' message. However, if you recompile using 'make build_mapl' without cleaning first, then you will need to dig a little deeper to ensure a successful rebuild. The best way to do this is to do keyword search for 'making install' in <tt>compile.log</tt> and scan the few lines directly above all instances of it. If there was a problem with MAPL you will spot it immediately in one of these areas. If you plan on developing within MAPL please make sure you fully understand this approach to debugging MAPL since it will save you a lot of time and frustration.
+
 
+
Why is this necessary? It is because MAPL will continue to compile even if a compile error occurs. MAPL compilation involves compiling a series of components, many of them dependent on components that came before, and compilation rules are relaxed to allow minor problems. One component may fail compilation but the compilation will not crash until the built file is needed later on in the build sequence. It is therefore necessary to search your log file for errors high above the final error in the event of compile failure. The log file will be long so this should be done by keyword search.
+
 
+
While this has already been stated, we will state it again since it is so useful. Here are strategies that typically hone in immediately on the original MAPL error:
+
 
+
# Search for string "making install" look at the lines immediately above all results of your keyword search.
+
# A second and more tedious option is to search for string "error". Ignore results where error is in a filename or in a source code string that triggered a warning.
+
 
+
If in doubt, check the source code directory to see the file times. If the binary for the file you updated is older than the other binaries then it encountered a compile error in your update.
+
 
+
== Advanced Compilation Topics ==
+
 
+
The <tt>Makefile</tt> in the run directory invokes a bash shell script called <tt>build.sh</tt> that includes changing into the source code directory and invoking source code Makefiles. At its core, building GCHP simply requires the inclusion of additional target <tt>HPC=yes</tt> if cleaning and <tt>hpc</tt> if compiling when invoking make in the GEOS-Chem repository. Cleaning GCHP also requires changing into the GCHP directory explicitly to clean ESMF, MAPL, and FV3 dycore.
+
 
+
If you are interested in seeing the core <tt>make</tt> commands used for all options provided in the run directory <tt>Makefile</tt>, see the commands defined in <tt>build.sh</tt>. You can then trace the build sequence by looking at the Makefiles in the GEOS-Chem and GCHP repositories. Note that calling <tt>make</tt> always invokes the <tt>Makefile</tt> in the directory you are in and changing into the GEOS-Chem and GCHP source code directories occurs within <tt>build.sh</tt>. Also note that the <tt>GRID=4x5</tt> argument has no effect on the resolution at which the model runs since GCHP functions on the cubed-sphere grid. However, passing <tt>GRID</tt> is required so that components of GEOS-Chem Classic are functional.
+
 
+
If you are interested in the build sequence for MAPL, look at the various *.mk files <tt>ESMA_base.mk</tt>, <tt>ESMA_arch.mk</tt>, and <tt>GMAO_base.mk</tt> in <tt>GCHP/Shared/Config</tt> as well as <tt>GNUMakefile</tt> within <tt>GCHP/Shared</tt> and all its subdirectories. Also see <tt>GIGC.mk</tt> in the highest level of the GCHP repository for the include dependencies between GCHP modules.
+
 
+
Currently GCHP does not compile with cmake but work is in progress to make this possible in the future.
+
  
 
--------------------------------------
 
--------------------------------------
  
'''''[[Setting Up the GCHP Environment|Previous]] | [[GCHP_Basic_Example_Run|Next]] | [[Getting_Started_With_GCHP|User Manual Home]] | [[GEOS-Chem_HP|GCHP Home]]'''''
+
'''''[[Downloading_GCHP|Previous]] | [[Obtaining_a_GCHP_Run_Directory|Next]] | [[Getting Started with GCHP]] | [[GCHP Main Page]]'''''

Revision as of 23:53, 9 November 2020

Previous | Next | Getting Started with GCHP | GCHP Main Page

  1. Hardware and Software Requirements
  2. Setting Up the GCHP Environment
  3. Downloading Source Code and Data Directories
  4. Compiling
  5. Obtaining a Run Directory
  6. Running GCHP: Basics
  7. Running GCHP: Configuration
  8. Output Data
  9. Developing GCHP
  10. Run Configuration Files


Compiling GCHP is the same procedure as compiling GEOS-Chem Classic. Please see Compiling with CMake for instructions.


Previous | Next | Getting Started with GCHP | GCHP Main Page