Skip to content

Commit

Permalink
Adding debug option for all build scripts (NOAA-EMC#2326)
Browse files Browse the repository at this point in the history
This PR addresses issue NOAA-EMC#300 that allows building in `debug` mode.
Co-authored-by: David Huber <69919478+DavidHuber-NOAA@users.noreply.github.com>
Co-authored-by: Rahul Mahajan <aerorahul@users.noreply.github.com>
  • Loading branch information
HenryRWinterbottom committed Mar 1, 2024
1 parent 91738cb commit 52fa3cb
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 92 deletions.
60 changes: 31 additions & 29 deletions sorc/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ function _usage() {
Builds all of the global-workflow components by calling the individual build
scripts in sequence.
Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-h][-j n][-v][-w]
Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-d][-h][-j n][-v][-w]
-a UFS_app:
Build a specific UFS app instead of the default
-d:
Build in debug mode
-g:
Build GSI
-h:
Expand All @@ -29,26 +31,29 @@ Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-h][-j n][-v][-w]
Build UFS-DA
-v:
Execute all build scripts with -v option to turn on verbose where supported
-w:
Use unstructured wave grid
-w:
Use unstructured wave grid
EOF
exit 1
}

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
cd "${script_dir}" || exit 1
# shellcheck disable=SC2155
readonly HOMEgfs=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )/.." && pwd -P)
cd "${HOMEgfs}/sorc" || exit 1

_build_ufs_opt=""
_build_ufsda="NO"
_build_gsi="NO"
_build_debug=""
_verbose_opt=""
_wave_unst=""
_build_job_max=20
# Reset option counter in case this script is sourced
OPTIND=1
while getopts ":a:ghj:uvw" option; do
while getopts ":a:dghj:uvw" option; do
case "${option}" in
a) _build_ufs_opt+="-a ${OPTARG} ";;
d) _build_debug="-d" ;;
g) _build_gsi="YES" ;;
h) _usage;;
j) _build_job_max="${OPTARG} ";;
Expand All @@ -68,24 +73,24 @@ done

shift $((OPTIND-1))

logs_dir="${script_dir}/logs"
logs_dir="${HOMEgfs}/sorc/logs"
if [[ ! -d "${logs_dir}" ]]; then
echo "Creating logs folder"
mkdir "${logs_dir}" || exit 1
mkdir -p "${logs_dir}" || exit 1
fi

# Check final exec folder exists
if [[ ! -d "../exec" ]]; then
echo "Creating ../exec folder"
mkdir ../exec
if [[ ! -d "${HOMEgfs}/exec" ]]; then
echo "Creating ${HOMEgfs}/exec folder"
mkdir -p "${HOMEgfs}/exec"
fi

#------------------------------------
# GET MACHINE
#------------------------------------
export COMPILER="intel"
source gfs_utils.fd/ush/detect_machine.sh
source gfs_utils.fd/ush/module-setup.sh
source "${HOMEgfs}/ush/detect_machine.sh"
source "${HOMEgfs}/ush/module-setup.sh"
if [[ -z "${MACHINE_ID}" ]]; then
echo "FATAL: Unable to determine target machine"
exit 1
Expand Down Expand Up @@ -117,19 +122,19 @@ declare -A build_opts
big_jobs=0
build_jobs["ufs"]=8
big_jobs=$((big_jobs+1))
build_opts["ufs"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt}"
build_opts["ufs"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt} ${_build_debug}"

build_jobs["upp"]=2
build_opts["upp"]=""
build_opts["upp"]="${_build_debug}"

build_jobs["ufs_utils"]=2
build_opts["ufs_utils"]="${_verbose_opt}"
build_opts["ufs_utils"]="${_verbose_opt} ${_build_debug}"

build_jobs["gfs_utils"]=1
build_opts["gfs_utils"]="${_verbose_opt}"
build_opts["gfs_utils"]="${_verbose_opt} ${_build_debug}"

build_jobs["ww3prepost"]=2
build_opts["ww3prepost"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt}"
build_opts["ww3prepost"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt} ${_build_debug}"

