Skip to content

Commit

Permalink
Add dev utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Nov 25, 2024
1 parent 8cef484 commit 531ab75
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/dev/utils/DEBUGGING_FLAGS.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/config/compiler.gfortran.mk b/config/compiler.gfortran.mk
index 007a335..3fdf8e4 100644
--- a/config/compiler.gfortran.mk
+++ b/config/compiler.gfortran.mk
@@ -24,7 +24,7 @@ endif

FMAKEDEP = $(SCRIPTS_DIR)/sfmakedepend
CPPFLAGS += -DCOMPILER_G95
-FFLAGS = -g -cpp -fconvert=big-endian -O2 -fno-range-check -fallow-argument-mismatch
+FFLAGS = -g -cpp -fconvert=big-endian -O0 -Wall -fcheck=bounds -fcheck=do -fcheck=mem -fcheck=recursion -fbacktrace -fallow-argument-mismatch
F90FLAGS = $(FFLAGS) -ffree-line-length-none
LFLAGS =
ifeq ($(MP),YES)
diff --git a/config/rules.mk b/config/rules.mk
index d981c80..87ef4f2 100644
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -62,7 +62,7 @@ I = I
# by default assume that fortran compiler can do cpp
EXTERNAL_CPP = NO
# assume that C compiler understands basic gcc flags
-CFLAGS = -O2
+CFLAGS = -O0
# check if ABI was specified
ifneq ($(ABI),)
CFLAGS += -m$(ABI)
@@ -430,7 +430,7 @@ endif
$(CPP) $(CPPFLAGS) $< > $@

%.o: %.c
- $(CC) -c -O2 -m64 $<
+ $(CC) -c -O0 -Wall -fcheck=bounds -fcheck=do -fcheck=mem -fcheck=recursion -g -fbacktrace -fallow-argument-mismatch -m64 $<

