Skip to content

Commit

Permalink
Successfully compile and run GCHP on ubuntu 18.04 with gcc 7.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiZhuang committed Dec 7, 2018
1 parent af8a2c9 commit 0a9f8f3
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 15 deletions.
31 changes: 16 additions & 15 deletions scripts/build_environment/GCHP/deploy_GCHP.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

GC_VERSION=12.1.0
GC_VERSION=b544322
GCHP_VERSION=12.1.0

# Input data directory, need to pull real data later
mkdir -p ~/ExtData/HEMCO
mkdir -p $HOME/ExtData/HEMCO

# Create tutorial folder for demo project
mkdir ~/tutorial
Expand All @@ -13,31 +13,32 @@ cd ~/tutorial
# Source code
git clone https://github.com/geoschem/geos-chem.git Code.GCHP
cd Code.GCHP
git checkout -b $GC_VERSION
git checkout $GC_VERSION

# GCHP subdirectory
git clone https://github.com/geoschem/gchp.git GCHP
cd GCHP
git checkout -b $GCHP_VERSION
git checkout $GCHP_VERSION

# generate run directory
cd Run
rm ${HOME}/.geoschem/config
echo "$HOME/ExtData
2
1
$HOME/tutorial
gchp_standard
n" | ./createRunDir.sh
printf "$HOME/ExtData \n 2 \n 1 \n $HOME/tutorial \n gchp_standard \n n" | ./createRunDir.sh

# compile source code
cd ~/tutorial/gchp_standard
ln -s gchp.env ~/gchp.ubuntu.env # need to copy ubuntu/gchp.ubuntu.env
make compile_clean

ln -sf /home/ec2-user/ExtData/GEOSCHEM_RESTARTS/v2018-11/initial_GEOSChem_rst.c24_standard.nc initial_GEOSChem_rst.c24_standard.nc

# read low-resolution metfields to save space
ln -sf /home/ec2-user/ExtData/GEOS_4x5/GEOS_FP MetDir
# modify run-time configurations

# correctly link restart file
ln -sf $HOME/ExtData/GEOSCHEM_RESTARTS/v2018-11/initial_GEOSChem_rst.c24_standard.nc initial_GEOSChem_rst.c24_standard.nc

# only scan the first few lines, do not modify non-metfields
sed -i -e 1,120s/025x03125.nc/4x5.nc/g ExtData.rc
# read low-resolution metfields to save space
ln -sf $HOME/ExtData/GEOS_4x5/GEOS_FP MetDir
sed -i -e 1,120s/025x03125.nc/4x5.nc/g ExtData.rc # only scan the first few lines, do not modify non-metfields

# hard to see why simulation crashes with default debug level 0
sed -i -e "s#DEBUG_LEVEL.*#DEBUG_LEVEL: 5#" CAP.rc
Expand Down
77 changes: 77 additions & 0 deletions scripts/build_environment/GCHP/ubuntu/gchp.ubuntu.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#==============================================================================
# Environment variables
#==============================================================================

# Specify compilers
export CC=gcc
export OMPI_CC=$CC

export CXX=g++
export OMPI_CXX=$CXX

export FC=gfortran
export F77=$FC
export F90=$FC
export OMPI_FC=$FC
export COMPILER=$FC
export ESMF_COMPILER=gfortran

# MPI Communication
export ESMF_COMM=mpich2
export MPI_ROOT=$( dirname $( dirname $( which mpirun ) ) )

# Base paths
export NETCDF_HOME=/usr
export NETCDF_FORTRAN_HOME=/usr

export GC_BIN="$NETCDF_HOME/bin"
export GC_INCLUDE="$NETCDF_HOME/include"
export GC_LIB="$NETCDF_HOME/lib"

# Add to primary path
export PATH=${NETCDF_HOME}/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NETCDF_HOME}/lib

# If using NetCDF after the C/Fortran split (4.3+), then you will need to
# specify the following additional environment variables
export GC_F_BIN="$NETCDF_FORTRAN_HOME/bin"
export GC_F_INCLUDE="$NETCDF_FORTRAN_HOME/include"
export GC_F_LIB="$NETCDF_FORTRAN_HOME/lib"
export PATH=${NETCDF_FORTRAN_HOME}/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NETCDF_FORTRAN_HOME}/lib

# Set ESMF optimization (g=debugging, O=optimized (capital o))
export ESMF_BOPT=O

#==============================================================================
# Raise memory limits
#==============================================================================

ulimit -c unlimited # coredumpsize
ulimit -l unlimited # memorylocked
ulimit -u 50000 # maxproc
ulimit -v unlimited # vmemoryuse

#==============================================================================
# additional fixes for MAPL
#==============================================================================
export GC_CODE_DIR=$HOME/tutorial/Code.GCHP

# --- Fixes for Makefile ---
# Dependencies files *.d in MAPL are messed up in that
# 1. It directly specifies library headers like mpi.h as dependency, which should have been handled by MPI wrapper like mpicc.
# 2. It cannot find *.mod files that are in another directory.
# VPATH allows makefile to search additional directories, although is not a good practice.
# This prevents the error "no rule to make target"
export VPATH=/usr/include/x86_64-linux-gnu:$VPATH # sys/resource.h
export VPATH=$GC_CODE_DIR/GCHP/Shared/MAPL_Base:$VPATH # mapl_*.mod
export VPATH=$GC_CODE_DIR/GCHP/ESMF/Linux/mod:$VPATH # esmf.mod

# --- Fixed for header files ("#include <xxx.h>" statement) ---
# This prevents the error "cannot find..."
export CPATH=$GC_CODE_DIR/GCHP/Shared/MAPL_Base:$CPATH # MAPL_Generic.h
export CPATH=$GC_CODE_DIR/GCHP/Shared/GFDL_fms/shared/include:$CPATH # fms_platform.h

# --- Fixes for module files ("USE xxx" statement) ---
# zonal.f is looking for mapl_constantsmod.mod in its own directory. Even /usr/include/ is not included
sudo ln -sf $GC_CODE_DIR/GCHP/Shared/MAPL_Base/mapl_constantsmod.mod $GC_CODE_DIR/GCHP/Shared/GEOS_Util/plots/
18 changes: 18 additions & 0 deletions scripts/build_environment/GCHP/ubuntu/install_libraries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Tested on ubuntu 18.04 LTS (ami-0ac019f4fcb7cb7e6)
sudo apt-get update

# The quickest way to install NetCDF libraries. Can compile GEOS-Chem classic.
sudo apt-get install -y bc gcc gfortran \
libnetcdf-dev libnetcdff-dev netcdf-bin \
python-numpy mpich

sudo ln -s /usr/include/mpich/* /usr/include/ # so that MAPL can find header files

# GCHP directly uses `gmake` command, which is not available on ubuntu
# https://ubuntuforums.org/showthread.php?t=1811030
sudo ln -s /usr/bin/make /usr/bin/gmake

# hemco_standalone.x and geos both links -lmpichf9 which doesn't exist.
sudo ln -s /usr/lib/mpich/lib/libmpichfort.so /usr/lib/mpich/lib/libmpichf90.so
sudo ln -s /usr/lib/mpich/lib/libmpichfort.a /usr/lib/mpich/lib/libmpichf90.a

0 comments on commit 0a9f8f3

Please sign in to comment.