# Optional DA builds
if [[ "${_build_ufsda}" == "YES" ]]; then
Expand All @@ -138,21 +143,21 @@ if [[ "${_build_ufsda}" == "YES" ]]; then
else
build_jobs["gdas"]=8
big_jobs=$((big_jobs+1))
build_opts["gdas"]="${_verbose_opt}"
build_opts["gdas"]="${_verbose_opt} ${_build_debug}"
fi
fi
if [[ "${_build_gsi}" == "YES" ]]; then
build_jobs["gsi_enkf"]=8
build_opts["gsi_enkf"]="${_verbose_opt}"
build_opts["gsi_enkf"]="${_verbose_opt} ${_build_debug}"
fi
if [[ "${_build_gsi}" == "YES" || "${_build_ufsda}" == "YES" ]] ; then
build_jobs["gsi_utils"]=1
build_opts["gsi_utils"]="${_verbose_opt}"
build_opts["gsi_utils"]="${_verbose_opt} ${_build_debug}"
if [[ "${MACHINE_ID}" == "hercules" ]]; then
echo "NOTE: The GSI Monitor is not supported on Hercules. Disabling build."
else
build_jobs["gsi_monitor"]=1
build_opts["gsi_monitor"]="${_verbose_opt}"
build_opts["gsi_monitor"]="${_verbose_opt} ${_build_debug}"
fi
fi

Expand Down Expand Up @@ -196,13 +201,10 @@ while [[ ${builds_started} -lt ${#build_jobs[@]} ]]; do
if [[ -n "${build_jobs[${build}]+0}" && -z "${build_ids[${build}]+0}" ]]; then
# Do we have enough processors to run it?
if [[ ${_build_job_max} -ge $(( build_jobs[build] + procs_in_use )) ]]; then
if [[ "${build}" != "upp" ]]; then
"./build_${build}.sh" -j "${build_jobs[${build}]}" "${build_opts[${build}]:-}" > \
"${logs_dir}/build_${build}.log" 2>&1 &
else
"./build_${build}.sh" "${build_opts[${build}]}" > \
"${logs_dir}/build_${build}.log" 2>&1 &
fi
# double-quoting build_opts here will not work since it is a string of options
#shellcheck disable=SC2086
"./build_${build}.sh" ${build_opts[${build}]:-} -j "${build_jobs[${build}]}" > \
"${logs_dir}/build_${build}.log" 2>&1 &
build_ids["${build}"]=$!
echo "Starting build_${build}.sh"
procs_in_use=$(( procs_in_use + build_jobs[${build}] ))
Expand Down
15 changes: 7 additions & 8 deletions sorc/build_gdas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
set -eux

OPTIND=1
_opts="-f " # forces a clean build
while getopts ":j:dv" option; do
case "${option}" in
d) export BUILD_TYPE="DEBUG";;
j) export BUILD_JOBS=${OPTARG};;
v) export BUILD_VERBOSE="YES";;
d) _opts+="-c -DCMAKE_BUILD_TYPE=Debug " ;;
j) BUILD_JOBS=${OPTARG};;
v) _opts+="-v ";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
usage
Expand All @@ -19,12 +20,10 @@ while getopts ":j:dv" option; do
done
shift $((OPTIND-1))

# TODO: GDASApp does not presently handle BUILD_TYPE

BUILD_TYPE=${BUILD_TYPE:-"Release"} \
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
# double quoting opts will not work since it is a string of options
# shellcheck disable=SC2086
BUILD_JOBS="${BUILD_JOBS:-8}" \
WORKFLOW_BUILD="ON" \
./gdas.cd/build.sh
./gdas.cd/build.sh ${_opts} -f

exit
10 changes: 4 additions & 6 deletions sorc/build_gfs_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ EOF
exit 1
}

cwd=$(pwd)

OPTIND=1
while getopts ":j:dvh" option; do
case "${option}" in
d) export BUILD_TYPE="DEBUG";;
v) export BUILD_VERBOSE="YES";;
j) export BUILD_JOBS="${OPTARG}";;
d) BUILD_TYPE="Debug";;
v) BUILD_VERBOSE="YES";;
j) BUILD_JOBS="${OPTARG}";;
h)
usage
;;
Expand All @@ -44,6 +42,6 @@ shift $((OPTIND-1))
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
BUILD_JOBS=${BUILD_JOBS:-8} \
"${cwd}/gfs_utils.fd/ush/build.sh"
"./gfs_utils.fd/ush/build.sh"

exit
6 changes: 3 additions & 3 deletions sorc/build_gsi_enkf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -eux
OPTIND=1
while getopts ":j:dv" option; do
case "${option}" in
d) export BUILD_TYPE="DEBUG";;
j) export BUILD_JOBS="${OPTARG}";;
v) export BUILD_VERBOSE="YES";;
d) BUILD_TYPE="Debug";;
j) BUILD_JOBS="${OPTARG}";;
v) BUILD_VERBOSE="YES";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
usage
Expand Down
10 changes: 4 additions & 6 deletions sorc/build_gsi_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#! /usr/bin/env bash
set -eux

cwd=$(pwd)