%.f: %.m4f
-rm -f $@
diff --git a/decks/Makefile b/decks/Makefile
index 4d2791a..c167dc6 100644
--- a/decks/Makefile
+++ b/decks/Makefile
@@ -140,7 +140,7 @@ ifeq ($(GC),YES)
-DCMAKE_Fortran_COMPILER="$(F90)" \
-DCMAKE_Fortran_FLAGS="$(F90FLAGS)" \
-DCMAKE_EXE_LINKER_FLAGS="$(CTM_LFLAGS)"
- cd $(GC_BUILD_DIR) && make -j install
+ cd $(GC_BUILD_DIR) && make VERBOSE=1 -j install
cp $(GC_BUILD_DIR)/mod/*.mod $(MODEL_DIR)/mod/
cp $(GC_BUILD_DIR)/src/HEMCO/mod/*.mod $(MODEL_DIR)/mod/
cp $(GC_BUILD_DIR)/src/Cloud-J/mod/*.mod $(MODEL_DIR)/mod/
diff --git a/modele-control.pyar b/modele-control.pyar
index cf10239..1d78b27 100644
--- a/modele-control.pyar
+++ b/modele-control.pyar
@@ -3447,7 +3447,7 @@ macro(modele_set_flags)
add_definitions(-DCOMPILER_G95)
# This breaks if you try to wrap the long line in the obvious way.
set (CMAKE_Fortran_FLAGS_RELEASE "${CPPFLAGS} -O2 -g -fconvert=big-endian -fno-range-check -ffree-line-length-none")
- set (CMAKE_Fortran_FLAGS_DEBUG "${CPPFLAGS} -O -g -fbacktrace -fconvert=big-endian -fno-range-check -ffree-line-length-none -fcheck=bounds -fcheck=do -fcheck=mem -fcheck=recursion")
+ set (CMAKE_Fortran_FLAGS_DEBUG "${CPPFLAGS} -O0 -g -fbacktrace -fconvert=big-endian -fno-range-check -ffree-line-length-none -fcheck=bounds -fcheck=do -fcheck=mem -fcheck=recursion")


if (CMAKE_BUILD_TYPE MATCHES Release)
106 changes: 106 additions & 0 deletions .github/dev/utils/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/bash

# Set up the environment used by GISS-GC
# NOTE: Path may need to be edited for your system
source ${HOME}/software/GISS-GC/setup.sh

# Default values
FRESH=false
OPENMP=false
GISS_ONLY=false
DEBUG=false

# Function to display help text
show_help() {
echo "Usage: $0 [MP=YES|NO] [--openmp] [--giss-only] [-f] [--debug]"
echo
echo "Options:"
echo " --help Show this help message and exit."
echo " --openmp Compile with OpenMP enabled."
echo " --giss-only Build without GEOS-Chem coupling."
echo " -f Fresh rebuild of the model."
echo " --debug Run with debugging turned on."
}

# Check for --help option
if [ "$1" = "--help" ]; then
show_help
exit 0
fi

# Parse arguments
for arg in "$@"; do
case $arg in
NP=*)
NP="${arg#*=}"
;;
--openmp)
OPENMP=true
shift
;;
-f)
FRESH=true
shift
;;
--giss-only)
GISS_ONLY=true
shift
;;
--debug)
DEBUG=true
shift
;;
*)
echo "Unknown argument: $arg"
show_help
exit 1
;;
esac
done

if [ "${GISS_ONLY}" = true ]; then
GC=NO
RUNID=GISS_ONLY
else
GC=YES
RUNID=GISS_GC_14
# Copy over configuration files
HUGE_SPACE=${HOME}/data/giss-gc/huge_space/${RUNID}
PROD_RUNS=${HOME}/run/giss-gc/prod_runs/${RUNID}
for RUNDIR in ${HUGE_SPACE} ${PROD_RUNS}; do
ln -s -f ${GISS_HOME}/geoschem_config.yml ${RUNDIR}/geoschem_config.yml
ln -s -f ${GISS_HOME}/HEMCO_Config.rc ${RUNDIR}/HEMCO_Config.rc
ln -s -f ${GISS_HOME}/HEMCO_Diagn.rc ${RUNDIR}/HEMCO_Diagn.rc
ln -s -f ${GISS_HOME}/HISTORY.rc ${RUNDIR}/HISTORY.rc
ln -s -f ${GISS_HOME}/species_database.yml ${RUNDIR}/species_database.yml
done
# Create output directories
mkdir -p ${HUGE_SPACE}/OutputDir
mkdir -p ${PROD_RUNS}/OutputDir
fi

# Print the values for verification
echo "NP=${NP}"
echo "OPENMP=${OPENMP}"
echo "GC=${GC}"
echo "FRESH=${FRESH}"
echo "DEBUG=${DEBUG}"

# Conditionally fresh rebuild of the model
cd ${GISS_HOME}/decks/
cp ${GISS_HOME}/.github/rundecks/${RUNID}.R .
if [ "${FRESH}" = true ]; then
make clean
make clean_all
fi

# Compile
if [ "${DEBUG}" = true ]; then
git apply .github/utils/DEBUGGING_FLAGS.patch
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=carbon \
TYPE=Debug DEBUG=YES COMPILE_WITH_TRAPS=YES TRACEBACK=YES OVERWRITE=YES
git apply -R .github/utils/DEBUGGING_FLAGS.patch
else
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=carbon \
TYPE=Release
fi
53 changes: 53 additions & 0 deletions .github/dev/utils/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/sh

# Default values
NP=1
GISS_ONLY=false

# Function to display help text
show_help() {
echo "Usage: $0 [NP=<integer>] [--giss-only]"
echo
echo "Arguments:"
echo " NP Set number of MPI processes (default: 1). Must be an integer."
echo
echo "Options:"
echo " --help Show this help message and exit."
echo " --giss-only Build without GEOS-Chem coupling."
}

# Check for --help option
if [ "$1" = "--help" ]; then
show_help
exit 0
fi

# Parse arguments
for arg in "$@"; do
case $arg in
NP=*)
NP="${arg#*=}"
;;
--giss-only)
GISS_ONLY=true
shift
;;
*)
echo "Unknown argument: $arg"
show_help
exit 1
;;
esac
done

# Set RUNID appropriately
if [ "${GISS_ONLY}" = true ]; then
RUNID=GISS_ONLY
else
RUNID=GISS_GC_14
fi

# Navigate to the run directory and run the model for one hour
cd ~/run/giss-gc/prod_runs/${RUNID}
./${RUNID}ln
mpiexec -np ${NP} ./${RUNID}.exe -i I -cold-restart
42 changes: 42 additions & 0 deletions .github/dev/utils/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/bash
# ============================================================================ #
# Activate the Python and spack environments used by GISS-GC. #
# ============================================================================ #

# Envronment variables for GISS modelE
# NOTE: Path may need to be edited for your system
export GISS_HOME=${SOFTWARE}/GISS-GC
export ModelE_Support=${HOME}/run/giss-gc
mkdir -p ${ModelE_Support}
# Environment variables for compiler
export CC=gcc
export CXX=g++
export FC=gfortran
export F90=${FC}
export F77=${FC}
# Misc. enviroment variables
export F_UFMTENDIAN=big
export KMP_STACKSIZE=100000000
export OMP_NUM_THREADS=1

# Spack setup
spack env activate -p giss-gc
export MPI_ROOT=${HOME}/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.4.0/openmpi-4.1.6-s3fu5gvaasgjy4jecnb6rvemx7oofexx

# Environment variables for passing NetCDF-C paths to GEOS-Chem
export NETCDF_HOME=$(nc-config --prefix)
export GC_BIN=${NETCDF_HOME}/bin
export GC_INCLUDE=${NETCDF_HOME}/include
export GC_LIB=${NETCDF_HOME}/lib

# Environment variables for passing NetCDF-Fortran paths to GEOS-Chem
export NETCDF_F_HOME=$(nf-config --prefix)
export GC_F_BIN=${NETCDF_F_HOME}/bin
export GC_F_INCLUDE=${NETCDF_F_HOME}/include
export GC_F_LIB=${NETCDF_F_HOME}/lib

# GEOS-Chem input data
export ROOT=${DATA}/gcclassic/ExtData/HEMCO/

# Put tools in the path
export PATH=${SOFTWARE}/tools/mk_diags:${PATH}

0 comments on commit 531ab75

Please sign in to comment.