Skip to content

Commit

Permalink
Merge pull request #70 from fetch4/better-debugging
Browse files Browse the repository at this point in the history
Better debugging approach
  • Loading branch information
jwallwork23 authored Jan 16, 2025
2 parents f119a98 + a760a88 commit 80760ee
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 98 deletions.
77 changes: 0 additions & 77 deletions .dev/utils/DEBUGGING_FLAGS.patch

This file was deleted.

26 changes: 13 additions & 13 deletions .dev/utils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ set -e
FRESH=false
OPENMP=false
GISS_ONLY=false
MECH=fullchem
DEBUG=false

# Function to display help text
show_help() {
echo "Usage: $0 [MP=YES|NO] [--openmp] [--giss-only] [-f] [--debug]"
echo "Usage: $0 [MECH=fullchem|carbon|Hg|custom] [--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."
echo " MECH=<mechanism> Set the chemical mechanism (defaults to fullchem)."
echo " --openmp Compile with OpenMP enabled."
echo " --giss-only Build without GEOS-Chem coupling."
echo " --debug Run with debugging turned on."
echo " -f Fresh rebuild of the model."
echo " --help Show this help message and exit."
}

# Check for --help option
Expand All @@ -32,8 +34,8 @@ fi
# Parse arguments
for arg in "$@"; do
case $arg in
NP=*)
NP="${arg#*=}"
MECH=*)
MECH="${arg#*=}"
;;
--openmp)
OPENMP=true
Expand Down Expand Up @@ -68,7 +70,7 @@ else
fi

# Print the values for verification
echo "NP=${NP}"
echo "MECH=${MECH}"
echo "OPENMP=${OPENMP}"
echo "GC=${GC}"
echo "FRESH=${FRESH}"
Expand All @@ -85,13 +87,11 @@ fi
if [ "${DEBUG}" = true ]; then
ln -s -f ${GISS_HOME}/.github/rundecks/${RUNID}.R $(pwd)/${RUNID}_DEBUG.R
RUNID="${RUNID}_DEBUG"
git apply ${GISS_HOME}/.dev/utils/DEBUGGING_FLAGS.patch
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=carbon \
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=${MECH} \
TYPE=Debug DEBUG=YES COMPILE_WITH_TRAPS=YES TRACEBACK=YES OVERWRITE=YES
git apply -R ${GISS_HOME}/.dev/utils/DEBUGGING_FLAGS.patch
else
ln -s -f ${GISS_HOME}/.github/rundecks/${RUNID}.R $(pwd)/${RUNID}.R
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=carbon \
make -j setup RUN=${RUNID} F90=mpif90 GC=${GC} MP=${OPENMP} MPI=YES MECH=${MECH} \
TYPE=Release OVERWRITE=YES
fi

Expand Down
6 changes: 5 additions & 1 deletion config/compiler.gfortran.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ endif

FMAKEDEP = $(SCRIPTS_DIR)/sfmakedepend
CPPFLAGS += -DCOMPILER_G95
ifeq ($(TYPE),Debug)
FFLAGS = -g -cpp -fconvert=big-endian -O0 -Wall -fcheck=bounds -fcheck=do -fcheck=mem -fcheck=recursion -fbacktrace -fallow-argument-mismatch
else
FFLAGS = -g -cpp -fconvert=big-endian -O2 -fno-range-check -fallow-argument-mismatch
endif
F90FLAGS = $(FFLAGS) -ffree-line-length-none
LFLAGS =
ifeq ($(MP),YES)
Expand All @@ -34,7 +38,7 @@ LFLAGS += -fopenmp
endif
CTM_LFLAGS = $(LFLAGS)
ifeq ($(GC),YES)
CTM_LFLAGS += -nostartfiles -Wno-main
CTM_LFLAGS += -nostartfiles
endif

F90_VERSION = $(shell $(F90) --version | head -1)
Expand Down
9 changes: 7 additions & 2 deletions config/compiler.intel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ IFORT_RELEASE := $(shell ifort --version | perl -e \
'while(<>){ if(/ifort.* (\d+\.\d+)/) { print "$$1"; } }')
FMAKEDEP = $(SCRIPTS_DIR)/sfmakedepend
CMP_MOD = $(SCRIPTS_DIR)/compare_module_file.pl -compiler INTEL-ifort-9-0-on-LINUX
ifeq ($(TYPE),Debug)
FFLAGS = -fpp -O0 -warn all -check bounds -check uninit -check pointers -traceback -assume byterecl -ftz -convert big_endian
LFLAGS = -O0 -ftz
else
FFLAGS = -fpp -O2 -ftz -convert big_endian
F90FLAGS = $(FFLAGS) -free
LFLAGS = -O2 -ftz
endif
F90FLAGS = $(FFLAGS) -free
CPPFLAGS += -DCOMPILER_Intel8 -DCONVERT_BIGENDIAN
F90_VERSION = $(shell $(F90) --version 2>&1)
ifeq ($(MP),YES)
Expand All @@ -16,7 +21,7 @@ LFLAGS += -qopenmp
endif
CTM_LFLAGS = $(LFLAGS)
ifeq ($(GC),YES)
CTM_LFLAGS += -nostartfiles -nofor-main
CTM_LFLAGS += -nostartfiles
endif
R8 = -r8
EXTENDED_SOURCE = -extend_source
Expand Down
6 changes: 5 additions & 1 deletion config/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ I = I
# by default assume that fortran compiler can do cpp
EXTERNAL_CPP = NO
# assume that C compiler understands basic gcc flags
ifeq ($(TYPE),Debug)
CFLAGS = -O0
else
CFLAGS = -O2
endif
# check if ABI was specified
ifneq ($(ABI),)
CFLAGS += -m$(ABI)
Expand Down Expand Up @@ -430,7 +434,7 @@ endif
$(CPP) $(CPPFLAGS) $< > $@

%.o: %.c
$(CC) -c -O2 -m64 $<
$(CC) -c $(CFLAGS) -m64 $<

%.f: %.m4f
-rm -f $@
Expand Down
9 changes: 6 additions & 3 deletions decks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ $(MODEL_DIR)/Makefile: $(MODEL_E_ROOT)/model/Makefile
cp $(MODEL_E_ROOT)/model/Makefile $(MODEL_DIR)/Makefile
endif

ifeq ($(TYPE),Debug)
DEBUG=1
else
DEBUG=0
endif

gcm $(BIN_DIR)/$(RUN).exe: $(RUN).mk $(BIN_DIR) depend check_vars
ifeq ($(GC),YES)
Expand All @@ -135,12 +140,10 @@ ifeq ($(GC),YES)
# If MECH is not specified, it defaults to "fullchem". May also be "carbon".
cd $(GC_BUILD_DIR) && cmake ../ -DINSTALLCOPY=.. \
-DCMAKE_BUILD_TYPE="$(TYPE)" -DOMP="$(MP)" -DMECH="$(MECH)" \
-DCMAKE_C_COMPILER="$(CC)" \
-DCMAKE_CXX_COMPILER="$(CXX)" \
-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=$(DEBUG) -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/
Expand Down
2 changes: 1 addition & 1 deletion modele-control.pyar
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 80760ee

Please sign in to comment.