Skip to content

Commit 13d25cf

Browse files
Add POSTAMBLE_CMD into preamble postamble (NOAA-EMC#2235)
This PR adds the ability to run a command at the end of jobs via the preamble's postamble function. A new command can be set via `POSTAMBLE_CMD` and will be invoked at the end of jobs. Users can add the command to the top of an env file to have every job run it or it can be placed within a job if-block in the env file to run for just that job. Resolves NOAA-EMC#1145
1 parent 7759163 commit 13d25cf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

env/HERA.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export npe_node_max=40
1818
export launcher="srun -l --export=ALL"
1919
export mpmd_opt="--multi-prog --output=mpmd.%j.%t.out"
2020

21+
#export POSTAMBLE_CMD='report-mem'
22+
2123
# Configure MPI environment
2224
#export I_MPI_ADJUST_ALLREDUCE=5
2325
#export MPI_BUFS_PER_PROC=2048

ush/preamble.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# TRACE (YES/NO): Whether to echo every command (set -x) [default: "YES"]
1717
# STRICT (YES/NO): Whether to exit immediately on error or undefined variable
1818
# (set -eu) [default: "YES"]
19+
# POSTAMBLE_CMD (empty/set): A command to run at the end of the job
20+
# [default: empty]
1921
#
2022
#######
2123
set +x
@@ -70,6 +72,24 @@ postamble() {
7072
start_time="${2}"
7173
rc="${3}"
7274

75+
# Execute postamble command
76+
#
77+
# Commands can be added to the postamble by appending them to $POSTAMBLE_CMD:
78+
# POSTAMBLE_CMD="new_thing; ${POSTAMBLE_CMD:-}" # (before existing commands)
79+
# POSTAMBLE_CMD="${POSTAMBLE_CMD:-}; new_thing" # (after existing commands)
80+
#
81+
# Always use this form so previous POSTAMBLE_CMD are not overwritten. This should
82+
# only be used for commands that execute conditionally (i.e. on certain machines
83+
# or jobs). Global changes should just be added to this function.
84+
# These commands will be called when EACH SCRIPT terminates, so be mindful. Please
85+
# consult with global-workflow CMs about permanent changes to $POSTAMBLE_CMD or
86+
# this postamble function.
87+
#
88+
89+
if [[ -v 'POSTAMBLE_CMD' ]]; then
90+
${POSTAMBLE_CMD}
91+
fi
92+
7393
# Calculate the elapsed time
7494
end_time=$(date +%s)
7595
end_time_human=$(date -d@"${end_time}" -u +%H:%M:%S)

0 commit comments

Comments
 (0)