Skip to content

Commit

Permalink
Modifications to allow workflow to run to completion with GNU build o…
Browse files Browse the repository at this point in the history
…n Hera (#526)

* Modifications to scripts to allow the workflow to run to completion
with the GNU build on Hera.  The python/miniconda3 module must be
unloaded prior to running the executable.

* "module" is not the best name for a variable, changed to a_module

* Address comments:

- Clarify message about why modules are being unloaded
- Remove print message if nothing is unloaded to reduce clutter in log file
- Rename "module_to_unload" to "modules_to_unload"
- Change "a_module" to "module_to_unload" for clarity

* Clarify purpose of the unload_python.sh function.

* Add the "why"
  • Loading branch information
JulieSchramm authored Jul 21, 2021
1 parent f5f5003 commit 19a872b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/exregional_make_ics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,13 @@ $settings"
# of chgres_cube is nonzero.
# A similar thing happens in the forecast task.
#
#-----------------------------------------------------------------------
# Deactivate the conda environment to avoid conflicts between the
# environment used by the regional workflow (prepended to your $PATH)
# and that used in the run environment.
#-----------------------------------------------------------------------
unload_python

${APRUN} ${exec_fp} || \
print_err_msg_exit "\
Call to executable (exec_fp) to generate surface and initial conditions
Expand Down
7 changes: 7 additions & 0 deletions scripts/exregional_make_lbcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ $settings"
# of chgres_cube is nonzero.
# A similar thing happens in the forecast task.
#
#-----------------------------------------------------------------------
# Deactivate the conda environment to avoid conflicts between the
# environment used by the regional workflow (prepended to your $PATH)
# and that used in the run environment.
#-----------------------------------------------------------------------
unload_python

${APRUN} ${exec_fp} || \
print_err_msg_exit "\
Call to executable (exec_fp) to generate lateral boundary conditions (LBCs)
Expand Down
7 changes: 7 additions & 0 deletions scripts/exregional_run_fcst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ fi
#
#-----------------------------------------------------------------------
#
#-----------------------------------------------------------------------
# Deactivate the conda environment to avoid conflicts between the
# environment used by the regional workflow (prepended to your $PATH)
# and that used in the run environment.
#-----------------------------------------------------------------------
unload_python

$APRUN ${FV3_EXEC_FP} || print_err_msg_exit "\
Call to executable to run FV3-LAM forecast returned with nonzero exit
code."
Expand Down
97 changes: 97 additions & 0 deletions ush/bash_utils/unload_python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
#-----------------------------------------------------------------------
#
# This file defines a function that detects if a python or miniconds3
# module is loaded, and if so, unloads that module. This may be
# necessary on machines where the loaded python environment isn't
# compatible with environment set for the compiler.
#
#-----------------------------------------------------------------------
#
function unload_python() {
#
#-----------------------------------------------------------------------
#
# Save current shell options (in a global array). Then set new options
# for this script/function.
#
#-----------------------------------------------------------------------
#
{ save_shell_opts; set -u +x; } > /dev/null 2>&1
#
#-----------------------------------------------------------------------
#
# Get the full path to the file in which this script/function is located
# (scrfunc_fp), the name of that file (scrfunc_fn), and the directory in
# which the file is located (scrfunc_dir).
#
#-----------------------------------------------------------------------
#
local scrfunc_fp=$( readlink -f "${BASH_SOURCE[0]}" )
local scrfunc_fn=$( basename "${scrfunc_fp}" )
local scrfunc_dir=$( dirname "${scrfunc_fp}" )
#
#-----------------------------------------------------------------------
#
# Get the name of this function.
#
#-----------------------------------------------------------------------
#
local func_name="${FUNCNAME[0]}"
#
#-----------------------------------------------------------------------
#
# Check arguments.
#
#-----------------------------------------------------------------------
#
if [ "$#" -ne 0 ]; then

print_err_msg_exit "
Incorrect number of arguments specified:
Function name: \"${func_name}\"
Number of arguments specified: $#
Usage:
${func_name}
"

fi
#
#-----------------------------------------------------------------------
#
# If the miniconda or python modules are loaded, unload them
#
#-----------------------------------------------------------------------
#

modules_to_unload=( python miniconda3 )
loaded_modules=$(module list 2>&1)

for module_to_unload in ${modules_to_unload[@]}; do
if [[ "${loaded_modules}" =~ "${module_to_unload}" ]]; then
print_info_msg "\
Unloading module ${module_to_unload} libraries needed for workflow generation but not for running the workflow... "
module unload ${module_to_unload}
fi
done

loaded_modules=$(module list 2>&1)
print_info_msg "\
Loaded modules are: $loaded_modules "

#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/func-
# tion.
#
#-----------------------------------------------------------------------
#
{ restore_shell_opts; } > /dev/null 2>&1

}

6 changes: 6 additions & 0 deletions ush/source_util_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ function source_util_funcs() {
#
#-----------------------------------------------------------------------
#
# Unload python or miniconda3 if loaded
#
#-----------------------------------------------------------------------
#
. ${bashutils_dir}/unload_python.sh
#
# Source the file containing the function that creates a symlink to a
# file (including performing checks).
#
Expand Down

0 comments on commit 19a872b

Please sign in to comment.