OPTIND=1
while getopts ":j:dv" option; do
case "${option}" in
d) export BUILD_TYPE="DEBUG";;
j) export BUILD_JOBS="${OPTARG}";;
v) export BUILD_VERBOSE="YES";;
d) BUILD_TYPE="Debug";;
j) BUILD_JOBS="${OPTARG}";;
v) BUILD_VERBOSE="YES";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
usage
Expand All @@ -24,6 +22,6 @@ shift $((OPTIND-1))
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
BUILD_JOBS=${BUILD_JOBS:-8} \
"${cwd}/gsi_monitor.fd/ush/build.sh"
"./gsi_monitor.fd/ush/build.sh"

exit
10 changes: 4 additions & 6 deletions sorc/build_gsi_utils.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#! /usr/bin/env bash
set -eux

cwd=$(pwd)

OPTIND=1
while getopts ":j:dv" option; do
case "${option}" in
d) export BUILD_TYPE="DEBUG";;
j) export BUILD_JOBS="${OPTARG}";;
v) export BUILD_VERBOSE="YES";;
d) BUILD_TYPE="Debug";;
j) BUILD_JOBS="${OPTARG}";;
v) BUILD_VERBOSE="YES";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
usage
Expand All @@ -25,6 +23,6 @@ BUILD_TYPE=${BUILD_TYPE:-"Release"} \
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
BUILD_JOBS=${BUILD_JOBS:-8} \
UTIL_OPTS="-DBUILD_UTIL_ENKF_GFS=ON -DBUILD_UTIL_NCIO=ON" \
"${cwd}/gsi_utils.fd/ush/build.sh"
"./gsi_utils.fd/ush/build.sh"

exit
4 changes: 2 additions & 2 deletions sorc/build_ufs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CCPP_SUITES="FV3_GFS_v17_p8_ugwpv1,FV3_GFS_v17_coupled_p8_ugwpv1" # TODO: does

while getopts ":da:j:vw" option; do
case "${option}" in
d) BUILD_TYPE="DEBUG";;
d) BUILD_TYPE="Debug";;
a) APP="${OPTARG}";;
j) BUILD_JOBS="${OPTARG}";;
v) export BUILD_VERBOSE="YES";;
Expand All @@ -30,7 +30,7 @@ source "./tests/module-setup.sh"

MAKE_OPT="-DAPP=${APP} -D32BIT=ON -DCCPP_SUITES=${CCPP_SUITES}"
[[ ${PDLIB:-"OFF"} = "ON" ]] && MAKE_OPT+=" -DPDLIB=ON"
[[ ${BUILD_TYPE:-"Release"} = "DEBUG" ]] && MAKE_OPT+=" -DDEBUG=ON"
[[ ${BUILD_TYPE:-"Release"} = "Debug" ]] && MAKE_OPT+=" -DDEBUG=ON"
COMPILE_NR=0
CLEAN_BEFORE=YES
CLEAN_AFTER=NO
Expand Down
11 changes: 5 additions & 6 deletions sorc/build_ufs_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ set -eux
OPTIND=1
while getopts ":j:dv" option; do
case "${option}" in
j) export BUILD_JOBS="${OPTARG}";;
v) export BUILD_VERBOSE="YES";;
d) BUILD_TYPE="Debug" ;;
j) BUILD_JOBS="${OPTARG}";;
v) BUILD_VERBOSE="YES";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
usage
Expand All @@ -18,13 +19,11 @@ while getopts ":j:dv" option; do
done
shift $((OPTIND-1))

script_dir=$(dirname "${BASH_SOURCE[0]}")
cd "${script_dir}/ufs_utils.fd" || exit 1

CMAKE_OPTS="-DGFS=ON" \
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
BUILD_JOBS=${BUILD_JOBS:-8} \
BUILD_VERBOSE=${BUILD_VERBOSE:-} \
./build_all.sh
./ufs_utils.fd/build_all.sh

exit

24 changes: 12 additions & 12 deletions sorc/build_upp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ cd "${script_dir}" || exit 1
OPTIND=1
_opts=""
while getopts ":dj:v" option; do
case "${option}" in
d) _opts+="-d ";;
j) export BUILD_JOBS="${OPTARG}" ;;
v) _opts+="-v ";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
;;
*)
echo "[${BASH_SOURCE[0]}]: Unrecognized option: ${option}"
;;
esac
case "${option}" in
d) _opts+="-d " ;;
j) BUILD_JOBS="${OPTARG}" ;;
v) _opts+="-v ";;
:)
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
;;
*)
echo "[${BASH_SOURCE[0]}]: Unrecognized option: ${option}"
;;
esac
done
shift $((OPTIND-1))

# Check final exec folder exists
if [[ ! -d "../exec" ]]; then
mkdir ../exec
mkdir -p ../exec
fi

cd ufs_model.fd/FV3/upp/tests
Expand Down
Loading

0 comments on commit 52fa3cb

Please sign in to comment.